Module:UpdateSchedule/sandbox

-- local p = {} local h = {}

local cargo = require('Module:CargoUtil') local yesno = require('Module:Yesno') local dataModel = require("Module:Data").model local wikiSafeName = require('Module:LinkUtils').wikiSafeName

local jobs   = mw.loadData("Module:DataJP/MasterParam/Job") local jobsets = mw.loadData("Module:DataJP/MasterParam/JobSet") local globalNameMap = mw.loadData("Module:UpdateSchedule/GlobalNameMap")

function h.getLoc(_pageName, param, lang) if _pageName == nil then return '???' end lang = lang or 'english' local rows = cargo.query{ tables='Loc', fields='value,lang', where={ '_pageName = "'..string.gsub(_pageName, '_', ' ')..'"', 'param = "'..param..'"', 'value <> ""', 'lang IN ("japanese", "english")', }, }  local t = {} for i, row in ipairs(rows) do   t[row.lang] = row.value end return t[lang] or t.japanese end

function h.getUnitName(iname) return globalNameMap[iname] or h.getLoc('Data:Game/MasterParam/Unit/' .. iname, 'name') end

function h.getCardName(iname) return h.getLoc('Data:Game/MasterParam/Card/' .. iname, 'name') end

function h.getJobName(iname) return globalNameMap[iname] or h.getLoc('Data:Game/MasterParam/Job/' .. iname, 'name') end

function h.render_icon(args) local file, name, link, rare, type, size, count, classes, content, inline file = args.file or args[1] name = args.name or args[2] link = args.link or args[3] rare = args.rare or args[4] type = args.type or args[5] size = args.size or args[6] count = args.count or args[7] classes = args.classes or args[8] content = args.content or args[9] inline = args.inline or args[10] size = size or 128 local padding = math.floor(size*14/128) size = size - padding inline = inline and 'span' or 'div' local sb = mw.html.create(inline) :addClass('item-icon') if classes ~= nil then sb:addClass(classes) end local img = sb:tag(inline) :addClass('img') :addClass('x-'..(rare or 0)) :addClass('y-'..(type or 0)) :css('width', size..'px') :css('height', size..'px') :css('padding', (padding/2)..'px') if count ~= nil then img:tag(inline) :addClass('item-count') :wikitext('x '..count) end img:wikitext(string.format( ,   file or , size, name and name ~=  and '|'..wikiSafeName(name) or , link and link ~=  and '|link='..wikiSafeName(link) or  )) if content ~= nil then sb:wikitext(content) end return tostring(sb) end

function h.render_gear_icon(args) local iname = args[1] if iname == nil then return nil end local page = cargo.query{ tables = 'Pages', fields = 'iname, _pageName', where = { 'type = "Gear"', '_pageName = "'..iname..'" OR iname = "'..iname..'"', },   limit = 1, }[1] if page then iname = page.iname end local data = args.data or cargo.query{ tables = 'Artifact', fields = 'iname, _pageName, server, rini, icon', where = {'iname="'..iname..'" OR _pageName="'..iname..'"'}, }[1] or {rare=0,type=0} local name = dataModel.getLoc(data._pageName, 'name') -- TODO Get the correct server local renderArgs = { file = data.icon and string.sub(data.icon,1,3) == 'AF_' and ('ArtiIcon,'..data.icon) or 'ItemIcon,IT_UNKNOWN', name = name, link = (data._pageName ~= nil and args['link'] ~= 'none' and (page or {})._pageName or name) or nil, rare = tonumber(data.rini), type = 2, size = 64, count = args['count'] ~= '' and args['count'] or nil, classes = args['classes'], content = nil, inline = false, } local name = args['name'] ~= 'none' and (renderArgs.link and renderArgs.link ~=  and (..renderArgs.name..'') or renderArgs.name) or nil if args['size'] == 'large' then renderArgs.size = 128 elseif args['size'] == 'small' then renderArgs.size = 24 renderArgs.content = name and ' '..name..' ' renderArgs.inline = true elseif args['size'] == 'compact' then renderArgs.content = name and ' '..renderArgs.name..' ' else renderArgs.content = name and ' '..name..' ' end return h.render_icon(renderArgs) end

