mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 21:41:32 +00:00
More stuff.
This commit is contained in:
@ -5,8 +5,9 @@ import com.github.ajalt.clikt.core.requireObject
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import com.github.ajalt.clikt.parameters.types.path
|
||||
import gay.pizza.foundation.heimdall.export.ExportedBlock
|
||||
import gay.pizza.foundation.heimdall.load.ExportedBlockTable
|
||||
import gay.pizza.foundation.heimdall.load.WorldLoadFormat
|
||||
import gay.pizza.foundation.heimdall.load.WorldLoadWorld
|
||||
import gay.pizza.foundation.heimdall.load.WorldLoadSimpleWorld
|
||||
import gay.pizza.foundation.heimdall.table.WorldChangeTable
|
||||
import gay.pizza.foundation.heimdall.tool.state.BlockChangelog
|
||||
import gay.pizza.foundation.heimdall.tool.state.BlockLogTracker
|
||||
@ -24,23 +25,32 @@ class GenerateWorldLoadFile : CliktCommand(name = "generate-world-load", help =
|
||||
val path by argument("load-format-file").path()
|
||||
|
||||
override fun run() {
|
||||
val worlds = mutableMapOf<String, WorldLoadWorld>()
|
||||
val worlds = mutableMapOf<String, WorldLoadSimpleWorld>()
|
||||
val worldChangelogs = BlockChangelog.query(db).splitBy { it.world }
|
||||
val worldNames = transaction(db) {
|
||||
WorldChangeTable.selectAll()
|
||||
.associate { it[WorldChangeTable.toWorld] to it[WorldChangeTable.toWorldName] }
|
||||
}
|
||||
|
||||
val blockTable = ExportedBlockTable()
|
||||
|
||||
for ((id, changelog) in worldChangelogs) {
|
||||
val tracker = BlockLogTracker()
|
||||
tracker.replay(changelog)
|
||||
val sparse = tracker.buildBlockMap { ExportedBlock(it.type, it.data) }
|
||||
val blocks = sparse.blocks
|
||||
worlds[id.toString().lowercase()] = WorldLoadWorld(
|
||||
worlds[id.toString().lowercase()] = WorldLoadSimpleWorld(
|
||||
worldNames[id] ?: "unknown_$id",
|
||||
blocks
|
||||
blocks.mapValues { levelOne ->
|
||||
levelOne.value.mapValues { levelTwo ->
|
||||
levelTwo.value.mapValues { entry ->
|
||||
blockTable.index(entry.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
val format = WorldLoadFormat(worlds)
|
||||
val format = WorldLoadFormat(blockTable.blocks, worlds)
|
||||
path.deleteIfExists()
|
||||
Json.encodeToStream(format, path.outputStream())
|
||||
}
|
||||
|
Reference in New Issue
Block a user