Thanos tool will now detect and ignore duplicate drop table, npc config, and item config entries

This commit is contained in:
ceikry 2022-09-05 10:38:06 -05:00
parent 3d76b929fa
commit 7a4abf3f13

View file

@ -8,6 +8,7 @@ import java.io.IOException
import java.lang.Exception
import java.lang.StringBuilder
import javax.script.ScriptEngineManager
import kotlin.io.println
enum class Editors(val data: EditorData) {
DROP_TABLES(object : EditorData("drop_tables.json"){
@ -15,10 +16,19 @@ enum class Editors(val data: EditorData) {
override fun parse() {
Logger.logInfo("Parsing Drop Tables")
configureParser()
data.forEach { dropTableRaw ->
val dropTable = dropTableRaw as org.json.simple.JSONObject
val usedIds = ArrayList<Int>()
data.forEach dataLoop@ { dropTableRaw ->
val dropTable = dropTableRaw as JSONObject
val table = NPCDropTable()
table.ids = dropTable["ids"].toString()
table.ids.split(",").map { it.toInt() }.forEach {id ->
if(usedIds.contains(id)) {
println("Detected duplicate ID, ignoring table: ")
println(dropTableRaw.toJSONString())
return@dataLoop
}
usedIds.add(id)
}
parseTable(dropTable["main"] as JSONArray,table,false)
parseTable(dropTable["default"] as JSONArray,table,true)
parseTable(dropTable["charm"] as JSONArray,table.charmTable,false)
@ -70,9 +80,16 @@ enum class Editors(val data: EditorData) {
override fun parse() {
Logger.logInfo("Parsing NPC configs")
configureParser()
val usedIds = ArrayList<Int>()
data.forEach { npcDataRaw ->
val npcData = npcDataRaw as JSONObject
val id = npcData["id"].toString().toInt()
if (usedIds.contains(id)) {
println("Duplicate NPC Config detected, ignoring config entry:")
println(npcDataRaw.toJSONString())
return@forEach
}
usedIds.add(id)
val name = npcData["name"].toString()
TableData.npcNames[id] = name
TableData.npcConfigKeys.addAll(npcData.keys.toHashSet() as HashSet<String>)
@ -104,9 +121,15 @@ enum class Editors(val data: EditorData) {
ITEM_CONFIGS(object : EditorData("item_configs.json"){
override fun parse() {
configureParser()
val usedIds = ArrayList<Int>()
data.forEach { itemDataRaw ->
val itemData = itemDataRaw as JSONObject
val id = itemData["id"].toString().toInt()
if (usedIds.contains(id)) {
println("Duplicate Item Config detected, ignoring config entry:")
println(itemDataRaw.toJSONString())
return@forEach
}
val name = itemData["name"].toString()
TableData.itemConfigKeys.addAll(itemData.keys.toHashSet() as HashSet<String>)
TableData.itemNames[id] = name