Compare commits

..

No commits in common. "830191e001ee58c9ac09b9fcb61eff1f01ef341d" and "ec745f87ab22ba6a011c0112abc5c31b0745ffa6" have entirely different histories.

7 changed files with 2004 additions and 1978 deletions

View file

@ -17,68 +17,31 @@ function lerp(a, b, amount)
return (1 - amount) * a + (amount * b) return (1 - amount) * a + (amount * b)
end end
local function sourceRoots() -- Write to the project tree itself (not LÖVE's save dir) so edits persist in the
local roots = {} -- repo during dev. Uses plain io.open against love.filesystem.getSource(), which
local seen = {} -- is the absolute project path when running `love .` from a folder. Falls back to
local function add(root) -- love.filesystem.write (save dir) if the source is a packaged .love archive.
if type(root) == "string" and root ~= "" and not seen[root] then function writeToSource(relPath, contents)
table.insert(roots, root) local base = love.filesystem.getSource()
seen[root] = true local file = io.open(base .. "/" .. relPath, "w")
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 false return love.filesystem.write(relPath, contents)
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)
for _, base in ipairs(sourceRoots()) do local base = love.filesystem.getSource()
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
@ -113,31 +76,19 @@ 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. This mirrors writeToSource's root order. -- can't shadow the real source file. Falls back to love.filesystem for a
-- packaged .love.
function readFromSource(relPath) function readFromSource(relPath)
for _, base in ipairs(sourceRoots()) do local base = love.filesystem.getSource()
local contents = readFromRoot(base, relPath) local file = io.open(base .. "/" .. relPath, "r")
if contents then return contents end if file then
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.

View file

@ -1,2 +0,0 @@
* 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,7 +1010,6 @@ 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(getSourceDirectoryItems("rooms")) do for _, file in ipairs(love.filesystem.getDirectoryItems("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