mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
working create-new-world
This commit is contained in:
@@ -61,7 +61,7 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
|
||||
|
||||
open var consoleHandler: ConsoleWindow = ConsoleWindow()
|
||||
|
||||
var paused: Boolean = false
|
||||
var paused: Boolean = false; protected set
|
||||
val consoleOpened: Boolean
|
||||
get() = consoleHandler.isOpened || consoleHandler.isOpening
|
||||
|
||||
@@ -71,7 +71,6 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
|
||||
open var uiTooltip: UITooltip = UITooltip()
|
||||
open var notifier: Notification = Notification()
|
||||
|
||||
|
||||
init {
|
||||
consoleHandler.setPosition(0, 0)
|
||||
notifier.setPosition(
|
||||
@@ -151,9 +150,11 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
|
||||
}
|
||||
|
||||
override fun pause() {
|
||||
paused = true
|
||||
}
|
||||
|
||||
override fun resume() {
|
||||
paused = false
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
|
||||
@@ -637,6 +637,8 @@ class UIContainer {
|
||||
fun contains(element: Any) = data.contains(element)
|
||||
|
||||
fun <T> map(transformation: (UICanvas?) -> T) = iterator().asSequence().map(transformation)
|
||||
|
||||
fun filter(predicate: (Any) -> Boolean) = data.filter(predicate)
|
||||
}
|
||||
|
||||
interface Id_UICanvasNullable {
|
||||
|
||||
@@ -137,6 +137,12 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
(this.hitbox.endX + world.width >= WorldCamera.x && this.hitbox.startX + world.width <= WorldCamera.xEnd) ||
|
||||
// x: neither
|
||||
(this.hitbox.endX >= WorldCamera.x && this.hitbox.startX <= WorldCamera.xEnd))
|
||||
|
||||
val SIZE_SMALL = Point2i(6030, 1800)
|
||||
val SIZE_NORMAL = Point2i(9000, 2250)
|
||||
val SIZE_LARGE = Point2i(13500, 2970)
|
||||
val SIZE_HUGE = Point2i(22500, 4500)
|
||||
val WORLDSIZE = arrayOf(SIZE_SMALL, SIZE_NORMAL, SIZE_LARGE, SIZE_HUGE)
|
||||
}
|
||||
|
||||
|
||||
@@ -1224,14 +1230,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
}
|
||||
|
||||
override fun pause() {
|
||||
paused = true
|
||||
}
|
||||
|
||||
override fun resume() {
|
||||
paused = false
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
uiContainer.forEach { it?.handler?.dispose() }
|
||||
}
|
||||
|
||||
@@ -6,12 +6,20 @@ import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.random.XXHash64
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.WorldgenLoadScreen
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
||||
import net.torvald.terrarum.savegame.ByteArray64Reader
|
||||
import net.torvald.terrarum.savegame.VirtualDisk
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.serialise.ReadActor
|
||||
import net.torvald.terrarum.ui.*
|
||||
import net.torvald.terrarum.utils.RandomWordsName
|
||||
|
||||
@@ -71,6 +79,28 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
|
||||
|
||||
goButton.touchDownListener = { _, _, _, _ ->
|
||||
printdbg(this, "generate! Size=${sizeSelector.selection}, Name=${nameInput.getTextOrPlaceholder()}, Seed=${seedInput.getTextOrPlaceholder()}")
|
||||
|
||||
val ingame = TerrarumIngame(App.batch)
|
||||
val player = ReadActor.invoke(UILoadGovernor.playerDisk!!, ByteArray64Reader(UILoadGovernor.playerDisk!!.getFile(-1L)!!.bytes, Common.CHARSET)) as IngamePlayer
|
||||
val seed = try {
|
||||
seedInput.getTextOrPlaceholder().toLong()
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
XXHash64.hash(seedInput.getTextOrPlaceholder().toByteArray(Charsets.UTF_8), 10000)
|
||||
}
|
||||
val (wx, wy) = TerrarumIngame.WORLDSIZE[sizeSelector.selection]
|
||||
val worldParam = TerrarumIngame.NewGameParams(
|
||||
player, TerrarumIngame.NewWorldParameters(
|
||||
wx, wy, seed, nameInput.getTextOrPlaceholder()
|
||||
)
|
||||
)
|
||||
ingame.gameLoadInfoPayload = worldParam
|
||||
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
|
||||
|
||||
Terrarum.setCurrentIngameInstance(ingame)
|
||||
val loadScreen = WorldgenLoadScreen(ingame, wx, wy)
|
||||
App.setLoadScreen(loadScreen)
|
||||
|
||||
}
|
||||
backButton.touchDownListener = { _, _, _, _ ->
|
||||
remoCon.openUI(UILoadDemoSavefiles(remoCon, 1))
|
||||
|
||||
@@ -26,9 +26,9 @@ class ConsoleWindow : UICanvas() {
|
||||
internal var UIColour = Color(0x404080_80.toInt())
|
||||
|
||||
private var inputCursorPos: Int = 0
|
||||
private val MESSAGES_MAX = 5000
|
||||
private val MESSAGES_MAX = 1000
|
||||
private val COMMAND_HISTORY_MAX = 100
|
||||
private var messages = Array(MESSAGES_MAX) { "" }
|
||||
private var messages = CircularArray<String>(MESSAGES_MAX, true)
|
||||
private var messageDisplayPos: Int = 0
|
||||
private var messagesCount: Int = 0
|
||||
|
||||
@@ -49,6 +49,8 @@ class ConsoleWindow : UICanvas() {
|
||||
|
||||
private var historyIndex = -1
|
||||
|
||||
private var iMadeTheGameToPause = false
|
||||
|
||||
init {
|
||||
reset()
|
||||
}
|
||||
@@ -94,9 +96,9 @@ class ConsoleWindow : UICanvas() {
|
||||
|
||||
|
||||
// messages
|
||||
for (i in 0..MESSAGES_DISPLAY_COUNT - 1) {
|
||||
val message = messages[messageDisplayPos + i]
|
||||
App.fontGame.draw(batch, message, 1f + drawOffX, (LINE_HEIGHT * (i + 1)).toFloat() + drawOffY)
|
||||
for (i in 0 until MESSAGES_DISPLAY_COUNT) {
|
||||
val message = messages[messageDisplayPos + i] ?: ""
|
||||
App.fontGame.draw(batch, message, 1f + drawOffX, (LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT - i)).toFloat() + drawOffY)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,11 +169,9 @@ class ConsoleWindow : UICanvas() {
|
||||
}
|
||||
|
||||
fun sendMessage(msg: String) {
|
||||
messages[messagesCount] = msg
|
||||
messages.appendHead(msg)
|
||||
messagesCount += 1
|
||||
if (messagesCount > MESSAGES_DISPLAY_COUNT) {
|
||||
messageDisplayPos = messagesCount - MESSAGES_DISPLAY_COUNT
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun setDisplayPos(change: Int) {
|
||||
@@ -195,7 +195,7 @@ class ConsoleWindow : UICanvas() {
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
messages = Array(MESSAGES_MAX) { "" }
|
||||
messages = CircularArray<String>(MESSAGES_MAX, true)
|
||||
messageDisplayPos = 0
|
||||
messagesCount = 0
|
||||
inputCursorPos = 0
|
||||
@@ -210,7 +210,17 @@ class ConsoleWindow : UICanvas() {
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
Terrarum.ingame?.pause()
|
||||
Terrarum.ingame?.let {
|
||||
println("Game was paused beforehand: ${it.paused}")
|
||||
if (!it.paused) {
|
||||
iMadeTheGameToPause = true
|
||||
it.pause()
|
||||
}
|
||||
else {
|
||||
iMadeTheGameToPause = false
|
||||
}
|
||||
println("I made the game to pause: $iMadeTheGameToPause")
|
||||
}
|
||||
/*openingTimeCounter += delta
|
||||
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
|
||||
-height.toFloat(), 0f
|
||||
@@ -218,7 +228,6 @@ class ConsoleWindow : UICanvas() {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
Terrarum.ingame?.resume()
|
||||
/*openingTimeCounter += delta
|
||||
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
|
||||
0f, -height.toFloat()
|
||||
@@ -226,16 +235,20 @@ class ConsoleWindow : UICanvas() {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
Terrarum.ingame?.pause()
|
||||
drawOffY = 0f
|
||||
openingTimeCounter = 0f
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
Terrarum.ingame?.setTooltipMessage(null)
|
||||
Terrarum.ingame?.resume()
|
||||
println("Close -- I made the game to pause: $iMadeTheGameToPause")
|
||||
if (iMadeTheGameToPause) {
|
||||
Terrarum.ingame?.resume()
|
||||
println("Close -- resume game")
|
||||
}
|
||||
drawOffY = -height.toFloat()
|
||||
openingTimeCounter = 0f
|
||||
iMadeTheGameToPause = false
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
|
||||
Reference in New Issue
Block a user