feat: add base script for new puzzles
This commit is contained in:
@@ -10,6 +10,15 @@ local CHOICES = {
|
|||||||
main = "Back to main menu"
|
main = "Back to main menu"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local PUZZLE_BASE = [[local puzzle%d = {}
|
||||||
|
|
||||||
|
function puzzle%d.solve(input)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
return puzzle%d
|
||||||
|
]]
|
||||||
|
|
||||||
---@class Day
|
---@class Day
|
||||||
---@field day integer
|
---@field day integer
|
||||||
---@field title string?
|
---@field title string?
|
||||||
@@ -102,20 +111,10 @@ end
|
|||||||
function Day:createFiles()
|
function Day:createFiles()
|
||||||
local srcDir = self:srcDir()
|
local srcDir = self:srcDir()
|
||||||
fs.makeDir(srcDir)
|
fs.makeDir(srcDir)
|
||||||
local files = {
|
utils.writeFile(srcDir .. "/puzzle1.lua", PUZZLE_BASE:format(1, 1, 1))
|
||||||
srcDir .. "/puzzle1.lua",
|
utils.writeFile(srcDir .. "/puzzle2.lua", PUZZLE_BASE:format(2, 2, 2))
|
||||||
srcDir .. "/puzzle2.lua",
|
utils.writeFile(self:examplePath(), "")
|
||||||
self:examplePath(),
|
utils.writeFile(self:inputPath(), "")
|
||||||
self:inputPath()
|
|
||||||
}
|
|
||||||
for _, path in ipairs(files) do
|
|
||||||
local f = fs.open(path, "a")
|
|
||||||
if f then
|
|
||||||
f.close()
|
|
||||||
else
|
|
||||||
printError("Could not create file " .. path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Day:getExampleData(suffix)
|
function Day:getExampleData(suffix)
|
||||||
|
|||||||
@@ -41,6 +41,21 @@ function utils.readFile(path)
|
|||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function utils.writeFile(path, content, overwrite)
|
||||||
|
overwrite = overwrite or false
|
||||||
|
if not overwrite and fs.exists(path) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
local f = fs.open(path, "w")
|
||||||
|
if not f then
|
||||||
|
printError("Could not open file " .. path)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
f.write(content)
|
||||||
|
f.close()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function utils.waitForKey(targetKey)
|
function utils.waitForKey(targetKey)
|
||||||
if targetKey then
|
if targetKey then
|
||||||
print("Press " .. keys.getName(targetKey):upper() .. " to continue")
|
print("Press " .. keys.getName(targetKey):upper() .. " to continue")
|
||||||
|
|||||||
Reference in New Issue
Block a user