mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-19 04:06:10 +02:00
fix(save-editor): guard event scraping for mobile environments and fix editor state reset on close
This commit is contained in:
@@ -40,10 +40,11 @@ end
|
|||||||
|
|
||||||
local function shellListLua(dir)
|
local function shellListLua(dir)
|
||||||
local out = {}
|
local out = {}
|
||||||
|
if not (io and io.popen) then return out end
|
||||||
if package.config:sub(1, 1) == "\\" then
|
if package.config:sub(1, 1) == "\\" then
|
||||||
-- cmd has no ls; dir /b prints bare names, so re-attach the directory
|
-- cmd has no ls; dir /b prints bare names, so re-attach the directory
|
||||||
local p = io.popen(string.format('dir /b "%s\\*.lua" 2>nul', dir))
|
local ok, p = pcall(io.popen, string.format('dir /b "%s\\*.lua" 2>nul', dir))
|
||||||
if p then
|
if ok and p then
|
||||||
for line in p:lines() do
|
for line in p:lines() do
|
||||||
if line ~= "" then table.insert(out, dir .. "/" .. line) end
|
if line ~= "" then table.insert(out, dir .. "/" .. line) end
|
||||||
end
|
end
|
||||||
@@ -51,8 +52,8 @@ local function shellListLua(dir)
|
|||||||
end
|
end
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
local p = io.popen(string.format('ls "%s"/*.lua 2>/dev/null', dir))
|
local ok, p = pcall(io.popen, string.format('ls "%s"/*.lua 2>/dev/null', dir))
|
||||||
if p then
|
if ok and p then
|
||||||
for line in p:lines() do
|
for line in p:lines() do
|
||||||
table.insert(out, line)
|
table.insert(out, line)
|
||||||
end
|
end
|
||||||
@@ -64,8 +65,8 @@ end
|
|||||||
local function readText(path)
|
local function readText(path)
|
||||||
local fs = love and love.filesystem
|
local fs = love and love.filesystem
|
||||||
if fs and fs.read and fs.getInfo and fs.getInfo(path) then
|
if fs and fs.read and fs.getInfo and fs.getInfo(path) then
|
||||||
local body = fs.read(path)
|
local ok, body = pcall(fs.read, path)
|
||||||
if body then return body end
|
if ok and body then return body end
|
||||||
end
|
end
|
||||||
local f = io.open(path, "r")
|
local f = io.open(path, "r")
|
||||||
if not f then return nil end
|
if not f then return nil end
|
||||||
@@ -78,7 +79,7 @@ end
|
|||||||
-- scripts show up beside the vanilla EVENT_ ones
|
-- scripts show up beside the vanilla EVENT_ ones
|
||||||
function Catalog.scrapeEvents(scriptDir, headerPath, listFiles, extraDirs)
|
function Catalog.scrapeEvents(scriptDir, headerPath, listFiles, extraDirs)
|
||||||
listFiles = listFiles or function(dir)
|
listFiles = listFiles or function(dir)
|
||||||
return loveListLua(dir) or shellListLua(dir)
|
return loveListLua(dir) or shellListLua(dir) or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local found = {}
|
local found = {}
|
||||||
@@ -97,7 +98,8 @@ function Catalog.scrapeEvents(scriptDir, headerPath, listFiles, extraDirs)
|
|||||||
dirs[#dirs + 1] = dir
|
dirs[#dirs + 1] = dir
|
||||||
end
|
end
|
||||||
for _, dir in ipairs(dirs) do
|
for _, dir in ipairs(dirs) do
|
||||||
for _, path in ipairs(listFiles(dir)) do
|
local files = listFiles(dir) or {}
|
||||||
|
for _, path in ipairs(files) do
|
||||||
local body = readText(path)
|
local body = readText(path)
|
||||||
if body then eat(body) end
|
if body then eat(body) end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user