cambridge/scene/mode_select.lua
MarkGamed7794 2384ceb3bf Hopefully this is the folder support
it better be
2021-10-19 19:32:16 -04:00

285 lines
8.8 KiB
Lua
Executable File

local ModeSelectScene = Scene:extend()
ModeSelectScene.title = "Game Start"
current_mode = 1
current_ruleset = 1
function ModeSelectScene:new()
-- reload custom modules
initModules()
if table.getn(game_modes) == 0 or table.getn(rulesets) == 0 then
self.display_warning = true
current_mode = 1
current_ruleset = 1
else
self.display_warning = false
if current_mode > table.getn(game_modes) then
current_mode = 1
end
if current_ruleset > table.getn(rulesets) then
current_ruleset = 1
end
end
self.menu_state = {
mode = current_mode,
mode_list = game_modes,
mode_list_history = {},
mode_path = (config.mode_path or {}),
ruleset = current_ruleset,
rule_list = rulesets,
rule_list_history = {},
rule_path = config.rule_path,
select = "mode",
}
self.secret_inputs = {}
self.das = 0
DiscordRPC:update({
details = "In menus",
state = "Choosing a mode",
largeImageKey = "ingame-000"
})
-- grab the filepaths from config to ensure you're dropped off on the correct mode and ruleset
local able_to_find = true
for _,looking_for in pairs(self.menu_state.mode_path) do
if(able_to_find) then
local found = false
for idx,file in pairs(self.menu_state.mode_list) do
if(not found) then
if(file.type == "directory" and file.name == looking_for) then
table.insert(self.menu_state.mode_list_history,self.menu_state.mode_list)
self.menu_state.mode_list = self.menu_state.mode_list[idx].content
found = true
end
end
end
able_to_find = (found and able_to_find)
end
end
if(not able_to_find) then
--directory doesn't exist, revert to default
self.menu_state.mode_list = game_modes
self.menu_state.mode_list_history = {}
self.menu_state.mode_path = {}
self.menu_state.mode = 1
current_mode = 1
end
-- do the same with the ruleset
local able_to_find = true
for _,looking_for in pairs(self.menu_state.rule_path) do
if(able_to_find) then
local found = false
for idx,file in pairs(self.menu_state.rule_list) do
if(not found) then
if(file.type == "directory" and file.name == looking_for) then
table.insert(self.menu_state.rule_list_history,self.menu_state.rule_list)
self.menu_state.rule_list = self.menu_state.rule_list[idx].content
found = true
end
end
end
able_to_find = (found and able_to_find)
end
end
if(not able_to_find) then
--directory doesn't exist, revert to default
self.menu_state.rule_list = game_modes
self.menu_state.rule_list_history = {}
self.menu_state.rule_path = {}
self.menu_state.rule = 1
current_mode = 1
end
end
function ModeSelectScene:update()
switchBGM(nil) -- experimental
if self.das_up or self.das_down then
self.das = self.das + 1
else
self.das = 0
end
if self.das >= 15 then
self:changeOption(self.das_up and -1 or 1)
self.das = self.das - 4
end
DiscordRPC:update({
details = "In menus",
state = "Choosing a " .. self.menu_state.select,
largeImageKey = "ingame-000"
})
end
function ModeSelectScene:render()
love.graphics.draw(
backgrounds[0],
0, 0, 0,
0.5, 0.5
)
love.graphics.draw(misc_graphics["select_mode"], 20, 40)
if self.display_warning then
love.graphics.setFont(font_3x5_3)
love.graphics.printf(
"You have no modes or rulesets.",
80, 200, 480, "center"
)
love.graphics.setFont(font_3x5_2)
love.graphics.printf(
"Come back to this menu after getting more modes or rulesets. " ..
"Press any button to return to the main menu.",
80, 250, 480, "center"
)
return
end
if self.menu_state.select == "mode" then
love.graphics.setColor(1, 1, 1, 0.5)
elseif self.menu_state.select == "ruleset" then
love.graphics.setColor(1, 1, 1, 0.25)
end
love.graphics.rectangle("fill", 20, 258, 240, 22)
if self.menu_state.select == "mode" then
love.graphics.setColor(1, 1, 1, 0.25)
elseif self.menu_state.select == "ruleset" then
love.graphics.setColor(1, 1, 1, 0.5)
end
love.graphics.rectangle("fill", 340, 258, 200, 22)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setFont(font_3x5_2)
for idx, mode in pairs(self.menu_state.mode_list) do
if(idx >= self.menu_state.mode-9 and idx <= self.menu_state.mode+9) then
if(mode.type == "directory") then
love.graphics.setColor(1,0.5,0,1)
elseif(mode.type == "back") then
love.graphics.setColor(1,1,0,1)
else
love.graphics.setColor(1,1,1,1)
end
love.graphics.printf((mode.type == "file" and mode.content.name or mode.name), 40, (260 - 20*(self.menu_state.mode)) + 20 * idx, 200, "left")
end
end
for idx, ruleset in pairs(self.menu_state.rule_list) do
if(idx >= self.menu_state.ruleset-9 and idx <= self.menu_state.ruleset+9) then
if(ruleset.type == "directory") then
love.graphics.setColor(1,0.5,0,1)
elseif(ruleset.type == "back") then
love.graphics.setColor(1,1,0,1)
else
love.graphics.setColor(1,1,1,1)
end
love.graphics.printf((ruleset.type == "file" and ruleset.content.name or ruleset.name), 360, (260 - 20*(self.menu_state.ruleset)) + 20 * idx, 200, "left")
end
end
end
function ModeSelectScene:onInputPress(e)
if self.display_warning and e.input then
scene = TitleScene()
elseif e.type == "wheel" then
if e.x % 2 == 1 then
self:switchSelect()
end
if e.y ~= 0 then
self:changeOption(-e.y)
end
elseif e.input == "menu_decide" or e.scancode == "return" then
if self.menu_state.mode_list[self.menu_state.mode].type == "directory" and self.menu_state.select == "mode" then
table.insert(self.menu_state.mode_list_history,self.menu_state.mode_list)
table.insert(self.menu_state.mode_path,self.menu_state.mode_list[self.menu_state.mode].name)
self.menu_state.mode_list = self.menu_state.mode_list[self.menu_state.mode].content
self.menu_state.mode = 1
elseif self.menu_state.mode_list[self.menu_state.mode].type == "back" and self.menu_state.select == "mode" then
table.remove(self.menu_state.mode_path)
self.menu_state.mode_list = table.remove(self.menu_state.mode_list_history)
self.menu_state.mode = 1
elseif self.menu_state.rule_list[self.menu_state.ruleset].type == "directory" and self.menu_state.select == "ruleset" then
table.insert(self.menu_state.rule_list_history,self.menu_state.rule_list)
table.insert(self.menu_state.rule_path,self.menu_state.rule_list[self.menu_state.ruleset].name)
self.menu_state.rule_list = self.menu_state.rule_list[self.menu_state.ruleset].content
self.menu_state.ruleset = 1
elseif self.menu_state.rule_list[self.menu_state.ruleset].type == "back" and self.menu_state.select == "ruleset" then
table.remove(self.menu_state.rule_path)
self.menu_state.rule_list = table.remove(self.menu_state.rule_list_history)
self.menu_state.ruleset = 1
elseif(self.menu_state.mode_list[self.menu_state.mode].type == "file" and self.menu_state.rule_list[self.menu_state.ruleset].type == "file") then -- make sure neither option is on a folder
current_mode = self.menu_state.mode
current_ruleset = self.menu_state.ruleset
config.current_mode = current_mode
config.mode_path = self.menu_state.mode_path
config.current_ruleset = current_ruleset
config.rule_path = self.menu_state.rule_path
playSE("mode_decide")
saveConfig()
scene = GameScene(
self.menu_state.mode_list[self.menu_state.mode].content,
self.menu_state.rule_list[self.menu_state.ruleset].content,
self.secret_inputs
)
end
elseif e.input == "up" or e.scancode == "up" then
self:changeOption(-1)
self.das_up = true
self.das_down = nil
elseif e.input == "down" or e.scancode == "down" then
self:changeOption(1)
self.das_down = true
self.das_up = nil
elseif e.input == "left" or e.input == "right" or e.scancode == "left" or e.scancode == "right" then
self:switchSelect()
elseif e.input == "menu_back" or e.scancode == "delete" or e.scancode == "backspace" then
scene = TitleScene()
elseif e.input then
self.secret_inputs[e.input] = true
end
end
function ModeSelectScene:onInputRelease(e)
if e.input == "up" or e.scancode == "up" then
self.das_up = nil
elseif e.input == "down" or e.scancode == "down" then
self.das_down = nil
elseif e.input then
self.secret_inputs[e.input] = false
end
end
function ModeSelectScene:changeOption(rel)
if self.menu_state.select == "mode" then
self:changeMode(rel)
elseif self.menu_state.select == "ruleset" then
self:changeRuleset(rel)
end
playSE("cursor")
end
function ModeSelectScene:switchSelect()
if self.menu_state.select == "mode" then
self.menu_state.select = "ruleset"
elseif self.menu_state.select == "ruleset" then
self.menu_state.select = "mode"
end
playSE("cursor_lr")
end
function ModeSelectScene:changeMode(rel)
local len = table.getn(self.menu_state.mode_list)
self.menu_state.mode = Mod1(self.menu_state.mode + rel, len)
end
function ModeSelectScene:changeRuleset(rel)
local len = table.getn(self.menu_state.rule_list)
self.menu_state.ruleset = Mod1(self.menu_state.ruleset + rel, len)
end
return ModeSelectScene