More stuff.

This commit is contained in:
2023-03-05 17:33:54 -08:00
parent c973a1a3c6
commit 3d4862adc0
25 changed files with 345 additions and 69 deletions

View File

@ -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())
}