mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 12:04:06 +09:00
trying to load a world
This commit is contained in:
@@ -12,8 +12,8 @@ import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.modulebasegame.ui.Notification
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerBlockChooser
|
||||
@@ -66,7 +66,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
private val timeNow = System.currentTimeMillis() / 1000
|
||||
|
||||
val gameWorld = GameWorldExtension(1, 1024, 256, timeNow, timeNow, 0)
|
||||
val gameWorld = GameWorld(1, 1024, 256, timeNow, timeNow, 0)
|
||||
|
||||
init {
|
||||
// ghetto world for building
|
||||
|
||||
@@ -28,8 +28,8 @@ import net.torvald.terrarum.gameactors.WireActor
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.*
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.physicssolver.CollisionSolver
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import net.torvald.terrarum.gameworld.WorldSimulator
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameEconomy
|
||||
import net.torvald.terrarum.modulebasegame.ui.*
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
|
||||
@@ -209,7 +209,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
lateinit var gameLoadMode: GameLoadMode
|
||||
lateinit var gameLoadInfoPayload: Any
|
||||
lateinit var gameworld: GameWorldExtension
|
||||
lateinit var theRealGamer: IngamePlayer
|
||||
// get() = actorGamer as IngamePlayer
|
||||
|
||||
@@ -229,14 +228,14 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
GameLoadMode.LOAD_FROM -> enterLoadFromSave(gameLoadInfoPayload as GameSaveData)
|
||||
}
|
||||
|
||||
IngameRenderer.setRenderedWorld(gameworld)
|
||||
IngameRenderer.setRenderedWorld(world)
|
||||
|
||||
|
||||
super.show() // gameInitialised = true
|
||||
}
|
||||
|
||||
data class GameSaveData(
|
||||
val world: GameWorldExtension,
|
||||
val world: GameWorld,
|
||||
val historicalFigureIDBucket: ArrayList<Int>,
|
||||
val realGamePlayer: IngamePlayer,
|
||||
val rogueS0: Long,
|
||||
@@ -270,18 +269,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
printdbg(this, "loaded successfully.")
|
||||
}
|
||||
else {
|
||||
AppLoader.getLoadScreen().addMessage("Loading world from save")
|
||||
|
||||
|
||||
gameworld = gameSaveData.world
|
||||
world = gameworld
|
||||
historicalFigureIDBucket = gameSaveData.historicalFigureIDBucket
|
||||
setTheRealGamerFirstTime(gameSaveData.realGamePlayer)
|
||||
|
||||
|
||||
// set the randomisers right
|
||||
RoguelikeRandomiser.loadFromSave(gameSaveData.rogueS0, gameSaveData.rogueS1)
|
||||
WeatherMixer.loadFromSave(gameSaveData.weatherS0, gameSaveData.weatherS1)
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,9 +290,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
// init map as chosen size
|
||||
val timeNow = System.currentTimeMillis() / 1000
|
||||
gameworld = GameWorldExtension(1, worldParams.width, worldParams.height, timeNow, timeNow, 0) // new game, so the creation time is right now
|
||||
gameworldIndices.add(gameworld.worldIndex)
|
||||
world = gameworld
|
||||
world = GameWorld(1, worldParams.width, worldParams.height, timeNow, timeNow, 0) // new game, so the creation time is right now
|
||||
gameworldIndices.add(world.worldIndex)
|
||||
world.extraFields["basegame.economy"] = GameEconomy()
|
||||
|
||||
// generate terrain for the map
|
||||
//WorldGenerator.attachMap(world)
|
||||
@@ -558,7 +546,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
* Ingame (world) related updates; UI update must go to renderGame()
|
||||
*/
|
||||
protected fun updateGame(delta: Float) {
|
||||
val world = this.world as GameWorldExtension
|
||||
val world = this.world
|
||||
worldWidth = world.width.toDouble() * TILE_SIZE
|
||||
|
||||
particlesActive = 0
|
||||
@@ -652,7 +640,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
private fun renderGame() {
|
||||
Gdx.graphics.setTitle(getCanonicalTitle())
|
||||
|
||||
WorldCamera.update(gameworld, actorNowPlaying)
|
||||
WorldCamera.update(world, actorNowPlaying)
|
||||
|
||||
measureDebugTime("Ingame.FilterVisibleActors") {
|
||||
filterVisibleActors()
|
||||
|
||||
@@ -37,22 +37,26 @@ object ExportMeta : ConsoleCommand {
|
||||
|
||||
object ExportWorld : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
try {
|
||||
val world = Terrarum.ingame!!.world
|
||||
val str = WriteWorld(Terrarum.ingame!! as TerrarumIngame).invoke()
|
||||
val writer = java.io.FileWriter(AppLoader.defaultDir + "/Exports/world${world.worldIndex}.json", false)
|
||||
writer.write(str)
|
||||
writer.close()
|
||||
Echo("Exportworld: exported to world${world.worldIndex}.json")
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
val str = WriteWorld(Terrarum.ingame!! as TerrarumIngame).invoke()
|
||||
val writer = java.io.FileWriter(AppLoader.defaultDir + "/Exports/${args[1]}", false)
|
||||
writer.write(str)
|
||||
writer.close()
|
||||
Echo("Exportworld: exported to ${args[1]}")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo("Exportworld: IOException raised.")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo("Exportworld: IOException raised.")
|
||||
e.printStackTrace()
|
||||
else {
|
||||
ImportWorld.printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: Exportworld")
|
||||
Echo("Usage: Exportworld filename.json")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.torvald.terrarum.modulebasegame.console
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-03-20.
|
||||
@@ -11,7 +10,7 @@ import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
internal object GetTime : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
|
||||
val worldTime = (Terrarum.ingame!!.world as GameWorldExtension).worldTime
|
||||
val worldTime = (Terrarum.ingame!!.world).worldTime
|
||||
Echo(worldTime.getFormattedTime())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.serialise.ReadWorld
|
||||
import net.torvald.terrarum.serialise.WriteMeta
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-08-25.
|
||||
*/
|
||||
object ImportWorld : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
val reader = java.io.FileReader(AppLoader.defaultDir + "/Exports/${args[1]}")
|
||||
ReadWorld(Terrarum.ingame!! as TerrarumIngame).invoke(reader)
|
||||
Echo("Importworld: imported a world from ${args[1]}")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo("Importworld: IOException raised.")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: Importworld filename.json")
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
*/
|
||||
internal object SetTime : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val world = (Terrarum.ingame!! as TerrarumIngame).gameworld
|
||||
val world = (Terrarum.ingame!! as TerrarumIngame).world
|
||||
|
||||
|
||||
if (args.size == 2) {
|
||||
|
||||
@@ -13,7 +13,7 @@ internal object SetTimeDelta : ConsoleCommand {
|
||||
val HARD_LIMIT = 60
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
val world = (Terrarum.ingame!! as TerrarumIngame).gameworld
|
||||
val world = (Terrarum.ingame!! as TerrarumIngame).world
|
||||
|
||||
|
||||
if (args.size == 2) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
object PlayerBuilder {
|
||||
|
||||
operator fun invoke(): Actor {
|
||||
val world = (Terrarum.ingame!! as TerrarumIngame).gameworld
|
||||
val world = (Terrarum.ingame!! as TerrarumIngame).world
|
||||
|
||||
val p: Actor = IngamePlayer("lol", "lol_glow", world.worldTime.TIME_T)
|
||||
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameworld
|
||||
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.badlogic.gdx.utils.JsonWriter
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2018-07-03.
|
||||
*/
|
||||
class GameWorldExtension : GameWorld {
|
||||
|
||||
constructor(worldIndex: Int, width: Int, height: Int, creationTIME_T: Long, lastPlayTIME_T: Long, totalPlayTime: Int) : super(worldIndex, width, height, creationTIME_T, lastPlayTIME_T, totalPlayTime)
|
||||
//internal constructor(worldIndex: Int, layerData: ReadLayerDataZip.LayerData, creationTIME_T: Long, lastPlayTIME_T: Long, totalPlayTime: Int) : super(worldIndex, layerData, creationTIME_T, lastPlayTIME_T, totalPlayTime)
|
||||
|
||||
|
||||
var economy = GameEconomy()
|
||||
internal set
|
||||
|
||||
// delegated properties //
|
||||
/*val layerWall: MapLayer; get() = baseworld.layerWall
|
||||
val layerTerrain: MapLayer; get() = baseworld.layerTerrain
|
||||
val layerWire: MapLayer; get() = baseworld.layerWire
|
||||
val layerWallLowBits: PairedMapLayer; get() = baseworld.layerWallLowBits
|
||||
val layerTerrainLowBits: PairedMapLayer; get() = baseworld.layerTerrainLowBits
|
||||
val layerHalfThermal: MapLayerHalfFloat; get() = baseworld.layerHalfThermal
|
||||
var spawnX: Int; get() = baseworld.spawnX; set(v) { baseworld.spawnX = v }
|
||||
var spawnY: Int; get() = baseworld.spawnY; set(v) { baseworld.spawnY = v }
|
||||
val wallDamages: HashMap<BlockAddress, BlockDamage>; get() = baseworld.wallDamages
|
||||
val terrainDamages: HashMap<BlockAddress, BlockDamage>; get() = baseworld.terrainDamages
|
||||
var globalLight: Color; get() = baseworld.globalLight; set(v) { baseworld.globalLight = v }
|
||||
var averageTemperature: Float; get() = baseworld.averageTemperature; set(v) { baseworld.averageTemperature = v }
|
||||
var generatorSeed: Long; get() = baseworld.generatorSeed; set(v) { baseworld.generatorSeed = v }
|
||||
val terrainArray: ByteArray; get() = baseworld.terrainArray
|
||||
val wallArray: ByteArray; get() = baseworld.wallArray
|
||||
val wireArray: ByteArray; get() = baseworld.wireArray
|
||||
val damageDataArray: ByteArray; get() = baseworld.damageDataArray*/
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
override fun getJsonFields(): List<String> {
|
||||
return super.getJsonFields() + arrayListOf(
|
||||
""""basegame.economy": ${Json(JsonWriter.OutputType.json).toJson(economy)}"""
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.WatchFont
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
@@ -39,7 +38,7 @@ class UITierOneWatch() : UICanvas() {
|
||||
//get() = if (ELon) lcdLitColELon else lcdLitColELoff
|
||||
|
||||
private val worldTime: WorldTime
|
||||
get() = (Terrarum.ingame!!.world as GameWorldExtension).worldTime
|
||||
get() = Terrarum.ingame!!.world.worldTime
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
|
||||
Reference in New Issue
Block a user