mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
hdd access sounds and playing access sounds in a few more cases (e.g. list, remove, rename); avoid spamming network packets if sounds are triggered in a tight loop
This commit is contained in:
parent
785caac5ae
commit
717aaa3e78
9
LICENSE
9
LICENSE
@ -21,7 +21,8 @@ THE SOFTWARE.
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
All images / textures and localization strings (resources) are put in the
|
||||
public domain. More specicially, see CC0 1.0 Universal:
|
||||
public domain, unless explicitly excluded below. More specicially, see CC0 1.0
|
||||
Universal:
|
||||
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
@ -30,3 +31,9 @@ Contributions:
|
||||
asie - Disk drive inject/eject and floppy disk access sound samples.
|
||||
|
||||
Thanks a lot!
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Assets from other sources:
|
||||
HDD access samples based on this sample from freesound.org:
|
||||
https://www.freesound.org/people/artykris/sounds/117401/
|
||||
|
BIN
src/main/resources/assets/opencomputers/sound/hdd_access1.ogg
Normal file
BIN
src/main/resources/assets/opencomputers/sound/hdd_access1.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/opencomputers/sound/hdd_access2.ogg
Normal file
BIN
src/main/resources/assets/opencomputers/sound/hdd_access2.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/opencomputers/sound/hdd_access3.ogg
Normal file
BIN
src/main/resources/assets/opencomputers/sound/hdd_access3.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/opencomputers/sound/hdd_access4.ogg
Normal file
BIN
src/main/resources/assets/opencomputers/sound/hdd_access4.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/opencomputers/sound/hdd_access5.ogg
Normal file
BIN
src/main/resources/assets/opencomputers/sound/hdd_access5.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/opencomputers/sound/hdd_access6.ogg
Normal file
BIN
src/main/resources/assets/opencomputers/sound/hdd_access6.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/opencomputers/sound/hdd_access7.ogg
Normal file
BIN
src/main/resources/assets/opencomputers/sound/hdd_access7.ogg
Normal file
Binary file not shown.
@ -1,18 +1,24 @@
|
||||
package li.cil.oc.common
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import li.cil.oc.Settings
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.client.event.sound.SoundLoadEvent
|
||||
import net.minecraftforge.event.ForgeSubscribe
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import scala.collection.mutable
|
||||
|
||||
object Sound {
|
||||
val lastPlayed = mutable.WeakHashMap.empty[TileEntity, Long]
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@ForgeSubscribe
|
||||
def onSoundLoad(event: SoundLoadEvent) {
|
||||
for (i <- 1 to 6) {
|
||||
event.manager.soundPoolSounds.addSound(Settings.resourceDomain + s":floppy_access$i.ogg")
|
||||
}
|
||||
for (i <- 1 to 7) {
|
||||
event.manager.soundPoolSounds.addSound(Settings.resourceDomain + s":hdd_access$i.ogg")
|
||||
}
|
||||
event.manager.soundPoolSounds.addSound(Settings.resourceDomain + ":floppy_insert.ogg")
|
||||
event.manager.soundPoolSounds.addSound(Settings.resourceDomain + ":floppy_eject.ogg")
|
||||
}
|
||||
@ -30,11 +36,16 @@ object Sound {
|
||||
}
|
||||
|
||||
def playDiskActivity(t: TileEntity) = this.synchronized {
|
||||
t match {
|
||||
case computer: tileentity.Computer => play(computer, "hdd_access")
|
||||
case rack: tileentity.Rack => play(rack, "hdd_access")
|
||||
case drive: tileentity.DiskDrive => play(drive, "floppy_access")
|
||||
case _ => // Huh?
|
||||
lastPlayed.get(t) match {
|
||||
case Some(time) if time > System.currentTimeMillis() => // Cooldown.
|
||||
case _ =>
|
||||
t match {
|
||||
case computer: tileentity.Computer => play(computer, "hdd_access")
|
||||
case rack: tileentity.Rack => play(rack, "hdd_access")
|
||||
case drive: tileentity.DiskDrive => play(drive, "floppy_access")
|
||||
case _ => // Huh?
|
||||
}
|
||||
lastPlayed += t -> (System.currentTimeMillis() + 500)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,9 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val container: O
|
||||
@Callback
|
||||
def list(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
||||
Option(fileSystem.list(clean(args.checkString(0)))) match {
|
||||
case Some(list) => Array(list)
|
||||
case Some(list) =>
|
||||
container.foreach(Sound.playDiskActivity)
|
||||
Array(list)
|
||||
case _ => null
|
||||
}
|
||||
}
|
||||
@ -85,19 +87,25 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val container: O
|
||||
def makeDirectory(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
||||
def recurse(path: String): Boolean = !fileSystem.exists(path) && (fileSystem.makeDirectory(path) ||
|
||||
(recurse(path.split("/").dropRight(1).mkString("/")) && fileSystem.makeDirectory(path)))
|
||||
result(recurse(clean(args.checkString(0))))
|
||||
val success = recurse(clean(args.checkString(0)))
|
||||
if (success) container.foreach(Sound.playDiskActivity)
|
||||
result(success)
|
||||
}
|
||||
|
||||
@Callback
|
||||
def remove(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
||||
def recurse(parent: String): Boolean = (!fileSystem.isDirectory(parent) ||
|
||||
fileSystem.list(parent).forall(child => recurse(parent + "/" + child))) && fileSystem.delete(parent)
|
||||
result(recurse(clean(args.checkString(0))))
|
||||
val success = recurse(clean(args.checkString(0)))
|
||||
if (success) container.foreach(Sound.playDiskActivity)
|
||||
result(success)
|
||||
}
|
||||
|
||||
@Callback
|
||||
def rename(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
||||
result(fileSystem.rename(clean(args.checkString(0)), clean(args.checkString(1))))
|
||||
val success = fileSystem.rename(clean(args.checkString(0)), clean(args.checkString(1)))
|
||||
if (success) container.foreach(Sound.playDiskActivity)
|
||||
result(success)
|
||||
}
|
||||
|
||||
@Callback(direct = true)
|
||||
|
Loading…
x
Reference in New Issue
Block a user