diff --git a/src/net/torvald/terrarum/IngameInstance.kt b/src/net/torvald/terrarum/IngameInstance.kt index 4725395fb..f1f7744a3 100644 --- a/src/net/torvald/terrarum/IngameInstance.kt +++ b/src/net/torvald/terrarum/IngameInstance.kt @@ -333,10 +333,10 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo protected open fun forceRemoveActor(actor: Actor, caller: Throwable = StackTraceRecorder()) { arrayOf(actorContainerActive, actorContainerInactive).forEach { actorContainer -> - val indexToDelete = actorContainer.searchFor(actor.referenceID) { it.referenceID } + val indexToDelete = actorContainer.searchForIndex(actor.referenceID) { it.referenceID } if (indexToDelete != null) { actor.dispose() - actorContainer.remove(indexToDelete) + actorContainer.removeAt(indexToDelete) } } } @@ -348,7 +348,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo throw ReferencedActorAlreadyExistsException(actor, caller) } else { - actorAdditionQueue.add(actor to StackTraceRecorder()) + actorContainerActive.add(actor) } } diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt index f436c673d..ba49f28f6 100644 --- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt +++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt @@ -32,27 +32,26 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) { private val menuYaml = Yaml(""" - File - - New flat ter. - - New rand. ter. + - New Flat ter. + - New Rand. ter. - Export… - - Export sel… - Import… - - Save terrain… - - Load terrain… - - + - Save World… + - Load World… - Exit to Title : net.torvald.terrarum.modulebasegame.YamlCommandExit - Edit - Undo - Redo - Time + - Dawn : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeDawn + - Sunrise : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeSunrise - Morning : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeMorning - Noon : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeNoon - Dusk : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeDusk + - Sunset : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeSunset - Night : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeNight + - Midnight : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeMidnight - Set… -- Weather - - Sunny - - Raining """.trimIndent()) private val timeNow = System.currentTimeMillis() / 1000 @@ -216,9 +215,11 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) { internal fun addBlockMarker(x: Int, y: Int) { try { val a = generateNewBlockMarkerVisible(x, y) - queueActorAddition(a) - actorsRenderOverlay.add(a) - selection.add(Point2i(x, y)) + if (!theGameHasActor(a.referenceID)) { + queueActorAddition(a) + actorsRenderOverlay.add(a) + selection.add(Point2i(x, y)) + } } catch (e: Error) { } } @@ -226,11 +227,11 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) { internal fun removeBlockMarker(x: Int, y: Int) { try { val a = getActorByID(blockPosToRefID(x, y)) - queueActorAddition(a) + queueActorRemoval(a) actorsRenderOverlay.remove(a) selection.remove(Point2i(x, y)) } - catch (e: IllegalArgumentException) { + catch (e: Throwable) { // no actor to erase, do nothing } } @@ -363,6 +364,13 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) { uiPenMenu.setAsOpen() } + + actorAdditionQueue.forEach { forceAddActor(it.first, it.second) } + actorAdditionQueue.clear() + actorRemovalQueue.forEach { forceRemoveActor(it.first, it.second) } + actorRemovalQueue.clear() + + BlockPropUtil.dynamicLumFuncTickClock() } @@ -581,27 +589,59 @@ class YamlCommandExit : YamlInvokable { } } +class YamlCommandSetTimeDawn : YamlInvokable { + override fun invoke(args: Array) { + (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("6h00")) + WeatherMixer.forceSolarElev = -3.0 + } +} + +class YamlCommandSetTimeSunrise : YamlInvokable { + override fun invoke(args: Array) { + (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("6h00")) + WeatherMixer.forceSolarElev = 0.0 + } +} + class YamlCommandSetTimeMorning : YamlInvokable { override fun invoke(args: Array) { - (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("7h00")) + (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("6h00")) + WeatherMixer.forceSolarElev = 5.0 } } class YamlCommandSetTimeNoon : YamlInvokable { override fun invoke(args: Array) { - (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("12h30")) + (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("12h00")) + WeatherMixer.forceSolarElev = 30.0 } } class YamlCommandSetTimeDusk : YamlInvokable { override fun invoke(args: Array) { - (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("18h40")) + (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("18h00")) + WeatherMixer.forceSolarElev = 3.0 + } +} + +class YamlCommandSetTimeSunset : YamlInvokable { + override fun invoke(args: Array) { + (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("18h00")) + WeatherMixer.forceSolarElev = 0.0 } } class YamlCommandSetTimeNight : YamlInvokable { override fun invoke(args: Array) { - (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("0h30")) + (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("18h00")) + WeatherMixer.forceSolarElev = -8.0 + } +} + +class YamlCommandSetTimeMidnight : YamlInvokable { + override fun invoke(args: Array) { + (args[0] as BuildingMaker).gameWorld.worldTime.setTimeOfToday(WorldTime.parseTime("0h00")) + WeatherMixer.forceSolarElev = -30.0 } } diff --git a/src/net/torvald/terrarum/ui/UINSMenu.kt b/src/net/torvald/terrarum/ui/UINSMenu.kt index 38efd62b3..b427b43df 100644 --- a/src/net/torvald/terrarum/ui/UINSMenu.kt +++ b/src/net/torvald/terrarum/ui/UINSMenu.kt @@ -137,7 +137,7 @@ class UINSMenu( // 2. push the new menu if (old != new) { - printdbg(this, "tree.children[new].children = ${tree.children[new].children}") +// printdbg(this, "tree.children[new].children = ${tree.children[new].children}") // push those new menus if (tree.children[new].children.isNotEmpty()) { @@ -205,7 +205,6 @@ class UINSMenu( batch.color = borderCol blendNormalStraightAlpha(batch) Toolkit.fillArea(batch, it.ui.posX + it.ui.width - 1, it.ui.posY - LINE_HEIGHT, 1, LINE_HEIGHT + it.ui.height) - Toolkit.fillArea(batch, it.ui.posX, it.ui.posY + it.ui.height - 1, it.ui.width - 1, 1) } }