diff --git a/internal/quickfort/build.lua b/internal/quickfort/build.lua new file mode 100644 index 0000000000..5be299949c --- /dev/null +++ b/internal/quickfort/build.lua @@ -0,0 +1,26 @@ +-- build-related logic for the quickfort script + +local _ENV = mkmodule('hack.scripts.internal.quickfort.build') + +local quickfort_common = require('hack.scripts.internal.quickfort.common') +local log = quickfort_common.log + +function do_run(zlevel, grid) + local stats = nil + print('"quickfort run" not yet implemented for mode: build') + return stats +end + +function do_orders(zlevel, grid) + local stats = nil + print('"quickfort orders" not yet implemented for mode: build') + return stats +end + +function do_undo(zlevel, grid) + local stats = nil + print('"quickfort undo" not yet implemented for mode: build') + return stats +end + +return _ENV diff --git a/internal/quickfort/common.lua b/internal/quickfort/common.lua new file mode 100644 index 0000000000..d7837e6ec9 --- /dev/null +++ b/internal/quickfort/common.lua @@ -0,0 +1,17 @@ +-- common logic for the quickfort modules + +local _ENV = mkmodule('hack.scripts.internal.quickfort.common') + +settings = { + blueprints_dir = 'blueprints', + force_marker_mode = false, + force_interactive_build = false, +} + +verbose = false + +function log(...) + if verbose then print(string.format(...)) end +end + +return _ENV diff --git a/internal/quickfort/dig.lua b/internal/quickfort/dig.lua new file mode 100644 index 0000000000..293c0669b2 --- /dev/null +++ b/internal/quickfort/dig.lua @@ -0,0 +1,25 @@ +-- dig-related logic for the quickfort script + +local _ENV = mkmodule('hack.scripts.internal.quickfort.dig') + +local quickfort_common = require('hack.scripts.internal.quickfort.common') +local log = quickfort_common.log + +function do_run(zlevel, grid) + local stats = nil + print('"quickfort run" not yet implemented for mode: dig') + return stats +end + +function do_orders(zlevel, grid) + log('nothing to do for blueprints in mode: dig') + return nil +end + +function do_undo(zlevel, grid) + local stats = nil + print('"quickfort undo" not yet implemented for mode: dig') + return stats +end + +return _ENV diff --git a/internal/quickfort/place.lua b/internal/quickfort/place.lua new file mode 100644 index 0000000000..a337f04e1e --- /dev/null +++ b/internal/quickfort/place.lua @@ -0,0 +1,25 @@ +-- place-related logic for the quickfort script + +local _ENV = mkmodule('hack.scripts.internal.quickfort.place') + +local quickfort_common = require('hack.scripts.internal.quickfort.common') +local log = quickfort_common.log + +function do_run(zlevel, grid) + local stats = nil + print('"quickfort run" not yet implemented for mode: place') + return stats +end + +function do_orders(zlevel, grid) + log('nothing to do for blueprints in mode: place') + return nil +end + +function do_undo(zlevel, grid) + local stats = nil + print('"quickfort undo" not yet implemented for mode: place') + return stats +end + +return _ENV diff --git a/internal/quickfort/query.lua b/internal/quickfort/query.lua new file mode 100644 index 0000000000..6395988a06 --- /dev/null +++ b/internal/quickfort/query.lua @@ -0,0 +1,24 @@ +-- query-related logic for the quickfort script + +local _ENV = mkmodule('hack.scripts.internal.quickfort.query') + +local quickfort_common = require('hack.scripts.internal.quickfort.common') +local log = quickfort_common.log + +function do_run(zlevel, grid) + local stats = nil + print('"quickfort run" not yet implemented for mode: query') + return stats +end + +function do_orders(zlevel, grid) + log('nothing to do for blueprints in mode: query') + return nil +end + +function do_undo(zlevel, grid) + print('cannot undo blueprints for mode: query') + return nil +end + +return _ENV diff --git a/quickfort.lua b/quickfort.lua index d3eb3d1b72..ab21939fb0 100644 --- a/quickfort.lua +++ b/quickfort.lua @@ -99,9 +99,20 @@ files are described in the files themselves. -- only initialize our globals once if not initialized then -initialized = true + +local utils = require('utils') +local quickfort_common = require('hack.scripts.internal.quickfort.common') +local quickfort_dig = require('hack.scripts.internal.quickfort.dig') +local quickfort_build = require('hack.scripts.internal.quickfort.build') +local quickfort_place = require('hack.scripts.internal.quickfort.place') +local quickfort_query = require('hack.scripts.internal.quickfort.query') local function do_reset() + reload('hack.scripts.internal.quickfort.common') + reload('hack.scripts.internal.quickfort.dig') + reload('hack.scripts.internal.quickfort.build') + reload('hack.scripts.internal.quickfort.place') + reload('hack.scripts.internal.quickfort.query') initialized = false end @@ -145,26 +156,19 @@ For more info, see: https://docs.dfhack.org/en/stable/docs/_auto/base.html#quick ]] end -local settings = { - blueprints_dir = 'blueprints', - force_marker_mode = false, - force_interactive_build = false, -} - local function do_set(args) if #args == 0 then print('active settings:') - printall(settings) + printall(quickfort_common.settings) return end if #args ~= 2 then error('error: expected "quickfort set [ ]"') end - -- TODO: validate and set settings + print('NOT YET IMPLEMENTED') + print(string.format('would set %s to "%s"', args[1], tostring(args[2]))) end -local utils = require('utils') - local valid_list_args = utils.invert({ 'l', '-library', @@ -178,11 +182,11 @@ local function do_list(in_args) 'would call "list" with show_library="%s"', tostring(show_library))) end -local valid_commands = utils.invert({ - 'run', - 'orders', - 'undo', -}) +local command_switch = { + run='do_run', + orders='do_orders', + undo='do_undo', +} local valid_command_args = utils.invert({ 'q', @@ -195,7 +199,7 @@ local valid_command_args = utils.invert({ local function do_command(in_args) local command = in_args.action - if not valid_commands[command] then + if not command or not command_switch[command] then error(string.format('invalid command: "%s"', command)) end @@ -204,19 +208,31 @@ local function do_command(in_args) error("expected or parameter") end local list_num = tonumber(filename) - -- TODO: convert list number into filename + if list_num then + print('NOT YET IMPLEMENTED') + print(string.format('would convert "%d" into blueprint filename', + list_num)) + end local args = utils.processArgs(in_args, valid_command_args) local quiet = args['q'] ~= nil or args['-quiet'] ~= nil local verbose = args['v'] ~= nil or args['-verbose'] ~= nil local sheet = tonumber(args['s']) or tonumber(args['-sheet']) + if command ~= 'orders' and df.global.cursor.x == -30000 then + error('please position the game cursor at the blueprint start location') + end + + quickfort_common.verbose = verbose + print('NOT YET IMPLEMENTED') print(string.format( 'would call "%s" with filename="%s", quiet=%s, verbose=%s, sheet=%s', command, filename, tostring(quiet), tostring(verbose), sheet)) end + +-- initialize script action_switch = { reset=do_reset, set=do_set, @@ -226,6 +242,8 @@ action_switch = { undo=do_command, } setmetatable(action_switch, {__index=function () return print_short_help end}) + +initialized = true end -- if not initialized