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)
end
-- Write to the project tree itself (not LÖVE's save dir) so edits persist in the
-- repo during dev. Uses plain io.open against love.filesystem.getSource(), which
-- is the absolute project path when running `love .` from a folder. Falls back to
-- love.filesystem.write (save dir) if the source is a packaged .love archive.
function writeToSource(relPath, contents)
local base = love.filesystem.getSource()
local file = io.open(base .. "/" .. relPath, "w")
local function sourceRoots()
local roots = {}
local seen = {}
local function add(root)
if type(root) == "string" and root ~= "" and not seen[root] then
table.insert(roots, root)
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
file:write(contents)
file:close()
return true
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
-- The editor occasionally needs to rename a source level after it has written
-- the replacement. Keep that operation alongside writeToSource so packaged
-- games still fall back to LÖVE's writable save directory.
function removeFromSource(relPath)
local base = love.filesystem.getSource()
local path = base .. "/" .. relPath
local file = io.open(path, "r")
if file then
file:close()
return os.remove(path)
for _, base in ipairs(sourceRoots()) do
local path = base .. "/" .. relPath
local file = io.open(path, "r")
if file then
file:close()
return os.remove(path)
end
end
return love.filesystem.remove(relPath)
end
@ -76,19 +113,31 @@ function clearRuntimeSaveData(roomName)
end
-- 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
-- packaged .love.
-- can't shadow the real source file. This mirrors writeToSource's root order.
function readFromSource(relPath)
local base = love.filesystem.getSource()
local file = io.open(base .. "/" .. relPath, "r")
if file then
local contents = file:read("*a")
file:close()
return contents
for _, base in ipairs(sourceRoots()) do
local contents = readFromRoot(base, relPath)
if contents then return contents end
end
return love.filesystem.read(relPath)
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
-- sprite is loaded on demand by path (deduped here) rather than from a
-- 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 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
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()
local names = {}
for _, file in ipairs(love.filesystem.getDirectoryItems("rooms")) do
for _, file in ipairs(getSourceDirectoryItems("rooms")) do
local name = file:match("^(.+)%.sav$")
if name and name ~= "world" then table.insert(names, name) end
end