mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
nsmenu to invoke class with defined args; working settime on buildingmaker
This commit is contained in:
@@ -196,5 +196,5 @@ inline class Yaml(val text: String) {
|
||||
*
|
||||
*/
|
||||
interface YamlInvokable {
|
||||
operator fun invoke(vararg args: Any?)
|
||||
operator fun invoke(args: Array<Any>)
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
|
||||
import net.torvald.terrarum.modulebasegame.ui.Notification
|
||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINSMenu
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
@@ -40,10 +41,10 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
- Undo
|
||||
- Redo
|
||||
- Time
|
||||
- Morning
|
||||
- Noon
|
||||
- Dusk
|
||||
- Night
|
||||
- Morning : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeMorning
|
||||
- Noon : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeNoon
|
||||
- Dusk : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeDusk
|
||||
- Night : net.torvald.terrarum.modulebasegame.YamlCommandSetTimeNight
|
||||
- Set…
|
||||
- Weather
|
||||
- Sunny
|
||||
@@ -132,6 +133,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
uiToolbox.setPosition(0, 0)
|
||||
uiToolbox.isVisible = true
|
||||
uiToolbox.invocationArgument = arrayOf(this)
|
||||
|
||||
notifier.setPosition(
|
||||
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
|
||||
@@ -166,6 +168,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
private fun updateGame(delta: Float) {
|
||||
KeyToggler.update(false)
|
||||
|
||||
WeatherMixer.update(delta, actorNowPlaying, gameWorld)
|
||||
blockPointingCursor.update(delta)
|
||||
actorNowPlaying?.update(delta)
|
||||
uiContainer.forEach { it.update(delta) }
|
||||
@@ -174,7 +177,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
private fun renderGame() {
|
||||
IngameRenderer(world as GameWorldExtension, actorsRenderOverlay = actorsRenderOverlay, uisToDraw = uiContainer)
|
||||
IngameRenderer.invoke(world as GameWorldExtension, actorsRenderOverlay = actorsRenderOverlay, uisToDraw = uiContainer)
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
@@ -260,7 +263,31 @@ class MovableWorldCamera : ActorHumanoid(0, usePhysics = false) {
|
||||
}
|
||||
|
||||
class YamlCommandExit : YamlInvokable {
|
||||
override fun invoke(vararg args: Any?) {
|
||||
override fun invoke(args: Array<Any>) {
|
||||
Terrarum.setScreen(TitleScreen(Terrarum.batch))
|
||||
}
|
||||
}
|
||||
|
||||
class YamlCommandSetTimeMorning : YamlInvokable {
|
||||
override fun invoke(args: Array<Any>) {
|
||||
(args[0] as BuildingMaker).gameWorld.time.setTimeOfToday(WorldTime.parseTime("7h00"))
|
||||
}
|
||||
}
|
||||
|
||||
class YamlCommandSetTimeNoon : YamlInvokable {
|
||||
override fun invoke(args: Array<Any>) {
|
||||
(args[0] as BuildingMaker).gameWorld.time.setTimeOfToday(WorldTime.parseTime("12h30"))
|
||||
}
|
||||
}
|
||||
|
||||
class YamlCommandSetTimeDusk : YamlInvokable {
|
||||
override fun invoke(args: Array<Any>) {
|
||||
(args[0] as BuildingMaker).gameWorld.time.setTimeOfToday(WorldTime.parseTime("18h40"))
|
||||
}
|
||||
}
|
||||
|
||||
class YamlCommandSetTimeNight : YamlInvokable {
|
||||
override fun invoke(args: Array<Any>) {
|
||||
(args[0] as BuildingMaker).gameWorld.time.setTimeOfToday(WorldTime.parseTime("0h30"))
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,9 @@ class WorldTime(initTime: Long = 0L) {
|
||||
|
||||
val EPOCH_YEAR = 125
|
||||
|
||||
/**
|
||||
* Parse a time in the format of "8h30" (hour and minute) or "39882" (second) and return a time of day, in seconds
|
||||
*/
|
||||
fun parseTime(s: String): Int =
|
||||
if (s.length >= 4 && s.contains('h')) {
|
||||
s.toLowerCase().substringBefore('h').toInt() * HOUR_SEC +
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package net.torvald.terrarum.tests
|
||||
|
||||
import com.badlogic.gdx.*
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.InputAdapter
|
||||
import com.badlogic.gdx.ScreenAdapter
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||
import net.torvald.terrarum.*
|
||||
|
||||
@@ -50,6 +50,8 @@ class UINSMenu(
|
||||
val selectedIndex: Int?
|
||||
get() = listStack.peek().ui.selectedIndex
|
||||
|
||||
var invocationArgument: Array<Any> = arrayOf(this)
|
||||
|
||||
init {
|
||||
addSubMenu(tree)
|
||||
}
|
||||
@@ -102,7 +104,7 @@ class UINSMenu(
|
||||
|
||||
// invoke whatever command there is
|
||||
//printdbg(this, "Selected: ${tree.children[new].data?.second}")
|
||||
tree.children[new].data?.second?.invoke()
|
||||
tree.children[new].data?.second?.invoke(invocationArgument)
|
||||
}
|
||||
// END List selection change listener
|
||||
|
||||
|
||||
Reference in New Issue
Block a user