Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ ground reloaded ]]--
- -- Projet non achevé d'éditeur de carte.
- --[[
- liste id TextArea
- 0 base en haut
- 1 type de sol selectionné
- 2 liste des sols
- 3 prop du sol selectionné (fond)
- 4 type et id du sol selectionné
- 5 X et Y du sol selectionné
- 6 L et H du sol selectionné
- 7-28 proppriétés du sol selectionné
- 29 selection prop avancées sol
- 30 selection tu type de sol
- 31-34 points déjà cliqués
- 35 obtenir xml et jouer map
- ]]--
- sol = {}
- sol[0] = {name="bois", prop={type=0,friction=0.3,restitution=0.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[1] = {name="glace", prop={type=1,friction=0,restitution=0.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[2] = {name="tramp", prop={type=2,friction=0,restitution=1.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[3] = {name="lave", prop={type=3,friction=0,restitution=20,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[4] = {name="choco", prop={type=4,friction=20,restitution=0.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[5] = {name="terre", prop={type=5,friction=0.3,restitution=0.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[6] = {name="herbe", prop={type=6,friction=0.3,restitution=0.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[7] = {name="sable", prop={type=7,friction=0.1,restitution=0.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[8] = {name="nuage", prop={type=8,friction=0.3,restitution=0.2,miceCollision=false,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[9] = {name="eau", prop={type=9,friction=0.3,restitution=0.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color','dynamic','mass','angle','fixedRotation','linearDamping','angularDamping','miceCollision','groundCollision','foreground'}}
- sol[10] = {name="pierre", prop={type=10,friction=0.3,restitution=0,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[11] = {name="neige", prop={type=11,friction=0.05,restitution=0.1,miceCollision=true,groundCollision=true,angle=0,foreground=false,dynamic=false}, fix={'color'}}
- sol[12] = {name="rect", prop={type=12,friction=0.3,restitution=0.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,color=0xaaaaaa,dynamic=false}, fix={}}
- sol[13] = {name="cercle", prop={type=13,friction=0.3,restitution=0.2,miceCollision=true,groundCollision=true,angle=0,foreground=false,color=0xaaaaaa,dynamic=false}, fix={'height'}}
- editor = {}
- editor.ground = {}
- editor.joint = {}
- editor.object = {}
- editor.setting = {}
- editor.other = {}
- editor.xml = {}
- interface = {}
- interface.ground = {}
- interface.ground.edit = {}
- interface.joint = {}
- interface.object = {}
- interface.setting = {}
- interface.other = {}
- interface.prop = { dynamic=8, mass=10, friction=12, restitution=14, angle=16, fixedRotation=18, linearDamping=20, angularDamping=22, color=24, miceCollision=26, groundCollision=28 }
- function init()
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoShaman(true)
- tfm.exec.disableAutoScore(true)
- info = {}
- editor.other.newMap()
- for name in pairs(tfm.get.room.playerList) do eventNewPlayer(name) end
- end
- function editor.other.newMap ()
- tfm.exec.newGame('<C><P DS="y;500" /><Z><S /><D /><O /></Z></C>')
- xml = {}
- xml.ground = {}
- xml.joint = {}
- xml.object = {}
- xml.setting = {}
- end
- function eventNewPlayer(name)
- system.bindMouse(name, true)
- info[name] = {}
- info[name].point = {}
- info[name].mode = "ground"
- info[name].type_g = 0
- info[name].page_g = 1
- info[name].lock = false
- ui.addTextArea(0,"", name, 5, -40, 790, 35, 0x324650, 0x324650, 1, true)
- interface.ground.base_show(name)
- end
- function interface.ground.base_show(name)
- ui.addTextArea(1, "", name, 10, -40, 80, 20, 0, 0, 0, true)
- ui.addTextArea(2, "", name, 805,5, 150, 200, 0x324650, 0x324650, 1, true)
- ui.addTextArea(35, "<b><a href='event:xml get'>xml</a>\n<a href='event:xml play'>jouer</a></b>", name, 750, -40, 45, 40, 1, 1, 1, true)
- interface.ground.type_refresh(name)
- interface.ground.list_refresh(name, 1)
- end
- function interface.ground.type_refresh(name)
- ui.updateTextArea(1,"<b><a href='event:ground type'>"..sol[info[name].type_g].name.."</a></b>", name)
- end
- function interface.ground.list_refresh(name, page)
- local nPage = math.floor(#xml.ground/10)+1
- local str = "<p align='center'><a href='event:ground list -1'>◀</a> page "..page.."/"..nPage.." <a href='event:ground list +1'>▶</a></p>\n<j>Id \ttype\tcoord<n>\n"
- for id=10*(page-1)+1,10*page do
- local g = xml.ground[id]
- if g then
- str = str..'\n'..tostring(id).." \t<j><b><a href='event:ground select "..id.."'>"..sol[g.prop.type].name.."</a></b><n> \t"..tostring(g.x)..","..tostring(g.y)
- end
- end
- ui.updateTextArea(2, str, name)
- info[name].page_g = page
- end
- function interface.ground.select_show(id, name)
- local text = ui.addTextArea
- text(3, "", name, 805, 215, 150, 380, 0x324650, 0x324650, 1, true)
- text(4, "<b>Trampo \t + 5 - </b>", name, 805, 220, 150, 20, 0, 0, 0, true)
- text(5, "X : \tY : ", name, 805, 245, 150, 20, 0x000000, 0, 0, true)
- text(6, "L : 1600 \tH : 30", name, 805, 260, 150, 20, 0, 0, 0, true)
- text(7, "Frottement :\nRestitution :\nAngle :\nCollision souris :\nCollision sols :\nAvant plan :\nCouleur \n\nDynamique :\nMasse :\nAngle fixe :\nAmort linéaire :\nAmort angulaire :", name, 805, 285, 150, 200, 0, 0, 0, true)
- text(8, "Non", name, 910, 285, 60, 200, 0, 0, 0, true)
- interface.ground.select_update(name, id)
- end
- --[[type
- x 3
- y 4
- width 5
- height 6
- dynamic 7
- mass 8
- friction 9
- restitution 10
- angle 11
- fixedRotation 12
- linearDamping 13
- angularDamping 14
- color 15
- miceCollision 16
- groundCollision 17
- m 18
- v 19
- i 20]]--
- interface.ground.prop_base = { "friction", "restitution", "angle", "miceCollision", "groundCollision", "foreground" }
- interface.ground.prop_dyna = { "dynamic", "mass", "fixedRotation", "linearDamping", "angularDamping" }
- function interface.ground.select_update(name, id)
- local typ = sol[xml.ground[id].prop.type].name
- local prop = xml.ground[id].prop
- local fix = sol[prop.type].fix
- ui.updateTextArea(4, "<b><a href='event:ground edit "..id.." type'>"..typ.."</a> \t <a href='event:ground edit "..id.." id -1'>-</a> "..id.." <a href='event:ground edit "..id.." id +1'>+</a></b>", name)
- ui.updateTextArea(5, "<b><a href='event:ground edit "..id.." x'>"..xml.ground[id].x.."</a> \t<a href='event:ground edit "..id.." y'>"..xml.ground[id].y.."</a></b>", name)
- ui.updateTextArea(6, "<b><a href='event:ground edit "..id.." witdh'>"..prop.width.."</a> \t<a href='event:ground edit "..id.." height'>"..prop.height.."</a></b>", name)
- local strB = "<b>"
- for _, v in ipairs(interface.ground.prop_base) do
- if table.find(fix, v) then
- strB = strB.."-"
- else
- strB = strB.."<a href='event:groud edit "..id.." "..v.."'>"
- if type(prop[v]) == "boolean" then
- strB = strB..((prop[v] and "oui") or "non")
- else
- strB = strB..tostring(prop[v])
- end
- strB = strB.."</a>"
- end
- strB = strB.."\n"
- end
- if prop.type == 12 or prop.type == 13 then
- strB = strB.."<a href='event:ground edit "..id.." color'>"..string.format("%x", prop.color or 0xaaaaaa).."</a>\n\n"
- else
- strB = strB.."-\n\n"
- end
- for _, v in ipairs(interface.ground.prop_dyna) do
- if table.find(fix, v) then
- strB = strB.."-"
- elseif v == "dynamic" then
- strB = strB.. "<a href='event:ground edit "..id.." dynamic'>"..((prop[v] and "oui") or "non").."</a>\n"
- elseif prop.dynamic then
- strB = strB.. "<a href='event:ground edit "..id.." "..v.."'>"
- if type(prop[v]) == "boolean" then
- strB = strB..((prop[v] and "oui") or "non")
- else
- strB = strB..tostring(prop[v])
- end
- strB = strB.."</a>\n"
- else
- strB = strB.."-\n"
- end
- end
- ui.updateTextArea(8, strB, name)
- end
- function eventTextAreaCallback(id, name, call)
- local lw = {}
- for w in call:gmatch('%S+') do table.insert(lw, w) end
- if not info[name].lock then
- print(name..' - text : '..call)
- if lw[1] == "ground" then
- if lw[2] == "type" then
- if lw[3] then
- ui.removeTextArea(id, name)
- info[name].type_g = tonumber(lw[3])
- interface.ground.type_refresh(name)
- else
- local str = "<b><a href='event:ground type 0'>bois</a>\n"
- for k,v in ipairs(sol) do
- str = str.."<a href='event:ground type "..k.."'>"..v.name.."</a>\n"
- end
- str = str.."</b>"
- ui.addTextArea(30, str, name, -75, -40, 70, 59, 0x324650, 0x324650, 1, true)
- end
- elseif lw[2] == "list" then
- local nPage = math.floor(#xml.ground/10)+1
- local page = info[name].page_g + tonumber(lw[3])
- if page < 1 then page = 1 elseif page > nPage then page = nPage end
- interface.ground.list_refresh(name, page)
- elseif lw[2] == "select" then
- interface.ground.select_show(tonumber(lw[3]), name)
- elseif lw[2] == "edit" then
- if lw[4]=="dynamic" or lw[4]=="foreground" or lw[4]=="miceCollision" or lw[4]=="groundCollision" or lw[4]=="fixedRotation" then
- editor.ground.edit(tonumber(lw[3]), lw[4], not xml.ground[tonumber(lw[3])].prop[lw[4]])
- interface.ground.select_update(name, tonumber(lw[3]))
- else
- info[name].lock = true
- info[name].ing = "ground "..lw[3]..' '..lw[4]
- ui.addPopup(1, 2, "<p align='center'>Entrer la nouvelle valeur</p>", name, 300, 200, 200, true)
- end
- end
- elseif lw[1]=="xml" then
- local str = editor.xml.get()
- if lw[2]=="get" then
- str = string.gsub (string.gsub (str, '<', '<'), '>', '>')
- comp = 0
- while comp < #str do
- print(str:sub(comp, comp+4500))
- comp = comp+4501
- end
- elseif lw[2]=="play" then
- tfm.exec.newGame(str)
- end
- end
- end
- end
- function eventPopupAnswer(id, name, ans)
- print(name..' - popup : '..info[name].ing..' / '..ans)
- local lw = {}
- for w in info[name].ing:gmatch('%S+') do table.insert(lw, w) end
- ans = tonumber(ans)
- if ans then editor.ground.edit(tonumber(lw[2]), lw[3], ans) end
- info[name].lock = false
- interface.ground.select_update(name, tonumber(lw[2]))
- end
- function eventMouse(name, x, y)
- if not info[name].lock then
- print(name..' - mouse : '..x..' '..y)
- if info[name].mode == "ground" then
- if info[name].point[1] then
- local x1, y1 = info[name].point[1].x, info[name].point[1].y
- local cx, cy = math.floor((x+x1)/2), math.floor((y+y1)/2)
- local l, h = math.abs(x-x1), math.abs(y-y1)
- local prop = table.copy(sol[info[name].type_g].prop)
- if prop.type == 13 then
- prop.width = math.floor(math.sqrt(l*l+h*h)/2)
- else
- prop.width, prop.height = l, h
- end
- editor.ground.add(cx, cy, prop)
- info[name].point[1] = nil
- else
- info[name].point[1] = {['x']=x, ['y']=y}
- end
- end
- end
- end
- function editor.xml.ground (id)
- local g = xml.ground[id]
- local pro = g.prop
- local str = '<S T="'..pro.type..'" X="'..g.x..'" Y="'..g.y..'" L="'..pro.width..'" '..((pro.type~=13 and ('H="'..pro.height..'" ')) or '')
- if pro.miceCollision then
- if not pro.groundCollision then
- str = str..'c="3" '
- end
- elseif pro.groundCollision then
- str = str..'c="2" '
- else
- str = str..'c="4" '
- end
- if pro.type == 12 or pro.type == 13 then
- str = str..'o="'..(string.format('%x', pro.color) or '')..'" '
- end
- str = (pro.v and (str..'v="'..pro.v..'" ')) or str
- str = (pro.m and (str..'m="" ')) or str
- str = (pro.foreground and (str..'N="" ')) or str
- str = (pro.i and (str..'i="'..pro.i..'" ')) or str
- str = (pro.lua and (str..'lua="'..pro.lua..'" ')) or str
- local str2 = 'P="'
- local d = pro.dynamic
- str2 = str2..((d and '1') or '')..','..((d and (pro.mass or '')) or 0)..','..(pro.friction or 0)..','..(pro.restituion or 0)..','..(pro.angle or 0)..','..((d and (pro.fixedRotation or '')) or '')..','..((d and (pro.linearDamping or '')) or '')..','..((d and (angularDamping or '')) or '')..'" '
- return str..str2..'/>'
- end
- function editor.xml.setting()
- return ''
- end
- function editor.xml.joint(id)
- return ''
- end
- function editor.xml.get()
- local str = '<C><P /><Z><S>'
- local S = editor.xml.ground
- for id in ipairs(xml.ground) do str = str..S(id) end
- str = str..'</S><D /><O /></Z></C>'
- return str
- --<C><P /><Z><S></S><D /><O /></Z></C>
- end
- function editor.ground.add(x, y, prop, id)
- id = id or #xml.ground+1
- local inf = {}
- inf.x, inf.y, inf.prop = x, y, prop
- xml.ground[id] = inf
- editor.ground.show(id)
- end
- function editor.ground.show(id)
- local inf = xml.ground[id]
- local pro = inf.prop
- tfm.exec.addPhysicObject(id, inf.x, inf.y, { ["type"]=pro.type, width=pro.width, height=pro.height, color=pro.color, miceCollision=false, objectCollision=false, angle=pro.angle, foreground=pro.foreground})
- end
- function editor.ground.delete(id)
- table.remove(xml.ground, id)
- tfm.exec.removePhysicObject(id)
- for i=id, #xml.ground do
- tfm.exec.removePhysicObject(i)
- editor.ground.show(i)
- end
- tfm.exec.removePhysicObject(#xml.ground+1)
- end
- function editor.ground.edit(id, prop, val)
- if prop == "x" or prop == "y" then
- xml.ground[id][prop] = val
- else
- xml.ground[id].prop[prop] = val
- end
- editor.ground.show(id)
- end
- function table.copy(tab)
- local res = {}
- for k, v in pairs(tab) do
- if type(v)=="table" then
- res[k] = table.copy(v)
- else
- res[k] = v
- end
- end
- return res
- end
- function table.find(tab, elmt)
- for k,v in pairs(tab) do if v==elmt then return true,k end end return false
- end
- updateTextArea = ui.updateTextArea
- function ui.updateTextArea(id, text, name)
- if type(name) == "table" then
- for _, n in ipairs(name) do
- updateTextArea(id, text, n)
- end
- else
- updateTextArea(id, text, name)
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement