diff --git a/src/main/kotlin/Editors.kt b/src/main/kotlin/Editors.kt index 1add965..fe5c4ad 100644 --- a/src/main/kotlin/Editors.kt +++ b/src/main/kotlin/Editors.kt @@ -315,6 +315,34 @@ enum class Editors(val data: EditorData) { e.printStackTrace() } } + }), + ITEM_SPAWNS(object : EditorData("ground_spawns.json") { + override fun parse() { + Logger.logInfo("Parsing ground spawn data...") + val spawnMap = HashMap>() + configureParser() + data.forEach { spawnRaw -> + val spawn = spawnRaw as JSONObject + val id = spawn["item_id"].toString().toInt() + val datas: Array = spawn["loc_data"].toString().split("-".toRegex()).toTypedArray() + var tokens: Array + for (d in datas) { + if(d.isEmpty()){ + continue + } + tokens = d.replace("{", "").replace("}", "").split(",".toRegex()).toTypedArray() + val amount = tokens[0].trim { it <= ' ' }.toInt() + val spawnCoords = intArrayOf(Integer.valueOf(tokens[1].trim { it <= ' ' }), Integer.valueOf(tokens[2].trim { it <= ' ' }), Integer.valueOf(tokens[3].trim { it <= ' ' })) + val respawnTime = tokens[4].trim { it <= ' ' }.toInt() and 0xFF + val item = TableData.ItemSpawn(id, TableData.Location(spawnCoords[0], spawnCoords[1], spawnCoords[2]), respawnTime, amount) + val regionId = Util.getRegionId(item.location) + if (!spawnMap.containsKey(regionId)) + spawnMap[regionId] = ArrayList() + spawnMap[regionId]!!.add(item) + } + } + TableData.itemSpawns = spawnMap + } }) } diff --git a/src/main/kotlin/MainScreen.kt b/src/main/kotlin/MainScreen.kt index 8230572..1a8c44c 100644 --- a/src/main/kotlin/MainScreen.kt +++ b/src/main/kotlin/MainScreen.kt @@ -139,7 +139,7 @@ fun showLoaded(){ "item_configs" -> MainScreen.openItem.isEnabled = true.also { Editors.ITEM_CONFIGS.data.parse() } "shops" -> MainScreen.openShops.isEnabled = true.also { Editors.SHOPS.data.parse() } "object_configs" -> MainScreen.openObjects.isEnabled = true.also { Editors.OBJECT_CONFIGS.data.parse()} - "npc_spawns" -> MainScreen.openNpcItemSpawns.isEnabled = true.also { Editors.NPC_SPAWNS.data.parse() } + "npc_spawns" -> MainScreen.openNpcItemSpawns.isEnabled = true.also { Editors.NPC_SPAWNS.data.parse(); Editors.ITEM_SPAWNS.data.parse() } } } } @@ -154,4 +154,4 @@ fun main() { DataStore.save() }) MainScreen.isVisible = true -} \ No newline at end of file +} diff --git a/src/main/kotlin/Rs2MapEditor.kt b/src/main/kotlin/Rs2MapEditor.kt index bfd3c06..dae786f 100644 --- a/src/main/kotlin/Rs2MapEditor.kt +++ b/src/main/kotlin/Rs2MapEditor.kt @@ -23,7 +23,7 @@ object Rs2MapEditor { val library = CacheLibrary.create(cachePath) var region = 12850 var npcs = TableData.npcSpawns[region] - var items = GroundItemSpawnParser.parseItemSpawns(region) + var items = TableData.itemSpawns[region] var sceneries = TileSceneryParser.parseRegion(region) val npcRows = ArrayList() val itemRows = ArrayList() @@ -240,7 +240,7 @@ object Rs2MapEditor { mapCell.layout = BorderLayout() mapCell.add(JLabel(YELLOW_DOT)) } - val itemSpawnsHere = items.filter { it.x == column && it.y == flippedY && it.plane == plane }.toList() + val itemSpawnsHere = items!!.filter { it.location == thisAbsolute }.toList() if (itemSpawnsHere.isNotEmpty()) { mapCell.layout = BorderLayout() mapCell.add(JLabel(RED_DOT)) @@ -379,7 +379,7 @@ object Rs2MapEditor { Rs2MapEditor.region = regionId Rs2MapEditor.plane = 0 npcs = TableData.npcSpawns[regionId] ?: ArrayList().also { TableData.npcSpawns[regionId] = it } - items = GroundItemSpawnParser.parseItemSpawns(regionId) + items = TableData.itemSpawns[regionId] ?: ArrayList().also { TableData.itemSpawns[regionId] = it } sceneries = TileSceneryParser.parseRegion(regionId) npcPanel.redrawRows() itemPanel.redrawRows() diff --git a/src/main/kotlin/TableData.kt b/src/main/kotlin/TableData.kt index f1a1d4f..eaa1f5f 100644 --- a/src/main/kotlin/TableData.kt +++ b/src/main/kotlin/TableData.kt @@ -20,7 +20,7 @@ object TableData { val npcConfigKeys = HashSet() val npcConfigs = ArrayList() var npcSpawns = HashMap>() - val itemSpawns = HashMap>() + var itemSpawns = HashMap>() val objConfigKeys = HashSet() val objConfigs = ArrayList() var itemConfigKeys = HashSet() diff --git a/src/main/kotlin/misc/GlobalKeybinds.kt b/src/main/kotlin/misc/GlobalKeybinds.kt index f9cc678..3fd4446 100644 --- a/src/main/kotlin/misc/GlobalKeybinds.kt +++ b/src/main/kotlin/misc/GlobalKeybinds.kt @@ -31,7 +31,8 @@ object GlobalKeybinds{ Editors.NPC_SPAWNS.data.save() } if(Rs2MapEditor.itemsUpdated){ - GroundItemEncoder.write(Rs2MapEditor.items) + //GroundItemEncoder.write(Rs2MapEditor.items) + Editors.ITEM_SPAWNS.data.save() } } diff --git a/src/main/kotlin/ui/ItemSpawnPanel.kt b/src/main/kotlin/ui/ItemSpawnPanel.kt index 2f8755a..743c49c 100644 --- a/src/main/kotlin/ui/ItemSpawnPanel.kt +++ b/src/main/kotlin/ui/ItemSpawnPanel.kt @@ -13,6 +13,7 @@ import javax.swing.BoxLayout import javax.swing.JLabel import javax.swing.JPanel import javax.swing.border.MatteBorder +import tools.* class ItemSpawnPanel : JPanel() { val rowBorder = MatteBorder(1, 1, 1, 1, Color.WHITE) @@ -21,7 +22,7 @@ class ItemSpawnPanel : JPanel() { add(ItemSpawnerPanel()) - Rs2MapEditor.items.forEach { + Rs2MapEditor.items!!.filter { it.location.z == Rs2MapEditor.plane }.forEach { val row = ItemRow(it, this) row.border = rowBorder Rs2MapEditor.itemRows.add(row) @@ -34,7 +35,7 @@ class ItemSpawnPanel : JPanel() { remove(it) } Rs2MapEditor.itemRows.clear() - Rs2MapEditor.items.filter { it.plane == Rs2MapEditor.plane }.forEach { + Rs2MapEditor.items!!.filter { it.location.z == Rs2MapEditor.plane }.forEach { val row = ItemRow(it, this) row.border = rowBorder Rs2MapEditor.itemRows.add(row) @@ -85,22 +86,34 @@ class ItemSpawnPanel : JPanel() { } } - class ItemRow(val item: Item, val parent: JPanel) : JPanel(){ + class ItemRow(val item: TableData.ItemSpawn, val parent: JPanel) : JPanel(){ init { - layout = FlowLayout() - add(JLabel("${item.definition.name} [${item.amount}] -- \uD83D\uDD64 ${item.respawnTime}")) + layout = BorderLayout() + val topPanel = JPanel(FlowLayout()) + val midPanel = JPanel(FlowLayout()) + val botPanel = JPanel(FlowLayout()) + val deleteButton = ImgButton(Image.DELETE_HI, Image.DELTE_LO) - add(deleteButton) - minimumSize = Dimension(300, 40) - preferredSize = Dimension(300, 40) - maximumSize = Dimension(300, 40) + topPanel.add(JLabel("${TableData.itemNames[item.id]} [${item.id}]")) + topPanel.add(deleteButton) + midPanel.add(JLabel("{${item.location.x},${item.location.y},${item.location.z}}")) + botPanel.add(JLabel("AMT: ${item.amount} \uD83D\uDD64 ${item.respawnTicks}")) + + add(topPanel, BorderLayout.NORTH) + add(midPanel, BorderLayout.CENTER) + add(botPanel, BorderLayout.SOUTH) + + minimumSize = Dimension(300, 80) + preferredSize = Dimension(300, 80) + maximumSize = Dimension(300, 80) + deleteButton.onClick { - Rs2MapEditor.items.remove(item) + Rs2MapEditor.items!!.remove(item) parent.remove(this) parent.repaint() Rs2MapEditor.itemRows.remove(this) - if(Rs2MapEditor.items.filter { it.x == item.x && it.y == item.y }.isEmpty()){ - Rs2MapEditor.componentPointMap.filter { it.key.x == item.x && it.key.y == item.y }.forEach { (_,cell) -> + if(Rs2MapEditor.items!!.filter { it.location == item.location }.isEmpty()){ + Rs2MapEditor.componentPointMap.filter { it.key.x == item.location.localCoords[0] && it.key.y == item.location.localCoords[1] }.forEach { (_,cell) -> cell.components.forEach { c -> if(c is JLabel && c.icon == Image.RED_DOT) cell.remove(c) } @@ -115,14 +128,14 @@ class ItemSpawnPanel : JPanel() { val defaultBorder = MatteBorder(1, 1, 1, 1, Color.GRAY) override fun mouseEntered(e: MouseEvent?) { super.mouseEntered(e) - Rs2MapEditor.componentPointMap.filter { it.key.x == item.x && it.key.y == item.y }.forEach { it.value.border = border } + Rs2MapEditor.componentPointMap.filter { it.key.x == item.location.localCoords[0] && it.key.y == item.location.localCoords[1] }.forEach { it.value.border = border } } override fun mouseExited(e: MouseEvent?) { super.mouseExited(e) - Rs2MapEditor.componentPointMap.filter { it.key.x == item.x && it.key.y == item.y }.forEach{ it.value.border = defaultBorder } + Rs2MapEditor.componentPointMap.filter { it.key.x == item.location.localCoords[0] && it.key.y == item.location.localCoords[1] }.forEach{ it.value.border = defaultBorder } } }) } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ui/MapCell.kt b/src/main/kotlin/ui/MapCell.kt index bfcce8d..6da59d3 100644 --- a/src/main/kotlin/ui/MapCell.kt +++ b/src/main/kotlin/ui/MapCell.kt @@ -119,15 +119,17 @@ class MapCell : JPanel() { return } - val item = Item( + val item = TableData.ItemSpawn( id, - Rs2MapEditor.selectedPointX, - Rs2MapEditor.selectedPointY, - Rs2MapEditor.plane, - respawnTime, - amount + TableData.Location( + Rs2MapEditor.selectedPointX, + Rs2MapEditor.selectedPointY, + Rs2MapEditor.plane + ), + amount, + respawnTime ) - Rs2MapEditor.items.add(item) + Rs2MapEditor.items!!.add(item) Rs2MapEditor.componentPointMap.filter { it.key.x == Rs2MapEditor.selectedPointX && it.key.y == Rs2MapEditor.selectedPointY }.forEach { (_, cell) -> var hasLabel = false cell.components.forEach { if(it is JLabel && it.icon == Image.RED_DOT) hasLabel = true } @@ -180,7 +182,7 @@ class MapCell : JPanel() { .append("") .append("
") val thisAbsolute = Util.getAbsoluteCoordinates(Rs2MapEditor.region, Rs2MapEditor.selectedPointX, Rs2MapEditor.selectedPointY, Rs2MapEditor.plane) - val itemsHere = Rs2MapEditor.items.filter { it.x == Rs2MapEditor.selectedPointX && it.y == Rs2MapEditor.selectedPointY && it.plane == Rs2MapEditor.plane }.toList() + val itemsHere = Rs2MapEditor.items!!.filter { it.location == thisAbsolute }.toList() val npcsHere = Rs2MapEditor.npcs!!.filter { it.location == thisAbsolute }.toList() if(npcsHere.isNotEmpty()) { @@ -213,7 +215,7 @@ class MapCell : JPanel() { for (item in itemsHere) { string.append("") string.append("${item.id}") - string.append("${item.definition.name}[${item.amount}] \uD83D\uDD64${item.respawnTime}") + string.append("${TableData.itemNames[item.id]}[${item.amount}] \uD83D\uDD64${item.respawnTicks}") string.append("") } string.append("
")