Skip to content

Commit

Permalink
create "internal" skeleton structure
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jul 25, 2020
1 parent 043a3c0 commit 35b8510
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 18 deletions.
26 changes: 26 additions & 0 deletions internal/quickfort/build.lua
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions internal/quickfort/common.lua
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions internal/quickfort/dig.lua
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions internal/quickfort/place.lua
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions internal/quickfort/query.lua
Original file line number Diff line number Diff line change
@@ -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
54 changes: 36 additions & 18 deletions quickfort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 [<key> <value>]"')
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',
Expand All @@ -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',
Expand All @@ -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

Expand All @@ -204,19 +208,31 @@ local function do_command(in_args)
error("expected <list_num> or <filename> 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,
Expand All @@ -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


Expand Down

0 comments on commit 35b8510

Please sign in to comment.