mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
world portal: autogenerating returning portal
This commit is contained in:
@@ -322,16 +322,18 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data class NewGameParams(
|
data class NewGameParams(
|
||||||
val player: IngamePlayer,
|
val player: IngamePlayer,
|
||||||
val newWorldParams: NewWorldParameters
|
val newWorldParams: NewWorldParameters,
|
||||||
|
val callbackAfterLoad: (TerrarumIngame) -> Unit
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class NewWorldParameters(
|
data class NewWorldParameters(
|
||||||
val width: Int,
|
val width: Int,
|
||||||
val height: Int,
|
val height: Int,
|
||||||
val worldGenSeed: Long,
|
val worldGenSeed: Long,
|
||||||
val savegameName: String
|
val savegameName: String
|
||||||
// other worldgen options
|
// other worldgen options
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
if (width % LandUtil.CHUNK_W != 0 || height % LandUtil.CHUNK_H != 0) {
|
if (width % LandUtil.CHUNK_W != 0 || height % LandUtil.CHUNK_H != 0) {
|
||||||
@@ -353,10 +355,11 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
val actors: List<ActorID>,
|
val actors: List<ActorID>,
|
||||||
val player: IngamePlayer,
|
val player: IngamePlayer,
|
||||||
val worldGenver: Long,
|
val worldGenver: Long,
|
||||||
val playerGenver: Long
|
val playerGenver: Long,
|
||||||
|
val callbackAfterLoad: (TerrarumIngame) -> Unit
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private var loadCallback: ((TerrarumIngame) -> Unit)? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init instance by loading saved world
|
* Init instance by loading saved world
|
||||||
@@ -378,6 +381,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
// feed info to the worldgen
|
// feed info to the worldgen
|
||||||
Worldgen.attachMap(world, WorldgenParams(world.generatorSeed))
|
Worldgen.attachMap(world, WorldgenParams(world.generatorSeed))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadCallback = codices.callbackAfterLoad
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Load rest of the game with GL context */
|
/** Load rest of the game with GL context */
|
||||||
@@ -547,6 +552,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KeyToggler.forceSet(Input.Keys.Q, false)
|
KeyToggler.forceSet(Input.Keys.Q, false)
|
||||||
|
|
||||||
|
loadCallback = newGameParams.callbackAfterLoad
|
||||||
}
|
}
|
||||||
|
|
||||||
val ingameController = IngameController(this)
|
val ingameController = IngameController(this)
|
||||||
@@ -666,6 +673,16 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
KeyToggler.forceSet(Input.Keys.F2, false)
|
KeyToggler.forceSet(Input.Keys.F2, false)
|
||||||
|
|
||||||
|
|
||||||
|
if (loadCallback != null) {
|
||||||
|
try {
|
||||||
|
loadCallback!!(this)
|
||||||
|
}
|
||||||
|
catch (e: Throwable) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
loadCallback = null
|
||||||
|
}
|
||||||
}// END enter
|
}// END enter
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.App.printdbg
|
||||||
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.FancyWorldgenLoadScreen
|
import net.torvald.terrarum.modulebasegame.FancyWorldgenLoadScreen
|
||||||
@@ -19,6 +20,10 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
|||||||
*/
|
*/
|
||||||
class FixtureWorldPortal : Electric {
|
class FixtureWorldPortal : Electric {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val ITEMID = "item@basegame:320"
|
||||||
|
}
|
||||||
|
|
||||||
constructor() : super(
|
constructor() : super(
|
||||||
BlockBox(BlockBox.NO_COLLISION, 5, 2),
|
BlockBox(BlockBox.NO_COLLISION, 5, 2),
|
||||||
nameFun = { Lang["ITEM_WORLD_PORTAL"] },
|
nameFun = { Lang["ITEM_WORLD_PORTAL"] },
|
||||||
@@ -85,7 +90,29 @@ class FixtureWorldPortal : Electric {
|
|||||||
printdbg(this, "generate for teleportation! Size=${wx}x${wy}, Name=$name, Seed=$seed")
|
printdbg(this, "generate for teleportation! Size=${wx}x${wy}, Name=$name, Seed=$seed")
|
||||||
|
|
||||||
val ingame = TerrarumIngame(App.batch)
|
val ingame = TerrarumIngame(App.batch)
|
||||||
val worldParam = TerrarumIngame.NewGameParams(player, it.worldLoadParam)
|
val worldParam = TerrarumIngame.NewGameParams(player, it.worldLoadParam) { ingame ->
|
||||||
|
val world = ingame.world
|
||||||
|
|
||||||
|
// flatten terrain
|
||||||
|
for (x in world.spawnX - 2..world.spawnX + 2) {
|
||||||
|
// clear ceiling
|
||||||
|
for (y in world.spawnY - 2..world.spawnY - 1) {
|
||||||
|
world.setTileTerrain(x, y, Block.AIR, true)
|
||||||
|
}
|
||||||
|
// fill bottom
|
||||||
|
for (y in world.spawnY..world.spawnY + 2) {
|
||||||
|
if (!BlockCodex[world.getTileFromTerrain(x, y)].isSolid) {
|
||||||
|
world.setTileTerrain(x, y, Block.DIRT, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// spawn a world portal
|
||||||
|
printdbg(this, "Portal new world callback; spawning portal at ${world.spawnX}, ${world.spawnY - 1}")
|
||||||
|
FixtureWorldPortal().spawn(world.spawnX, world.spawnY - 1, player.uuid)
|
||||||
|
printdbg(this, "Spawn complete")
|
||||||
|
|
||||||
|
}
|
||||||
ingame.gameLoadInfoPayload = worldParam
|
ingame.gameLoadInfoPayload = worldParam
|
||||||
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
|
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
|
||||||
|
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ object LoadSavegame {
|
|||||||
|
|
||||||
|
|
||||||
val actors = world.actors.distinct()
|
val actors = world.actors.distinct()
|
||||||
val worldParam = TerrarumIngame.Codices(newIngame.worldDisk, world, actors, player, worldGenver, playerGenver)
|
val worldParam = TerrarumIngame.Codices(newIngame.worldDisk, world, actors, player, worldGenver, playerGenver) {}
|
||||||
|
|
||||||
|
|
||||||
newIngame.gameLoadInfoPayload = worldParam
|
newIngame.gameLoadInfoPayload = worldParam
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
|
|||||||
player, TerrarumIngame.NewWorldParameters(
|
player, TerrarumIngame.NewWorldParameters(
|
||||||
wx, wy, seed, nameInput.getTextOrPlaceholder()
|
wx, wy, seed, nameInput.getTextOrPlaceholder()
|
||||||
)
|
)
|
||||||
)
|
) {}
|
||||||
ingame.gameLoadInfoPayload = worldParam
|
ingame.gameLoadInfoPayload = worldParam
|
||||||
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
|
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class UIProxyNewRandomGame(val remoCon: UIRemoCon) : UICanvas() {
|
|||||||
// PlayerBuilderTestSubject1(),
|
// PlayerBuilderTestSubject1(),
|
||||||
PlayerBuilderWerebeastTest(),
|
PlayerBuilderWerebeastTest(),
|
||||||
TerrarumIngame.NewWorldParameters(2880, 1350, HQRNG().nextLong(), RandomWordsName(4))
|
TerrarumIngame.NewWorldParameters(2880, 1350, HQRNG().nextLong(), RandomWordsName(4))
|
||||||
)
|
) {}
|
||||||
// val worldParam = TerrarumIngame.NewWorldParameters(2880, 1350, 0x51621D)
|
// val worldParam = TerrarumIngame.NewWorldParameters(2880, 1350, 0x51621D)
|
||||||
|
|
||||||
// val worldParam = TerrarumIngame.NewWorldParameters(6030, 1800, HQRNG().nextLong()) // small
|
// val worldParam = TerrarumIngame.NewWorldParameters(6030, 1800, HQRNG().nextLong()) // small
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.sudoplay.joise.module.*
|
|||||||
import net.torvald.random.XXHash64
|
import net.torvald.random.XXHash64
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.*
|
import net.torvald.terrarum.App.*
|
||||||
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.gameitems.ItemID
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
import net.torvald.terrarum.gameworld.BlockAddress
|
import net.torvald.terrarum.gameworld.BlockAddress
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
@@ -198,8 +199,8 @@ object Worldgen {
|
|||||||
val y = posY
|
val y = posY
|
||||||
val yUp = posY - 1
|
val yUp = posY - 1
|
||||||
val tile = BlockCodex[world.getTileFromTerrain(x, y)]
|
val tile = BlockCodex[world.getTileFromTerrain(x, y)]
|
||||||
val tileUp = BlockCodex[world.getTileFromTerrain(x, yUp)]
|
val tileUp = world.getTileFromTerrain(x, yUp)
|
||||||
if (tile.isSolid && !tileUp.isSolid)
|
if (tile.isSolid && tileUp == Block.AIR)
|
||||||
flatness += 1
|
flatness += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user