mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
More refactoring.
This commit is contained in:
parent
0005aac05f
commit
b464e816c6
@ -145,14 +145,14 @@ public final class FileSystem {
|
|||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @param label the label of the file system.
|
* @param label the label of the file system.
|
||||||
|
* @param host the tile entity containing the file system.
|
||||||
* @param accessSound the name of the sound effect to play when the file
|
* @param accessSound the name of the sound effect to play when the file
|
||||||
* system is accessed.
|
* system is accessed.
|
||||||
* @param host the tile entity containing the file system.
|
|
||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final Label label, final String accessSound, final EnvironmentHost host) {
|
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final Label label, final EnvironmentHost host, final String accessSound) {
|
||||||
if (instance != null)
|
if (instance != null)
|
||||||
return instance.asManagedEnvironment(fileSystem, label, accessSound, host);
|
return instance.asManagedEnvironment(fileSystem, label, host, accessSound);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,14 +162,14 @@ public final class FileSystem {
|
|||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @param label the read-only label of the file system.
|
* @param label the read-only label of the file system.
|
||||||
|
* @param host the tile entity containing the file system.
|
||||||
* @param accessSound the name of the sound effect to play when the file
|
* @param accessSound the name of the sound effect to play when the file
|
||||||
* system is accessed.
|
* system is accessed.
|
||||||
* @param host the tile entity containing the file system.
|
|
||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final String label, final String accessSound, final EnvironmentHost host) {
|
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final String label, final EnvironmentHost host, final String accessSound) {
|
||||||
if (instance != null)
|
if (instance != null)
|
||||||
return instance.asManagedEnvironment(fileSystem, label, accessSound, host);
|
return instance.asManagedEnvironment(fileSystem, label, host, accessSound);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,12 +100,12 @@ public interface FileSystemAPI {
|
|||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @param label the label of the file system.
|
* @param label the label of the file system.
|
||||||
|
* @param host the tile entity containing the file system.
|
||||||
* @param accessSound the name of the sound effect to play when the file
|
* @param accessSound the name of the sound effect to play when the file
|
||||||
* system is accessed.
|
* system is accessed.
|
||||||
* @param host the tile entity containing the file system.
|
|
||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, String accessSound, EnvironmentHost host);
|
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, EnvironmentHost host, String accessSound);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, String, li.cil.oc.api.driver.EnvironmentHost)},
|
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, String, li.cil.oc.api.driver.EnvironmentHost)},
|
||||||
@ -113,12 +113,12 @@ public interface FileSystemAPI {
|
|||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @param label the read-only label of the file system.
|
* @param label the read-only label of the file system.
|
||||||
|
* @param host the tile entity containing the file system.
|
||||||
* @param accessSound the name of the sound effect to play when the file
|
* @param accessSound the name of the sound effect to play when the file
|
||||||
* system is accessed.
|
* system is accessed.
|
||||||
* @param host the tile entity containing the file system.
|
|
||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label, String accessSound, EnvironmentHost host);
|
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label, EnvironmentHost host, String accessSound);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, String, li.cil.oc.api.driver.EnvironmentHost)},
|
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, String, li.cil.oc.api.driver.EnvironmentHost)},
|
||||||
|
@ -2,24 +2,20 @@ package li.cil.oc.server.component
|
|||||||
|
|
||||||
import java.io.{FileNotFoundException, IOException}
|
import java.io.{FileNotFoundException, IOException}
|
||||||
|
|
||||||
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.api.Network
|
import li.cil.oc.api.Network
|
||||||
import li.cil.oc.api.driver.EnvironmentHost
|
import li.cil.oc.api.driver.EnvironmentHost
|
||||||
import li.cil.oc.api.fs.{Label, Mode, FileSystem => IFileSystem}
|
import li.cil.oc.api.fs.{Label, Mode, FileSystem => IFileSystem}
|
||||||
import li.cil.oc.api.machine.{Arguments, Callback, Context}
|
import li.cil.oc.api.machine.{Arguments, Callback, Context}
|
||||||
import li.cil.oc.api.network._
|
import li.cil.oc.api.network._
|
||||||
import li.cil.oc.common.{Sound, component}
|
import li.cil.oc.common.{Sound, component}
|
||||||
import li.cil.oc.server.driver.item.ComputerCraftMedia
|
|
||||||
import li.cil.oc.server.fs.FileSystem.ItemLabel
|
|
||||||
import li.cil.oc.util.ExtendedNBT._
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
import li.cil.oc.util.mods.Mods
|
|
||||||
import li.cil.oc.{Settings, api}
|
|
||||||
import net.minecraft.item.ItemStack
|
|
||||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagIntArray, NBTTagList}
|
import net.minecraft.nbt.{NBTTagCompound, NBTTagIntArray, NBTTagList}
|
||||||
import net.minecraftforge.common.util.Constants.NBT
|
import net.minecraftforge.common.util.Constants.NBT
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
class FileSystem(val fileSystem: IFileSystem, var label: Label, val sound: Option[String] = None, val host: Option[EnvironmentHost] = None) extends component.ManagedComponent {
|
class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option[EnvironmentHost] = None, val sound: Option[String] = None) extends component.ManagedComponent {
|
||||||
val node = Network.newNode(this, Visibility.Network).
|
val node = Network.newNode(this, Visibility.Network).
|
||||||
withComponent("filesystem", Visibility.Neighbors).
|
withComponent("filesystem", Visibility.Neighbors).
|
||||||
withConnector().
|
withConnector().
|
||||||
@ -302,14 +298,6 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val sound: Optio
|
|||||||
if (!owners.contains(owner) || !owners(owner).contains(handle))
|
if (!owners.contains(owner) || !owners(owner).contains(handle))
|
||||||
throw new IOException("bad file descriptor")
|
throw new IOException("bad file descriptor")
|
||||||
|
|
||||||
private lazy val floppies = Set(api.Items.get("floppy"), api.Items.get("lootDisk"), api.Items.get("openOS"))
|
|
||||||
|
|
||||||
private lazy val hdds = Set(api.Items.get("hdd1"), api.Items.get("hdd2"), api.Items.get("hdd3"))
|
|
||||||
|
|
||||||
private def isFloppy(stack: ItemStack) = floppies contains api.Items.get(stack)
|
|
||||||
|
|
||||||
private def isHardDisk(stack: ItemStack) = hdds contains api.Items.get(stack)
|
|
||||||
|
|
||||||
private def makeSomeNoise() {
|
private def makeSomeNoise() {
|
||||||
(sound, host) match {
|
(sound, host) match {
|
||||||
case (Some(s), Some(h)) => Sound.playDiskActivity(h, s)
|
case (Some(s), Some(h)) => Sound.playDiskActivity(h, s)
|
||||||
|
@ -16,7 +16,7 @@ object ComputerCraftMedia extends Item {
|
|||||||
if (Mods.ComputerCraft.isAvailable && ComputerCraft.isDisk(stack) && host != null) {
|
if (Mods.ComputerCraft.isAvailable && ComputerCraft.isDisk(stack) && host != null) {
|
||||||
val address = addressFromTag(dataTag(stack))
|
val address = addressFromTag(dataTag(stack))
|
||||||
val mount = ComputerCraft.createDiskMount(stack, host.world)
|
val mount = ComputerCraft.createDiskMount(stack, host.world)
|
||||||
Option(oc.api.FileSystem.asManagedEnvironment(mount, new ComputerCraftLabel(stack), "floppy_access", host)) match {
|
Option(oc.api.FileSystem.asManagedEnvironment(mount, new ComputerCraftLabel(stack), host, "floppy_access")) match {
|
||||||
case Some(environment) =>
|
case Some(environment) =>
|
||||||
environment.node.asInstanceOf[oc.server.network.Node].address = address
|
environment.node.asInstanceOf[oc.server.network.Node].address = address
|
||||||
environment
|
environment
|
||||||
|
@ -40,7 +40,7 @@ object FileSystem extends Item {
|
|||||||
val address = addressFromTag(dataTag(stack))
|
val address = addressFromTag(dataTag(stack))
|
||||||
val isFloppy = api.Items.get(stack) == api.Items.get("floppy")
|
val isFloppy = api.Items.get(stack) == api.Items.get("floppy")
|
||||||
val fs = oc.api.FileSystem.fromSaveDirectory(address, capacity, Settings.get.bufferChanges)
|
val fs = oc.api.FileSystem.fromSaveDirectory(address, capacity, Settings.get.bufferChanges)
|
||||||
val environment = oc.api.FileSystem.asManagedEnvironment(fs, new ReadWriteItemLabel(stack), if (isFloppy) "floppy_access" else "hdd_access", host)
|
val environment = oc.api.FileSystem.asManagedEnvironment(fs, new ReadWriteItemLabel(stack), host, if (isFloppy) "floppy_access" else "hdd_access")
|
||||||
if (environment != null && environment.node != null) {
|
if (environment != null && environment.node != null) {
|
||||||
environment.node.asInstanceOf[oc.server.network.Node].address = address
|
environment.node.asInstanceOf[oc.server.network.Node].address = address
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ object Loot extends Item {
|
|||||||
dataTag(stack).getString(Settings.namespace + "fs.label")
|
dataTag(stack).getString(Settings.namespace + "fs.label")
|
||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
api.FileSystem.asManagedEnvironment(fs, label, "floppy_disk", host)
|
api.FileSystem.asManagedEnvironment(fs, label, host, "floppy_disk")
|
||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
|
|
||||||
|
@ -101,11 +101,11 @@ object FileSystem extends api.detail.FileSystemAPI {
|
|||||||
else null
|
else null
|
||||||
}
|
}
|
||||||
|
|
||||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, sound: String, host: EnvironmentHost) =
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: EnvironmentHost, sound: String) =
|
||||||
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label, Option(sound), Option(host)))).orNull
|
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label, Option(host), Option(sound)))).orNull
|
||||||
|
|
||||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String, sound: String, host: EnvironmentHost) =
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String, host: EnvironmentHost, sound: String) =
|
||||||
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label), sound, host)
|
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label), host, sound)
|
||||||
|
|
||||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label) =
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label) =
|
||||||
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label))).orNull
|
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label))).orNull
|
||||||
|
Loading…
x
Reference in New Issue
Block a user