mirror of
https://github.com/cave-story-randomizer/cave-story-randomizer
synced 2024-12-25 22:47:14 +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'
|
||||
|
||||
local Randomizer = require 'randomizer'
|
||||
local Screen = require 'draw'
|
||||
local random = require 'randomizer'
|
||||
local settings = require 'settings'
|
||||
Randomizer = random()
|
||||
Screen = require 'ui.draw'
|
||||
Settings = settings()
|
||||
|
||||
local csdirectory
|
||||
|
||||
function love.load()
|
||||
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
|
||||
|
||||
function love.directorydropped(path)
|
||||
local randomizer = Randomizer()
|
||||
Screen:setStatus(randomizer:randomize(path))
|
||||
local success = Randomizer:_mountDirectory(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
|
||||
|
||||
function love.keypressed(key)
|
||||
|
|
|
@ -16,6 +16,8 @@ do
|
|||
end
|
||||
end
|
||||
|
||||
local csdirectory
|
||||
|
||||
local function mkdir(path)
|
||||
local mkdir_str
|
||||
if package.config:sub(1,1) == '\\' then -- Windows
|
||||
|
@ -32,10 +34,14 @@ function C:new()
|
|||
self.worldGraph = WorldGraph(self.itemDeck)
|
||||
end
|
||||
|
||||
function C:randomize(path)
|
||||
function C:setPath(path)
|
||||
csdirectory = path
|
||||
end
|
||||
|
||||
function C:randomize()
|
||||
resetLog()
|
||||
logNotice('=== Cave Story Randomizer v' .. VERSION .. ' ===')
|
||||
local success, dirStage = self:_mountDirectory(path)
|
||||
local success, dirStage = self:_mountDirectory(csdirectory)
|
||||
if not success then
|
||||
return "Could not find \"data\" subfolder.\n\nMaybe try dropping your Cave Story \"data\" folder in directly?"
|
||||
end
|
||||
|
@ -47,7 +53,7 @@ function C:randomize(path)
|
|||
self:_writeModifiedData(tscFiles)
|
||||
self:_writePlaintext(tscFiles)
|
||||
self:_writeLog()
|
||||
self:_unmountDirectory(path)
|
||||
self:_unmountDirectory(csdirectory)
|
||||
return self:_getStatusMessage()
|
||||
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 layout = Luigi(require 'layout')
|
||||
layout:setStyle(require 'style')
|
||||
local layout = Luigi(require 'ui.main')
|
||||
--local settings = Luigi(require 'ui.settings')
|
||||
layout:setStyle(require 'ui.style')
|
||||
--settings:setStyle(require 'ui.style')
|
||||
|
||||
function C:setup()
|
||||
background = lg.newImage('assets/background.png')
|
||||
self:setStatus("Drag and drop your Cave Story folder here.")
|
||||
end
|
||||
|
||||
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.go:onPress(function()
|
||||
C:setStatus(Randomizer:randomize())
|
||||
Randomizer:new()
|
||||
end)
|
||||
|
||||
function C:draw()
|
||||
lg.draw(background, 0, 0)
|
||||
layout:show()
|
|
@ -25,7 +25,6 @@ return { id = 'window',
|
|||
flow = 'x',
|
||||
height = '40',
|
||||
{ width = false },
|
||||
--[[
|
||||
{
|
||||
type = 'button',
|
||||
id = 'settings',
|
||||
|
@ -40,7 +39,6 @@ return { id = 'window',
|
|||
width = 100,
|
||||
height = 32,
|
||||
},
|
||||
]]
|
||||
{ width = false }
|
||||
},
|
||||
{
|
Loading…
Reference in a new issue