Advertisement
Eliaseeg

Map Listener fork

Mar 27th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.00 KB | None | 0 0
  1. info = [[
  2.     Insert your lsmap content here
  3. ]]
  4.  
  5. viewer = "Noonehasseen"
  6. author = info:match("(%S+)'s maps:") or info:match("(%S+) %- @")
  7. if not author then
  8.     error("Invalid Author")
  9. end
  10.  
  11. string.split = function(value,pattern,f)
  12.     local out = {}
  13.     for v in string.gmatch(value,pattern) do
  14.         out[#out + 1] = (f and f(v) or v)
  15.     end
  16.     return out
  17. end
  18. tableconcat = table.concat
  19. table.concat = function(list,sep,f,i,j)
  20.     local txt = ""
  21.     sep = sep or ""
  22.     i,j = i or 1,j or #list
  23.     for k,v in next,list do
  24.         if type(k) ~= "number" and true or (k >= i and k <= j) then
  25.             txt = txt .. (f and f(k,v) or v) .. sep
  26.         end
  27.     end
  28.     return string.sub(txt,1,-1-#sep)
  29. end
  30. table.find = function(list,value,index,f)
  31.     for k,v in next,list do
  32.         local i = (type(v) == "table" and index and v[index] or v)
  33.         if (f and f(i) or i) == value then
  34.             return true,k
  35.         end
  36.     end
  37.     return false,0
  38. end
  39. do
  40.     local printf = print
  41.     print = function(txt)
  42.         txt = tostring(txt)
  43.         if #txt > 2000 then
  44.             local total = 0
  45.             while #txt > total do
  46.                 printf(string.sub(txt,total,total + 2000))
  47.                 total = total + 2001
  48.             end
  49.         else
  50.             printf(txt)
  51.         end
  52.     end
  53.    
  54.     ui.checkBoxData = {}
  55.     ui.addCheckBox = function(id,txt,n,x,y,checked,w,h,event)
  56.         local thisId = id
  57.         id = id * 4
  58.        
  59.         w = w or 200
  60.         h = h or 20
  61.        
  62.         ui.addTextArea(-id,"",n,x-1,y-1,4,4,1,1,1,true)
  63.         ui.addTextArea(-id + 1,"",n,x,y,4,4,0x3A5A66,0x3A5A66,1,true)
  64.         ui.addTextArea(-id + 2,"",n,x,y,3,3,0x233238,0x233238,1,true)
  65.         ui.addTextArea(-id + 3,"<font size='12' color='#324650'><a href='event:checkBox."..thisId.."'>&nbsp;&nbsp;&nbsp;</a><n>&nbsp;&nbsp;"..txt,n,x-6,y-8,w,h,1,1,0,true)
  66.  
  67.         ui.checkBoxData[thisId] = {
  68.             text = txt,
  69.             isChecked = checked,
  70.             event = event or (function() end)
  71.         }
  72.  
  73.         if checked then
  74.             ui.updateCheckBox(thisId,true,n)
  75.         end
  76.     end
  77.     ui.updateCheckBox = function(id,checked,n)
  78.         if ui.checkBoxData[id] then
  79.             local char = "&nbsp;&nbsp;&nbsp;"
  80.             if checked then
  81.                 char = "✓"
  82.             end
  83.             ui.updateTextArea(-(id*4) + 3,"<font size='12'><a href='event:checkBox."..id.."'>"..char.."</a><n>&nbsp;&nbsp;"..ui.checkBoxData[id].text,n)
  84.             ui.checkBoxData[id].event(checked,n)
  85.             ui.checkBoxData[id].isChecked = checked
  86.         end
  87.     end
  88.     ui.removeCheckBox = function(id,n)
  89.         id = id * 4
  90.         for i = id - 3,id do
  91.             ui.removeTextArea(-i,n)
  92.         end
  93.     end
  94. end
  95.  
  96. languages = {1,{"EN","ES","BR","FR"}}
  97. categories = {
  98.     -- Names are En, Es, Br, Fr, respectively
  99.     {
  100.         name = "Normal",
  101.         category = 0,
  102.         checked = false,
  103.         color = "ACA99F",
  104.         image = "AjcGgyx",
  105.     },
  106.     {
  107.         name = {"Protected","Protegido","Protegido","Protégée"},
  108.         category = 1,
  109.         checked = true,
  110.         color = "FCD46E",
  111.         image = "dnuppaW",
  112.     },
  113.     {
  114.         name = "Prime",
  115.         category = 2,
  116.         checked = false,
  117.         color = "FDD17B",
  118.         image = "4tsd2Jp",
  119.     },
  120.     {
  121.         name = {"Prime Bootcamp","Bootcamp","Bootcamp Primário","Bootcamp"},
  122.         category = 3,
  123.         checked = true,
  124.         color = "A19A6C",
  125.         image = "KQmIe6z",
  126.     },
  127.     {
  128.         name = {"Shaman","Chamán","Shaman","Chamane"},
  129.         category = 4,
  130.         checked = true,
  131.         color = "95D9D6",
  132.         image = "W2DuMvz",
  133.     },
  134.     {
  135.         name = {"Art","Arte","Arte","Art"},
  136.         category = 5,
  137.         checked = true,
  138.         color = "D16C41",
  139.         image = "JefkO6b",
  140.     },
  141.     {
  142.         name = {"Mechanism","Mecanismo","Mecanismo","Mécanisme"},
  143.         category = 6,
  144.         checked = true,
  145.         color = "DBDBDB",
  146.         image = "EyQAQ10",
  147.     },
  148.     {
  149.         name = {"No Shaman","Sin Chamán","Sem Shaman","Sans Chamane"},
  150.         category = 7,
  151.         checked = true,
  152.         color = "E9E9E9",
  153.         image = "RV32jmm",
  154.     },
  155.     {
  156.         name = {"Dual Shaman","Dos Chamanes","Dois Shamans","Co-opération Chamanes"},
  157.         category = 8,
  158.         checked = true,
  159.         color = "C9C0E4",
  160.         image = "DoACCNh",
  161.     },
  162.     {
  163.         name = {"Miscellaneous","Misceláneos","Diversos","Divers"},
  164.         category = 9,
  165.         checked = true,
  166.         color = "E9BA5C",
  167.         image = "PYRguTf",
  168.     },
  169.     {
  170.         name = "Survivor",
  171.         category = 10,
  172.         checked = true,
  173.         color = "7C7C7C",
  174.         image = "gdxuJWr",
  175.     },
  176.     {
  177.         name = "Vampire Survivor",
  178.         category = 11,
  179.         checked = false,
  180.         color = "AC3736",
  181.         image = "44zz3dC",
  182.     },
  183.     {
  184.         name = "Bootcamp",
  185.         category = 13,
  186.         checked = true,
  187.         color = "A19A6C",
  188.         image = "KQmIe6z",
  189.     },
  190.     {
  191.         name = "Racing",
  192.         category = 17,
  193.         checked = true,
  194.         color = "CA8A7F",
  195.         image = "pUB90w0",
  196.     },
  197.     {
  198.         name = {"Defilante","Defilante","Defilante","Défilante"},
  199.         category = 18,
  200.         checked = false,
  201.         color = "84D329",
  202.         image = "wM2TiWg",
  203.     },
  204.     {
  205.         name = {"Music","Música","Música","Musique"},
  206.         category = 19,
  207.         checked = false,
  208.         color = "9FAAB2",
  209.         image = "QbMYTsP",
  210.     },
  211.     {
  212.         name = "Survivor Test",
  213.         category = 20,
  214.         checked = false,
  215.         color = "7C7C7C",
  216.         image = "gdxuJWr",
  217.         ref = 10,
  218.     },
  219.     {
  220.         name = "Vampire Test",
  221.         category = 21,
  222.         checked = false,
  223.         color = "AC3736",
  224.         image = "44zz3dC",
  225.         ref = 11,
  226.     },
  227.     {
  228.         name = {"Tribe House","Casa de Tribu","Cafofo da Tribo","Maison de Tribu"},
  229.         category = 22,
  230.         checked = false,
  231.         color = "937456",
  232.         image = "Lxvjj1M",
  233.     },
  234.     {
  235.         name = "Bootcamp Test",
  236.         category = 23,
  237.         checked = false,
  238.         color = "A19A6C",
  239.         image = "KQmIe6z",
  240.         ref = 13,
  241.     },
  242.     {
  243.         name = {"Dual Shaman Survivor","Doble Chamán Survivor","Survivor com Dois Shamans","Deux Chamanes Survivor"},
  244.         category = 24,
  245.         checked = false,
  246.         color = "7C7C7C",
  247.         image = "gdxuJWr",
  248.     },
  249.     {
  250.         name = "Dual Shaman Test",
  251.         category = 32,
  252.         checked = false,
  253.         color = "C9C0E4",
  254.         image = "DoACCNh",
  255.         ref = 8,
  256.     },
  257.     {
  258.         name = "Racing Test",
  259.         category = 38,
  260.         checked = false,
  261.         color = "CA8A7F",
  262.         image = "pUB90w0",
  263.         ref = 17,
  264.     },
  265.     {
  266.         name = "Module",
  267.         category = 41,
  268.         checked = false,
  269.         color = "009D9D",
  270.         image = "GmbpOc6",
  271.     },
  272.     {
  273.         name = "No shaman Test",
  274.         category = 42,
  275.         checked = false,
  276.         color = "E9E9E9",
  277.         image = "RV32jmm",
  278.         ref = 7,
  279.     },
  280.     {
  281.         name = "High Deleted",
  282.         category = 43,
  283.         checked = false,
  284.         color = "FA6A40",
  285.         image = "BLabBxr",
  286.     },
  287.     {
  288.         name = "Deleted",
  289.         category = 44,
  290.         checked = false,
  291.         color = "FA6A40",
  292.         image = "BLabBxr",
  293.     },
  294.     {
  295.         name = "Vanilla",
  296.         category = 87,
  297.         checked = true,
  298.         color = "5D7602",
  299.         image = "GmbpOc6",
  300.     }
  301. }
  302.  
  303. do
  304.     local _DATA = {}
  305.    
  306.     setMeta = function(cat)
  307.         return setmetatable({},{
  308.             __call = function()
  309.                 return _DATA[cat]
  310.             end
  311.         })
  312.     end
  313.     setData = function(cat,i)
  314.         _DATA[cat] = i
  315.     end
  316. end
  317.  
  318. getMaps = function(data)
  319.     local out = {}
  320.    
  321.     for code,cat in data:gmatch("(@%d+).-P(%d+)") do
  322.         cat = tonumber(cat)
  323.         if not out[cat] then
  324.             out[cat] = setMeta(cat)
  325.         end
  326.        
  327.         out[cat][#out[cat] + 1] = code
  328.         setData(cat,#out[cat])
  329.     end
  330.    
  331.     for cat,codes in next,out do
  332.         table.sort(codes)
  333.     end
  334.    
  335.     return out
  336. end
  337. maps = getMaps(info)
  338.  
  339. displayList = function()
  340.     local text = {"<BV>Total : <V>%s"}
  341.    
  342.     local total = 0
  343.     local highperm = 0
  344.     for k,v in next,categories do
  345.         if maps[v.category] then
  346.             text[#text + 1] = string.format("<BV><a href='event:list.%s'>P%s</a> : <V>%s",v.category,v.category,#maps[v.category])
  347.            
  348.             total = total + #maps[v.category]
  349.             if v.category > 2 and v.category < 10 then
  350.                 highperm = highperm + #maps[v.category]
  351.             end
  352.         end
  353.     end
  354.     text[1] = string.format(text[1],total)
  355.     if highperm > 0 then
  356.         text[#text + 1] = "<BV>High perm : <V>" .. highperm
  357.     end
  358.    
  359.     text = table.concat(text,"\n")
  360.     print(text)
  361.     ui.addTextArea(0,text,viewer,5,30,nil,nil,nil,nil,1,true)
  362. end
  363. displayList()
  364.  
  365. categoryBoxesThread = function()
  366.     local y = 80
  367.     for i = 1,#categories do
  368.         local cat = categories[i]
  369.        
  370.         if (i-1) % 7 == 0 then
  371.             y = y + 20
  372.         end
  373.        
  374.         ui.addCheckBox(10 + i,"P" .. cat.category,viewer,437 + (((i-1) % 7) * 50),y,cat.checked,50,20)
  375.         if i % 5 == 0 then
  376.             coroutine.yield()
  377.         end
  378.     end
  379. end
  380.  
  381. -- Generation
  382. getMapsFromCategory = function(mapList,isHighPerm,ignoreRule,avoidLinkedMaps)
  383.     local insertSpoil = "[spoiler=%s]%s%s[/spoiler]"
  384.     local insertImage = "[p=center][img]http://api.micetigri.fr/share/maps/%s[/img][/p]"
  385.  
  386.     local out = table.concat(mapList,"\n",function(k,v)
  387.         v = v .. "!"
  388.         if not ignoreRule and ui.checkBoxData[4].isChecked and (not ui.checkBoxData[5].isChecked and true or isHighPerm) then
  389.             return insertSpoil:format(
  390.                 v, -- @Code
  391.                 ui.checkBoxData[6].isChecked and "Add your commentary here!" or "", -- Description
  392.                 insertImage:format(v:gsub("@","")) -- Image
  393.             )
  394.         else
  395.             return v -- @Code
  396.         end
  397.     end,1,(avoidLinkedMaps and #mapList - (#mapList - (mapList() or #mapList))))
  398.    
  399.     return out
  400. end
  401. createSingularTab = function(list,form,title)
  402.     if list[1] > 0 then
  403.         return "\n" .. form:format(
  404.             "",
  405.             ui.checkBoxData[3].isChecked and string.format("[b]%03d[/b] ",list[1]) or "",
  406.             "",
  407.             title,
  408.             table.concat(list[2],"\n")
  409.         )
  410.     end
  411.     return ""
  412. end
  413.  
  414. -- Interface
  415. ui.addTextArea(1,"<p align='center'><font size='20'>BBCODE SETTINGS",viewer,110,55,300,320,0x192A31,0x192A31,1,true)
  416.  
  417. ui.addCheckBox(1,"Display icons",viewer,120,100,true)
  418. ui.addCheckBox(2,"Display category",viewer,120,130,true)
  419. ui.addCheckBox(3,"Display amount",viewer,120,160,true)
  420.  
  421. ui.addCheckBox(4,"Insert map image",viewer,120,190,false,200,20,function(checked)
  422.     if checked then
  423.         ui.addCheckBox(5,"Only in high perms",viewer,140,205,true)
  424.         ui.addCheckBox(6,"Add description",viewer,140,220,false)
  425.     else
  426.         for i = 5,6 do
  427.             ui.removeCheckBox(i,viewer)
  428.         end
  429.     end
  430. end)
  431.  
  432. ui.addCheckBox(7,"List all categories",viewer,120,240,true,200,20,function(checked)
  433.     if checked then
  434.         for i = 2,3 do
  435.             ui.removeTextArea(i,viewer)
  436.         end
  437.  
  438.         for i = 1,#categories do
  439.             ui.removeCheckBox(10 + i,viewer)
  440.         end
  441.        
  442.         createCategoryBoxes = coroutine.create(categoryBoxesThread)
  443.     else
  444.         ui.addTextArea(2,"<p align='center'><font size='20'>CATEGORIES",viewer,430,55,350,250,0x192A31,0x192A31,1,true)
  445.         ui.addTextArea(3,"<p align='center'><a href='event:uncheckCategories'>Uncheck all",viewer,435,280,200,20,0x333348,0x333348,1,true)     
  446.     end
  447. end)
  448.  
  449. ui.addCheckBox(8,"Link test categories",viewer,140,260)
  450. ui.addCheckBox(9,"Create high perm list",viewer,120,280)
  451. ui.addCheckBox(10,"Create maps in test list",viewer,120,310)
  452.  
  453. ui.addTextArea(4,"<a href='event:language'>Language : " .. languages[2][languages[1]],viewer,115,320,290,20,1,1,0,true)
  454. ui.addTextArea(5,"<p align='center'>Create BBCode&nbsp;&nbsp;&nbsp;&nbsp;<a href='event:generate'>ASCII</a>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a href='event:generate.byte'>BYTE</a>",viewer,115,350,290,20,0x333348,0x333348,1,true)
  455.  
  456. eventLoop = function()
  457.     if not ui.checkBoxData[7].isChecked then
  458.         if createCategoryBoxes and coroutine.status(createCategoryBoxes) ~= "dead" then
  459.             coroutine.resume(createCategoryBoxes)
  460.         end
  461.     end
  462. end
  463.  
  464. eventTextAreaCallback = function(i,n,c)
  465.     local p = string.split(c,"[^%.]+")
  466.    
  467.     if p[1] == "list" then
  468.         p[2] = tonumber(p[2])
  469.        
  470.         if maps[p[2]] then
  471.             print(string.format("<BV>P%s : <V>%s",p[2],table.concat(maps[p[2]],",")))
  472.         end
  473.         return
  474.     end
  475.    
  476.     if p[1] == "checkBox" then
  477.         p[2] = tonumber(p[2])
  478.         ui.updateCheckBox(p[2],not ui.checkBoxData[p[2]].isChecked,n)
  479.         return
  480.     end
  481.    
  482.     if p[1] == "uncheckCategories" then
  483.         if not ui.checkBoxData[7].isChecked and coroutine.status(createCategoryBoxes) == "dead" then
  484.             for i = 1,#categories do
  485.                 ui.updateCheckBox(10 + i,false,n)
  486.             end
  487.         end
  488.         return
  489.     end
  490.    
  491.     if p[1] == "language" then
  492.         languages[1] = languages[1] + 1
  493.         if languages[1] > #languages[2] then
  494.             languages[1] = 1
  495.         end
  496.        
  497.         ui.updateTextArea(4,"<a href='event:language'>Language : " .. languages[2][languages[1]],n)
  498.         return
  499.     end
  500.  
  501.     if p[1] == "generate" then
  502.         local insertTab = "[spoiler=[color=#%s]%s %s %s[/color]][size=13]%s[/size][/spoiler]"
  503.        
  504.         if ui.checkBoxData[8].isChecked then
  505.             for k,v in next,categories do
  506.                 if v.ref and maps[v.category] then
  507.                     if not maps[v.ref] then
  508.                         maps[v.ref] = setMeta(v.ref)
  509.                         setData(v.ref,0)
  510.                     end
  511.                    
  512.                     for m,n in next,maps[v.category] do
  513.                         maps[v.ref][#maps[v.ref] + 1] = n
  514.                     end
  515.                 end
  516.             end
  517.         end
  518.        
  519.         local bbcode,discussion,highperm = {},{0,{}},{0,{}}
  520.         -- Categories
  521.         for i = 1,#categories do
  522.             local this = categories[i]
  523.            
  524.             if maps[this.category] then
  525.                 if ui.checkBoxData[7].isChecked or ui.checkBoxData[10 + i].isChecked then
  526.                     local canInsertInto = not ui.checkBoxData[8].isChecked and true or not this.ref
  527.                    
  528.                     local isHighPerm = this.category > 2 and this.category < 10
  529.                    
  530.                     local mapCodes = getMapsFromCategory(maps[this.category],isHighPerm)
  531.                     local clearCodes = getMapsFromCategory(maps[this.category],isHighPerm,true,true)
  532.                    
  533.                     if canInsertInto then
  534.                         bbcode[#bbcode + 1] = insertTab:format(
  535.                             this.color,
  536.                             ui.checkBoxData[3].isChecked and string.format("[b]%03d[/b] ",#maps[this.category]) or "", -- Amount
  537.                             ui.checkBoxData[1].isChecked and string.format("[img]http://i.imgur.com/%s.png[/img]",this.image) or "", -- Icon
  538.                             ui.checkBoxData[2].isChecked and (this.name[languages[1]] or this.name) or "", -- Name
  539.                             mapCodes:gsub("!","") -- Map Codes
  540.                         )
  541.                        
  542.                         if ui.checkBoxData[9].isChecked and isHighPerm then
  543.                             highperm[1] = highperm[1] + #maps[this.category] - (#maps[this.category] - (maps[this.category]() or #maps[this.category])) -- Total maps
  544.                             highperm[2][#highperm[2] + 1] = clearCodes:gsub("!"," - P" .. this.category) -- Insert into the highperm list
  545.                         end
  546.                     end
  547.                    
  548.                     if ui.checkBoxData[10].isChecked and this.ref then
  549.                         discussion[1] = discussion[1] + #maps[this.category] - (#maps[this.category] - (maps[this.category]() or #maps[this.category])) -- Total maps
  550.                         discussion[2][#discussion[2] + 1] = clearCodes:gsub("!",string.format(" - P%s (P%s)",this.category,this.ref)) -- Insert into the discussion list
  551.                     end
  552.                 end
  553.             end
  554.         end
  555.        
  556.         local result = table.concat(bbcode,"\n") .. createSingularTab(highperm,insertTab,"High Perm") .. createSingularTab(discussion,insertTab,"Maps in test")
  557.        
  558.         if p[2] == "byte" then
  559.             local out = {}
  560.             result:gsub(".",function(v)
  561.                 out[#out + 1] = v:byte()
  562.             end)
  563.             print(tableconcat(out,"."))
  564.         else
  565.             print(result)
  566.         end
  567.        
  568.         maps = getMaps(info)
  569.         return
  570.     end
  571. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement