This commit is contained in:
Your Name 2026-08-07 03:22:28 -04:00
parent f8e3d78332
commit b9b0726506
6 changed files with 140 additions and 81 deletions

View file

@ -8,6 +8,7 @@ function World:initialize()
self.rooms = {}
self.roomByName = {}
self.previewCache = {}
self.lastRoom = nil
self:load()
end
@ -26,6 +27,7 @@ function World:load()
if not raw then return end
local ok, save = pcall(TSerial.unpack, raw)
if not ok or type(save) ~= "table" then return end
self.lastRoom = save.lastRoom
for _, room in ipairs(save.rooms or {}) do
if room.name and self:isInBounds(room.x, room.y) then
self:_putRoom(room.name, room.x, room.y)
@ -38,7 +40,7 @@ function World:save()
for _, room in ipairs(self.rooms) do
table.insert(rooms, { name = room.name, x = room.x, y = room.y })
end
return writeToSource("rooms/world.sav", TSerial.pack({ width = self.width, height = self.height, rooms = rooms }, nil, true))
return writeToSource("rooms/world.sav", TSerial.pack({ width = self.width, height = self.height, lastRoom = self.lastRoom, rooms = rooms }, nil, true))
end
function World:isInBounds(x, y)
@ -87,6 +89,7 @@ function World:removeRoom(x, y)
if room.x == x and room.y == y then
self.roomByName[room.name] = nil
table.remove(self.rooms, i)
if self.lastRoom == room.name then self.lastRoom = nil end
return self:save(), room.name
end
end
@ -99,11 +102,20 @@ function World:renameRoom(oldName, newName)
self.roomByName[oldName] = nil
room.name = newName
self.roomByName[newName] = room
if self.lastRoom == oldName then self.lastRoom = newName end
self:invalidatePreview(oldName)
self:invalidatePreview(newName)
return self:save()
end
function World:setLastRoom(name)
if name and self.lastRoom ~= name then
self.lastRoom = name
return self:save()
end
return true
end
function World:getNeighbor(name, exit)
local room = self:roomLocation(name)
if not room then return nil end
@ -149,7 +161,12 @@ function World:drawRoomPreview(name, x, y, size)
else
local props = globalAssetProperties[object.class]
if props and props.sprites then
local colors = object.class == "door" and { "red", "green", "blue" } or { object.color }
local colors
if object.class == "door" then
colors = object.color and { object.color } or { "red", "green", "blue" }
else
colors = { object.color }
end
for _, color in ipairs(colors) do
local path = props.sprites[color]
if path then