Save editor player positions by default
This commit is contained in:
parent
c3a2692351
commit
e5e80c2754
2 changed files with 4 additions and 27 deletions
25
room.lua
25
room.lua
|
|
@ -662,32 +662,9 @@ end
|
|||
-- This is intentionally separate from Room:save. It is the editor's explicit
|
||||
-- "write this level into the project" action; gameplay autosaves must never
|
||||
-- call it.
|
||||
function Room:saveToSource(name, savePlayerPositions, playerSourceName)
|
||||
function Room:saveToSource(name, savePlayerPositions)
|
||||
name = name or self.name or "test"
|
||||
local saveTable = self:serialize(savePlayerPositions ~= false)
|
||||
if savePlayerPositions == false then
|
||||
-- A normal editor save keeps the authored spawn positions from the
|
||||
-- existing source level. During a rename that source is still oldName.
|
||||
local sourceName = playerSourceName or name
|
||||
local existing = readFromSource("rooms/" .. sourceName .. ".sav")
|
||||
local keptPlayer = false
|
||||
if existing then
|
||||
local previous = TSerial.unpack(existing)
|
||||
for _, object in ipairs(previous.objects or {}) do
|
||||
if object.class == "player" then
|
||||
table.insert(saveTable.objects, object)
|
||||
keptPlayer = true
|
||||
end
|
||||
end
|
||||
end
|
||||
-- A newly named blank level has no prior source spawn to retain.
|
||||
if not keptPlayer then
|
||||
for color, player in pairs(self.player) do
|
||||
local pos = player:getGridPos()
|
||||
table.insert(saveTable.objects, { class = "player", color = color, x = pos.x, y = pos.y })
|
||||
end
|
||||
end
|
||||
end
|
||||
local room = TSerial.pack(saveTable, nil, true)
|
||||
return writeToSource("rooms/" .. name .. ".sav", room)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue