Save editor player positions by default
This commit is contained in:
parent
c3a2692351
commit
e5e80c2754
2 changed files with 4 additions and 27 deletions
|
|
@ -469,8 +469,8 @@ local function saveRoomFromEditor()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local savePlayerPositions = love.keyboard.isDown("lshift", "rshift")
|
local savePlayerPositions = not love.keyboard.isDown("lshift", "rshift")
|
||||||
if not currentRoom:saveToSource(name, savePlayerPositions, oldName) then
|
if not currentRoom:saveToSource(name, savePlayerPositions) then
|
||||||
editorStatus = "Could not save '" .. name .. "'."
|
editorStatus = "Could not save '" .. name .. "'."
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -492,7 +492,7 @@ local function saveRoomFromEditor()
|
||||||
editorRoomName = name
|
editorRoomName = name
|
||||||
roomNameField:editText(name)
|
roomNameField:editText(name)
|
||||||
activeField = nil
|
activeField = nil
|
||||||
editorStatus = "Saved source level '" .. name .. "'" .. (savePlayerPositions and " with player positions." or ".")
|
editorStatus = "Saved source level '" .. name .. "'" .. (savePlayerPositions and " with player positions." or " without player positions.")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function clearRuntimeSaves()
|
local function clearRuntimeSaves()
|
||||||
|
|
|
||||||
25
room.lua
25
room.lua
|
|
@ -662,32 +662,9 @@ end
|
||||||
-- This is intentionally separate from Room:save. It is the editor's explicit
|
-- This is intentionally separate from Room:save. It is the editor's explicit
|
||||||
-- "write this level into the project" action; gameplay autosaves must never
|
-- "write this level into the project" action; gameplay autosaves must never
|
||||||
-- call it.
|
-- call it.
|
||||||
function Room:saveToSource(name, savePlayerPositions, playerSourceName)
|
function Room:saveToSource(name, savePlayerPositions)
|
||||||
name = name or self.name or "test"
|
name = name or self.name or "test"
|
||||||
local saveTable = self:serialize(savePlayerPositions ~= false)
|
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)
|
local room = TSerial.pack(saveTable, nil, true)
|
||||||
return writeToSource("rooms/" .. name .. ".sav", room)
|
return writeToSource("rooms/" .. name .. ".sav", room)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue