still WIP inventory impl, held item impl

Former-commit-id: 9468cfae21ff09c3dd30352a849910364e01d780
Former-commit-id: 50247ccebf3284f739877a1d6c6d8574449a9824
This commit is contained in:
Song Minjae
2016-12-14 00:28:42 +09:00
parent 22bb5d83e1
commit 1dd156d172
22 changed files with 126 additions and 116 deletions

View File

@@ -20,9 +20,9 @@ object WriteCSV {
val META_FILENAME_MAT = "worldinfo4"
fun write(saveDirectoryName: String): Boolean {
val tileCSV = CSVFetcher.readCSVasString(TilePropCodex.CSV_PATH)
val itemCSV = CSVFetcher.readCSVasString(ItemPropCodex.CSV_PATH)
val matCSV = CSVFetcher.readCSVasString(MaterialPropCodex.CSV_PATH)
//val tileCSV = CSVFetcher.readCSVasString(TilePropCodex.CSV_PATH)
//val itemCSV = CSVFetcher.readCSVasString(ItemPropCodex.CSV_PATH)
//val matCSV = CSVFetcher.readCSVasString(MaterialPropCodex.CSV_PATH)
val pathTile = Paths.get("${Terrarum.defaultSaveDir}" +
"/$saveDirectoryName/${META_FILENAME_TILE}")
@@ -37,9 +37,9 @@ object WriteCSV {
// TODO gzip
// write CSV to path
Files.write(tempPathTile, tileCSV.toByteArray(Charsets.UTF_8))
Files.write(tempPathItem, itemCSV.toByteArray(Charsets.UTF_8))
Files.write(tempPathMat, matCSV.toByteArray(Charsets.UTF_8))
//Files.write(tempPathTile, tileCSV.toByteArray(Charsets.UTF_8))
//Files.write(tempPathItem, itemCSV.toByteArray(Charsets.UTF_8))
//Files.write(tempPathMat, matCSV.toByteArray(Charsets.UTF_8))
// replace savemeta with tempfile
try {

View File

@@ -5,6 +5,7 @@ import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.itemproperties.ItemPropCodex
import net.torvald.terrarum.itemproperties.MaterialPropCodex
import net.torvald.terrarum.tileproperties.TilePropCSV
import net.torvald.terrarum.tileproperties.TilePropCodex
import org.apache.commons.codec.digest.DigestUtils
import java.io.FileInputStream
@@ -42,24 +43,17 @@ object WriteMeta {
val savenameAsByteArray: ByteArray =
(savegameName ?: saveDirectoryName).toByteArray(Charsets.UTF_8)
// define files to get hash
val fileArray: Array<File> = arrayOf(
File(TilePropCodex.CSV_PATH)
, File(ItemPropCodex.CSV_PATH)
, File(MaterialPropCodex.CSV_PATH)
//,
// define Strings to be hashed
val props = arrayOf(
TilePropCSV.text
//, (item, mat, ...)
)
// get and store hash from fileArray
for (file in fileArray) {
val inputStream = FileInputStream(file)
val hash = DigestUtils.sha256(inputStream)
hashArray.add(hash)
}
// get and store hash from the list
props.map { hashArray.add(DigestUtils.sha256(it)) }
// open file and delete it
val metaPath = Paths.get("${Terrarum.defaultSaveDir}" +
val metaPath = Paths.get("$Terrarum.defaultSaveDir" +
"/$saveDirectoryName/$META_FILENAME")
val metaTempPath = Files.createTempFile(metaPath.toString(), "_temp")

View File

@@ -188,8 +188,8 @@ constructor() : BasicGameState() {
///////////////////////////
// input-related updates //
///////////////////////////
GameController.processInput(gc.input)
uiContainer.forEach { it.processInput(gc.input) }
GameController.processInput(gc, delta, gc.input)
uiContainer.forEach { it.processInput(gc, delta, gc.input) }
////////////////////////////

View File

@@ -149,7 +149,7 @@ class StateMonitorCheck : BasicGameState() {
}
override fun processInput(input: Input) {
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
}
override fun doOpening(gc: GameContainer, delta: Int) {

View File

@@ -6,6 +6,7 @@ import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gamecontroller.EnumKeyFunc
import net.torvald.terrarum.gamecontroller.KeyMap
import net.torvald.terrarum.gameitem.InventoryItem
import net.torvald.terrarum.realestate.RealEstateUtility
import org.dyn4j.geometry.Vector2
import org.lwjgl.input.Controller
@@ -25,6 +26,12 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
/** Must be set by PlayerFactory */
override var inventory: ActorInventory = ActorInventory()
override var itemHolding: InventoryItem
get() = throw TODO("itemHolding")
set(value) {
throw TODO("itemHolding")
}
/** Must be set by PlayerFactory */
override var faction: HashSet<Faction> = HashSet()
/**
@@ -126,7 +133,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
protected var isRightDown = false
protected var isJumpDown = false
protected val isGamer: Boolean
get() = this is Player
get() = this is Player // FIXME true iff composed by PlayableActorDelegate
override fun update(gc: GameContainer, delta: Int) {
@@ -174,7 +181,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
}
}
override fun processInput(input: Input) {
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
if (isGamer && Terrarum.hasController) {
gamepad = Controllers.getController(0)
axisX = gamepad!!.getAxisValue(0)
@@ -189,6 +196,24 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
if (Math.abs(axisRY) < Terrarum.CONTROLLER_DEADZONE) axisRY = 0f
}
///////////////////
// MOUSE CONTROL //
///////////////////
// PRIMARY/SECONDARY IS FIXED TO LEFT/RIGHT BUTTON //
/**
* Primary Use
*/
// Left mouse
if (isGamer && input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
itemHolding.primaryUse(gc, delta)
}
// Right mouse
if (isGamer && input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
itemHolding.secondaryUse(gc, delta)
}
/**
* L-R stop
*/

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import org.dyn4j.geometry.Vector2
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input
/**
@@ -10,7 +11,7 @@ import org.newdawn.slick.Input
*/
interface Controllable {
fun processInput(input: Input)
fun processInput(gc: GameContainer, delta: Int, input: Input)
fun keyPressed(key: Int, c: Char)

View File

@@ -26,7 +26,7 @@ class DroppedItem(private val item: InventoryItem) : ActorWithBody() {
}
override fun update(gc: GameContainer, delta: Int) {
item.worldActorEffect(gc, delta)
item.effectWhenTakenOut(gc, delta)
}
override fun drawBody(gc: GameContainer, g: Graphics) {

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameactors.ActorHumanoid
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input
/**
@@ -16,8 +17,8 @@ class PlayableActorDelegate(val actor: ActorHumanoid) {
throw IllegalArgumentException("Player must be 'Controllable'!")
}
fun processInput(input: Input) {
(actor as Controllable).processInput(input)
fun processInput(gc: GameContainer, delta: Int, input: Input) {
(actor as Controllable).processInput(gc, delta, input)
}
fun keyPressed(key: Int, c: Char) {

View File

@@ -1,5 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameitem.InventoryItem
/**
* Created by minjaesong on 16-01-15.
*/
@@ -7,4 +9,7 @@ interface Pocketed {
var inventory: ActorInventory
/** Item currentry holding, like tools/weapons/scrolls/magic/etc. */
var itemHolding: InventoryItem
}

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.tileproperties.TileNameCode
import net.torvald.terrarum.tileproperties.TilePropCodex
import net.torvald.terrarum.ui.UIHandler
import org.dyn4j.geometry.Vector2
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input
/**
@@ -17,38 +18,45 @@ import org.newdawn.slick.Input
*/
object GameController {
val mouseX: Float
// these four values can also be accessed with GameContainer.<varname>
// e.g. gc.mouseTileX
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
internal val mouseX: Float
get() = (MapCamera.cameraX + Terrarum.appgc.input.mouseX / Terrarum.ingame.screenZoom)
val mouseY: Float
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise)*/
internal val mouseY: Float
get() = (MapCamera.cameraY + Terrarum.appgc.input.mouseY / Terrarum.ingame.screenZoom)
val mouseTileX: Int
/** currently pointing tile coordinate */
internal val mouseTileX: Int
get() = (mouseX / MapDrawer.TILE_SIZE).toInt()
val mouseTileY: Int
/** currently pointing tile coordinate */
internal val mouseTileY: Int
get() = (mouseY / MapDrawer.TILE_SIZE).toInt()
fun processInput(input: Input) {
fun processInput(gc: GameContainer, delta: Int, input: Input) {
KeyToggler.update(input)
if (!Terrarum.ingame.consoleHandler.isTakingControl) {
if (Terrarum.ingame.player is Player && (Terrarum.ingame.player as Player).vehicleRiding != null) {
(Terrarum.ingame.player as Player).vehicleRiding!!.processInput(input)
(Terrarum.ingame.player as Player).vehicleRiding!!.processInput(gc, delta, input)
}
Terrarum.ingame.player.processInput(input)
Terrarum.ingame.player.processInput(gc, delta, input)
for (ui in Terrarum.ingame.uiContainer) {
ui.processInput(input)
ui.processInput(gc, delta, input)
}
}
else {
Terrarum.ingame.consoleHandler.processInput(input)
Terrarum.ingame.consoleHandler.processInput(gc, delta, input)
}
if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
// test tile remove
// test tile remove
/*if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
try {
Terrarum.ingame.world.setTileTerrain(mouseTileX, mouseTileY, TileNameCode.AIR)
// terrarum.game.map.setTileWall(mouseTileX, mouseTileY, TileNameCode.AIR);
@@ -58,8 +66,8 @@ object GameController {
}
// test tile place
else if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
// test tile place
try {
Terrarum.ingame.world.setTileTerrain(
mouseTileX, mouseTileY,
@@ -69,7 +77,22 @@ object GameController {
catch (e: ArrayIndexOutOfBoundsException) {
}
}
}*/
///////////////////
// MOUSE CONTROL //
///////////////////
// PRIMARY/SECONDARY IS FIXED TO LEFT/RIGHT BUTTON //
/////////////////////
// GAMEPAD CONTROL //
/////////////////////
}
fun keyPressed(key: Int, c: Char) {
@@ -109,13 +132,14 @@ object GameController {
}
fun mousePressed(button: Int, x: Int, y: Int) {
if (button == 0) {
// bullet test
/*if (button == 0) {
Terrarum.ingame.addActor(ProjectileSimple(
0,
Terrarum.ingame.player.centrePosition,
Vector2(mouseX.toDouble(), mouseY.toDouble())
))
}
}*/
}
fun mouseReleased(button: Int, x: Int, y: Int) {
@@ -138,3 +162,16 @@ object GameController {
return KeyMap.getKeyCode(fn) == key
}
}
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
val GameContainer.mouseX: Float
get() = GameController.mouseX
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
val GameContainer.mouseY: Float
get() = GameController.mouseY
/** currently pointing tile coordinate */
val GameContainer.mouseTileX: Int
get() = GameController.mouseTileX
/** currently pointing tile coordinate */
val GameContainer.mouseTileY: Int
get() = GameController.mouseTileY

View File

@@ -13,13 +13,6 @@ import org.newdawn.slick.GameContainer
* Created by minjaesong on 16-09-08.
*/
open class DynamicItem(val baseItemID: Int, val newMass: Double? = null, val newScale: Double? = null) : InventoryItem {
/**
* Effects applied (continuously or not) while thrown to the world,
* called by the proxy Actor
*/
override fun worldActorEffect(gc: GameContainer, delta: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
/**
* Internal ID of an Item, Long

View File

@@ -1,54 +0,0 @@
package net.torvald.terrarum.gameitem
import net.torvald.terrarum.tileproperties.TilePropCodex
import org.newdawn.slick.GameContainer
/**
* Created by minjaesong on 16-03-15.
*/
class TileAsItem(tileNum: Int) : InventoryItem {
override var itemID: Int = 0
override var mass: Double = 0.0
override var scale: Double = 1.0
init {
itemID = tileNum
mass = TilePropCodex.getProp(tileNum).density / 1000.0
}
override fun effectWhileInPocket(gc: GameContainer, delta_t: Int) {
throw UnsupportedOperationException()
}
override fun effectWhenPickedUp(gc: GameContainer, delta_t: Int) {
throw UnsupportedOperationException()
}
override fun primaryUse(gc: GameContainer, delta_t: Int) {
throw UnsupportedOperationException()
}
override fun secondaryUse(gc: GameContainer, delta_t: Int) {
throw UnsupportedOperationException()
}
override fun effectWhenThrown(gc: GameContainer, delta_t: Int) {
throw UnsupportedOperationException()
}
/**
* Effects applied (continuously or not) while thrown to the world
*/
override fun effectWhenTakenOut(gc: GameContainer, delta: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
/**
* Effects applied (continuously or not) while thrown to the world,
* called by the proxy Actor
*/
override fun worldActorEffect(gc: GameContainer, delta: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}

View File

@@ -5,6 +5,8 @@ import net.torvald.terrarum.KVHashMap
import net.torvald.terrarum.gameactors.CanBeAnItem
import net.torvald.terrarum.gameitem.InventoryItem
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gamecontroller.mouseTileX
import net.torvald.terrarum.gamecontroller.mouseTileY
import net.torvald.terrarum.gameitem.InventoryItemAdapter
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.tileproperties.TileProp
@@ -46,7 +48,13 @@ object ItemPropCodex {
}
override fun secondaryUse(gc: GameContainer, delta: Int) {
// TODO place block to the world
// TODO check if occupied by ANY ActorWithBodies
Terrarum.ingame.world.setTileTerrain(
gc.mouseTileX,
gc.mouseTileY,
i
)
}
}
}

View File

@@ -40,7 +40,7 @@ class BasicDebugInfoWindow : UICanvas {
val ccR = GameFontBase.colToCode["r"]
val ccM = GameFontBase.colToCode["m"]
override fun processInput(input: Input) {
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
}

View File

@@ -128,7 +128,7 @@ class ConsoleWindow : UICanvas, KeyboardControlled {
}
override fun processInput(input: Input) {
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
}

View File

@@ -85,7 +85,7 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
}
}
override fun processInput(input: Input) {
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
}

View File

@@ -67,7 +67,7 @@ constructor() : UICanvas {
handler!!.opacity = 0f
}
override fun processInput(input: Input) {
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
}
fun sendNotification(message: Array<String>) {

View File

@@ -28,7 +28,7 @@ interface UICanvas {
fun render(gc: GameContainer, g: Graphics)
fun processInput(input: Input)
fun processInput(gc: GameContainer, delta: Int, input: Input)
/**
* Do not modify handler!!.openCloseCounter here.

View File

@@ -190,9 +190,9 @@ constructor(val UI: UICanvas) {
}
}
fun processInput(input: Input) {
fun processInput(gc: GameContainer, delta: Int, input: Input) {
if (isVisible) {
UI.processInput(input)
UI.processInput(gc, delta, input)
}
}

View File

@@ -68,7 +68,7 @@ class UIPieMenu : UICanvas {
}
}
override fun processInput(input: Input) {
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
if (handler!!.isOpened || handler!!.isOpening) {
val cursorPos = Vector2(input.mouseX.toDouble(), input.mouseY.toDouble())
val centre = Vector2(Terrarum.WIDTH / 2.0, Terrarum.HEIGHT / 2.0)

View File

@@ -51,7 +51,7 @@ class UIQuickBar : UICanvas, MouseControlled {
}
}
override fun processInput(input: Input) {
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
}
override fun doOpening(gc: GameContainer, delta: Int) {

View File

@@ -61,7 +61,7 @@ class UITextTerminal(val terminal: Terminal) : UICanvas, KeyboardControlled, Mou
terminal.render(gc, terminalDisplay.graphics)
}
override fun processInput(input: Input) {
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
}
/**