Module:UpdateSchedule/sandbox2

local render_gear_icon = require('Module:Render/Gear')._icon local render_card_icon = require('Module:Render/Memento')._icon

-- require("Module:Util") -- require("Module:Database") local dataModel = require("Module:Data").model

local f = {} function f.loadJobSets local jobsets = mw.loadData("Module:DataJP/MasterParam/JobSet") local new = {} for k, v in pairs(jobsets) do       new[k] = { job = v.job, }   end return new end

local p = {}

-- 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 jobUpgradeTarget = string.byte('+') local jobs   = mw.loadData("Module:DataJP/MasterParam/Job") local jobsets = f.loadJobSets local unitsLoc = mw.loadData("Module:Loc/en/LocalizedMasterParam/Unit") local jobsLoc = mw.loadData("Module:Loc/en/LocalizedMasterParam/Job") local gearsLoc = mw.loadData("Module:Loc/en/LocalizedMasterParam/Artifact") local globalNameMap = mw.loadData("Module:UpdateSchedule/GlobalNameMap") 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" width="100%"\n', '! data-sort-type="isoDate" width="115px" class="shortspacer" | JP Date\n', '! width="115px" | Type\n', '! class="spacer" | Description\n', '! data-sort-type="isoDate" width="115px" class="shortspacer" | GL Date', } local getUnitName = function(iname) return globalNameMap[iname] or dataModel.getLoc('Data:Game/MasterParam/Unit/' .. string.gsub(iname, '_', ' '), 'name') end local getCardName = function(iname) return dataModel.getLoc('Data:Game/MasterParam/Card/' .. string.gsub(iname, '_', ' '), 'name') end local getJobName = function(iname) return globalNameMap[iname] or dataModel.getLoc('Data:Game/MasterParam/Job/' .. string.gsub(iname, '_', ' '), 'name') end local insertUnitUpgradeEntry = function(img, name, iname) if (name == 'nil' or name == '') then name = iname end -- local link = 'http://www.alchemistcodedb.com/jp/unit/' .. string.lower(string.gsub(string.gsub(iname, 'UN_V2_', ''), '_', '-')) local output = " [[File:"    output = output..(img and ("Game,PortraitsM,"..img) or "Game,PortraitsS,unknown")    output = output..".png|29px|"    output = output..name    output = output.."|link="    output = output..name    output = output.."]] "

return output end local insertHistoryEntry = function(iname, img, name, rare, typeI) if (name == 'nil' or name == '') then name = iname end local output = {} table.insert(output, ' ') table.insert(output, '') table.insert(output, '[[File:')   table.insert(output, (img or 'Item_IT_UNKNOWN'))    table.insert(output, '.png|57px|')    table.insert(output, name)    table.insert(output, '|link=')    table.insert(output, name)    table.insert(output, ']] ') table.insert(output, " ") table.insert(output, name) table.insert(output, " ") return table.concat( output, '') end local insertUpgradeEntry = function(name, iname) if (name == 'nil' or name == '') then name = iname end local output = " " output = output..name output = output.." " return output end local insertJobUpgrade = function(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.." "..getJobName(job.iname) end -- name = name.." "..((jobsLoc[job.iname] or mw.loadData("Module:LocJP/en/LocalizedMasterParam/Job")[job.iname] or {NAME = job.name or job.iname}).NAME or "???") local output = " [[File:"     -- table.insert(sb, job.ranks and ("Game,ItemIcon,"..job.ranks[1].eqid1) or job.ac2d and ("Game,JobIconM,"..job.ac2d) or job.mdl and ("Game,JobIconM,"..job.mdl) or "Item_IT_UNKNOWN")      output = output..(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")      output = output..".png|29px]] " output = output..insertUpgradeEntry(name, iname) return output end

for i, entry in pairs(mw.loadData("Module:UpdateSchedule/Data")) do if entry.jpDate 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 = getUnitName(iname) -- local name = (unitsLoc[iname] or mw.loadData("Module:LocJP/en/LocalizedMasterParam/Unit")[iname] or {NAME = unit.name or iname}).NAME table.insert(sb, insertUnitUpgradeEntry(unit.img, name, iname)) if type == "job" then table.insert(sb, insertJobUpgrade(iname, name, unit.jobsets[subentry[2]], subentry[3])) elseif type == "master" then table.insert(sb, " ") table.insert(sb, insertUpgradeEntry(name, iname)) elseif type == "gate" then table.insert(sb, " ") table.insert(sb, insertUpgradeEntry(name, iname)) end -- table.insert(sb, insertHistoryEntry(iname, img, name, rare, typeI)) elseif type == "gear" or type == "card" then if type == 'gear' then table.insert(sb, render_gear_icon({iname, size='compact'})) elseif type == 'card' then table.insert(sb, render_card_icon({iname, size='compact'})) end -- table.insert(sb, insertHistoryEntry(iname, img, name, rare, typeI)) else local obj = {} local name = nil local img = nil local rare = nil local typeI = nil if type == "unit" or type == "hard" then obj = dataModel.query("Unit", "rare,jobsets,img,piece", {where = 'iname="'..iname..'" and server = "jp"'})[1] or {jobsets = {}} rare = obj.rare or 0 name = 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 table.insert(sb, insertHistoryEntry(iname, img, name, rare, typeI)) if type == "unit" and subentry[2] then local tempJobUpgrades = subentry[2] for idx = 1, #tempJobUpgrades do               if tempJobUpgrades:byte(idx) == jobUpgradeTarget and obj.jobsets[idx] then -- table.insert(sb, "Job upgrade found at: "..obj.jobsets[idx]) table.insert(sb, insertUnitUpgradeEntry(obj.img, name, iname)) table.insert(sb, insertJobUpgrade(iname, name, obj.jobsets[idx], true)) end end end end end end table.insert( sb, "\n|" ) table.insert( sb, entry.glDate or 'data-sort-value="9999-12-31"|' ) --sb = {table.concat( sb )} end end table.insert( sb, "\n|}" ) return table.concat(sb) end

return p