Removed type from the 'fromComputerCraft' factory methods in the FileSystem API to remove the dependency on the CC API.

This commit is contained in:
Florian Nücke 2014-05-28 13:13:05 +02:00
parent 81268ac186
commit 1ddb6841dd
7 changed files with 47 additions and 101 deletions

View File

@ -1,6 +1,5 @@
package li.cil.oc.api;
import cpw.mods.fml.common.Optional;
import li.cil.oc.api.detail.FileSystemAPI;
import li.cil.oc.api.driver.Container;
import li.cil.oc.api.fs.Label;
@ -110,52 +109,18 @@ public final class FileSystem {
}
/**
* Creates a new file system based on a read-only ComputerCraft mount.
* Creates a new file system based on a ComputerCraft mount.
* <p/>
* This supports read-only and writable mounts from either CC 1.5x or
* CC 1.6x. The argument is kept untyped to avoid having the OC API
* depend on the CC API.
* <p/>
* If the passed type is unsupported, this will throw an exception.
*
* @param mount the mount to wrap with a file system.
* @return a file system wrapping the specified mount.
*/
@Optional.Method(modid = "ComputerCraft")
public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final dan200.computer.api.IMount mount) {
if (instance != null)
return instance.fromComputerCraft(mount);
return null;
}
/**
* Creates a new file system based on a read-write ComputerCraft mount.
*
* @param mount the mount to wrap with a file system.
* @return a file system wrapping the specified mount.
*/
@Optional.Method(modid = "ComputerCraft")
public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final dan200.computer.api.IWritableMount mount) {
if (instance != null)
return instance.fromComputerCraft(mount);
return null;
}
/**
* Creates a new file system based on a read-only ComputerCraft mount.
*
* @param mount the mount to wrap with a file system.
* @return a file system wrapping the specified mount.
*/
@Optional.Method(modid = "ComputerCraft")
public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final dan200.computercraft.api.filesystem.IMount mount) {
if (instance != null)
return instance.fromComputerCraft(mount);
return null;
}
/**
* Creates a new file system based on a read-write ComputerCraft mount.
*
* @param mount the mount to wrap with a file system.
* @return a file system wrapping the specified mount.
*/
@Optional.Method(modid = "ComputerCraft")
public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final dan200.computercraft.api.filesystem.IWritableMount mount) {
public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final Object mount) {
if (instance != null)
return instance.fromComputerCraft(mount);
return null;

View File

@ -1,6 +1,5 @@
package li.cil.oc.api.detail;
import cpw.mods.fml.common.Optional;
import li.cil.oc.api.driver.Container;
import li.cil.oc.api.fs.FileSystem;
import li.cil.oc.api.fs.Label;
@ -70,39 +69,17 @@ public interface FileSystemAPI {
/**
* Creates a new file system based on a read-only ComputerCraft mount.
* <p/>
* This supports read-only and writable mounts from either CC 1.5x or
* CC 1.6x. The argument is kept untyped to avoid having the OC API
* depend on the CC API.
* <p/>
* If the passed type is unsupported, this will return <tt>null</tt>.
*
* @param mount the mount to wrap with a file system.
* @return a file system wrapping the specified mount.
*/
@Optional.Method(modid = "ComputerCraft")
FileSystem fromComputerCraft(dan200.computer.api.IMount mount);
/**
* Creates a new file system based on a read-write ComputerCraft mount.
*
* @param mount the mount to wrap with a file system.
* @return a file system wrapping the specified mount.
*/
@Optional.Method(modid = "ComputerCraft")
FileSystem fromComputerCraft(dan200.computer.api.IWritableMount mount);
/**
* Creates a new file system based on a read-only ComputerCraft mount.
*
* @param mount the mount to wrap with a file system.
* @return a file system wrapping the specified mount.
*/
@Optional.Method(modid = "ComputerCraft")
FileSystem fromComputerCraft(dan200.computercraft.api.filesystem.IMount mount);
/**
* Creates a new file system based on a read-write ComputerCraft mount.
*
* @param mount the mount to wrap with a file system.
* @return a file system wrapping the specified mount.
*/
@Optional.Method(modid = "ComputerCraft")
FileSystem fromComputerCraft(dan200.computercraft.api.filesystem.IWritableMount mount);
FileSystem fromComputerCraft(Object mount);
/**
* Creates a network node that makes the specified file system available via

View File

@ -57,7 +57,6 @@ class Proxy {
}
def init(e: FMLInitializationEvent) {
api.Driver.add(driver.item.AbstractBusCard)
api.Driver.add(driver.item.FileSystem)
api.Driver.add(driver.item.GraphicsCard)
api.Driver.add(driver.item.InternetCard)
@ -85,6 +84,9 @@ class Proxy {
api.Driver.add(driver.item.UpgradeAngel)
api.Driver.add(driver.item.WirelessNetworkCard)
if (Mods.StargateTech2.isAvailable) {
api.Driver.add(driver.item.AbstractBusCard)
}
if (Mods.ComputerCraft15.isAvailable) {
api.Driver.add(driver.item.CC15Media)
}

View File

@ -12,7 +12,7 @@ trait Item extends driver.Item {
override def dataTag(stack: ItemStack) = Item.dataTag(stack)
protected def isOneOf(stack: ItemStack, items: api.detail.ItemInfo*) = items.contains(api.Items.get(stack))
protected def isOneOf(stack: ItemStack, items: api.detail.ItemInfo*) = items.filter(_ != null).contains(api.Items.get(stack))
}
object Item {

View File

@ -9,6 +9,7 @@ import li.cil.oc.server.component
import li.cil.oc.{Settings, api}
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.DimensionManager
import li.cil.oc.util.mods.{ComputerCraft15, ComputerCraft16, Mods}
object FileSystem extends api.detail.FileSystemAPI {
override def fromClass(clazz: Class[_], domain: String, root: String): api.fs.FileSystem = {
@ -66,17 +67,16 @@ object FileSystem extends api.detail.FileSystemAPI {
def fromMemory(capacity: Long): api.fs.FileSystem = new RamFileSystem(capacity)
@Optional.Method(modid = "ComputerCraft")
def fromComputerCraft(mount: dan200.computer.api.IMount) = new CC15FileSystem(mount)
@Optional.Method(modid = "ComputerCraft")
def fromComputerCraft(mount: dan200.computer.api.IWritableMount) = new CC15WritableFileSystem(mount)
@Optional.Method(modid = "ComputerCraft")
def fromComputerCraft(mount: dan200.computercraft.api.filesystem.IMount) = new CC16FileSystem(mount)
@Optional.Method(modid = "ComputerCraft")
def fromComputerCraft(mount: dan200.computercraft.api.filesystem.IWritableMount) = new CC16WritableFileSystem(mount)
def fromComputerCraft(mount: AnyRef): api.fs.FileSystem = {
var result: Option[api.fs.FileSystem] = None
if (result.isEmpty && Mods.ComputerCraft16.isAvailable) {
result = ComputerCraft16.createFileSystem(mount)
}
if (result.isEmpty && Mods.ComputerCraft15.isAvailable) {
result = ComputerCraft15.createFileSystem(mount)
}
result.orNull
}
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, container: Container) =
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label, Option(container)))).orNull

View File

@ -2,17 +2,18 @@ package li.cil.oc.util.mods
import dan200.computer.api.{IMount, IWritableMount, IMedia}
import li.cil.oc
import li.cil.oc.server.fs.{CC15FileSystem, CC15WritableFileSystem}
import net.minecraft.item.ItemStack
import net.minecraft.world.World
object ComputerCraft15 {
def isDisk(stack: ItemStack) = stack.getItem.isInstanceOf[IMedia]
def createDiskMount(stack: ItemStack, world: World) = if (isDisk(stack)) {
stack.getItem.asInstanceOf[IMedia].createDataMount(stack, world) match {
case mount: IWritableMount => oc.api.FileSystem.fromComputerCraft(mount)
case mount: IMount => oc.api.FileSystem.fromComputerCraft(mount)
case _ => null
}
} else null
def createDiskMount(stack: ItemStack, world: World) =
if (isDisk(stack)) oc.api.FileSystem.fromComputerCraft(stack.getItem.asInstanceOf[IMedia].createDataMount(stack, world)) else null
def createFileSystem(mount: AnyRef) = Option(mount) collect {
case rw: IWritableMount => new CC15WritableFileSystem(rw)
case ro: IMount => new CC15FileSystem(ro)
}
}

View File

@ -2,13 +2,14 @@ package li.cil.oc.util.mods
import dan200.computercraft.api.ComputerCraftAPI
import dan200.computercraft.api.filesystem.{IMount, IWritableMount}
import dan200.computercraft.api.lua.ILuaContext
import dan200.computercraft.api.media.IMedia
import dan200.computercraft.api.peripheral.{IComputerAccess, IPeripheral, IPeripheralProvider}
import li.cil.oc
import li.cil.oc.common.tileentity.{ComputerWrapper, Router}
import li.cil.oc.server.fs.{CC16FileSystem, CC16WritableFileSystem}
import net.minecraft.item.ItemStack
import net.minecraft.world.World
import dan200.computercraft.api.lua.ILuaContext
import scala.collection.mutable
object ComputerCraft16 {
@ -23,13 +24,13 @@ object ComputerCraft16 {
def isDisk(stack: ItemStack) = stack.getItem.isInstanceOf[IMedia]
def createDiskMount(stack: ItemStack, world: World) = if (isDisk(stack)) {
stack.getItem.asInstanceOf[IMedia].createDataMount(stack, world) match {
case mount: IWritableMount => oc.api.FileSystem.fromComputerCraft(mount)
case mount: IMount => oc.api.FileSystem.fromComputerCraft(mount)
case _ => null
}
} else null
def createDiskMount(stack: ItemStack, world: World) =
if (isDisk(stack)) oc.api.FileSystem.fromComputerCraft(stack.getItem.asInstanceOf[IMedia].createDataMount(stack, world)) else null
def createFileSystem(mount: AnyRef) = Option(mount) collect {
case rw: IWritableMount => new CC16WritableFileSystem(rw)
case ro: IMount => new CC16FileSystem(ro)
}
class RouterPeripheral(val router: Router) extends IPeripheral {
override def getType = router.getType