Little cleanup and update to gm-editor

develop
Warmist 2012-09-07 17:25:39 +03:00
parent 0db873493a
commit 85fc3384dd
3 changed files with 19 additions and 67 deletions

@ -1,7 +0,0 @@
<ld:data-definition xmlns:ld="http://github.com/peterix/dfhack/lowered-data-definition">
<ld:global-type ld:meta="struct-type" type-name="coord">
<ld:field name="x" ld:meta="number" ld:subtype="int16_t" ld:bits="16"/>
<ld:field name="y" ld:meta="number" ld:subtype="int16_t" ld:bits="16"/>
<ld:field name="z" ld:meta="number" ld:subtype="int16_t" ld:bits="16"/>
</ld:global-type>
</ld:data-definition>

@ -1,55 +0,0 @@
function parseargs(s)
local arg = {}
string.gsub(s, "([%w%-]+)=([\"'])(.-)%2", function (w, _, a)
arg[w] = a
end)
return arg
end
function collect(s)
local stack = {}
local top = {}
table.insert(stack, top)
local ni,c,label,xarg, empty
local i, j = 1, 1
while true do
ni,j,c,label,xarg, empty = string.find(s, "<(%/?)([%w:%-]+)(.-)(%/?)>", i)
if not ni then break end
local text = string.sub(s, i, ni-1)
if not string.find(text, "^%s*$") then
table.insert(top, text)
end
if empty == "/" then -- empty element tag
table.insert(top, {label=label, xarg=parseargs(xarg), empty=1})
elseif c == "" then -- start tag
top = {label=label, xarg=parseargs(xarg)}
table.insert(stack, top) -- new level
else -- end tag
local toclose = table.remove(stack) -- remove top
top = stack[#stack]
if #stack < 1 then
error("nothing to close with "..label)
end
if toclose.label ~= label then
error("trying to close "..toclose.label.." with "..label)
end
table.insert(top, toclose)
end
i = j+1
end
local text = string.sub(s, i)
if not string.find(text, "^%s*$") then
table.insert(stack[#stack], text)
end
if #stack > 1 then
error("unclosed "..stack[#stack].label)
end
return stack[1]
end
function parseXmlFile(path)
local f, e = io.open(path, "r")
local xml = f:read("*a")
return collect(xml)
end

@ -1,6 +1,7 @@
-- Interface powered item editor. -- Interface powered item editor.
-- TODO use this: MechanismList = defclass(MechanismList, guidm.MenuOverlay) -- TODO use this: MechanismList = defclass(MechanismList, guidm.MenuOverlay)
local gui = require 'gui' local gui = require 'gui'
local dialog = require 'gui.dialogs'
local my_trg local my_trg
if dfhack.gui.getCurFocus() == 'item' then if dfhack.gui.getCurFocus() == 'item' then
@ -47,12 +48,25 @@ local item_screen={
mode=MODE_BROWSE, mode=MODE_BROWSE,
keys={}, keys={},
insertNew=function(self)
--[=[local trg=self:currentTarget() -- not sure if possible... insertNew=function(self,typename)
local tp=typename
if typename== nil then
dialog.showInputPrompt("Class type","Input class type\n:",COLOR_WHITE,"",dfhack.curry(self.insertNew,self))
return
end
local ntype=df[tp]
if ntype== nil then
dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_RED)
return
end
local trg=self:currentTarget()
if trg.target and trg.target._kind and trg.target._kind=="container" then if trg.target and trg.target._kind and trg.target._kind=="container" then
local thing=df.new('general_ref_contained_itemst') local thing=ntype:new()
trg.target:insert('#',trg.keys[trg.selected]) dfhack.call_with_finalizer(1,false,df.delete,thing,trg.target.insert,trg.target,'#',thing)
end]=]
end
end, end,
deleteSelected=function(self) deleteSelected=function(self)
local trg=self:currentTarget() local trg=self:currentTarget()