mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
jukebox wip
This commit is contained in:
@@ -26,6 +26,7 @@ id;classname
|
||||
25;net.torvald.terrarum.modulebasegame.gameitems.ItemClayBall
|
||||
26;net.torvald.terrarum.modulebasegame.gameitems.IngotSteel
|
||||
27;net.torvald.terrarum.modulebasegame.gameitems.ItemFurnaceAndAnvil
|
||||
28;net.torvald.terrarum.modulebasegame.gameitems.ItemJukebox
|
||||
|
||||
# ingots
|
||||
112;net.torvald.terrarum.modulebasegame.gameitems.IngotCopper
|
||||
|
||||
|
BIN
assets/mods/basegame/sprites/fixtures/jukebox.tga
LFS
Normal file
BIN
assets/mods/basegame/sprites/fixtures/jukebox.tga
LFS
Normal file
Binary file not shown.
@@ -411,7 +411,7 @@ object AudioMixer: Disposable {
|
||||
requestFadeOut(ambientTrack, DEFAULT_FADEOUT_LEN * 4)
|
||||
}
|
||||
|
||||
fun requestFadeOut(track: TerrarumAudioMixerTrack, length: Double, target: Double = 0.0, source: Double? = null, jobAfterFadeout: () -> Unit = {}) {
|
||||
fun requestFadeOut(track: TerrarumAudioMixerTrack, length: Double = DEFAULT_FADEOUT_LEN, target: Double = 0.0, source: Double? = null, jobAfterFadeout: () -> Unit = {}) {
|
||||
val req = fadeReqs[track]!!
|
||||
if (!req.fadeoutFired) {
|
||||
req.fadeLength = length.coerceAtLeast(1.0/1024.0)
|
||||
|
||||
@@ -37,7 +37,7 @@ class MixerTrackProcessor(val buffertaille: Int, val rate: Int, val track: Terra
|
||||
|
||||
private var breakBomb = false
|
||||
|
||||
private val distFalloff = 2048.0
|
||||
private val distFalloff = 1024.0
|
||||
|
||||
private fun printdbg(msg: Any) {
|
||||
if (true) App.printdbg("AudioAdapter ${track.name}", msg)
|
||||
|
||||
@@ -381,6 +381,8 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
/** force disable despawn when inventory is not empty */
|
||||
val canBeDespawned: Boolean get() = inventory?.isEmpty() ?: true
|
||||
|
||||
@Transient open var despawnHook: (FixtureBase) -> Unit = {}
|
||||
|
||||
/**
|
||||
* Removes this instance of the fixture from the world
|
||||
*/
|
||||
@@ -405,6 +407,8 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
wireEmission.clear()
|
||||
wireConsumption.clear()
|
||||
}
|
||||
|
||||
despawnHook(this)
|
||||
}
|
||||
else {
|
||||
printdbg(this, "failed to despawn at T${INGAME.WORLD_UPDATE_TIMER}: ${nameFun()}")
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.audio.AudioMixer
|
||||
import net.torvald.terrarum.audio.AudioMixer.DEFAULT_FADEOUT_LEN
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.MusicContainer
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumMusicGovernor
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-11.
|
||||
*/
|
||||
class FixtureJukebox : Electric {
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 2, 3),
|
||||
nameFun = { Lang["ITEM_LOGIC_SIGNAL_EMITTER"] }
|
||||
)
|
||||
|
||||
@Transient private var discCurrentlyPlaying: Int? = null
|
||||
|
||||
@Transient private val testMusic = ModMgr.getGdxFile("basegame", "audio/music/discs/01 Thousands of Shards.ogg").let {
|
||||
MusicContainer("Thousands of Shards", it.file(), Gdx.audio.newMusic(it)) {
|
||||
discCurrentlyPlaying = null
|
||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = Math.random().toFloat() * 30f + 30f)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/jukebox.tga")
|
||||
|
||||
density = 1400.0
|
||||
setHitboxDimension(TILE_SIZE * 2, TILE_SIZE * 3, 0, 0)
|
||||
|
||||
makeNewSprite(TextureRegionPack(itemImage.texture, TILE_SIZE * 2, TILE_SIZE * 3)).let {
|
||||
it.setRowsAndFrames(1,1)
|
||||
}
|
||||
|
||||
actorValue[AVKey.BASEMASS] = 200.0
|
||||
|
||||
setWireSinkAt(0, 2, "appliance_power")
|
||||
setWireConsumptionAt(0, 2, Vector2(350.0, 0.0))
|
||||
}
|
||||
|
||||
private var waitAkku = 0f
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
if (discCurrentlyPlaying == null) {
|
||||
// wait 3 seconds
|
||||
if (waitAkku >= 3f) {
|
||||
discCurrentlyPlaying = 0
|
||||
playDisc(discCurrentlyPlaying!!)
|
||||
waitAkku = 0f
|
||||
}
|
||||
|
||||
waitAkku += delta
|
||||
}
|
||||
else if (!flagDespawn) {
|
||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic()
|
||||
}
|
||||
}
|
||||
|
||||
private fun playDisc(index: Int) {
|
||||
AudioMixer.requestFadeOut(AudioMixer.musicTrack, DEFAULT_FADEOUT_LEN / 2f) {
|
||||
startAudio(testMusic)
|
||||
}
|
||||
}
|
||||
|
||||
@Transient override var despawnHook: (FixtureBase) -> Unit = {
|
||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = Math.random().toFloat() * 30f + 30f)
|
||||
}
|
||||
|
||||
override fun reload() {
|
||||
super.reload()
|
||||
// cannot resume playback, just stop the music
|
||||
discCurrentlyPlaying = null
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
super.dispose()
|
||||
// testMusic.gdxMusic.dispose()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-11.
|
||||
*/
|
||||
class ItemJukebox(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureJukebox") {
|
||||
|
||||
|
||||
override var baseMass = 200.0
|
||||
override val isDynamic = false
|
||||
override val materialId = ""
|
||||
override val itemImage: TextureRegion
|
||||
get() = getItemImageFromSingleImage("basegame", "sprites/fixtures/jukebox.tga")
|
||||
|
||||
override var baseToolSize: Double? = baseMass
|
||||
override var originalName = "ITEM_JUKEBOX"
|
||||
|
||||
}
|
||||
@@ -496,7 +496,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
batch.color = COL_METER_TROUGH
|
||||
val intensity = fullscaleToDecibels(fs.coerceAtMost(1.0)).plus(dbLow).div(dbLow).coerceIn(0.0, 1.0).toFloat()
|
||||
Toolkit.fillArea(batch, x, y + 2, miniW, 8)
|
||||
batch.color = if (fs > 1.0) LAMP_OVERRANGE else Color(0.1f, intensity, 0.1f, 0.666f)
|
||||
batch.color = if (fs > 1.0) LAMP_OVERRANGE else Color(0.1f, intensity, 0.1f, 1f)
|
||||
Toolkit.fillArea(batch, x + 2 + 13*ch, y + 4, 11, 4)
|
||||
|
||||
oldPeakDS[index][ch] = fs
|
||||
|
||||
BIN
work_files/graphics/sprites/fixtures/jukebox.kra
LFS
Normal file
BIN
work_files/graphics/sprites/fixtures/jukebox.kra
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user