refactor: rework choice lists

This commit is contained in:
2025-11-28 21:55:11 +01:00
parent 7490ea5b47
commit b059d8e381

View File

@@ -4,14 +4,6 @@ local days = {}
local DAY_CACHE_PATH = CACHE_PATH .. "/days" local DAY_CACHE_PATH = CACHE_PATH .. "/days"
local CHOICES = {
create = "Create files",
example = "Run examples",
real = "Run with real input",
star = "Mark solved",
main = "Back to main menu"
}
local PUZZLE_BASE = [[local puzzle%d = {} local PUZZLE_BASE = [[local puzzle%d = {}
function puzzle%d.solve(input) function puzzle%d.solve(input)
@@ -196,23 +188,21 @@ function Day:menuStars()
while true do while true do
self:printTitle() self:printTitle()
local choices = { local choices = {
puzzle1 = "Mark puzzle 1 as " .. solvedTxt(not self.puzzle1), {"Mark puzzle 1 as " .. solvedTxt(not self.puzzle1), 1},
puzzle2 = "Mark puzzle 2 as " .. solvedTxt(not self.puzzle2), {"Mark puzzle 2 as " .. solvedTxt(not self.puzzle2), 2},
back = "Back" "Back"
} }
local c = utils.promptChoices({choices.puzzle1, choices.puzzle2, choices.back}, c0) local c = utils.promptChoices(choices, c0)
if c == choices.back then if c == "Back" then
return return
end end
if c == choices.puzzle1 then c0 = c
if c == 1 then
self.puzzle1 = not self.puzzle1 self.puzzle1 = not self.puzzle1
self:saveStats() elseif c == 2 then
c0 = 1
elseif c == choices.puzzle2 then
self.puzzle2 = not self.puzzle2 self.puzzle2 = not self.puzzle2
self:saveStats()
c0 = 2
end end
self:saveStats()
end end
end end
@@ -261,27 +251,35 @@ function Day:show()
while true do while true do
self:printTitle() self:printTitle()
if fs.exists(self:srcDir()) then if fs.exists(self:srcDir()) then
local c = utils.promptChoices({CHOICES.example, CHOICES.real, CHOICES.star, CHOICES.main}) local c = utils.promptChoices({
if c == CHOICES.main then {"Run examples", "examples"},
{"Run with real input", "inputs"},
{"Mark solved", "stars"},
{"Back to main menu", "main"}
})
if c == "main" then
return return
elseif c == CHOICES.star then elseif c == "stars" then
self:menuStars() self:menuStars()
else else
local puzzle = self:choosePuzzle(c == CHOICES.real) local puzzle = self:choosePuzzle(c == "inputs")
if puzzle ~= "Back" then if puzzle ~= "Back" then
if c == CHOICES.example then if c == "examples" then
self:execExample(puzzle) self:execExample(puzzle)
elseif c == CHOICES.real then elseif c == "inputs" then
self:execReal(puzzle) self:execReal(puzzle)
end end
utils.waitForKey(keys.enter) utils.waitForKey(keys.enter)
end end
end end
else else
local c = utils.promptChoices({CHOICES.create, CHOICES.main}) local c = utils.promptChoices({
if c == CHOICES.main then {"Create files", "create"},
{"Back to main menu", "main"}
})
if c == "main" then
return return
elseif c == CHOICES.create then elseif c == "create" then
self:createFiles() self:createFiles()
end end
end end