mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-17 11:11:10 +02:00
more bugs squashed + portable mode
CLOSES #28: PC in the beginning of the game isn't interactable (The one in your house) CLOSES #34: Bug when calculating exp after one or many fainted team members. CLOSES #37: No Grass Cutting CLOSES #38: Blind TMs CLOSES #53: Portable Mode CLOSES #55: changing palletes with hot key CLOSES #62: Poison status damage issue.
This commit is contained in:
+16
-4
@@ -283,10 +283,22 @@ function Game:keypressed(key)
|
||||
self:zoomStep(1)
|
||||
return
|
||||
elseif key == "2" then
|
||||
-- cycle COLORS (GBC / OG / OG INV / GBC INV / CLASSIC); always on
|
||||
local PaletteFX = require("src.render.PaletteFX")
|
||||
self.save.options.colors = PaletteFX.cycleMode()
|
||||
self:writeOptions()
|
||||
-- cycle COLORS (GBC / OG / OG INV / GBC INV / CLASSIC); the pack change
|
||||
-- forces Game.overworld:reloadMap, which rebuilds the live NPC array, so
|
||||
-- hold it while a warp/transition or an on-screen scripted cutscene is
|
||||
-- driving the overworld rather than tear the escort's NPCs out mid-move
|
||||
local ow = self.overworld
|
||||
local top = self.stack:top()
|
||||
local busy = ow and (ow.transitioning
|
||||
or (top == ow and (
|
||||
(ow.runner and ow.runner.isRunning and ow.runner:isRunning())
|
||||
or (ow.scriptMoves and #ow.scriptMoves > 0)
|
||||
or ow.engaging or ow.emote)))
|
||||
if not busy then
|
||||
local PaletteFX = require("src.render.PaletteFX")
|
||||
self.save.options.colors = PaletteFX.cycleMode()
|
||||
self:writeOptions()
|
||||
end
|
||||
return
|
||||
elseif key == "3" then
|
||||
-- cycle TILT OFF → 15 → 35 → 50 → OFF (mnemonic: 3D), free-roam only
|
||||
|
||||
+106
-5
@@ -27,6 +27,107 @@ local OPTIONS_FILENAME = "options.lua"
|
||||
local BACKUP_FILENAME = FILENAME .. ".bak"
|
||||
local TMP_FILENAME = FILENAME .. ".tmp"
|
||||
|
||||
-- ------- portable mode
|
||||
-- LÖVE's save directory is always the OS per-user path derived from the
|
||||
-- identity (conf.lua), so it can't be relocated at runtime. Portable mode
|
||||
-- instead drops a plain-Lua io.* filesystem next to the game whenever a
|
||||
-- `portable.txt` marker sits beside the executable/source, letting a USB
|
||||
-- copy carry its own save.lua/options.lua (and, through options.lua, the
|
||||
-- mod enable-state) rather than leaving them on the host machine.
|
||||
local PORTABLE_MARKER = "portable.txt"
|
||||
local SEP = package.config:sub(1, 1)
|
||||
|
||||
local portableChecked = false
|
||||
local portableBase = false -- resolved base dir when active, else false
|
||||
local portableFsCache = nil
|
||||
|
||||
local function pathExists(path)
|
||||
local f = io.open(path, "rb")
|
||||
if not f then return false end
|
||||
f:close()
|
||||
return true
|
||||
end
|
||||
|
||||
-- an io.* filesystem exposing the love.filesystem subset the save/options
|
||||
-- round-trip needs (getInfo/read/write/remove), rooted at `dir`
|
||||
local function makePortableFs(dir)
|
||||
local function full(name) return dir .. SEP .. name end
|
||||
return {
|
||||
getInfo = function(name)
|
||||
if not pathExists(full(name)) then return nil end
|
||||
return { type = "file" }
|
||||
end,
|
||||
read = function(name)
|
||||
local f = io.open(full(name), "rb")
|
||||
if not f then return nil, "no file: " .. name end
|
||||
local data = f:read("*a")
|
||||
f:close()
|
||||
return data
|
||||
end,
|
||||
write = function(name, data)
|
||||
local f, err = io.open(full(name), "wb")
|
||||
if not f then return false, err end
|
||||
f:write(data)
|
||||
f:close()
|
||||
return true
|
||||
end,
|
||||
remove = function(name)
|
||||
os.remove(full(name))
|
||||
return true
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
local function detectPortable()
|
||||
if portableChecked then return portableBase end
|
||||
portableChecked = true
|
||||
portableBase = false
|
||||
if not (love and love.filesystem) then return false end
|
||||
local candidates = {}
|
||||
if love.filesystem.getSourceBaseDirectory then
|
||||
candidates[#candidates + 1] = love.filesystem.getSourceBaseDirectory()
|
||||
end
|
||||
if love.filesystem.getSource then
|
||||
candidates[#candidates + 1] = love.filesystem.getSource()
|
||||
end
|
||||
for _, base in ipairs(candidates) do
|
||||
if base and base ~= "" and pathExists(base .. SEP .. PORTABLE_MARKER) then
|
||||
portableBase = base
|
||||
break
|
||||
end
|
||||
end
|
||||
return portableBase
|
||||
end
|
||||
|
||||
function SaveData.isPortable()
|
||||
return detectPortable() ~= false
|
||||
end
|
||||
|
||||
-- the raw portable-folder path (for callers building their own nested
|
||||
-- paths, e.g. the ROM-derived asset cache), or nil when portable mode
|
||||
-- is off
|
||||
function SaveData.portableBaseDir()
|
||||
return detectPortable() or nil
|
||||
end
|
||||
|
||||
-- the io.* filesystem for the active portable folder, or nil when off
|
||||
function SaveData.portableFs()
|
||||
local base = detectPortable()
|
||||
if not base then return nil end
|
||||
if not portableFsCache then portableFsCache = makePortableFs(base) end
|
||||
return portableFsCache
|
||||
end
|
||||
|
||||
-- Resolve the filesystem a persistent read/write should land on: an
|
||||
-- explicitly injected non-love fs (headless tests, the mod loader's stub)
|
||||
-- always wins; otherwise portable mode reroutes off the OS save directory.
|
||||
local function persistFs(fs)
|
||||
if fs and love and love.filesystem and fs ~= love.filesystem then
|
||||
return fs
|
||||
end
|
||||
return SaveData.portableFs() or fs or (love and love.filesystem)
|
||||
end
|
||||
|
||||
-- Port + original Options menu defaults. Missing keys on load are filled
|
||||
-- from this table so old options.lua files stay compatible.
|
||||
function SaveData.defaultOptions()
|
||||
@@ -94,7 +195,7 @@ end
|
||||
-- love.filesystem, so the mod loader's injected filesystem can carry the
|
||||
-- options round-trip headless (no love global).
|
||||
function SaveData.saveOptions(opts, fs)
|
||||
fs = fs or love.filesystem
|
||||
fs = persistFs(fs)
|
||||
opts = SaveData.mergeOptions(opts)
|
||||
-- modOptions is per-mod nested state: fold the on-disk sub-tree
|
||||
-- underneath (newest value winning per key) so one caller's partial
|
||||
@@ -123,7 +224,7 @@ function SaveData.saveOptions(opts, fs)
|
||||
end
|
||||
|
||||
function SaveData.loadOptions(fs)
|
||||
fs = fs or love.filesystem
|
||||
fs = persistFs(fs)
|
||||
local data, err = readTable(fs, OPTIONS_FILENAME)
|
||||
if not data then
|
||||
if fs.getInfo(OPTIONS_FILENAME) then
|
||||
@@ -311,7 +412,7 @@ end)
|
||||
-- afterwards either way
|
||||
SaveData.addCoreMigration(1, function(save)
|
||||
if type(save.options) == "table"
|
||||
and not love.filesystem.getInfo(OPTIONS_FILENAME) then
|
||||
and not persistFs(nil).getInfo(OPTIONS_FILENAME) then
|
||||
SaveData.saveOptions(save.options)
|
||||
end
|
||||
end)
|
||||
@@ -342,7 +443,7 @@ function SaveData.save(data, mods)
|
||||
if k ~= "options" then gameOnly[k] = v end
|
||||
end
|
||||
local encoded = SaveSerializer.encode(gameOnly)
|
||||
local fs = love.filesystem
|
||||
local fs = persistFs(nil)
|
||||
if fs.getInfo(FILENAME) then
|
||||
local prev = fs.read(FILENAME)
|
||||
if prev then fs.write(BACKUP_FILENAME, prev) end
|
||||
@@ -371,7 +472,7 @@ end
|
||||
-- or corrupt and a staged/backup copy was promoted; Game surfaces the
|
||||
-- recovery on the load report
|
||||
function SaveData.load()
|
||||
local fs = love.filesystem
|
||||
local fs = persistFs(nil)
|
||||
local data, err = readTable(fs, FILENAME)
|
||||
local recovered
|
||||
if not data then
|
||||
|
||||
Reference in New Issue
Block a user