player is now nullable; wtf is calling Ingame 5 times?

This commit is contained in:
minjaesong
2018-09-17 01:46:50 +09:00
parent 967eafe8a3
commit 03b642ddd3
35 changed files with 252 additions and 150 deletions

View File

@@ -2,12 +2,9 @@ package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.*
@@ -49,7 +46,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
}
override var playableActor: ActorHumanoid = MovableWorldCamera(world)
override var actorNowPlaying: ActorHumanoid? = MovableWorldCamera(world)
val uiToolbox = UIBuildingMakerToolbox()
val notifier = Notification()
@@ -104,7 +101,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
playableActor.setPosition(512 * 16.0, 149 * 16.0)
actorNowPlaying?.setPosition(512 * 16.0, 149 * 16.0)
@@ -153,10 +150,10 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
private fun updateGame(delta: Float) {
blockPointingCursor.update(delta)
playableActor.update(delta)
actorNowPlaying?.update(delta)
uiContainer.forEach { it.update(delta) }
WorldCamera.update(world, playableActor)
WorldCamera.update(world, actorNowPlaying)
}
private fun renderGame() {

View File

@@ -16,7 +16,6 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.worlddrawer.WorldCamera
@@ -24,14 +23,12 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
import java.util.ArrayList
import java.util.concurrent.locks.ReentrantLock
import net.torvald.random.HQRNG
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.modulebasegame.console.AVTracker
import net.torvald.terrarum.modulebasegame.console.ActorsList
import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.console.SetGlobalLightOverride
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.gameactors.*
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegMain
@@ -53,9 +50,6 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var historicalFigureIDBucket: ArrayList<Int>
lateinit var gameworld: GameWorldExtension
lateinit var theRealGamer: IngamePlayer
/**
* list of Actors that is sorted by Actors' referenceID
@@ -150,6 +144,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var gameLoadMode: GameLoadMode
lateinit var gameLoadInfoPayload: Any
lateinit var gameworld: GameWorldExtension
lateinit var theRealGamer: IngamePlayer
enum class GameLoadMode {
CREATE_NEW, LOAD_FROM
@@ -189,6 +185,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// other worldgen options
)
private fun setTheRealGamerFirstTime(actor: IngamePlayer) {
actorNowPlaying = actor
theRealGamer = actor
addNewActor(actorNowPlaying)
}
/**
* Init instance by loading saved world
*/
@@ -203,17 +205,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
gameworld = gameSaveData.world
world = gameworld
historicalFigureIDBucket = gameSaveData.historicalFigureIDBucket
theRealGamer = gameSaveData.realGamePlayer
playableActor = gameSaveData.realGamePlayer
addNewActor(playableActor)
setTheRealGamerFirstTime(gameSaveData.realGamePlayer)
// set the randomisers right
RoguelikeRandomiser.loadFromSave(gameSaveData.rogueS0, gameSaveData.rogueS1)
WeatherMixer.loadFromSave(gameSaveData.weatherS0, gameSaveData.weatherS1)
//initGame()
}
}
@@ -221,6 +218,11 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
* Init instance by creating new world
*/
private fun enter(worldParams: NewWorldParameters) {
printdbg(this, "Ingame called")
Thread.currentThread().getStackTrace().forEach {
printdbg(this, "-> $it")
}
if (gameInitialised) {
printdbg(this, "loaded successfully.")
}
@@ -252,8 +254,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// test actor
//addNewActor(PlayerBuilderCynthia())
//initGame()
setTheRealGamerFirstTime(PlayerBuilderSigrid())
}
}
@@ -303,7 +304,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
-uiInventoryPlayer.width,
70
)*/
uiInventoryPlayer = UIInventoryFull(playableActor,
uiInventoryPlayer = UIInventoryFull(actorNowPlaying,
toggleKeyLiteral = Terrarum.getConfigInt("keyinventory")
)
uiInventoryPlayer.setPosition(0, 0)
@@ -329,11 +330,11 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
//uiVitalItem.setAsAlwaysVisible()
// basic watch-style notification bar (temperature, new mail)
uiWatchBasic = UIBasicNotifier(playableActor)
uiWatchBasic = UIBasicNotifier(actorNowPlaying)
uiWatchBasic.setAsAlwaysVisible()
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0)
uiWatchTierOne = UITierOneWatch(playableActor)
uiWatchTierOne = UITierOneWatch(actorNowPlaying)
uiWatchTierOne.setAsAlwaysVisible()
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2)
@@ -421,15 +422,15 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
if (!gameFullyLoaded) {
if (gameLoadMode == GameLoadMode.CREATE_NEW) {
playableActor = PlayerBuilderSigrid()
actorNowPlaying = PlayerBuilderSigrid()
// go to spawn position
playableActor.setPosition(
actorNowPlaying?.setPosition(
world.spawnX * FeaturesDrawer.TILE_SIZE.toDouble(),
world.spawnY * FeaturesDrawer.TILE_SIZE.toDouble()
)
addNewActor(playableActor)
addNewActor(actorNowPlaying)
}
postInit()
@@ -505,7 +506,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
BlockPropUtil.dynamicLumFuncTickClock()
world.updateWorldTime(delta)
//WorldSimulator(player, delta)
WeatherMixer.update(delta, playableActor)
WeatherMixer.update(delta, actorNowPlaying)
BlockStats.update()
if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride)
gameworld.globalLight = WeatherMixer.globalLightNow
@@ -515,7 +516,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// camera-related updates //
////////////////////////////
FeaturesDrawer.update(delta)
WorldCamera.update(gameworld, playableActor)
WorldCamera.update(gameworld, actorNowPlaying)
@@ -558,7 +559,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderMidTop,
actorsRenderFront,
particlesContainer,
playableActor,
actorNowPlaying,
uiContainer
)
}
@@ -566,7 +567,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private fun repossessActor() {
// check if currently pocessed actor is removed from game
if (!theGameHasActor(playableActor)) {
if (!theGameHasActor(actorNowPlaying)) {
// re-possess canonical player
if (theGameHasActor(Terrarum.PLAYER_REF_ID))
changePossession(Terrarum.PLAYER_REF_ID)
@@ -576,12 +577,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
private fun changePossession(newActor: ActorHumanoid) {
if (!theGameHasActor(playableActor)) {
if (!theGameHasActor(actorNowPlaying)) {
throw IllegalArgumentException("No such actor in the game: $newActor")
}
playableActor = newActor
WorldSimulator(playableActor, Terrarum.deltaTime)
actorNowPlaying = newActor
WorldSimulator(actorNowPlaying, Terrarum.deltaTime)
}
private fun changePossession(refid: Int) {
@@ -665,11 +666,11 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
ThreadParallel.startAll()
playableActor.update(delta)
actorNowPlaying?.update(delta)
}
else {
actorContainer.forEach {
if (it != playableActor) {
if (it != actorNowPlaying) {
it.update(delta)
if (it is Pocketed) {
@@ -682,7 +683,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
}
}
playableActor.update(delta)
actorNowPlaying?.update(delta)
//AmmoMeterProxy(player, uiVitalItem.UI as UIVitalMetre)
}
}
@@ -734,7 +735,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
* Any values behind the index will be automatically pushed to front.
* This is how remove function of [java.util.ArrayList] is defined.
*/
override fun removeActor(actor: Actor) {
override fun removeActor(actor: Actor?) {
if (actor == null) return
if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
throw RuntimeException("Attempted to remove player.")
val indexToDelete = actorContainer.binarySearch(actor.referenceID!!)
@@ -769,7 +772,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
/**
* Check for duplicates, append actor and sort the list
*/
override fun addNewActor(actor: Actor) {
override fun addNewActor(actor: Actor?) {
if (actor == null) return
if (theGameHasActor(actor.referenceID!!)) {
throw Error("The actor $actor already exists in the game")
}

View File

@@ -16,7 +16,7 @@ internal object AVTracker : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size < 2) {
jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).playableActor))
jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).actorNowPlaying))
}
else {
try {

View File

@@ -15,8 +15,11 @@ internal object ExportAV : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
try {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
JsonWriter.writeToFile(
(Terrarum.ingame!! as Ingame).playableActor.actorValue,
player.actorValue,
Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
Echo("ExportAV: exported to " + args[1] + ".json")

View File

@@ -15,11 +15,13 @@ internal object GetAV : ConsoleCommand {
override fun execute(args: Array<String>) {
try {
val ingame = Terrarum.ingame!! as Ingame
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
if (args.size == 1 && ingame.playableActor != null) {
if (args.size == 1 && player != null) {
// print all actorvalue of player
val av = ingame.playableActor.actorValue
val av = player.actorValue
val keyset = av.keySet
Echo("$ccW== ActorValue list for ${ccY}player $ccW==")
@@ -36,15 +38,15 @@ internal object GetAV : ConsoleCommand {
// check if args[1] is number or not
if (!args[1].isNum()) { // args[1] is ActorValue name
Echo("${ccW}player.$ccM${args[1]} $ccW= " +
ccG +
ingame.playableActor.actorValue[args[1]] +
" $ccO" +
ingame.playableActor.actorValue[args[1]]!!.javaClass.simpleName
ccG +
player.actorValue[args[1]] +
" $ccO" +
player.actorValue[args[1]]!!.javaClass.simpleName
)
println("[GetAV] player.${args[1]} = " +
ingame.playableActor.actorValue[args[1]] +
player.actorValue[args[1]] +
" " +
ingame.playableActor.actorValue[args[1]]!!.javaClass.simpleName
player.actorValue[args[1]]!!.javaClass.simpleName
)
}
else {

View File

@@ -16,7 +16,7 @@ import java.io.IOException
internal object GsonTest : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).playableActor)
val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).actorNowPlaying)
val jsonString = avelem.toString()

View File

@@ -21,7 +21,7 @@ object ImportLayerData : ConsoleCommand {
//val fis = GZIPInputStream(FileInputStream(args[1])) // this gzip is kaput
val fis = FileInputStream(args[1])
(Terrarum.ingame!!.world) = ReadLayerData(fis)
(Terrarum.ingame!! as Ingame).playableActor.setPosition(
(Terrarum.ingame!! as Ingame).actorNowPlaying?.setPosition(
(Terrarum.ingame!!.world).spawnY * FeaturesDrawer.TILE_SIZE.toDouble(),
(Terrarum.ingame!!.world).spawnX * FeaturesDrawer.TILE_SIZE.toDouble()
)

View File

@@ -4,7 +4,6 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame
@@ -14,7 +13,7 @@ import net.torvald.terrarum.modulebasegame.Ingame
*/
internal object Inventory : ConsoleCommand {
private var target: Pocketed? = (Terrarum.ingame!! as Ingame).playableActor
private var target: Pocketed? = (Terrarum.ingame!! as Ingame).actorNowPlaying
override fun execute(args: Array<String>) {
if (args.size == 1) {

View File

@@ -63,9 +63,16 @@ internal object SetAV : ConsoleCommand {
return
}
(Terrarum.ingame!! as Ingame).playableActor.actorValue[args[1]] = newValue
Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue")
println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.")
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) {
EchoError("Player does not exist")
println("[SetAV] Player does not exist")
}
else {
player.actorValue[args[1]] = newValue
Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue")
println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.")
}
}
else if (args.size == 4) {
try {

View File

@@ -14,7 +14,11 @@ internal object SetScale : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2 || args.size == 3) {
try {
val targetID = if (args.size == 3) args[1].toInt() else (Terrarum.ingame!! as Ingame).playableActor.referenceID
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
val targetID = if (args.size == 3) args[1].toInt() else player.referenceID
val scale = args[if (args.size == 3) 2 else 1].toDouble()
val target = Terrarum.ingame!!.getActorByID(targetID!!)

View File

@@ -27,7 +27,7 @@ internal object Teleport : ConsoleCommand {
return
}
(Terrarum.ingame!! as Ingame).playableActor.setPosition(x.toDouble(), y.toDouble())
(Terrarum.ingame!! as Ingame).actorNowPlaying?.setPosition(x.toDouble(), y.toDouble())
}
else if (args.size == 4) {
if (args[2].toLowerCase() != "to") {
@@ -38,8 +38,15 @@ internal object Teleport : ConsoleCommand {
val targetActor: ActorWBMovable
try {
val fromActorID = args[1].toInt()
val targetActorID = if (args[3].toLowerCase() == "player")
(Terrarum.ingame!! as Ingame).playableActor.referenceID!!
val targetActorID = if (args[3].toLowerCase() == "player") {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) {
EchoError("Player does not exist")
return
}
else
player.referenceID!!
}
else
args[3].toInt()

View File

@@ -10,9 +10,13 @@ import net.torvald.terrarum.modulebasegame.Ingame
*/
internal object ToggleNoClip : ConsoleCommand {
override fun execute(args: Array<String>) {
val status = (Terrarum.ingame!! as Ingame).playableActor.isNoClip
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
(Terrarum.ingame!! as Ingame).playableActor.isNoClip = !status
val status = player.isNoClip
player.isNoClip = !status
Echo("Set no-clip status to " + (!status).toString())
}

View File

@@ -84,7 +84,7 @@ class ActorValueTracker constructor() : JFrame() {
buttonChangeActor.addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent?) {
if (actorIDField.text.toLowerCase() == "player") {
actor = (Terrarum.ingame!! as Ingame).playableActor
actor = (Terrarum.ingame!! as Ingame).actorNowPlaying
actorValue = actor!!.actorValue
}
else if (actorIDField.text.isNotBlank()) {

View File

@@ -145,7 +145,7 @@ open class ActorHumanoid(
protected var isRightDown = false
protected var isJumpDown = false
protected inline val isGamer: Boolean
get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.playableActor
get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.actorNowPlaying
private val nullItem = object : GameItem() {

View File

@@ -64,7 +64,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
if (item.originalID == Terrarum.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic
throw IllegalArgumentException("Attempted to put human player into the inventory.")
if (((Terrarum.ingame as? Ingame)?.gameFullyLoaded ?: false) &&
(item.originalID == (Terrarum.ingame as? Ingame)?.playableActor?.referenceID))
(item.originalID == (Terrarum.ingame as? Ingame)?.actorNowPlaying?.referenceID))
throw IllegalArgumentException("Attempted to put active player into the inventory.")
if ((!item.stackable || item.dynamicID in ITEM_DYNAMIC) && count > 1)
throw IllegalArgumentException("Attempting to adding stack of item but the item is not stackable; item: $item, count: $count")

View File

@@ -8,9 +8,10 @@ import net.torvald.terrarum.gameactors.Controllable
* @param actor : here you 'attach' the actor you wish to control
* Created by minjaesong on 2016-10-23.
*/
@Deprecated("The ingame should discriminate 'theRealGamer' and 'actorNowPlaying'")
class PlayableActorDelegate(val actor: ActorHumanoid) {
init {
/*init {
if (actor !is Controllable)
throw IllegalArgumentException("Player must be 'Controllable'!")
}
@@ -27,5 +28,5 @@ class PlayableActorDelegate(val actor: ActorHumanoid) {
// LightmapRenderer.fireRecalculateEvent()
//}
// not going to work: think about stationery tiki torches, global lights, etc
}
}*/
}

View File

@@ -35,7 +35,10 @@ class SmarterSlimes : ActorAI {
// TEST: just target player
val playerXPos = (Terrarum.ingame!! as Ingame).playableActor.centrePosPoint.x
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
val playerXPos = player.centrePosPoint.x
val thisXPos = actor.centrePosPoint.x
val xDiff = thisXPos - playerXPos

View File

@@ -34,11 +34,14 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
}
override fun primaryUse(delta: Float): Boolean {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
val mouseTileX = Terrarum.mouseTileX
val mouseTileY = Terrarum.mouseTileY
val mousePoint = Point2d(mouseTileX.toDouble(), mouseTileY.toDouble())
val actorvalue = (Terrarum.ingame!! as Ingame).playableActor.actorValue
val actorvalue = player.actorValue
using = true
@@ -58,16 +61,19 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
(Terrarum.ingame!!.world).inflictTerrainDamage(
mouseTileX, mouseTileY,
Calculate.pickaxePower((Terrarum.ingame!! as Ingame).playableActor, material) * swingDmgToFrameDmg
Calculate.pickaxePower(player, material) * swingDmgToFrameDmg
)
return true
}
override fun endPrimaryUse(delta: Float): Boolean {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
using = false
// reset action timer to zero
(Terrarum.ingame!! as Ingame).playableActor.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
player.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
return true
}
}

View File

@@ -38,8 +38,8 @@ class UIPieMenu : UICanvas() {
var selection: Int = -1
override fun updateUI(delta: Float) {
if (selection >= 0)
(Terrarum.ingame!! as Ingame).playableActor.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
if (selection >= 0 && (Terrarum.ingame!! as Ingame).actorNowPlaying != null)
(Terrarum.ingame!! as Ingame).actorNowPlaying!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
selection % slotCount
@@ -83,7 +83,11 @@ class UIPieMenu : UICanvas() {
// draw item
val itemPair = (Terrarum.ingame!! as Ingame).playableActor.inventory.getQuickBar(i)
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return // don't draw actual items
val itemPair = player.inventory.getQuickBar(i)
if (itemPair != null) {
val itemImage = ItemCodex.getItemImage(itemPair.item)

View File

@@ -28,8 +28,8 @@ class UIQuickBar : UICanvas() {
private val startPointY = ItemSlotImageBuilder.slotImage.tileH / 2
private var selection: Int
get() = (Terrarum.ingame!! as Ingame).playableActor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { (Terrarum.ingame!! as Ingame).playableActor.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
get() = (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
override fun updateUI(delta: Float) {
}
@@ -54,7 +54,11 @@ class UIQuickBar : UICanvas() {
)
// draw item
val itemPair = (Terrarum.ingame!! as Ingame).playableActor.inventory.getQuickBar(i)
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return // if player is null, don't draw actual items
val itemPair = player.inventory.getQuickBar(i)
if (itemPair != null) {
val itemImage = ItemCodex.getItemImage(itemPair.item)

View File

@@ -5,10 +5,14 @@ import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.random.HQRNG
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.AppLoader.printdbgerr
import net.torvald.terrarum.LoadScreen
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.PlayerBuilderSigrid
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButton
import net.torvald.terrarum.ui.UIItemTextButtonList
@@ -100,6 +104,22 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
throw NullPointerException("No parent node to return")
}
}
else if (it.labelText.contains("Start New Random Game")) {
printdbg(this, 1)
val ingame = Ingame(Terrarum.batch)
ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
ingame.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
printdbg(this, 2)
Terrarum.ingame = ingame
LoadScreen.screenToLoad = ingame
Terrarum.setScreen(LoadScreen)
printdbg(this, 3)
}
else {
// check if target exists
//println("current node: ${currentRemoConContents.data}")

View File

@@ -84,7 +84,9 @@ internal object WeatherMixer : RNGConsumer {
/**
* Part of Ingame update
*/
fun update(delta: Float, player: ActorWithBody) {
fun update(delta: Float, player: ActorWithBody?) {
if (player == null) return
currentWeather = weatherList[WEATHER_GENERIC]!![0]