mirror of
https://gitlab.com/2009scape/tools/rs09-thanos-tool.git
synced 2026-08-01 14:39:20 -06:00
Item spawn saving
This commit is contained in:
parent
d23e13d5de
commit
f8a80f34b8
1 changed files with 32 additions and 0 deletions
|
|
@ -343,6 +343,38 @@ enum class Editors(val data: EditorData) {
|
|||
}
|
||||
TableData.itemSpawns = spawnMap
|
||||
}
|
||||
|
||||
override fun save() {
|
||||
Logger.logInfo("Saving Item spawn info...")
|
||||
val spawnMap = HashMap<Int, StringBuilder>()
|
||||
for ((_, spawns) in TableData.itemSpawns) {
|
||||
for (spawn in spawns) {
|
||||
if (!spawnMap.contains(spawn.id)) spawnMap[spawn.id] = StringBuilder()
|
||||
spawnMap[spawn.id]!!.append("{${spawn.amount},${spawn.location.x},${spawn.location.y},${spawn.location.z},${spawn.respawnTicks}}-")
|
||||
}
|
||||
}
|
||||
val spawnsJsonArray = JSONArray()
|
||||
for ((id, spawnString) in spawnMap.entries.sortedBy { it.key.toInt() }) {
|
||||
val spawn = JSONObject()
|
||||
spawn["item_id"] = id.toString()
|
||||
spawn["loc_data"] = spawnString.toString()
|
||||
spawnsJsonArray.add(spawn)
|
||||
}
|
||||
val manager = ScriptEngineManager()
|
||||
val scriptEngine = manager.getEngineByName("JavaScript")
|
||||
scriptEngine.put("jsonString", spawnsJsonArray.toJSONString())
|
||||
scriptEngine.eval("result = JSON.stringify(JSON.parse(jsonString), null, 2)")
|
||||
val prettyPrintedJson = scriptEngine["result"] as String
|
||||
|
||||
try {
|
||||
FileWriter(EditorConstants.CONFIG_PATH + File.separator + fileName).use { file ->
|
||||
file.write(prettyPrintedJson)
|
||||
file.flush()
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue