Actor reference ID on debug window, RefID is now Int, added Japanese on help page

Former-commit-id: 3519b8746d611c4badd65f01644ba05e41d10d04
Former-commit-id: 45bb407c2d932e5d70aab9c9eb4f3ef55ce68d27
This commit is contained in:
Song Minjae
2016-04-16 01:03:19 +09:00
parent f0d2415906
commit 7c6d232ba6
15 changed files with 114 additions and 36 deletions

View File

@@ -156,9 +156,7 @@ constructor() : Font {
override fun getLineHeight() = H
override fun drawString(x: Float, y: Float, s: String) {
drawString(x, y, s, Color.white)
}
override fun drawString(x: Float, y: Float, s: String) = drawString(x, y, s, Color.white)
override fun drawString(x: Float, y: Float, s: String, color: Color) {
GL11.glEnable(GL11.GL_BLEND)
@@ -364,10 +362,13 @@ constructor() : Font {
)*/
sheetKey[prevInstance].getSubImage(sheetX, sheetY).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat() // Interchar: pull punct right next to hangul to the left
+ if (i > 0 && isHangul(s[i - 1])) -3f else 0f,
+ if (i > 0 && isHangul(s[i - 1])) -3f
else 0f,
Math.round(y).toFloat() + (if (prevInstance == SHEET_CJK_PUNCT) -1
else if (prevInstance == SHEET_FW_UNI) (H - H_HANGUL) / 2
else 0).toFloat(),
color
)
}

View File

@@ -0,0 +1,50 @@
package net.torvald.imagefont
import org.newdawn.slick.Color
import org.newdawn.slick.Font
import org.newdawn.slick.SpriteSheet
/**
* Created by minjaesong on 16-04-15.
*/
class SmallNumbers : Font {
internal val fontSheet: SpriteSheet
internal val W = 8
internal val H = 8
private val chars = arrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-')
init {
fontSheet = SpriteSheet("./res/graphics/fonts/numeric_small.png", W, H)
}
override fun getHeight(str: String): Int = H
override fun getWidth(str: String): Int = str.length * W
override fun getLineHeight(): Int = H
override fun drawString(x: Float, y: Float, text: String) = drawString(x, y, text, Color.white)
override fun drawString(x: Float, y: Float, text: String, col: Color) {
for (i in 0..text.length - 1) {
val index = charToSpriteNum(text.codePointAt(i))
if (index != null) {
fontSheet.getSubImage(index, 0).draw(
x + i * W, y, col
)
}
}
}
override fun drawString(x: Float, y: Float, text: String, col: Color, startIndex: Int, endIndex: Int) {
throw UnsupportedOperationException()
}
private fun charToSpriteNum(ch: Int): Int? =
if (ch in '0'.toInt()..'9'.toInt()) ch - '0'.toInt()
else if (ch == '-'.toInt()) 10
else null
}

View File

