From b0b1d185ad2500a891b9e82d3f1218fba66f8e76 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 26 Oct 2021 22:54:46 +0900 Subject: [PATCH] barehand action will not remove fixtures (more pricisely, actorblocks) --- src/net/torvald/UniTextShortcuts.kt | 47 ++++++++++++++++++- .../torvald/terrarum/blockproperties/Block.kt | 1 + .../terrarum/modulebasegame/TerrarumIngame.kt | 2 +- .../gameitems/PickaxeGeneric.kt | 8 +++- .../terrarum/modulebasegame/ui/UINewWorld.kt | 6 +-- .../terrarum/ui/UIItemTextLineInput.kt | 5 +- 6 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/net/torvald/UniTextShortcuts.kt b/src/net/torvald/UniTextShortcuts.kt index b54ac18de..c9925f593 100644 --- a/src/net/torvald/UniTextShortcuts.kt +++ b/src/net/torvald/UniTextShortcuts.kt @@ -1,5 +1,7 @@ package net.torvald +import net.torvald.terrarum.savegame.ByteArray64 + /** * Created by minjaesong on 2019-08-05. */ @@ -27,4 +29,47 @@ fun getKeycapFkeys(n: Int) = when (n) { in 1..9 -> "\uE090${(0xE090 + n).toChar()}" in 10..12 -> "\uE09D${(0xE090 + n).toChar()}" else -> throw IllegalArgumentException("Not in range: $n") -} \ No newline at end of file +} + +fun List.toJavaString(): String { + val sb = StringBuilder() + this.forEach { + if (it > 65535) { + val u = it - 65536 + sb.append((0xD800 or (u ushr 10).and(1023)).toChar()) + sb.append((0xDC00 or (u and 1023)).toChar()) + } + else { + sb.append(it.toChar()) + } + } + return sb.toString() +} + +fun List.toUTF8Bytes64(): ByteArray64 { + val ba = ByteArray64() + this.forEach { codepoint -> + when (codepoint) { + in 0..127 -> ba.add(codepoint.toByte()) + in 128..2047 -> { + ba.add((0xC0 or codepoint.ushr(6).and(31)).toByte()) + ba.add((0x80 or codepoint.and(63)).toByte()) + } + in 2048..65535 -> { + ba.add((0xE0 or codepoint.ushr(12).and(15)).toByte()) + ba.add((0x80 or codepoint.ushr(6).and(63)).toByte()) + ba.add((0x80 or codepoint.and(63)).toByte()) + } + in 65536..1114111 -> { + ba.add((0xF0 or codepoint.ushr(18).and(7)).toByte()) + ba.add((0x80 or codepoint.ushr(12).and(63)).toByte()) + ba.add((0x80 or codepoint.ushr(6).and(63)).toByte()) + ba.add((0x80 or codepoint.and(63)).toByte()) + } + else -> throw IllegalArgumentException("Not a unicode code point: U+${codepoint.toString(16).toUpperCase()}") + } + } + return ba +} + +fun List.toUTF8Bytes() = this.toUTF8Bytes64().toByteArray() \ No newline at end of file diff --git a/src/net/torvald/terrarum/blockproperties/Block.kt b/src/net/torvald/terrarum/blockproperties/Block.kt index faa4d6e93..17ea34209 100644 --- a/src/net/torvald/terrarum/blockproperties/Block.kt +++ b/src/net/torvald/terrarum/blockproperties/Block.kt @@ -132,6 +132,7 @@ object Block { const val NULL = "basegame:-1" val actorblocks = listOf( + ACTORBLOCK_TILING_PLACEHOLDER, ACTORBLOCK_NO_COLLISION, ACTORBLOCK_FULL_COLLISION, ACTORBLOCK_ALLOW_MOVE_DOWN, diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index 654ff1531..5a6170572 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -1220,7 +1220,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { // else, punch a block val punchBlockSize = punchSize.div(TILE_SIZED).floorInt() if (punchBlockSize > 0) { - PickaxeCore.startPrimaryUse(actor, delta, null, Terrarum.mouseTileX, Terrarum.mouseTileY, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize) + PickaxeCore.startPrimaryUse(actor, delta, null, Terrarum.mouseTileX, Terrarum.mouseTileY, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize, false) } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt index 627f6b29b..c98723e0e 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt @@ -26,7 +26,10 @@ object PickaxeCore { * @param mw width of the digging * @param mh height of the digging */ - fun startPrimaryUse(actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int, dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1) = inInteractableRange(actor) { + fun startPrimaryUse( + actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int, + dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1, attackActorBlocks: Boolean = true + ) = inInteractableRange(actor) { // un-round the mx val ww = INGAME.world.width val apos = actor.centrePosPoint @@ -50,6 +53,7 @@ object PickaxeCore { val mousePoint = Point2d(x.toDouble(), y.toDouble()) val actorvalue = actor.actorValue + val tile = (INGAME.world).getTileFromTerrain(x, y) item?.using = true @@ -64,7 +68,7 @@ object PickaxeCore { if (!ret1) return ret1*/ // return false if here's no tile - if (Block.AIR == (INGAME.world).getTileFromTerrain(x, y)) { + if (Block.AIR == tile || (!attackActorBlocks && tile in Block.actorblocks)) { usageStatus = usageStatus or false continue } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt index 7b0fc08f8..0ee169f77 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt @@ -70,15 +70,15 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() { tex.forEach { it.flip(false, true) } goButton.touchDownListener = { _, _, _, _ -> - printdbg(this, "generate!") + printdbg(this, "generate! Size=${sizeSelector.selection}, Name=${nameInput.getTextOrPlaceholder()}, Seed=${seedInput.getTextOrPlaceholder()}") } backButton.touchDownListener = { _, _, _, _ -> printdbg(this, "back!") } addUIitem(sizeSelector) - addUIitem(nameInput) - addUIitem(seedInput) + addUIitem(seedInput) // order is important + addUIitem(nameInput) // because of the IME candidates overlay addUIitem(goButton) addUIitem(backButton) } diff --git a/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt b/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt index 9dd03109c..40315c307 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt @@ -14,6 +14,7 @@ import net.torvald.terrarum.gamecontroller.TerrarumInputMethod import net.torvald.terrarum.utils.Clipboard import net.torvald.terrarumsansbitmap.gdx.CodepointSequence import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import net.torvald.toJavaString import kotlin.streams.toList data class InputLenCap(val count: Int, val unit: CharLenUnit) { @@ -336,7 +337,7 @@ class UIItemTextLineInput( } private fun textbufToString(): String { - return "" + return textbuf.toJavaString() } override fun render(batch: SpriteBatch, camera: Camera) { @@ -457,7 +458,7 @@ class UIItemTextLineInput( } fun getText() = textbufToString() - fun getTextOrPlaceholder() = if (textbuf.isEmpty()) currentPlaceholderText else getText() + fun getTextOrPlaceholder(): String = if (textbuf.isEmpty()) currentPlaceholderText.toJavaString() else getText() override fun dispose() { fbo.dispose()