mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
completely abolishing GSON; new save format impl wip
This commit is contained in:
@@ -2,13 +2,12 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.random.Fudge3
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import com.google.gson.JsonObject
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.ActorValue
|
||||
import java.security.SecureRandom
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-03-25.
|
||||
@@ -27,46 +26,44 @@ object InjectCreatureRaw {
|
||||
operator fun invoke(actorValueRef: ActorValue, module: String, jsonFileName: String) {
|
||||
val jsonObj = JsonFetcher(ModMgr.getPath(module, "creatures/$jsonFileName"))
|
||||
|
||||
jsonObj.keySet().filter { !it.startsWith("_") }.forEach { key ->
|
||||
|
||||
JsonFetcher.forEach(jsonObj) { key, value -> if (!key.startsWith("_")) {
|
||||
val diceRollers = ArrayList<String>()
|
||||
|
||||
jsonObj[key].let {
|
||||
if (it.isJsonPrimitive) {
|
||||
val raw = it.asString
|
||||
val lowraw = raw.toLowerCase()
|
||||
// can the value be cast to Boolean?
|
||||
if (lowraw == "true") actorValueRef[key] = true
|
||||
else if (lowraw == "false") actorValueRef[key] = false
|
||||
else {
|
||||
try {
|
||||
actorValueRef[key] =
|
||||
if (raw.contains('.')) it.asDouble
|
||||
else it.asInt
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
actorValueRef[key] = raw
|
||||
}
|
||||
if (!value.isArray && !value.isObject) {
|
||||
val raw = value.asString()
|
||||
val lowraw = raw.lowercase()
|
||||
// can the value be cast to Boolean?
|
||||
if (lowraw == "true") actorValueRef[key] = true
|
||||
else if (lowraw == "false") actorValueRef[key] = false
|
||||
else {
|
||||
try {
|
||||
actorValueRef[key] =
|
||||
if (raw.contains('.')) value.asDouble()
|
||||
else value.asLong().toInt()
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
actorValueRef[key] = raw
|
||||
}
|
||||
}
|
||||
else if (key.endsWith(JSONMULT) && it.isJsonArray) {
|
||||
diceRollers.add(key)
|
||||
}
|
||||
else {
|
||||
printdbg(this, "Unknown Creature Raw key: $key")
|
||||
}
|
||||
}
|
||||
else if (key.endsWith(JSONMULT) && value.isArray) {
|
||||
diceRollers.add(key)
|
||||
}
|
||||
else {
|
||||
printdbg(this, "Unknown Creature Raw key: $key")
|
||||
}
|
||||
|
||||
diceRollers.forEach { keymult ->
|
||||
val keybase = keymult.substring(0, keymult.length - 4)
|
||||
val baseValue = jsonObj[keybase].asDouble
|
||||
val baseValue = jsonObj[keybase].asDouble()
|
||||
val selected = Fudge3(SecureRandom()).rollForArray()
|
||||
val mult = jsonObj[keymult].asJsonArray.get(selected).asInt
|
||||
val mult = jsonObj[keymult].asIntArray()[selected]
|
||||
val realValue = baseValue * mult / 100.0
|
||||
|
||||
actorValueRef[keybase] = realValue
|
||||
actorValueRef[keybase + BUFF] = 1.0
|
||||
}
|
||||
}
|
||||
} }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user