Module:Memento/sandbox

local cargo = require('Module:CargoUtil') local yesno = require('Module:Yesno') local enums = require('Module:Data/Enums')

local types = { [0] = 'None', [1] = 'Equipment', [2] = 'Enhance EXP', [3] = 'Enhance Trust', } local origins = { [0] = "Other", [100] = "Other", [1] = "Envylia", [2] = "Wratharis", [3] = "Slothstein", [4] = "Lustburg", [5] = "Gluttony Foss", [6] = "Greed Dike", [7] = "Saga Region", [8] = "Wadatsumi", [9] = "Desert Zone", [10] = "Northern Pride", [11] = "Lost Blue", }

local p = {} local h = {} local cats = {}

function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {parentFirst=true}) return p._main(args) end

function p._main(args) local iname = args[1] local row = cargo.query{ tables='ConceptCard=CC,ConceptCardLoc=CCLoc', fields={ 'CC.iname=iname', 'CC.icon=icon', 'CC.type=type', 'CC.birth_id=birth_id', 'CC.rare=rare', 'CC.lvcap=lvcap', 'CC.en_cost=en_cost', 'CC.en_exp=en_exp', 'CC.trust_artifact_names=trust_artifact_names', 'CC.trust_artifact_counts=trust_artifact_counts', 'CC.trust_item_names=trust_item_names', 'CC.trust_item_counts=trust_item_counts', 'CC.leader_skill=leader_skill', 'CC.concept_card_groups=concept_card_groups', 'CCLoc.name=name', 'CCLoc.expr=expr', 'CCLoc.flavor=flavor', },		join='CC.iname=CCLoc.iname', where={ ('CC.iname="%s"'):format(iname), 'CC.server="gl"', 'CCLoc.lang="english"', }	}[1]	if not row then return end for k, v in pairs(mw.loadData('Module:Data/Model/ConceptCard')) do		if row[k] then if v == 'Integer' then row[k] = tonumber(row[k]) elseif v == 'Boolean' then row[k] = yesno(row[k]) elseif type(v) == 'table' and v.list then local t = {} for str in mw.text.gsplit(row[k], v.list, true) do					if v[1] == 'Integer' then str = tonumber(str) elseif v[1] == 'Boolean' then str = yesno(str) end t[#t+1] = str end if #t > 0 then row[k] = t				end end end end row.extra = mw.loadData("Module:Data/Extra/Memento")[iname]

local root = mw.html.create

-- h.printInfobox(root, row)

root:newline:tag('h2'):wikitext('Basic information') -- root:newline:wikitext('') -- root:newline:tag('h3'):wikitext('Description') -- root:newline:wikitext(data.flavor)

-- leader skill h.printLeaderSkill(root, row)

return tostring(root) end

function p.test return p._main{'TS_WADA_KURT'} end

function h.printInfobox(root, data) local infobox = root:tag('div') infobox:newline:wikitext('* Name: ', data.name) infobox:newline:wikitext('* Type: ', types[tonumber(data.type)]) infobox:newline:wikitext('* Origin: ', origins[data.birth_id]) infobox:newline:wikitext('* Rarity: ', (data.rare or 0)+1, '★') infobox:newline:wikitext('* Max Level: ', data.lvcap or (data.rare * 5 + 20)) infobox:newline:wikitext('* Enhancer Cost: ', data.en_cost) infobox:newline:wikitext('* Enhancer EXP: ', data.en_exp) infobox:newline:wikitext('* Vision Clear Reward: ', h.vcr(data) or 'N/A') infobox:newline:wikitext('* Gives unit: ', h.unitReward(data) or 'N/A') infobox:newline:wikitext('* Source: ', data.extra.source or 'Unreleased') infobox:newline:wikitext('* Release dates: ', h.releaseDates(data) or 'N/A') infobox:newline:wikitext('* Global only: ', yesno(data.extra.glOnly) and 'Yes' or 'No') infobox:newline:wikitext('* External links: ', ''-'):lower..' AlchemistCodeDB') end

function h.vcr(data) local t = {} local inames = {} local counts = {} if data.trust_item_names then for i, name in ipairs(data.trust_item_names) do			inames[#inames+1] = ('"%s"'):format(name) counts[name] = data.trust_item_counts[i] end end if data.trust_artifact_names then for i, name in ipairs(data.trust_artifact_names) do			inames[#inames+1] = ('"%s"'):format(name) counts[name] = data.trust_artifact_counts[i] end end if #inames == 0 then return end

for i, row in ipairs(cargo.query{		tables = {			'Pages=P',			'Item=IT', 'ItemLoc=ITLoc',			'Artifact=AF', 'ArtifactLoc=AFLoc',		},		join = {			'P.iname=IT.iname',			'P.iname=AF.iname',			'IT.iname=ITLoc.iname',			'AF.iname=AFLoc.iname',		},		fields = {			'P.iname = iname',			'P._pageName = link',			'P.type = pagetype',			'COALESCE(IT.rare, AF.rini) = rare',			'COALESCE(IT.type, AF.type) = type',			'COALESCE(IT.icon, AF.icon) = file',			'COALESCE(ITLoc.name, AFLoc.name) = name',		},		where = {			'P.type IN ("Item","Gear")',			('P.iname IN (%s)'):format(table.concat(inames,',')),			'COALESCE(AF.server, IT.server) = "gl"',			'COALESCE(AFLoc.lang, ITLoc.lang) = "english"',		}	}) do		if row.pagetype == 'Gear' then row.type = 2 elseif row.pagetype == 'Item' then row.type = ({[1] = 1, [11] = 1, [14] = 3})[row.type] or 0 end if row.file and row.file:sub(1,3) == 'AF_' then row.file = 'ArtiIcon,'..row.icon elseif row.file then row.file = 'ItemIcon,'..row.icon end row.size = 64 row.count = counts[row.iname] t[#t+1] = h.icon(row) end return table.concat(t) end

function h.unitReward(data) if not data.first_get_unit then return end local row = cargo.query{ tables = {'Unit=UN','UnitLoc=UNLoc','Pages=C'}, fields = { 'UN.iname=iname', 'UN.rare=rare', 'UN.img=file', 'UNLoc.name=name', 'C._pageName=link', },		join = {'UN.iname=UNLoc.iname','UN.iname=C.iname'}, where = { ('UN.iname="%s"'):format(data.first_get_unit), 'UN.server="gl"', 'UNLoc.lang="english"', },	}[1]	if not row then return end if row.file then row.file = 'PortraitsM,'..row.file end row.size = 32 return (''):format(row.file, row.name, row.link) end

function h.releaseDates(data) local extra = data.extra if not extra then return end local root for _, region in ipairs{'gl', 'jp'} do		local date = extra[region..'Date'] if date then root = root or mw.html.create('ul') root:tag('li'):wikitext(region:upper, ': ', date) end end return tostring(root) end

function h.printLeaderSkill(root, data) if not data.leader_skill then return end

local skill = cargo.query{ tables = { 'Skill=SK','SkillLoc=SKLoc', },		join = { 'SK.iname=SKLoc.iname', },		fields = { 'SK.iname=iname', 'SKLoc.name=name', 'SKLoc.expr=expr', 'SK.type=type', 'SK.eff_type=eff_type', 'SK.target=target', 'SK.cond=cond', 'SK.timing=timing', 'SK.t_buff=t_buff', },		where = { ('SK.iname="%s"'):format(data.leader_skill), 'SK.server="gl"', 'SKLoc.lang="english"', },	}[1]

mw.logObject(skill, 'skill')

if not skill then return end

root:newline:tag('h3'):wikitext('Leader Skill') root:newline:tag('h4'):wikitext(skill.name) root:newline:tag('p'):wikitext(skill.expr) -- skill.type = enums.ESkillType[tonumber(skill.type)] -- skill.eff_type = enums.SkillEffectTypes[tonumber(skill.eff_type)] skill.target = enums.ESkillTarget[tonumber(skill.target)] skill.cond = enums.ESkillCondition[tonumber(skill.cond)] -- skill.timing = enums.ESkillTiming[tonumber(skill.timing)]

if skill.t_buff then mw.logObject(skill.t_buff, 't_buff') local buff_details = cargo.query{ tables = { 'BuffDetail=BD', },			fields = { 'BD.idx=idx', 'BD.calc=calc', 'BD.tktag=tktag', 'BD.type=type', 'BD.vini=vini', 'BD.vmax=vmax', 'BD.vone=vone', },			where = { ('BD.buff_iname="%s"'):format(skill.t_buff), 'BD.server="gl"', },			orderBy = 'BD.idx', }

mw.logObject(buff_details, 'buff details')

if #buff_details > 0 then local tbl = root:newline:tag('table'):addClass('wikitable') tbl:newline:tag('caption'):wikitext('Target Buff ('..skill.target..') ('..skill.cond..')') tbl:newline:tag('tr'):tag('th'):attr('colspan', 3):wikitext('Stats') tbl:newline:tag('tr') :tag('th'):wikitext('Type'):done :tag('th'):wikitext('Min'):done :tag('th'):wikitext('Max'):done for i, buff in ipairs(buff_details) do				local tr = tbl:newline:tag('tr') local statName = enums.statNameFromType(tonumber(buff.type), buff.tktag) local fmt = yesno(buff.calc) and '%+d%%' or '%+d' tr:tag('th'):wikitext(statName) tr:tag('td'):wikitext(fmt:format(tonumber(buff.vini))) tr:tag('td'):wikitext(fmt:format(tonumber(buff.vmax))) if buff.tktag then cats[#cats+1] = statName end end end local custom_targets = cargo.query{ tables = { 'Buff=BF', 'Buff__custom_targets=BFCT', 'CustomTarget=CT', },			join = { 'BF._ID=BFCT._rowID', 'BFCT._value=CT.iname', },			fields = { 'CT.birth_id=birth_id', -- integer 'CT.sex=sex', -- integer 'CT.dark=dark', -- integer 'CT.fire=fire', -- integer 'CT.shine=shine', -- integer 'CT.thunder=thunder', -- integer 'CT.water=water', -- integer 'CT.wind=wind', -- integer 'CT.concept_card_groups=concept_card_groups', -- list of string 'CT.job_groups=job_groups', -- list of string 'CT.unit_groups=unit_groups', -- list of string 'CT.units=units', -- list of string },			where = { ('BF.iname="%s"'):format(skill.t_buff), 'BF.server="gl"', 'CT.server="gl"', },		}		for _, custom_target in ipairs(custom_targets) do			if custom_target.concept_card_groups then local cards = cargo.query{ tables = { 'ConceptCardGroup=CCG', 'ConceptCardGroup__cards=CCGC', 'ConceptCard=CC', 'ConceptCardLoc=CCLoc', 'Pages=Pages', },					join = { 'CCG._ID=CCGC._rowID', 'CCGC._value=CC.iname', 'CC.iname=Pages.iname', 'CC.iname=CCLoc.iname', },					fields = { 'CC.iname=iname', 'CC.icon=icon', 'CC.type=type', 'CC.rare=rare', 'Pages._pageName=PAGENAME', 'CCLoc.name=name', },					where = { ('CCG.iname="%s"'):format(custom_target.concept_card_groups), 'CCG.server="gl"', 'CC.server="gl"', 'CCLoc.lang="english"', }				}				root:newline:tag('h4'):wikitext('Memento Group') local ul = root:newline:tag('ul') for _, card in ipairs(cards) do					local icon = (	       	' %s'					):format(card.icon, card.PAGENAME, card.PAGENAME, card.name) ul:newline:tag('li'):wikitext(icon) end end end end end

function h.icon(args) local file = args.file or 'ItemIcon,IT_UNKNOWN' local name = h.wikiSafeName(args.name) local link = h.wikiSafeName(args.link) local size = args.size or 128 local tagName = args.inline and 'span' or 'div' local padding = math.floor(size*14/128) size = size - padding local sb = mw.html.create(tagName) :addClass(args.classes) :addClass('item-icon') local img = sb:tag(tagName) :addClass('img') :addClass('x-'..(args.rare or 0)) :addClass('y-'..(args.type or 0)) :css('width', size..'px') :css('height', size..'px') :css('padding', (padding/2)..'px') if args.count and args.count > 1 then img:tag(tagName) :addClass('item-count') :wikitext('x '..args.count) end img:wikitext(string.format( '',		file, size, name and name ~=  and '|'..name or , link and link ~=  and '|link='..link or  ))	sb:wikitext(args.content) return tostring(sb) end

function h.wikiSafeName(name) if not name then return end return name:gsub('[%[%]]', {		['['] = '【',		[']'] = '】',	}) end

return p