mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
shorter share code if allowed; flickering teleporter beams
This commit is contained in:
Binary file not shown.
@@ -34,6 +34,10 @@ abstract class SpriteAnimation(@Transient val parentActor: ActorWithBody) : Disp
|
||||
|
||||
/**
|
||||
* This class should not be serialised; save its Animation Description Language instead.
|
||||
*
|
||||
* Maximum rows: 64
|
||||
*
|
||||
* Maximum frames: unlimited
|
||||
*/
|
||||
class SheetSpriteAnimation(parentActor: ActorWithBody) : SpriteAnimation(parentActor) {
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.random.XXHash64
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
@@ -48,7 +50,7 @@ class FixtureWorldPortal : Electric {
|
||||
density = 2900.0
|
||||
setHitboxDimension(80, 32, 0, 0)
|
||||
makeNewSprite(TextureRegionPack(itemImage.texture, 80, 32)).let {
|
||||
it.setRowsAndFrames(1,1)
|
||||
it.setRowsAndFrames(1,3)
|
||||
}
|
||||
|
||||
actorValue[AVKey.BASEMASS] = FixtureLogicSignalEmitter.MASS
|
||||
@@ -58,8 +60,9 @@ class FixtureWorldPortal : Electric {
|
||||
|
||||
@Transient internal var teleportRequest: TeleportRequest? = null
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
(sprite as SheetSpriteAnimation).currentFrame = (Math.random() * 3).toInt()
|
||||
super.drawBody(batch)
|
||||
}
|
||||
|
||||
override fun onRisingEdge(readFrom: BlockBoxIndex) {
|
||||
|
||||
@@ -7,7 +7,9 @@ import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.imagefont.BigAlphNum
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.serialise.toBig64
|
||||
import net.torvald.terrarum.serialise.toUint
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.utils.PasswordBase32
|
||||
@@ -28,15 +30,9 @@ class UIShare : UICanvas() {
|
||||
}
|
||||
|
||||
private var shareCode = ""
|
||||
private var dash = ' '
|
||||
|
||||
override fun show() {
|
||||
shareCode = PasswordBase32.encode(
|
||||
INGAME.world.worldIndex.mostSignificantBits.toBig64() +
|
||||
INGAME.world.worldIndex.leastSignificantBits.toBig64()
|
||||
).let {
|
||||
"${it.substring(0..3)}$dash${it.substring(4..5)}$dash${it.substring(6..10)}$dash${it.substring(11..15)}$dash${it.substring(16..20)}$dash${it.substring(21)}"
|
||||
}
|
||||
shareCode = Common.encodeUUID(INGAME.world.worldIndex)
|
||||
|
||||
App.printdbg(this, shareCode)
|
||||
App.printdbg(this, INGAME.world.worldIndex)
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
|
||||
import net.torvald.terrarum.imagefont.BigAlphNum
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.serialise.toBig64
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
@@ -47,15 +48,10 @@ class UIWorldPortalShare(private val full: UIWorldPortal) : UICanvas() {
|
||||
}
|
||||
|
||||
private var shareCode = ""
|
||||
private var dash = ' '
|
||||
|
||||
override fun show() {
|
||||
shareCode = PasswordBase32.encode(
|
||||
INGAME.world.worldIndex.mostSignificantBits.toBig64() +
|
||||
INGAME.world.worldIndex.leastSignificantBits.toBig64()
|
||||
).let {
|
||||
"${it.substring(0..3)}$dash${it.substring(4..5)}$dash${it.substring(6..10)}$dash${it.substring(11..15)}$dash${it.substring(16..20)}$dash${it.substring(21)}"
|
||||
}
|
||||
shareCode = Common.encodeUUID(INGAME.world.worldIndex)
|
||||
|
||||
|
||||
printdbg(this, shareCode)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.printStackTrace
|
||||
import net.torvald.terrarum.savegame.VirtualDisk
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.serialise.toBigInt64
|
||||
import net.torvald.terrarum.ui.*
|
||||
import net.torvald.terrarum.utils.PasswordBase32
|
||||
@@ -68,10 +69,7 @@ class UIWorldPortalUseInvitation(val full: UIWorldPortal) : UICanvas() {
|
||||
{ Lang["MENU_LABEL_CONFIRM_BUTTON"] }, buttonBaseX + (goButtonWidth + gridGap) * 2, buttonY, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also {
|
||||
|
||||
it.clickOnceListener = { _, _ ->
|
||||
val code = codeInput.getText().replace(" ", "")
|
||||
val uuid = PasswordBase32.decode(code, 16).let {
|
||||
UUID(it.toBigInt64(0), it.toBigInt64(8))
|
||||
}
|
||||
val uuid = Common.decodeToUUID(codeInput.getText())
|
||||
val world = App.savegameWorlds[uuid]
|
||||
|
||||
App.printdbg(this, "Decoded UUID=$uuid")
|
||||
|
||||
@@ -503,6 +503,70 @@ object Common {
|
||||
return ByteArray64Reader(strToBytes(StringReader(s)), CHARSET).readText()
|
||||
}
|
||||
|
||||
fun encodeUUID(uuid: UUID): String {
|
||||
val dash = ' '
|
||||
val useShort = (uuid.mostSignificantBits.and(0xF000L) == 0x4000L && uuid.leastSignificantBits.ushr(62) == 0b10L)
|
||||
|
||||
/*(uuid.mostSignificantBits.toBig64() + uuid.leastSignificantBits.toBig64()).forEach {
|
||||
print("${it.toUint().toString(2).padStart(8,'0')} ")
|
||||
}
|
||||
println()*/
|
||||
|
||||
val bytes = if (useShort) {
|
||||
(uuid.mostSignificantBits.toBig64() +
|
||||
uuid.leastSignificantBits.toBig64()).let {
|
||||
it.sliceArray(0..5) +
|
||||
(it[6].toUint().and(15).shl(4) or it[8].toUint().and(0x0F)).toByte() +
|
||||
it[7] +
|
||||
it.sliceArray(9..15) +
|
||||
(it[8].toUint().and(0x30).shl(2)).toByte()
|
||||
}
|
||||
}
|
||||
else {
|
||||
uuid.mostSignificantBits.toBig64() +
|
||||
uuid.leastSignificantBits.toBig64()
|
||||
}
|
||||
|
||||
/*bytes.forEach {
|
||||
print("${it.toUint().toString(2).padStart(8,'0')} ")
|
||||
}
|
||||
println()*/
|
||||
|
||||
return PasswordBase32.encode(bytes).let {
|
||||
if (useShort)
|
||||
"${it.substring(0..4)} ${it.substring(5..9)} ${it.substring(10..14)} ${it.substring(15..19)} ${it.substring(20..24)}"
|
||||
else
|
||||
"${it.substring(0..3)}$dash${it.substring(4..5)}$dash${it.substring(6..10)}$dash${it.substring(11..15)}$dash${it.substring(16..20)}$dash${it.substring(21)}"
|
||||
}
|
||||
}
|
||||
|
||||
fun decodeToUUID(str: String): UUID {
|
||||
val code = str.replace(" ", "").trim()
|
||||
val b = PasswordBase32.decode(code + (if (code.length == 25) "Y" else ""), 16)
|
||||
|
||||
/*b.forEach {
|
||||
print("${it.toUint().toString(2).padStart(8,'0')} ")
|
||||
}
|
||||
println()*/
|
||||
|
||||
val bytes = if (code.length == 25) {
|
||||
val b6 = b[6].toUint()
|
||||
val jh = b[15].toUint().ushr(2) // 0b JJ00 0000 -> 0b 00JJ 0000
|
||||
b.sliceArray(0..5) +
|
||||
(b6.and(0xF0).ushr(4) or 0x40).toByte() +
|
||||
b[7] +
|
||||
(b6.and(0x0F) or jh or 0x80).toByte() +
|
||||
b.sliceArray(8..14)
|
||||
}
|
||||
else b
|
||||
|
||||
/*bytes.forEach {
|
||||
print("${it.toUint().toString(2).padStart(8,'0')} ")
|
||||
}
|
||||
println()*/
|
||||
|
||||
return UUID(bytes.toBigInt64(0), bytes.toBigInt64(8))
|
||||
}
|
||||
}
|
||||
|
||||
class SaveLoadError(file: File?, cause: Throwable) : RuntimeException("An error occured while loading save file '${file?.absolutePath}'", cause)
|
||||
Binary file not shown.
Reference in New Issue
Block a user