mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
Cleanup in fs access sound stuff.
This commit is contained in:
parent
aed8c63079
commit
164a501f38
@ -108,7 +108,7 @@ public interface FileSystemAPI {
|
||||
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, li.cil.oc.api.driver.EnvironmentHost, String)},
|
||||
* but creates a read-only label initialized to the specified value.
|
||||
*
|
||||
* @param fileSystem the file system to wrap.
|
||||
@ -121,7 +121,7 @@ public interface FileSystemAPI {
|
||||
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, li.cil.oc.api.driver.EnvironmentHost, String)},
|
||||
* but does not provide a container and access sound.
|
||||
*
|
||||
* @param fileSystem the file system to wrap.
|
||||
|
@ -6,10 +6,15 @@ import li.cil.oc.api.driver.EnvironmentHost
|
||||
import scala.collection.mutable
|
||||
|
||||
object Sound {
|
||||
val lastPlayed = mutable.WeakHashMap.empty[EnvironmentHost, Long]
|
||||
val globalTimeouts = mutable.WeakHashMap.empty[EnvironmentHost, mutable.Map[String, Long]]
|
||||
|
||||
def play(host: EnvironmentHost, name: String) {
|
||||
host.world.playSoundEffect(host.xPosition, host.yPosition, host.zPosition, Settings.resourceDomain + ":" + name, Settings.get.soundVolume, 1)
|
||||
def play(host: EnvironmentHost, name: String) = this.synchronized {
|
||||
globalTimeouts.get(host) match {
|
||||
case Some(hostTimeouts) if hostTimeouts.getOrElse(name, 0L) > System.currentTimeMillis() => // Cooldown.
|
||||
case _ =>
|
||||
host.world.playSoundEffect(host.xPosition, host.yPosition, host.zPosition, Settings.resourceDomain + ":" + name, Settings.get.soundVolume, 1)
|
||||
globalTimeouts.getOrElseUpdate(host, mutable.Map.empty) += name -> (System.currentTimeMillis() + 500)
|
||||
}
|
||||
}
|
||||
|
||||
def playDiskInsert(host: EnvironmentHost) {
|
||||
@ -19,13 +24,4 @@ object Sound {
|
||||
def playDiskEject(host: EnvironmentHost) {
|
||||
play(host, "floppy_eject")
|
||||
}
|
||||
|
||||
def playDiskActivity(host: EnvironmentHost, sound: String) = this.synchronized {
|
||||
lastPlayed.get(host) match {
|
||||
case Some(time) if time > System.currentTimeMillis() => // Cooldown.
|
||||
case _ =>
|
||||
play(host, sound)
|
||||
lastPlayed += host -> (System.currentTimeMillis() + 500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option
|
||||
|
||||
private def makeSomeNoise() {
|
||||
(sound, host) match {
|
||||
case (Some(s), Some(h)) => Sound.playDiskActivity(h, s)
|
||||
case (Some(s), Some(h)) => Sound.play(h, s)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ object Loot extends Item {
|
||||
dataTag(stack).getString(Settings.namespace + "fs.label")
|
||||
}
|
||||
else null
|
||||
api.FileSystem.asManagedEnvironment(fs, label, host, "floppy_disk")
|
||||
api.FileSystem.asManagedEnvironment(fs, label, host, "floppy_access")
|
||||
}
|
||||
else null
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user