mirror of
https://github.com/bryanthaboi/gen1recomp
synced 2026-10-07 01:18:32 -04:00
35 lines
834 B
Lua
35 lines
834 B
Lua
local WorkerFs = {}
|
|
|
|
function WorkerFs.normalize(prefix)
|
|
if type(prefix) == "string" and prefix ~= "" then return prefix end
|
|
return nil
|
|
end
|
|
|
|
function WorkerFs.prefix()
|
|
if not require("src.core.Platform").isNX() then return nil end
|
|
return WorkerFs.normalize(require("src.core.GameVersion").cachePrefix())
|
|
end
|
|
|
|
function WorkerFs.read(prefix, rel, fs)
|
|
fs = fs or love.filesystem
|
|
prefix = WorkerFs.normalize(prefix)
|
|
if prefix then
|
|
local bytes = fs.read(prefix .. rel)
|
|
if bytes then return bytes end
|
|
end
|
|
return fs.read(rel)
|
|
end
|
|
|
|
function WorkerFs.cache(prefix, fs)
|
|
local cache = { prefix = WorkerFs.normalize(prefix) }
|
|
function cache:setPrefix(p)
|
|
self.prefix = WorkerFs.normalize(p)
|
|
end
|
|
function cache:read(rel)
|
|
return WorkerFs.read(self.prefix, rel, fs)
|
|
end
|
|
return cache
|
|
end
|
|
|
|
return WorkerFs
|