44 lines
1.6 KiB
Lua
44 lines
1.6 KiB
Lua
|
|
-- Convert a pre-flat-schema room save into the current { objects = { ... } }
|
||
|
|
-- format. Usage:
|
||
|
|
-- lua tools/migrate_legacy_room.lua legacy.sav migrated.sav
|
||
|
|
|
||
|
|
local inputPath, outputPath = arg[1], arg[2]
|
||
|
|
assert(inputPath and outputPath, "usage: lua tools/migrate_legacy_room.lua legacy.sav migrated.sav")
|
||
|
|
|
||
|
|
local input = assert(io.open(inputPath, "r"))
|
||
|
|
local chunk, err = load("return " .. input:read("*a"))
|
||
|
|
input:close()
|
||
|
|
assert(chunk, err)
|
||
|
|
local legacy = chunk()
|
||
|
|
|
||
|
|
local objects = {}
|
||
|
|
local function append(class, object, includeColor)
|
||
|
|
local converted = {
|
||
|
|
class = class,
|
||
|
|
x = object.x,
|
||
|
|
y = object.y,
|
||
|
|
}
|
||
|
|
if includeColor ~= false then converted.color = object.color end
|
||
|
|
table.insert(objects, converted)
|
||
|
|
end
|
||
|
|
|
||
|
|
for _, color in ipairs({ "red", "green", "blue" }) do
|
||
|
|
for _, object in ipairs(legacy.players[color] or {}) do append("player", object) end
|
||
|
|
-- Doors are shared between color layers in the current schema, so they have
|
||
|
|
-- no color field when serialized.
|
||
|
|
for _, object in ipairs(legacy.doors[color] or {}) do append("door", object, false) end
|
||
|
|
for _, object in ipairs(legacy.static_walls[color] or {}) do append("static_wall", object) end
|
||
|
|
-- The legacy wall sprite was renamed to box when assets became data-driven.
|
||
|
|
for _, object in ipairs(legacy.walls[color] or {}) do append("box", object) end
|
||
|
|
for _, object in ipairs(legacy.switches[color] or {}) do append("switch", object) end
|
||
|
|
end
|
||
|
|
|
||
|
|
for _, sage in pairs(legacy.sages or {}) do
|
||
|
|
table.insert(objects, { class = "npc", x = sage.x, y = sage.y })
|
||
|
|
end
|
||
|
|
|
||
|
|
require "libs/TSerial"
|
||
|
|
local output = assert(io.open(outputPath, "w"))
|
||
|
|
output:write(TSerial.pack({ objects = objects }, nil, true))
|
||
|
|
output:close()
|