2012-04-21 05:43:52 -06:00
|
|
|
local _ENV = mkmodule('plugins.sort')
|
|
|
|
|
|
|
|
local utils = require('utils')
|
|
|
|
local units = require('plugins.sort.units')
|
2012-05-18 09:18:49 -06:00
|
|
|
local items = require('plugins.sort.items')
|
2012-04-21 05:43:52 -06:00
|
|
|
|
|
|
|
orders = orders or {}
|
|
|
|
orders.units = units.orders
|
2012-05-18 09:18:49 -06:00
|
|
|
orders.items = items.orders
|
2012-04-21 05:43:52 -06:00
|
|
|
|
|
|
|
function parse_ordering_spec(type,...)
|
|
|
|
local group = orders[type]
|
|
|
|
if group == nil then
|
|
|
|
dfhack.printerr('Invalid ordering class: '..tostring(type))
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local specs = table.pack(...)
|
|
|
|
local rv = { }
|
2012-04-21 06:53:17 -06:00
|
|
|
|
2012-04-21 05:43:52 -06:00
|
|
|
for _,spec in ipairs(specs) do
|
2012-04-21 06:53:17 -06:00
|
|
|
local nil_first = false
|
|
|
|
if string.sub(spec,1,1) == '<' then
|
|
|
|
nil_first = true
|
|
|
|
spec = string.sub(spec,2)
|
|
|
|
end
|
|
|
|
|
|
|
|
local reverse = false
|
|
|
|
if string.sub(spec,1,1) == '>' then
|
|
|
|
reverse = true
|
|
|
|
spec = string.sub(spec,2)
|
|
|
|
end
|
|
|
|
|
2012-04-21 05:43:52 -06:00
|
|
|
local cm = group[spec]
|
2012-04-21 06:53:17 -06:00
|
|
|
|
2012-04-21 05:43:52 -06:00
|
|
|
if cm == nil then
|
|
|
|
dfhack.printerr('Unknown order for '..type..': '..tostring(spec))
|
|
|
|
return nil
|
|
|
|
end
|
2012-04-21 06:53:17 -06:00
|
|
|
|
|
|
|
if nil_first or reverse then
|
|
|
|
cm = copyall(cm)
|
|
|
|
cm.nil_first = nil_first
|
|
|
|
cm.reverse = reverse
|
|
|
|
end
|
|
|
|
|
2012-04-21 05:43:52 -06:00
|
|
|
rv[#rv+1] = cm
|
|
|
|
end
|
|
|
|
|
|
|
|
return rv
|
|
|
|
end
|
|
|
|
|
|
|
|
make_sort_order = utils.make_sort_order
|
|
|
|
|
|
|
|
return _ENV
|