mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
load screen actually draws the world
transition still not working
This commit is contained in:
@@ -180,8 +180,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
// gameLoadMode and gameLoadInfoPayload must be set beforehand!!
|
// gameLoadMode and gameLoadInfoPayload must be set beforehand!!
|
||||||
|
|
||||||
when (gameLoadMode) {
|
when (gameLoadMode) {
|
||||||
GameLoadMode.CREATE_NEW -> enter(gameLoadInfoPayload as NewWorldParameters)
|
GameLoadMode.CREATE_NEW -> enterCreateNewWorld(gameLoadInfoPayload as NewWorldParameters)
|
||||||
GameLoadMode.LOAD_FROM -> enter(gameLoadInfoPayload as GameSaveData)
|
GameLoadMode.LOAD_FROM -> enterLoadFromSave(gameLoadInfoPayload as GameSaveData)
|
||||||
}
|
}
|
||||||
|
|
||||||
IngameRenderer.setRenderedWorld(gameworld)
|
IngameRenderer.setRenderedWorld(gameworld)
|
||||||
@@ -220,7 +220,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
/**
|
/**
|
||||||
* Init instance by loading saved world
|
* Init instance by loading saved world
|
||||||
*/
|
*/
|
||||||
private fun enter(gameSaveData: GameSaveData) {
|
private fun enterLoadFromSave(gameSaveData: GameSaveData) {
|
||||||
if (gameInitialised) {
|
if (gameInitialised) {
|
||||||
printdbg(this, "loaded successfully.")
|
printdbg(this, "loaded successfully.")
|
||||||
}
|
}
|
||||||
@@ -243,7 +243,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
/**
|
/**
|
||||||
* Init instance by creating new world
|
* Init instance by creating new world
|
||||||
*/
|
*/
|
||||||
private fun enter(worldParams: NewWorldParameters) {
|
private fun enterCreateNewWorld(worldParams: NewWorldParameters) {
|
||||||
printdbg(this, "Ingame called")
|
printdbg(this, "Ingame called")
|
||||||
printStackTrace(this)
|
printStackTrace(this)
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import kotlin.math.roundToInt
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2019-11-09.
|
* Created by minjaesong on 2019-11-09.
|
||||||
*/
|
*/
|
||||||
class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, worldwidth: Int, worldheight: Int) : LoadScreenBase() {
|
class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidth: Int, private val worldheight: Int) : LoadScreenBase() {
|
||||||
|
|
||||||
// a Class impl is chosen to make resize-handling easier, there's not much benefit making this a singleton anyway
|
// a Class impl is chosen to make resize-handling easier, there's not much benefit making this a singleton anyway
|
||||||
|
|
||||||
@@ -23,8 +23,9 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, worldwidth: Int, worl
|
|||||||
AppLoader.disposableSingletonsPool.add(this)
|
AppLoader.disposableSingletonsPool.add(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val world = screenToBeLoaded.world
|
|
||||||
override var screenToLoad: IngameInstance? = screenToBeLoaded
|
override var screenToLoad: IngameInstance? = screenToBeLoaded
|
||||||
|
private val world: GameWorld // must use Getter, as the field WILL BE redefined by the TerrarumIngame.enterCreateNewWorld() !
|
||||||
|
get() = screenToLoad!!.world
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val WIDTH_RATIO = 0.7
|
private const val WIDTH_RATIO = 0.7
|
||||||
@@ -43,6 +44,8 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, worldwidth: Int, worl
|
|||||||
|
|
||||||
private var previewRenderCounter = 0f
|
private var previewRenderCounter = 0f
|
||||||
|
|
||||||
|
// NOTE: actual world init and terragen is called by TerrarumIngame.enterLoadFromSave()
|
||||||
|
|
||||||
override fun show() {
|
override fun show() {
|
||||||
super.show()
|
super.show()
|
||||||
|
|
||||||
@@ -86,18 +89,20 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, worldwidth: Int, worl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun renderToPreview() {
|
private fun renderToPreview() {
|
||||||
for (y in 0 until previewWidth) {
|
for (y in 0 until previewHeight) {
|
||||||
for (x in 0 until previewHeight) {
|
for (x in 0 until previewWidth) {
|
||||||
val wx = (world.width / previewWidth * x).toInt()
|
val wx = (world.width.toFloat() / previewWidth * x).roundToInt()
|
||||||
val wy = (world.height / previewHeight * y).toInt()
|
val wy = (world.height.toFloat() / previewHeight * y).roundToInt()
|
||||||
|
|
||||||
val colT = if (world.getTileFromTerrain(wx, wy) != 0) COL_WALL else COL_TERR
|
val colT = if (world.getTileFromTerrain(wx, wy) != 0) COL_WALL else COL_TERR
|
||||||
val colW = if (world.getTileFromWall(wx, wy) != 0) COL_WALL else COL_AIR
|
val colW = if (world.getTileFromWall(wx, wy) != 0) COL_WALL else COL_AIR
|
||||||
val outCol = colW mul colT
|
val outCol = colW mul colT
|
||||||
|
|
||||||
previewPixmap.setColor(outCol)
|
previewPixmap.setColor(outCol)
|
||||||
previewPixmap.drawPixel(x, y)
|
previewPixmap.drawPixel(x, previewHeight - 1 - y) // this flips Y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addMessage(msg: String) {
|
override fun addMessage(msg: String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user