function h.render_card_icon(args) local iname = args[1] if iname == nil then return nil end local page = cargo.query{ tables = 'Pages', fields = 'iname, _pageName', where = { 'type = "Memento"', '_pageName = "'..iname..'" OR iname = "'..iname..'"', },   limit = 1, }[1] if page then iname = page.iname end local data = args.data or dataModel.query('ConceptCard','_pageName,server,rare,icon',{where='iname="'..iname..'"'})[1] or {rare=0} -- TODO Get the correct server local name = dataModel.getLoc(data._pageName, 'name') local renderArgs = { file = (data.icon == nil or data.icon == '') and 'ItemIcon,IT_UNKNOWN' or ('ConceptCardIcon,'..data.icon), name = name, link = (data._pageName ~= nil and args['link'] ~= 'none' and (page or {})._pageName or name) or nil, rare = data.rare, type = 4, size = 64, count = args['count'] ~= '' and args['count'] or nil, classes = args['classes'], content = nil, inline = false, } local name = args['name'] ~= 'none' and (renderArgs.link and renderArgs.link ~=  and (..renderArgs.name..'') or renderArgs.name) or nil if args['size'] == 'large' then renderArgs.size = 128 elseif args['size'] == 'small' then renderArgs.size = 24 renderArgs.content = name and ' '..name..' ' renderArgs.inline = true elseif args['size'] == 'compact' then renderArgs.content = name and ' '..renderArgs.name..' ' else renderArgs.content = name and ' '..name..' ' end return h.render_icon(renderArgs) end

function h.insertUnitUpgradeEntry(sb, img, name, iname) if (name == 'nil' or name == '') then name = iname end table.insert(sb, " [[File:")  table.insert(sb, img and "Game,Portraits,"..img or "Game,PortraitsS,unknown")  table.insert(sb, ".png|57px|")  table.insert(sb, name)  table.insert(sb, "|link=")  table.insert(sb, name)  table.insert(sb, "]] ")

return output end

function h.insertHistoryEntry(sb, iname, img, name, rare, typeI) if (name == 'nil' or name == '') then name = iname end table.insert(sb, ' ') table.insert(sb, '') table.insert(sb, img or 'Item_IT_UNKNOWN')  table.insert(sb, '.png ') table.insert(sb, ' ') table.insert(sb, name) table.insert(sb, ' ') end

function h.insertUpgradeEntry(sb, name, iname) if (name == 'nil' or name == '') then name = iname end table.insert(sb, " ") table.insert(sb, name) table.insert(sb, " ") end

function h.insertJobUpgrade(sb, iname, name, js, isChange) if isChange ~= false then js = ((jobsets[js] or {}).jobc or {})[iname] -- Special handling for 2nd level job upgrade if isChange == 2 then js = ((jobsets[js] or {}).jobc or {})[iname] end end js = jobsets[js] or {} local job = jobs[js.job] or {iname = js.job} if job.iname == nil then name = name..' ???' else name = name.." "..h.getJobName(job.iname) end table.insert(sb, " [[File:") table.insert(sb, job.jobToken and ("Game,ItemIcon,"..job.jobToken) or job.ac2d and ("Game,JobIconM,"..job.ac2d) or job.mdl and ("Game,JobIconM,"..job.mdl) or "Item_IT_UNKNOWN")  table.insert(sb, ".png|29px|link=]] ") h.insertUpgradeEntry(sb, name, iname) end

--==============================================================

-- args: list of unit inames function p.jp( frame ) local args = require('Module:Arguments').getArgs(frame, {   parentFirst = true,  }) return p._jp(args) end

