Cleanup in fs access sound stuff.

This commit is contained in:
Florian Nücke 2014-09-20 07:02:19 +02:00
parent aed8c63079
commit 164a501f38
4 changed files with 12 additions and 16 deletions

View File

@ -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.

View File

@ -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)
}
}
}

View File

@ -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 _ =>
}
}

View File

@ -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