@@ -172,18 +172,20 @@ constructor() : BasicGameState() {
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
setBlendNormal()
// determine if lightmap blending should be done
Terrarum.gameConfig["smoothlighting"] = KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH)
// set antialias as on
if (!g.isAntiAlias) g.isAntiAlias = true
drawSkybox(g)
// compensate for zoom. UIs have to be treated specially! (see UIHandler)
g.translate(
-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
g.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
MapCamera.renderBehind(gc, g)
// draw actors
actorContainer.forEach { actor -> if (actor is Visible) actor.drawBody(gc, g) }
player.drawBody(gc, g)
@@ -201,9 +203,27 @@ constructor() : BasicGameState() {
setBlendNormal()
// draw actor glows
actorContainer.forEach { actor -> if (actor is Glowing) actor.drawGlow(gc, g) }
player.drawGlow(gc, g)
// draw reference ID if debugWindow is open
if (debugWindow.isVisible) {
actorContainer.forEach { actor ->
if (actor is Visible) {
g.color = Color.white
g.font = Terrarum.smallNumbers
g.drawString(
actor.referenceID.toString(),
actor.hitbox.posX,
actor.hitbox.pointedY + 4
)
g.font = Terrarum.gameFont
}
}
}
// draw UIs
uiContainer.forEach { ui -> ui.render(gc, g) }
debugWindow.render(gc, g)
consoleHandler.render(gc, g)
@@ -287,14 +307,14 @@ constructor() : BasicGameState() {
/**
* actorContainer extensions
*/
fun hasActor(ID: Long): Boolean {
fun hasActor(ID: Int): Boolean {
for (actor in actorContainer) {
if (actor.referenceID == ID) return true
}
return false
}
fun removeActor(ID: Long) {
fun removeActor(ID: Int) {
for (actor in actorContainer) {
if (actor.referenceID == ID)
actorContainer.remove(actor)
@@ -307,7 +327,7 @@ constructor() : BasicGameState() {
return true
}
fun getActor(ID: Long): Actor {
fun getActor(ID: Int): Actor {
for (actor in actorContainer) {
if (actor.referenceID == ID)
return actor

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum
import net.torvald.imagefont.GameFontWhite
import net.torvald.JsonFetcher
import net.torvald.JsonWriter
import net.torvald.imagefont.SmallNumbers
import org.lwjgl.input.Controllers
import org.lwjgl.opengl.GL11
import org.newdawn.slick.*
@@ -46,6 +47,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
@Throws(SlickException::class)
override fun initStatesList(gc: GameContainer) {
gameFont = GameFontWhite()
smallNumbers = SmallNumbers()
hasController = gc.input.controllerCount > 0
if (hasController) {
@@ -100,6 +102,9 @@ constructor(gamename: String) : StateBasedGame(gamename) {
var gameLocale = "" // locale override
lateinit var gameFont: Font
private set
lateinit var smallNumbers: Font
private set
val SCENE_ID_HOME = 1
val SCENE_ID_GAME = 3

View File

@@ -11,9 +11,9 @@ interface Actor {
/**
* Valid RefID is equal to or greater than 32768.
* @return Reference ID. (32768-0x7FFF_FFFF_FFFF_FFFF)
* @return Reference ID. (32768-0xFFFF_FFFF)
*/
var referenceID: Long
var referenceID: Int
var actorValue: ActorValue
}

View File

@@ -23,7 +23,7 @@ class ActorInventory() {
/**
* <ReferenceID, Amounts>
*/
private val itemList: HashMap<Long, Int> = HashMap()
private val itemList: HashMap<Int, Int> = HashMap()
/**
* Default constructor with no encumbrance.
@@ -74,7 +74,7 @@ class ActorInventory() {
* Get reference to the itemList
* @return
*/
fun getItemList(): Map<Long, Int>? {
fun getItemList(): Map<Int, Int>? {
return itemList
}
@@ -83,8 +83,8 @@ class ActorInventory() {
* @return
*/
@Suppress("UNCHECKED_CAST")
fun getCopyOfItemList(): Map<Long, Int>? {
return itemList.clone() as Map<Long, Int>
fun getCopyOfItemList(): Map<Int, Int>? {
return itemList.clone() as Map<Int, Int>
}
fun getTotalWeight(): Float {

View File

@@ -53,11 +53,11 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
internal var baseSpriteWidth: Int = 0
internal var baseSpriteHeight: Int = 0
override var referenceID: Long = 0L
override var referenceID: Int = 0
/**
* Positions: top-left point
*/
val hitbox = Hitbox(0f,0f,0f,0f)
override val hitbox = Hitbox(0f,0f,0f,0f)
@Transient val nextHitbox = Hitbox(0f,0f,0f,0f)
/**
@@ -137,7 +137,7 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
init {
do {
referenceID = HQRNG().nextLong() // set new ID
referenceID = HQRNG().nextInt() // set new ID
} while (Terrarum.game.hasActor(referenceID)) // check for collision
map = Terrarum.game.map

View File

@@ -15,7 +15,7 @@ open class NPCIntelligentBase : ActorWithBody()
, AIControlled, Pocketed, CanBeAnItem, Factionable, LandHolder {
override var itemData: InventoryItem = object : InventoryItem {
override var itemID = HQRNG().nextLong()
override var itemID = HQRNG().nextInt()
override var mass: Float
get() = actorValue.get("mass") as Float
@@ -55,7 +55,7 @@ open class NPCIntelligentBase : ActorWithBody()
private val factionSet = HashSet<Faction>()
override var referenceID: Long = HQRNG().nextLong()
override var referenceID: Int = HQRNG().nextInt()
override var faction: HashSet<Faction> = HashSet()

View File

@@ -79,7 +79,7 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
@Transient internal const val WALK_STOP_ACCEL = 0.32f
@Transient internal const val WALK_ACCEL_BASE = 0.32f
@Transient const val PLAYER_REF_ID: Long = 0x51621D
@Transient const val PLAYER_REF_ID: Int = 0x51621D
@Transient const val BASE_HEIGHT = 40
}

View File

@@ -7,6 +7,8 @@ import org.newdawn.slick.Graphics
* Created by minjaesong on 16-03-14.
*/
interface Visible {
val hitbox: Hitbox
fun drawBody(gc: GameContainer, g: Graphics)
fun updateBodySprite(gc: GameContainer, delta: Int)

View File

@@ -12,7 +12,7 @@ interface InventoryItem {
* 4097-32767: Various items
* >=32768: Actor RefID
*/
var itemID: Long
var itemID: Int
/**
* Weight of the item, Float

View File

@@ -8,12 +8,12 @@ import org.newdawn.slick.GameContainer
*/
class TileAsItem(tileNum: Int) : InventoryItem {
override var itemID: Long = -1
override var itemID: Int = 0
override var mass: Float = 0f
override var scale: Float = 1f
init {
itemID = tileNum.toLong()
itemID = tileNum
mass = TilePropCodex.getProp(tileNum).density / 1000f
}

View File

@@ -29,9 +29,9 @@ object ItemPropCodex {
}
fun getItem(code: Long): InventoryItem {
fun getItem(code: Int): InventoryItem {
if (code < ITEM_UNIQUE_MAX)
return itemCodex[(code and 0xFFFFFFFF).toInt()]
return itemCodex[code]
else {
for (actor in Terrarum.game.actorContainer) {
if (actor is CanBeAnItem && actor.referenceID == code)