function p._jp(args) local includeGlobalReleased = not yesno(args.excludeGlobalReleased) local jobUpgradeTarget = string.byte('+') local typeKeys = { unit  = "New Units", hard  = "Hard Quests Added", job   = "New Jobs", master = "Character Quests Added", gate  = "Enlightenment Added", job   = "New Jobs", gear  = "New Gear", card  = "New Memento", event = "Event", } local sb = { '{| class="wikitable sortable frozen-header update-schedule" width="100%"\n', '! data-sort-type="isoDate" width="115px" class="shortspacer" | JP Date\n', '! width="115px" | Type\n', '! class="spacer" | Description\n', } if includeGlobalReleased then table.insert(sb, '! data-sort-type="isoDate" width="115px" class="shortspacer" | GL Date') end

local data = mw.loadData("Module:UpdateSchedule/Data") for i, entry in pairs(data) do if entry.jpDate and (includeGlobalReleased or not entry.glDate) then table.insert( sb, "\n|-\n|" ) table.insert( sb, entry.jpDate or 'data-sort-value="9999-12-31"|' ) table.insert( sb, "\n|" ) table.insert( sb, typeKeys[entry.type] or entry.type ) if entry.name then table.insert( sb, " "..entry.name.." " ) end table.insert( sb, "\n|" ) for j, subentry in ipairs( entry ) do     if type(subentry) == "string" then subentry = {subentry} end local type = subentry.type or entry.type local iname = subentry[1] if type == "job" or type == "master" or type == "gate" then local unit = dataModel.query("Unit", "rare,jobsets,img", {where = 'iname="'..iname..'" and server = "jp"'})[1] or {rare = 0, jobsets = {}} local name = h.getUnitName(iname) h.insertUnitUpgradeEntry(sb, unit.img, name, iname) if type == "job" then h.insertJobUpgrade(sb, iname, name, unit.jobsets[subentry[2]], subentry[3]) elseif type == "master" then table.insert(sb, " ") h.insertUpgradeEntry(sb, name, iname) elseif type == "gate" then table.insert(sb, " ") h.insertUpgradeEntry(sb, name, iname) end -- table.insert(sb, insertHistoryEntry(iname, img, name, rare, typeI)) elseif type == "gear" or type == "card" then table.insert(sb, h['render_'..type..'_icon']{iname, size='compact'}) -- table.insert(sb, insertHistoryEntry(iname, img, name, rare, typeI)) elseif type == "unit" or type == "hard" then local name = nil local img = nil local rare = nil local typeI = nil local objs = cargo.query{ tables = 'Unit, Unit__jobsets', fields = 'rare, _value = jobset, img, piece', join = 'Unit._ID = Unit__jobsets._rowID', where = { 'Unit.iname = "'..iname..'"', 'Unit.server = "jp"' },       } or {} local obj = objs[1] or {} -- mw.logObject(obj2, iname)

rare = tonumber(obj.rare or 0) name = h.getUnitName(iname) -- name = (unitsLoc[iname] or mw.loadData("Module:LocJP/en/LocalizedMasterParam/Unit")[iname] or {}).NAME or obj.name or iname if type == "unit" then img = obj.img and ("Game,Portraits,"..obj.img) or "Game,PortraitsS,unknown" else img = obj.piece and ("Game,ItemIcon,"..obj.piece) or "Game,PortraitsS,unknown" typeI = 1 end h.insertHistoryEntry(sb, iname, img, name, rare, typeI) if type == "unit" and subentry[2] then local tempJobUpgrades = subentry[2] local l = #tempJobUpgrades for idx = 1, l do           obj = objs[idx] if tempJobUpgrades:byte(idx) == jobUpgradeTarget and obj.jobset then h.insertUnitUpgradeEntry(sb, obj.img, name, iname) h.insertJobUpgrade(sb, iname, name, obj.jobset, true) end end end end end table.insert( sb, "\n" ) if includeGlobalReleased then table.insert( sb, '|'..(entry.glDate or 'data-sort-value="9999-12-31"|') ) end --sb = {table.concat( sb )} end end table.insert( sb, "\n|}" ) return table.concat(sb) end

return p