Module:Factiongfx

local p = {} local faction_img_data = mw.loadData( 'Module:Factiongfx/faction_tip_link.json' ) -- load json local getArgs = require('Module:Arguments').getArgs local strlower = string.lower -- Convert to lower case -- Get data from json page given main type name and piece name function getFactionInfo(faction_type, faction_piece) faction_type = strlower(faction_type) local faction_DB = mw.loadData("Module:Factiongfx/faction_tip_link.json") local faction_chunk = faction_DB[faction_type] if faction_chunk and faction_DB[faction_type][faction_piece] then return faction_DB[faction_type][faction_piece] end end function p.Factiongfx(frame) -- Implements local args = getArgs(frame) return p._Factiongfx(args) end function p._Factiongfx( args ) local img_faction = args['faction'] -- use faction param for faction if args['faction'] == nil then -- use param 1, if no faction= img_faction = args[1] elseif args[1] == nil then -- blank faction if no param 1 img_faction = '' end if img_faction ~= nil then -- if not nil, make lowercase img_faction = string.lower(img_type) end local img_size = args['size'] -- use size param for size if args['size'] == nil then -- use param 2, if no size= img_size = args[2] elseif args[2] == nil then -- blank size if no param 1 img_size = '' end local img_filename = img_faction .. '.png' local img_wikitext = '' local img_tip = 'Neutral' local img_link = 'Neutral' -- Get tool tip for image if img_faction ~= nil and getFactionInfo(img_faction, "tip") ~= nil then img_tip = getFactionInfo(img_faction, "tip") end -- Get link for image if img_faction ~= nil and getFactionInfo(img_faction) ~= nil then img_link = getFactionInfo(img_faction, "link") end -- Build filename and image wikitext if img_faction ~= nil and img_tip ~= nil and img_link ~= nil then local tmp_faction_frag = img_filename; -- replace lower case elite with Elite tmp_faction_frag = mw.ustring.gsub( tmp_faction_frag, "elite", "Elite" ); -- replace lower case npc with NPC tmp_faction_frag = mw.ustring.gsub( tmp_faction_frag, "npc", "NPC" ); -- replace lower case rare with Rare tmp_faction_frag = mw.ustring.gsub( tmp_faction_frag, "rare", "Rare" ); img_filename = tmp_faction_frag; -- Build image wikitext img_wikitext = '' end -- Return image wikitext return img_wikitext end return p