mirror of
https://github.com/cave-story-randomizer/cave-story-randomizer
synced 2025-12-02 01:18:11 +00:00
adds support for saving the cs directory in settings - doesn't work tho!
This commit is contained in:
parent
c75e39c0b0
commit
0b2e76305c
28
src/main.lua
28
src/main.lua
|
|
@ -12,16 +12,36 @@ U = require 'util'
|
||||||
|
|
||||||
require 'log'
|
require 'log'
|
||||||
|
|
||||||
local Randomizer = require 'randomizer'
|
local random = require 'randomizer'
|
||||||
local Screen = require 'draw'
|
local settings = require 'settings'
|
||||||
|
Randomizer = random()
|
||||||
|
Screen = require 'ui.draw'
|
||||||
|
Settings = settings()
|
||||||
|
|
||||||
|
local csdirectory
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
Screen:setup()
|
Screen:setup()
|
||||||
|
Settings:init()
|
||||||
|
if Settings.settings.csdirectory ~= "" then
|
||||||
|
Screen:setStatus("Cave Story folder found!")
|
||||||
|
Randomizer:setPath(Settings.settings.csdirectory)
|
||||||
|
else
|
||||||
|
Screen:setStatus("Drag and drop your Cave Story folder here.")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.directorydropped(path)
|
function love.directorydropped(path)
|
||||||
local randomizer = Randomizer()
|
local success = Randomizer:_mountDirectory(path)
|
||||||
Screen:setStatus(randomizer:randomize(path))
|
Randomizer:_unmountDirectory(path)
|
||||||
|
if success then
|
||||||
|
Settings.settings.csdirectory = path
|
||||||
|
Settings:update()
|
||||||
|
Randomizer:setPath(path)
|
||||||
|
Screen:setStatus("Cave Story folder updated!")
|
||||||
|
else
|
||||||
|
Screen:setStatus("Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keypressed(key)
|
function love.keypressed(key)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local csdirectory
|
||||||
|
|
||||||
local function mkdir(path)
|
local function mkdir(path)
|
||||||
local mkdir_str
|
local mkdir_str
|
||||||
if package.config:sub(1,1) == '\\' then -- Windows
|
if package.config:sub(1,1) == '\\' then -- Windows
|
||||||
|
|
@ -32,10 +34,14 @@ function C:new()
|
||||||
self.worldGraph = WorldGraph(self.itemDeck)
|
self.worldGraph = WorldGraph(self.itemDeck)
|
||||||
end
|
end
|
||||||
|
|
||||||
function C:randomize(path)
|
function C:setPath(path)
|
||||||
|
csdirectory = path
|
||||||
|
end
|
||||||
|
|
||||||
|
function C:randomize()
|
||||||
resetLog()
|
resetLog()
|
||||||
logNotice('=== Cave Story Randomizer v' .. VERSION .. ' ===')
|
logNotice('=== Cave Story Randomizer v' .. VERSION .. ' ===')
|
||||||
local success, dirStage = self:_mountDirectory(path)
|
local success, dirStage = self:_mountDirectory(csdirectory)
|
||||||
if not success then
|
if not success then
|
||||||
return "Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?"
|
return "Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?"
|
||||||
end
|
end
|
||||||
|
|
@ -47,7 +53,7 @@ function C:randomize(path)
|
||||||
self:_writeModifiedData(tscFiles)
|
self:_writeModifiedData(tscFiles)
|
||||||
self:_writePlaintext(tscFiles)
|
self:_writePlaintext(tscFiles)
|
||||||
self:_writeLog()
|
self:_writeLog()
|
||||||
self:_unmountDirectory(path)
|
self:_unmountDirectory(csdirectory)
|
||||||
return self:_getStatusMessage()
|
return self:_getStatusMessage()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
33
src/settings.lua
Normal file
33
src/settings.lua
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
local C = Class:extend()
|
||||||
|
|
||||||
|
function C:init()
|
||||||
|
self.settings = {}
|
||||||
|
if lf.getInfo('settings.txt') == nil then
|
||||||
|
self:setDefaults()
|
||||||
|
end
|
||||||
|
self.settings = lf.load('settings.txt')()
|
||||||
|
end
|
||||||
|
|
||||||
|
function C:setDefaults()
|
||||||
|
self.settings.csdirectory = nil
|
||||||
|
self:update()
|
||||||
|
end
|
||||||
|
|
||||||
|
function C:update()
|
||||||
|
lf.write('settings.txt', self:serialize())
|
||||||
|
end
|
||||||
|
|
||||||
|
function C:serialize()
|
||||||
|
local line = "return {"
|
||||||
|
|
||||||
|
line = line .. ("csdirectory = [[%s]],\r\n"):format(self.settings.csdirectory or "")
|
||||||
|
|
||||||
|
line = line .. "}"
|
||||||
|
return line
|
||||||
|
end
|
||||||
|
|
||||||
|
function C:getSettings()
|
||||||
|
return self.settings
|
||||||
|
end
|
||||||
|
|
||||||
|
return C
|
||||||
|
|
@ -4,12 +4,13 @@ local background
|
||||||
|
|
||||||
local C = Class:extend()
|
local C = Class:extend()
|
||||||
|
|
||||||
local layout = Luigi(require 'layout')
|
local layout = Luigi(require 'ui.main')
|
||||||
layout:setStyle(require 'style')
|
--local settings = Luigi(require 'ui.settings')
|
||||||
|
layout:setStyle(require 'ui.style')
|
||||||
|
--settings:setStyle(require 'ui.style')
|
||||||
|
|
||||||
function C:setup()
|
function C:setup()
|
||||||
background = lg.newImage('assets/background.png')
|
background = lg.newImage('assets/background.png')
|
||||||
self:setStatus("Drag and drop your Cave Story folder here.")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
layout.version.text = 'Cave Story Randomizer [Open Mode] v' .. VERSION
|
layout.version.text = 'Cave Story Randomizer [Open Mode] v' .. VERSION
|
||||||
|
|
@ -18,6 +19,11 @@ layout.twitter.text = '(@shruuu and @duncathan_salt)'
|
||||||
|
|
||||||
layout.footer.text = 'Original randomizer:\r\nshru.itch.io/cave-story-randomizer'
|
layout.footer.text = 'Original randomizer:\r\nshru.itch.io/cave-story-randomizer'
|
||||||
|
|
||||||
|
layout.go:onPress(function()
|
||||||
|
C:setStatus(Randomizer:randomize())
|
||||||
|
Randomizer:new()
|
||||||
|
end)
|
||||||
|
|
||||||
function C:draw()
|
function C:draw()
|
||||||
lg.draw(background, 0, 0)
|
lg.draw(background, 0, 0)
|
||||||
layout:show()
|
layout:show()
|
||||||
|
|
@ -25,7 +25,6 @@ return { id = 'window',
|
||||||
flow = 'x',
|
flow = 'x',
|
||||||
height = '40',
|
height = '40',
|
||||||
{ width = false },
|
{ width = false },
|
||||||
--[[
|
|
||||||
{
|
{
|
||||||
type = 'button',
|
type = 'button',
|
||||||
id = 'settings',
|
id = 'settings',
|
||||||
|
|
@ -40,7 +39,6 @@ return { id = 'window',
|
||||||
width = 100,
|
width = 100,
|
||||||
height = 32,
|
height = 32,
|
||||||
},
|
},
|
||||||
]]
|
|
||||||
{ width = false }
|
{ width = false }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Loading…
Reference in a new issue