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,69 +17,32 @@ function lerp(a, b, amount)
return (1 - amount) * a + (amount * b) return (1 - amount) * a + (amount * b)
end end
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:close()
return true
end
return false
end
-- Write to the project tree itself (not LÖVE's save dir) so edits persist in the -- 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. -- 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) function writeToSource(relPath, contents)
for _, base in ipairs(sourceRoots()) do local base = love.filesystem.getSource()
local path = base .. "/" .. relPath local file = io.open(base .. "/" .. relPath, "w")
local file, err = io.open(path, "w")
if file then if file then
file:write(contents) file:write(contents)
file:close() file:close()
print("Saved source: " .. path)
return true return true
end end
print("Save source failed: " .. path .. " (" .. tostring(err) .. ")") return love.filesystem.write(relPath, contents)
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