Compare commits

..

2 commits

Author SHA1 Message Date
Your Name
830191e001 puzzle ideas org 2026-08-12 17:20:14 -04:00
Your Name
7c38a4f619 supposedly fix saving 2026-08-12 17:20:11 -04:00
7 changed files with 2215 additions and 2241 deletions

View file

@ -17,31 +17,68 @@ function lerp(a, b, amount)
return (1 - amount) * a + (amount * b) return (1 - amount) * a + (amount * b)
end end
-- Write to the project tree itself (not LÖVE's save dir) so edits persist in the local function sourceRoots()
-- repo during dev. Uses plain io.open against love.filesystem.getSource(), which local roots = {}
-- is the absolute project path when running `love .` from a folder. Falls back to local seen = {}
-- love.filesystem.write (save dir) if the source is a packaged .love archive. local function add(root)
function writeToSource(relPath, contents) if type(root) == "string" and root ~= "" and not seen[root] then
local base = love.filesystem.getSource() table.insert(roots, root)
local file = io.open(base .. "/" .. relPath, "w") seen[root] = true
end
end
add("/home/happy/code/chroma_solstice")
if love and love.filesystem then
if love.filesystem.getSource then add(love.filesystem.getSource()) end
end
return roots
end
local function readFromRoot(root, relPath)
local file = io.open(root .. "/" .. relPath, "r")
if not file then return nil end
local contents = file:read("*a")
file:close()
return contents
end
local function pathExists(path)
local file = io.open(path, "r")
if file then if file then
file:write(contents)
file:close() file:close()
return true return true
end end
return love.filesystem.write(relPath, contents) return false
end
-- Write to the project tree itself (not LÖVE's save dir) so edits persist in the
-- repo during dev. Packaged games still fall back to love.filesystem.write.
function writeToSource(relPath, contents)
for _, base in ipairs(sourceRoots()) do
local path = base .. "/" .. relPath
local file, err = io.open(path, "w")
if file then
file:write(contents)
file:close()
print("Saved source: " .. path)
return true
end
print("Save source failed: " .. path .. " (" .. tostring(err) .. ")")
end
print("Save failed: did not write fallback for " .. relPath)
return false
end end
-- The editor occasionally needs to rename a source level after it has written -- The editor occasionally needs to rename a source level after it has written
-- the replacement. Keep that operation alongside writeToSource so packaged -- the replacement. Keep that operation alongside writeToSource so packaged
-- games still fall back to LÖVE's writable save directory. -- games still fall back to LÖVE's writable save directory.
function removeFromSource(relPath) function removeFromSource(relPath)
local base = love.filesystem.getSource() for _, base in ipairs(sourceRoots()) do
local path = base .. "/" .. relPath local path = base .. "/" .. relPath
local file = io.open(path, "r") local file = io.open(path, "r")
if file then if file then
file:close() file:close()
return os.remove(path) return os.remove(path)
end
end end
return love.filesystem.remove(relPath) return love.filesystem.remove(relPath)
end end
@ -76,19 +113,31 @@ function clearRuntimeSaveData(roomName)
end end
-- Read from the project tree directly so a stale copy in LÖVE's save directory -- Read from the project tree directly so a stale copy in LÖVE's save directory
-- can't shadow the real source file. Falls back to love.filesystem for a -- can't shadow the real source file. This mirrors writeToSource's root order.
-- packaged .love.
function readFromSource(relPath) function readFromSource(relPath)
local base = love.filesystem.getSource() for _, base in ipairs(sourceRoots()) do
local file = io.open(base .. "/" .. relPath, "r") local contents = readFromRoot(base, relPath)
if file then if contents then return contents end
local contents = file:read("*a")
file:close()
return contents
end end
return love.filesystem.read(relPath) return love.filesystem.read(relPath)
end end
function getSourceDirectoryItems(relPath)
for _, base in ipairs(sourceRoots()) do
local dir = base .. "/" .. relPath
if pathExists(dir) then
local ok, proc = pcall(io.popen, "find " .. string.format("%q", dir) .. " -maxdepth 1 -mindepth 1 -printf '%f\n'")
local items = {}
if ok and proc then
for item in proc:lines() do table.insert(items, item) end
proc:close()
end
return items
end
end
return love.filesystem.getDirectoryItems(relPath)
end
-- Cached image loader. The filesystem is the source of truth for art, so every -- Cached image loader. The filesystem is the source of truth for art, so every
-- sprite is loaded on demand by path (deduped here) rather than from a -- sprite is loaded on demand by path (deduped here) rather than from a
-- hand-maintained central table. -- hand-maintained central table.

2
puzzles.org Normal file
View file

@ -0,0 +1,2 @@
* ideas
- puzzles where the room is filled with NOISE and in order to see the real thing you have to go in with the right color

View file

@ -1010,6 +1010,7 @@ function Room:save()
local room = TSerial.pack(self:serialize(), nil, true) local room = TSerial.pack(self:serialize(), nil, true)
local success = love.filesystem.write("rooms/" .. name .. ".sav", room) local success = love.filesystem.write("rooms/" .. name .. ".sav", room)
if success then print("Saved runtime: " .. love.filesystem.getSaveDirectory() .. "/rooms/" .. name .. ".sav") end
if not success then error "great job u fool" end if not success then error "great job u fool" end
end end

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -83,7 +83,7 @@ end
function World:listRoomNames() function World:listRoomNames()
local names = {} local names = {}
for _, file in ipairs(love.filesystem.getDirectoryItems("rooms")) do for _, file in ipairs(getSourceDirectoryItems("rooms")) do
local name = file:match("^(.+)%.sav$") local name = file:match("^(.+)%.sav$")
if name and name ~= "world" then table.insert(names, name) end if name and name ~= "world" then table.insert(names, name) end
end end