Documentation for this module may be created at Module:UpdateSchedule/sandbox/doc
local render_gear_icon = require('Module:Render/Gear')._icon
local render_card_icon = require('Module:Render/Memento')._icon
local itemLink = require('Module:LinkUtils').releasedVersLink
local cargo = require('Module:CargoUtil')
local util_table = require('Module:TableUtil')
local util_vars = require('Module:VarsUtil')
-- require("Module:Util")
-- require("Module:Database")
local dataModel = require("Module:Data").model
local p = {}
local h = {}
function p.test()
util_vars.setVar('cargo query count', 0)
local start = os.clock()
local thatOutput = require('Module:UpdateSchedule')._jp{}
local finish = os.clock()
local thatTime = math.abs(finish - start)
local thatCount = tonumber(util_vars.getVar('cargo query count'))
local thatMd5 = mw.hash.hashValue('md5', thatOutput)
util_vars.setVar('cargo query count', 0)
local start = os.clock()
local thisOutput = p._jp{}
local finish = os.clock()
local thisTime = math.abs(finish - start)
local thisCount = tonumber(util_vars.getVar('cargo query count'))
local thisMd5 = mw.hash.hashValue('md5', thisOutput)
assert(thatMd5 == thisMd5, thisMd5 .. ' = ' .. thatMd5)
assert(thatCount >= thisCount)
local result = table.concat({
('* old cargo query count: %d'):format(thatCount),
('* new cargo query count: %d'):format(thisCount),
('* time spent: %0.3f seconds'):format(thisTime),
}, '\n')
mw.log(result)
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 yesNo = require('Module:Yesno')
local includeGlobalReleased = not yesNo(args.excludeGlobalReleased)
local jobUpgradeTarget = string.byte('+')
local jobs = mw.loadData("Module:DataJP/MasterParam/Job")
local jobsets = mw.loadData("Module:DataJP/MasterParam/JobSet")
-- 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 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 getJobName = function(iname)
return globalNameMap[iname] or dataModel.getLoc('Data:Game/MasterParam/Job/' .. string.gsub(iname, '_', ' '), 'name')
end
local insertUnitUpgradeEntry = function(img, name, iname, link)
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 = "<div class='item-icon'><div class='img x-6 y-0 unit-upgrade-entry'>[[File:"
output = output..(img and ("Game,PortraitsM,"..img) or "Game,PortraitsS,unknown")
output = output..".png|29px|"
output = output..name
output = output.."|link="
output = output..link
output = output.."]]</div>"
return output
end
local insertHistoryEntry = function(iname, img, name, rare, typeI, link)
if (name == 'nil' or name == '') then name = iname end
local output = {}
table.insert(output, '<div class="item-icon">')
table.insert(output, '<div class="img x-')
table.insert(output, (rare or 0))
table.insert(output, ' y-')
table.insert(output, (typeI or 0))
table.insert(output, ' generic-item-entry">')
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, link)
table.insert(output, ']]</div>')
table.insert(output, "<div class='item-count upgrade-name'>")
table.insert(output, name)
table.insert(output, "</div></div>")
return table.concat( output, '')
end
local insertUpgradeEntry = function(name, iname)
if (name == 'nil' or name == '') then name = iname end
local output = "<div class='item-count upgrade-name'>"
output = output..name
output = output.."</div></div>"
return output
end
local getJobUpgrade = function(iname, 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 {}
return jobs[js.job] or {iname = js.job}
end
local insertJobUpgrade = function(iname, name, js, isChange)
local job = getJobUpgrade(iname, js, isChange)
if job.iname == nil then
name = name..'<br/>???'
else
name = name.."<br/>"..( globalNameMap[job.iname] or dataModel.getLoc('Data:Game/MasterParam/Job/' .. string.gsub(job.iname, '_', ' '), 'name') )
end
-- name = name.."<br/>"..((jobsLoc[job.iname] or mw.loadData("Module:LocJP/en/LocalizedMasterParam/Job")[job.iname] or {NAME = job.name or job.iname}).NAME or "???")
local output = "<div class='job-upgrade-entry'>[[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]]</div>"
output = output..insertUpgradeEntry(name, iname)
return output
end
local INAMES = {}
for i, entry in pairs(mw.loadData("Module:UpdateSchedule/Data")) do if entry.jpDate and (includeGlobalReleased or not entry.glDate) then
local jpOnly = true
if entry.glDate then jpOnly = false end
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'
or _type == "unit" or _type == "hard" then
table.insert(INAMES, iname)
end
end
end end
local UNIT_DATA = h.getUnitDatas(INAMES)
for i, entry in pairs(mw.loadData("Module:UpdateSchedule/Data")) do if entry.jpDate and (includeGlobalReleased or not entry.glDate) then
local jpOnly = true
if entry.glDate then jpOnly = false end
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, "<br/><em>"..entry.name.."</em>" ) 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 = UNIT_DATA[iname] or {rare = 0, jobsets = {}}
local name = globalNameMap[iname] or unit.name or ''
local entryLink = itemLink(name, iname, jpOnly)
table.insert(sb, insertUnitUpgradeEntry(unit.img, name, iname, entryLink))
if _type == "job" then
local jobupgrade = insertJobUpgrade(iname, name, unit.jobsets[subentry[2]], subentry[3])
table.insert(sb, jobupgrade)
elseif _type == "master" then
table.insert(sb, "<div class='master-entry'>[[File:Ability_master.png|21px]]</div>")
table.insert(sb, insertUpgradeEntry(name, iname))
elseif _type == "gate" then
table.insert(sb, ("<div class='background-gate background-gate-pos-"..subentry[2].."></div>"))
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', jplink=jpOnly}))
elseif _type == 'card' then
local icon = render_card_icon({iname, size='compact', server="jp", lang="japanese", jplink=jpOnly})
table.insert(sb, icon)
end
-- table.insert(sb, insertHistoryEntry(iname, img, name, rare, typeI))
elseif _type == "unit" or _type == "hard" then
local obj = UNIT_DATA[iname] or {rare = 0, jobsets = {}}
local name = globalNameMap[iname] or obj.name or ''
local rare = tonumber(obj.rare) or 0
local img = nil
local typeI = nil
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
local entryLink = itemLink(name, iname, jpOnly)
table.insert(sb, insertHistoryEntry(iname, img, name, rare, typeI, entryLink))
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, entryLink))
local jobupgrade = insertJobUpgrade(iname, name, obj.jobsets[idx], true)
table.insert(sb, jobupgrade)
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
function h.quote(s)
if not s then return nil end
return ('%q'):format(s)
end
function h.getUnitDatas(inames)
if #inames == 0 then return {} end
local inames = util_table.concat(inames, ',', h.quote)
local units = {}
local unitRows = cargo.query{
tables={"Unit","UnitLoc"},
join = {"Unit.iname = UnitLoc.iname"},
fields={"Unit.iname=iname","rare","jobsets","img","piece","name","lang"},
where = {'Unit.iname IN ('..inames..')', 'Unit.server = "jp"', 'lang IN ("english", "japanese")'},
}
for i, row in ipairs(unitRows) do
local lang = row.lang
local iname = row.iname
local unit = units[iname] or {}
unit.rare = unit.rare or tonumber(row.rare)
unit.jobsets = unit.jobsets or mw.text.split(row.jobsets, '|')
unit.img = unit.img or row.img
unit.piece = unit.piece or row.piece
unit._names = unit._names or {}
unit._names[lang] = unit._names[lang] or row.name
units[iname] = unit
end
for k, unit in pairs(units) do
unit.name = unit._names.english or unit._names.japanese
end
return units
end
return p