Module:Sandbox/DutyS12345

-- local p   = {}

local lib      = require('Module:Feature') -- local json     = require('Module:JSON') -- local userError = require('Dev:User error') -- local FN       = require('Module:Filename')

--[=[   does not strip URI links FSM States: s=0 Seen s=1 Seen [ s=2 Seen [\[ s=3 Seen [\[ + s=4 Seen [\[ +: s=5 s=6 s=7 Seen [\[ *:?.* s=8 Seen [\[ *:?.*] s=9 Seen [\[ *:?.*| s=10 Seen [\[ *:?.*|.* s=11 Seen [\[ *:?.*|.*] s=11 Seen [\[ *:?.*|] s=13 Seen [\[: * s=. Seen [ + s=. Seen [ *.* s=. Seen [ *.* s=. Seen [ *.* * s=. Seen [ *.* *.* ]=] function p.striplinks(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local instring = args[1] local ret = '' local fstart, fend, bstart, bend local fcolon, fpipe = -1, -1 local s = 0 -- local strace = '0' for i = 1, #instring do --       local nextchar = string.gmatch(args[1],'.') local nextchar = mw.ustring.sub(instring, i, i)       if s == 0 then if nextchar == '[' then s = 1 fstart = i           else s = 0 ret = ret .. nextchar end elseif s == 1 then --Seen [ if nextchar == '[' then s = 2 fend = i           end elseif s == 2 then --Seen [[           if nextchar == ' ' then                s = 3                fend = i-1            elseif nextchar == ':' then                s = 13                fcolon = i            else                s = 7            end        elseif s == 3 then --Seen [[ +            if nextchar == ' ' then                s = 3                fend = i-1            elseif nextchar == ':' then                s = 4                fcolon = i            else                s = 7                fend = i-1            end        elseif s == 4 then --Seen [\[ +:            if nextchar == ']' then                s = 8                fcolon = -1                bstart = i            else                s = 7            end        elseif s == 5 then        elseif s == 6 then         elseif s == 7 then --Seen [\[ *:?.*            if nextchar == '|' then                s = 9                fpipe = i            elseif nextchar == ']' then                s = 8                bstart = i            else                s = 7            end        elseif s == 8 then --Seen [\[ *:?.*]            if nextchar == ']' then                s = 0                if fcolon ~= -1 and fcolon ~= fstart + 2 then                    ret = ret .. mw.ustring.sub(instring, fcolon, bstart - 1)                    fcolon = -1                elseif fcolon ~= -1 then                    ret = ret .. mw.ustring.sub(instring, fcolon, bstart - 1)                    fcolon = -1                else                    ret = ret .. mw.ustring.sub(instring, fend + 1, bstart - 1)                    fcolon = -1                end            else                s = 7            end        elseif s == 9 then --Seen [\[ *:?.*|            if nextchar == ']' then                s = 12                bstart = i            else                s = 10            end        elseif s == 10 then --Seen [\[ *:?.*|.*            if nextchar == ']' then                s = 11                bstart = i            else                s = 10            end        elseif s == 11 then --Seen [\[ *:?.*|.*]            if nextchar == ']' then                s = 0                ret = ret .. mw.ustring.sub(instring, fpipe + 1, bstart - 1)                fcolon = -1            else            end        elseif s == 12 then --Seen [\[ *:?.*|]            if nextchar == ']' then                s = 0                ret = ret .. mw.ustring.sub(instring, fend + 1, fpipe - 1)                fcolon = -1            else                s = 10            end        elseif s == 13 then --Seen [\[: *            if nextchar == ' ' then                s = 13            elseif nextchar == '|' then                s = 0                ret = ret .. mw.ustring.sub(instring, fstart, i)            elseif nextchar == ']' then                s = 0                ret = ret .. mw.ustring.sub(instring, fstart, i)            else                s = 7                fcolon = i-1            end        elseif s == 14 then         elseif s == 15 then         elseif s == 16 then        else            return instring        end        -- strace = strace .. ' ' .. s    end    if s ~= 0 then ret = ret .. mw.ustring.sub(instring, fstart, -1) end    -- if s ~= 0 then return 'error, state trace: ' .. strace .. '; ' .. ret end    if args[2] ~= nil then ret = ' ' .. ret .. ' ' end    -- if args[2] ~= nil then return ret .. ': ' .. strace end    return ret end

function p.querychamps(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local lolData  = mw.loadData('Module:ChampionData/data') local get      = require('Module:ChampionData/getter') local stat     = args['stat'] local value    = args['value'] local output   = args['output'] local result  = {} for champname in pairs(lolData) do       local v = get[stat](champname) if v == nil then elseif '' .. v == value then table.insert(result, champname) end end table.sort(result) if output ~= nil then if output == "custom" then return frame:preprocess(lib.tbl_concat{result, prepend = args['prepend'], append = args['append'], separator = args['separator'], index = args["index"]}) elseif output == "template" then return frame:preprocess(lib.tbl_concat{result, prepend = "", separator = args['separator']}) else return lib.tbl_concat{result} end else return lib.tbl_concat{result} end end

function p.queryoptions(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local lolData  = mw.loadData('Module:ChampionData/data') local get      = require('Module:ChampionData/getter') local stat     = args['stat'] local output   = args['output'] local champ1    = false if champ1 == false then if args['t_name'] == 'cai' or args['t_name'] == 'ai' then champ1 = true end end local result  = {} for champname in pairs(lolData) do       if stat == 'skills' then local v = get['skill_i'](champname) for k2,v2 in pairs(v) do               if result[v2] == nil then if output == "template" and champ1 then result[v2] = v2 .. '|' .. champname else result[v2] = v2                   end end end local v = get['skill_q'](champname) for k2,v2 in pairs(v) do               if result[v2] == nil then if output == "template" and champ1 then result[v2] = v2 .. '|' .. champname else result[v2] = v2                   end end end local v = get['skill_w'](champname) for k2,v2 in pairs(v) do               if result[v2] == nil then if output == "template" and champ1 then result[v2] = v2 .. '|' .. champname else result[v2] = v2                   end end end local v = get['skill_e'](champname) for k2,v2 in pairs(v) do               if result[v2] == nil then if output == "template" and champ1 then result[v2] = v2 .. '|' .. champname else result[v2] = v2                   end end end local v = get['skill_r'](champname) for k2,v2 in pairs(v) do               if result[v2] == nil then if output == "template" and champ1 then result[v2] = v2 .. '|' .. champname else result[v2] = v2                   end end end elseif stat == 'key' then if false and (               lolData[champname]["date"] == ("Upcoming" or "N/A" or "Cancelled" or "")                or                 champname == ("Mega Gnar" or "Rhaast" or "Shadow Assassin") ) then --ignore champion else table.insert(result, champname) end else local v = get[stat](champname) if type(v) == 'table' then for k2,v2 in pairs(v) do                   if result[v2] == nil then if output == "template" and champ1 then result[v2] = v2 .. '|' .. champname else result[v2] = v2                       end end end else if v == nil then elseif result[v] == nil then result[v] = v               end end end end result[''] = nil table.sort(result) if output ~= nil then if output == "custom" then return frame:preprocess(lib.tbl_concat{result, prepend = args['prepend'], append = args['append'], separator = args['separator'], index = args["index"]}) elseif output == "template" then return frame:preprocess(lib.tbl_concat{result, prepend = "", separator = args['separator']}) elseif output == "table" then return tableprettyprint(result) else return lib.tbl_concat{result} end else return lib.tbl_concat{result} end end

function p.test(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end return args[1] .. #args[1] end

function p.transfer(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local lolData  = mw.loadData('Module:ChampionData/data') local get      = require('Module:ChampionData/getter') local stat     = args['stat'] local output   = args['output'] local result   = '' local sorted   = {} for champname in pairs(lolData) do       table.insert(sorted, champname) end table.sort(sorted) for _,champname in ipairs(sorted) do       result = result .. '["' .. champname .. '"] = {\n' result = result .. '["skill_i"] = {\n' local v = get['skill_i'](champname) for k2,v2 in ipairs(v) do           result = result .. '["' .. v2 .. '"] = {\n},\n' end result = result .. '},\n' result = result .. '["skill_q"] = {\n' local v = get['skill_q'](champname) for k2,v2 in ipairs(v) do           result = result .. '["' .. v2 .. '"] = {\n},\n' end result = result .. '},\n' result = result .. '["skill_w"] = {\n' local v = get['skill_w'](champname) for k2,v2 in ipairs(v) do           result = result .. '["' .. v2 .. '"] = {\n},\n' end result = result .. '},\n' result = result .. '["skill_e"] = {\n' local v = get['skill_e'](champname) for k2,v2 in ipairs(v) do           result = result .. '["' .. v2 .. '"] = {\n},\n' end result = result .. '},\n' result = result .. '["skill_r"] = {\n' local v = get['skill_r'](champname) for k2,v2 in ipairs(v) do           result = result .. '["' .. v2 .. '"] = {\n},\n' end result = result .. '},\n' result = result .. '},\n' end return result end

function p.getfi(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local flashData  = mw.loadData('Module:Sandbox/DutyS12345/data') local champion = args['champion'] or args[1] local ability  = args['ability'] or args[2] local output   = args['output']  or args[3] or nil local s        = '' champion = lib.validateName(champion) local fi = flashData[champion]['skill_i'][ability] or flashData[champion]['skill_q'][ability] or flashData[champion]['skill_w'][ability] or flashData[champion]['skill_e'][ability] or flashData[champion]['skill_r'][ability] or '' local notes = flashData[champion]['skill_i']['notes'][ability] or flashData[champion]['skill_q']['notes'][ability] or flashData[champion]['skill_w']['notes'][ability] or flashData[champion]['skill_e']['notes'][ability] or flashData[champion]['skill_r']['notes'][ability] or '' if fi ~= nil and fi ~= '' then for i,v in pairs(fi) do           if s ~= '' then s = s .. ','           end s = s .. 'i:' .. 'v'       end end if output ~= nil then if output == 'notes' then return notes else return '' end else return s   end end

function tableprettyprint(tbl) local s = '' for k,v in pairs(tbl) do       if k == nil then s = s .. 'nil' .. ' : '       else s = s .. k .. ' : '        end if v == nil then s = s .. 'nil' .. ' '       else s = s .. v .. ' '       end end return s end

return p -- --