Module:Location Table: Difference between revisions

Repurpose so this can work with the seperate LocTableHead/LocLine/LocTableBottom templates
m (Artoire moved page Module:Sandbox/User:Artoire/Location Table to Module:Location Table without leaving a redirect: Move out of sandbox)
(Repurpose so this can work with the seperate LocTableHead/LocLine/LocTableBottom templates)
Line 1:
require('strict')
local persistant = require('Module:Break Isolation').get_module_store('Module:Location Table')
local parse = require('Module:Param Parse')
local edit = 'Unknown <span class="small plainlinks">' .. require('Module:Edit button')() .. '</span>'
 
persistant.counter = persistant.counter or 0
 
local p = {}
 
function p.mainhead(frame)
returnlocal args = p._main(frame:getParent().args)
assert(not persistant.in_table, 'Second {{LocTableHead}} (Missing {{LocTableBottom}}?)')
persistant.in_table = true
persistant.json = {}
local loc_versionpersistant.version = args.version
local persistant.location_object = mw.title.getCurrentTitle().fullText
if loc_versionargs.version then
persistant.location_object = persistant.location_object .. '#' .. loc_version args.version
end
end
 
function p._mainline(argsframe)
assert(persistant.in_table, '{{LocLine}} when not in a location table (Missing {{LocTableHead}}?)')
local tbl = mw.html.create('table')
local args = frame:getParent().args
:addClass('wikitable sortable filterable sticky-header loctable autosort=1,a')
local loc = args['.loc'..i]
:css{ ['text-align'] = 'center' }
local qty = args['qty'..i]quantity
:tag('tr')
qty = tonumber(qty or '')
:tag('th'):wikitext('Location'):done()
loc_json persistant.json[loc] = qty or -1
:tag('th'):wikitext('Episode'):done()
local loc_link = ('[[%s]]'):format(loc)
:tag('th'):wikitext('Qty.'):done()
local episode = mw.smw.ask{loc_link, '?Episode#=', 'mainlabel=-'}
:done()
episode = episode and episode[1][1]
 
persistant.counter = persistant.counter + 1
local loc_version = args.version
local id = 'LOC_' .. persistant.counter
local location_object = mw.title.getCurrentTitle().fullText
local id_prefix = 'LOC_'
if loc_version then
location_object = location_object .. '#' .. loc_version
id_prefix = id_prefix .. loc_version .. '_'
end
local loc_json = {}
 
mw.smw.subobject({
for i = 1, 9007199254740992 do
['Location object'] = persistant.location_object,
local loc = args['loc'..i]
['Located in'] = loc,
if not loc then
['Location quantity'] = qty or 'Unknown'
break
}, id)
end
local qty = args['qty'..i]
qty = tonumber(qty or '')
loc_json[loc] = qty or -1
local loc_link = ('[[%s]]'):format(loc)
local episode = mw.smw.ask{loc_link, '?Episode#=', 'mainlabel=-'}
episode = episode and episode[1][1]
local id = id_prefix .. loc
 
tbl:tag return mw.html.create('tr')
:attr{ id = id }
:tag('td'):wikitext(loc_link):done()
:tag('td'):wikitext(parse.episode_func(episode)):done()
:tag('td'):wikitext(qty or edit):done()
:done()
end
 
function p.bottom(frame)
mw.smw.subobject({
assert(persistant.in_table, '{{LocTableBottom}} when not in a location table (Missing {{LocTableHead}}?)')
['Location object'] = location_object,
['Located in'] = loc,
['Location quantity'] = qty or 'Unknown'
}, id)
end
 
if loc_versionpersistant.version then
mw.smw.subobject({ ['Location JSON'] = mw.text.jsonEncode(loc_jsonpersistant.json) }, loc_versionpersistant.version)
else
mw.smw.set{ ['Location JSON'] = mw.text.jsonEncode(loc_jsonpersistant.json) }
end
 
persistant.in_table = nil
return tbl
persistant.json = nil
persistant.version = nil
persistant.location_object = nil
end
 
1,471

edits