Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ xml_unpack [v1.0] + Explorateur Lua [v1.1]
- Ce module est une version de xml_unpack couplé au module Explorateur Lua permettant de connaitre toutes les informations sur une carte.
- Commandes :
- !loadXml (permet de charger les informations concernant le code xml d'une carte, le tableau correspondant se trouve dans la variable xml_unpack.xml (à afficher grâce à l'Explorateur Lua)
- N.B : ce module est inspiré d'une partie de l'excellent XML Editor : http://atelier801.com/topic?f=6&t=520844
- N.B² : Il existe une version de ce module sans l'Explorateur Lua qui contient le strict nescessaire pour décompiler un code xml, simple à ajouter à un module plus grand : http://pastebin.com/rK0hCyik
- ]]
- --[[ Module exploLua (début)
- Merci de ne rien modifier
- ]]
- local exploLua = {}
- function exploLua.init()
- exploLua.info = {}
- for name in pairs(tfm.get.room.playerList) do exploLua.newP(name) end
- end
- function exploLua.newP(name)
- exploLua.info[name] = {}
- exploLua.info[name].path = {"_G"}
- ui.addTextArea(2112, "<a href='event:open'>open</a>", name, 5, 377, 50, 18, 0x27373f, 0x27373f, 1, true)
- end
- function exploLua.openWind(name)
- ui.addTextArea(2113, "<b><p align='right'><a href='event:'>X</a></p></b>", name, 150, 50, 500, 300, 0x27373f, 0x27373f, 1, true) -- fond1
- ui.addTextArea(2114, "", name, 150, 75, 500, 275, 0x324650, 0x27373f, 1, true) -- fond2
- ui.addTextArea(2115, "", name, 175, 85, 450, 20, 0x27373f, 0x27373f, 1, true) -- chemin
- ui.addTextArea(2116, "", name, 175, 120, 140, 200, 0x27373f, 0x27373f, 1, true) -- liste noms
- ui.addTextArea(2117, "", name, 330, 120, 140, 200, 0x27373f, 0x27373f, 1, true) -- liste types
- ui.addTextArea(2118, "", name, 485, 120, 140, 200, 0x27373f, 0x27373f, 1, true) -- liste valeurs
- eventTextAreaCallback(2115, name, #exploLua.info[name].path)
- end
- function exploLua.closeWind(name)
- ui.removeTextArea(2113, name); ui.removeTextArea(2114, name); ui.removeTextArea(2115, name); ui.removeTextArea(2116, name); ui.removeTextArea(2117, name); ui.removeTextArea(2118, name)
- ui.addTextArea(2112, "<a href='event:open'>open</a>", name, 5, 377, 50, 20, 0x27373f, 0x27373f, 1, true)
- end
- function exploLua.open(name)
- local path = exploLua.info[name].path
- local tab, path = exploLua.folder(table.copy(exploLua.info[name].path))
- exploLua.info[name].path = path
- local files = ""
- local typ = ""
- local values = ""
- local way = ""
- for key, val in pairs(tab) do
- files = files.."<a href='event:"..tostring(key).."'>"..tostring(key).."</a>\n"
- values = values..tostring(val)..'\n'
- typ = typ..type(val)..'\n'
- end
- for key, val in ipairs(path) do
- way = way.."<a href='event:"..tostring(key).."'>"..val..".</a>"
- end
- ui.updateTextArea(2115, way, name)
- ui.updateTextArea(2116, files, name)
- ui.updateTextArea(2117, typ, name)
- ui.updateTextArea(2118, values, name)
- end
- function exploLua.folder(path, tab, way)
- tab = tab or _G
- way = way or {"_G"}
- if path[2] then
- if type(tab[path[2]]) == "table" then
- tab = tab[path[2]]
- table.insert(way, path[2])
- table.remove(path, 2)
- return exploLua.folder(path, tab, way)
- else
- local code = string.gsub (string.gsub (tostring(tab[path[2]]), '<', '<'), '>', '>')
- local comp = 0
- while comp < #code do
- print(code:sub(comp, comp+4500))
- comp = comp+4501
- end
- end
- end
- return tab, way
- end
- function table.copy(tab)
- local res = {}
- for key, val in pairs(tab) do res[key] = val end
- return res
- end
- --[[Module exploLua (fin)
- Vous pouvez modifier les fonctions qui suivent
- (attention à ne pas empècher les tests de la fonction eventTextAreaCallback)
- ]]
- function eventTextAreaCallback(id, name, call)
- --
- -- Module exploLua (début)
- if id==2115 then
- local i = #exploLua.info[name].path - tonumber(call)
- for k=1,i do table.remove(exploLua.info[name].path) end
- exploLua.open(name)
- elseif id == 2116 then
- table.insert(exploLua.info[name].path, tonumber(call) or call)
- exploLua.open(name)
- elseif id == 2112 then
- ui.removeTextArea(2112, name)
- exploLua.openWind(name)
- elseif id == 2113 then exploLua.closeWind(name)
- end
- -- Module exploLua (fin)
- end
- -- Ligne d'initialisation du module exploLua
- exploLua.init()
- -------------------------- Module xml_unpack
- xml_unpack = {}
- function xml_unpack.loadXml(code)
- local xml = {}
- xml.xml = code
- xml.xPropFull = xml.xml:match('<P .->')
- xml.xProp = {}
- for prop, val in xml.xPropFull:gmatch('(%S+)="(%S-)"') do xml.xProp[prop] = val or '' end
- xml.xGroundFull = xml.xml:match('<S>.-</S>',#xml.xProp)
- xml.xGround = { id={}, type={} }
- if xml.xGroundFull then
- local way, id = xml.xGround.id, 0
- local wayB = xml.xGround.type
- for str in xml.xGroundFull:gmatch('<S .-/>') do
- way[id] = {xml=str}
- xml_unpack.unpackProp(way[id], str)
- local T = tonumber(way[id].T) or 0
- if not wayB[T] then wayB[T] = {} end
- wayB[T][id] = way[id]
- id = id+1
- end
- end
- xml.xDecoFull = xml.xml:match('<D>.-</D>')
- xml.xDeco = { id={}, T={}, F={}, DS={}, DC={}, P={}, type={} }
- if xml.xDecoFull then
- local way, id = xml.xDeco.id, 0
- local wayB = xml.xDeco
- for str in xml.xDecoFull:gmatch('<%a%a? .-/>') do
- way[id] = {xml=str}
- xml_unpack.unpackProp(way[id], str)
- wayB[str:match('%a%a?')][id] = way[id]
- id = id+1
- end
- local wayD = xml.xDeco.type
- for id, prop in pairs(wayB.P) do
- local T = tonumber(prop.T) or 0
- if not wayD[T] then wayD[T] = {} end
- wayD[T][id] = prop
- end
- end
- xml.xObjectFull = xml.xml:match('<O>.-</O>')
- xml.xObject = { id={}, type={} }
- if xml.xObjectFull then
- local way, id = xml.xObject.id, 0
- local wayB = xml.xObject.type
- for str in xml.xObjectFull:gmatch('<O .-/>') do
- way[id] = {xml=str}
- xml_unpack.unpackProp(way[id], str)
- local C = tonumber(way[id].C) or 0
- if not wayB[C] then wayB[C] = {} end
- wayB[C][id] = way[id]
- id = id+1
- end
- end
- xml.xJointFull = xml.xml:match('<L>.-</L>')
- xml.xJoint = { id={}, JD={}, JP={}, JR={}, JPL={} }
- if xml.xJointFull then
- local way, id = xml.xJoint.id, 0
- local wayB = xml.xJoint
- for str in xml.xJointFull:gmatch('<J.- />') do
- way[id] = {xml=str}
- xml_unpack.unpackProp(way[id], str)
- way[id].type = str:match('%a%a%a?')
- wayB[way[id].type][id] = way[id]
- id = id+1
- end
- end
- return xml
- end
- function xml_unpack.unpackProp(tab, str)
- for prop, val in str:gmatch('([^%s"]+)="([^%s"]-)"') do
- if val:find(',') then tab[prop]=string.split(val, ',') else tab[prop] = val or '' end
- end
- end
- function string.split(str, del)
- local del=del or ','
- local res={}
- for s in str:gmatch('[^'..del..']+') do
- table.insert(res, s)
- end
- return res
- end
- function eventChatCommand(name, command)
- if command == "loadXml" then
- if tfm.get.room.xmlMapInfo then
- xml_unpack.xml = xml_unpack.loadXml(tfm.get.room.xmlMapInfo.xml)
- print('xml chargé')
- else
- print('xml non chargé : pas de xml disponible.')
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement