From 046698ddc554437d6d875a6d7eadbe9dea0e4af9 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 28 Mar 2023 19:07:26 +0700 Subject: [PATCH] root.npcConfig --- .../ru/dbotthepony/kstarbound/Starbound.kt | 19 ++++++++++++++++++- .../kstarbound/defs/npc/NpcTypeDefinition.kt | 9 +++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/npc/NpcTypeDefinition.kt diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index a5814847..2e26f922 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -30,6 +30,7 @@ import ru.dbotthepony.kstarbound.defs.item.ItemPrototype import ru.dbotthepony.kstarbound.defs.item.LegsArmorItemPrototype import ru.dbotthepony.kstarbound.defs.item.LiquidItemPrototype import ru.dbotthepony.kstarbound.defs.item.MaterialItemPrototype +import ru.dbotthepony.kstarbound.defs.npc.NpcTypeDefinition import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition import ru.dbotthepony.kstarbound.defs.particle.ParticleDefinition import ru.dbotthepony.kstarbound.defs.player.BlueprintLearnList @@ -119,6 +120,9 @@ class Starbound : ISBFileLocator { private val _json2Functions = ObjectRegistry("json 2functions") val json2Functions = _json2Functions.view + private val _npcTypes = ObjectRegistry("npc types") + val npcTypes = _npcTypes.view + val gson: Gson = with(GsonBuilder()) { serializeNulls() setDateFormat(DateFormat.LONG) @@ -381,7 +385,7 @@ class Starbound : ISBFileLocator { val table = args.lua.stackTop for ((i, value) in values.withIndex()) { - args.lua.push(i) + args.lua.push(i + 1) args.lua.push(value) args.lua.setTableValue(table) } @@ -394,6 +398,18 @@ class Starbound : ISBFileLocator { 1 } + state.setTableFunction("npcConfig", this) { args -> + // Json root.npcConfig(String npcType) + val name = args.getString() + args.lua.push(npcTypes[name]?.copy() ?: throw NoSuchElementException("No such NPC type $name")) + 1 + } + + state.setTableFunction("npcVariant", this) { args -> + // Json root.npcVariant(String species, String npcType, float level, [unsigned seed], [Json parameters]) + TODO() + } + state.pop() state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua") @@ -599,6 +615,7 @@ class Starbound : ISBFileLocator { loadStage(callback, _particles, ext2files["particle"] ?: listOf()) loadStage(callback, _questTemplates, ext2files["questtemplate"] ?: listOf()) loadStage(callback, _techs, ext2files["tech"] ?: listOf()) + loadStage(callback, _npcTypes, ext2files["npctype"] ?: listOf()) pathStack.block("/") { //playerDefinition = gson.fromJson(locate("/player.config").reader(), PlayerDefinition::class.java) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/npc/NpcTypeDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/npc/NpcTypeDefinition.kt new file mode 100644 index 00000000..f70e7533 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/npc/NpcTypeDefinition.kt @@ -0,0 +1,9 @@ +package ru.dbotthepony.kstarbound.defs.npc + +import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory + +@JsonFactory +data class NpcTypeDefinition( + val type: String, + val baseType: String? = null, +)