Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Joint drawing [v1.0]
- !color ff00ff => Changer la couleur (mettez un code hexadecimal)
- !alpha xx => Changer la transparence de ses joints (entre 0 et 1)
- !line xx => Changer l'épaisseur de ses joints
- !bezier xx => Changer le nombre de joints pour former un bezier
- !xml => Afficher le code xml du dessin pour l'éditeur de cartes
- ]]--
- interface = {}
- interface.joint = {}
- xml = {}
- xml.joint = {}
- editor = {}
- editor.joint = {}
- tool = {}
- function init ()
- info = {}
- for name in pairs(tfm.get.room.playerList) do eventNewPlayer(name) end
- eventNewGame()
- end
- function interface.joint.affiche (name)
- ui.addTextArea( 0, "<b>type de joint : <a href='event:joint type •'>•</a> <a href='event:joint type /'>/</a> <a href='event:joint type ~'>~</a></b>", name, 0, -30, 150, 20, 0x324650, 0x324650, 0.8, true)
- ui.addTextArea( 1, "<b>taille : "..tostring(info[name].prop.line).."</b>", name, 160, -30, 80, 20, 0x324650, 0x324650, 0.8, true)
- ui.addTextArea( 2, "<b>couleur : <font color='#"..string.format('%x', info[name].prop.color).."'>•</font></b>", name, 250, -30, 80, 20, 0x324650, 0x324650, 0.8, true)
- ui.addTextArea( 3, "<b>alpha : "..tostring(info[name].prop.alpha).."</b>", name, 340, -30, 80, 20, 0x324650, 0x324650, 0.8, true)
- ui.addTextArea( 4, "<b>bezier : "..tostring(info[name].bezier).."</b>", name, 430, -30, 80, 20, 0x324650, 0x324650, 0.8, true)
- end
- function eventNewPlayer(name)
- system.bindMouse(name, true)
- tfm.exec.bindKeyboard(name, 8, true, true)
- info[name] = {joint="/", point={}, bezier=10, prop = { color=0xffffff, alpha=0.8, line=10, foreground=true}}
- interface.joint.affiche (name)
- end
- function eventNewGame ()
- joint = {}
- tfm.exec.addPhysicObject(1, -500, -500, {['type']=1})
- end
- function eventKeyboard(name, key, down, x, y)
- if key == 8 then editor.joint.delete(#xml.joint) end
- end
- function eventChatCommand(name, command)
- if command:sub(0,5) == "color" then
- info[name].prop.color = tonumber(command:sub(7),16)
- ui.updateTextArea(2, "<b>couleur : <font color='#"..string.format('%x', info[name].prop.color).."'>•</font></b>", name)
- elseif command:sub(0,4) == "line" then
- info[name].prop.line = tonumber(command:sub(6))
- ui.updateTextArea(1, "<b>taille : "..tostring(info[name].prop.line).."</b>", name)
- elseif command:sub(0,5) == "alpha" then
- info[name].prop.alpha = tonumber(command:sub(7))
- ui.updateTextArea(3, "<b>alpha : "..tostring(info[name].prop.alpha).."</b>", name)
- elseif command:sub(0,6) == "bezier" then
- local n = math.abs(tonumber(command:sub(8)))
- info[name].bezier = n>0 and n or 10
- ui.updateTextArea(4, "<b>bezier : "..tostring(info[name].bezier).."</b>", name)
- elseif command == 'xml' then
- tool.get_xml()
- end
- end
- function eventTextAreaCallback (id, name, call)
- local section = {}
- for w in string.gmatch(call, "%S+") do
- table.insert(section, w)
- end
- if section[1] == "joint" then
- if section[2] == "type" then
- info[name].joint = section[3]
- tool.reset_point(name)
- end
- end
- end
- function eventMouse (name, x, y)
- if info[name].joint == '•' then
- local prop = info[name].prop
- prop.point1 = tool.s_coord(x,y)
- prop.point2 = tool.s_coord(x+1,y)
- editor.joint.add(prop)
- tool.reset_point(name)
- elseif info[name].point[1] then
- if info[name].joint == '/' then
- local prop = info[name].prop
- prop.point1 = tool.s_coord(info[name].point[1].x, info[name].point[1].y)
- prop.point2 = tool.s_coord(x,y)
- editor.joint.add(prop)
- tool.reset_point(name)
- elseif info[name].point[2] then
- if info[name].point[3] then
- editor.joint.bezier (info[name].point[1].x, info[name].point[1].y , info[name].point[2].x, info[name].point[2].y , info[name].point[3].x, info[name].point[3].y , x,y , info[name].bezier , info[name].prop)
- tool.reset_point(name)
- else
- info[name].point[3] = {x=x, y=y}
- end
- else
- info[name].point[2] = {x=x, y=y}
- end
- else
- info[name].point[1] = {x=x, y=y}
- end
- end
- function editor.joint.add (prop)
- local last = #xml.joint+1
- xml.joint[last] = {}
- for key, val in pairs(prop) do
- xml.joint[last][key] = val
- end
- -- table.insert(xml.joint, prop)
- tfm.exec.addJoint (#xml.joint, 1, 1, prop)
- end
- function editor.joint.delete (id)
- if id ~= 0 then
- tfm.exec.removeJoint (id)
- table.remove(xml.joint, id)
- end
- end
- function editor.joint.bezier ( x1,y1 , x2,y2 , x3,y3 , x4,y4 , div, prop )
- local x = 1/div
- local xb, yb = x1,y1
- local floor = math.floor
- prop.point1 = tostring(xb)..','..tostring(yb)
- for i=1, div do
- xn = floor((1-x)^3*x1 + 3*x*(1-x)^2*x2 + 3*x^2*(1-x)*x3 +x ^3*x4)
- yn = floor((1-x)^3*y1 + 3*x*(1-x)^2*y2 + 3*x^2*(1-x)*y3 +x ^3*y4)
- x= x+1/div
- prop.point2 = tool.s_coord (xn,yn)
- editor.joint.add(prop)
- prop.point1 = prop.point2
- end
- end
- function tool.s_coord (x, y)
- return tostring(x)..','..tostring(y)
- end
- function tool.reset_point (name)
- info[name].point = {}
- end
- function tool.get_xml ()
- local code = "<L>"
- for _, tab in ipairs(xml.joint) do
- code = code.. '<JD P1="'..tab.point1..'" P2="'..tab.point2..'" c="'..string.format('%x', tab.color)..','..tab.line..','..tab.alpha..',1" />'
- end
- code = code.."<L /></L>"
- comp = 0
- while comp < #code do
- print(code:sub(comp, comp+4500))
- comp = comp+4501
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement