Module:Location Table: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
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: | Line 1: | ||
require('strict') |
require('strict') |
||
local persistant = require('Module:Break Isolation').get_module_store('Module:Location Table') |
|||
local parse = require('Module:Param Parse') |
local parse = require('Module:Param Parse') |
||
local edit = 'Unknown <span class="small plainlinks">' .. require('Module:Edit button')() .. '</span>' |
local edit = 'Unknown <span class="small plainlinks">' .. require('Module:Edit button')() .. '</span>' |
||
persistant.counter = persistant.counter or 0 |
|||
local p = {} |
local p = {} |
||
function p. |
function p.head(frame) |
||
local args = frame:getParent().args |
|||
assert(not persistant.in_table, 'Second {{LocTableHead}} (Missing {{LocTableBottom}}?)') |
|||
persistant.in_table = true |
|||
persistant.json = {} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
function p. |
function p.line(frame) |
||
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') |
|||
⚫ | |||
:css{ ['text-align'] = 'center' } |
|||
⚫ | |||
:tag('tr') |
|||
⚫ | |||
:tag('th'):wikitext('Location'):done() |
|||
⚫ | |||
:tag('th'):wikitext('Episode'):done() |
|||
⚫ | |||
:tag('th'):wikitext('Qty.'):done() |
|||
⚫ | |||
:done() |
|||
⚫ | |||
persistant.counter = persistant.counter + 1 |
|||
⚫ | |||
local id = 'LOC_' .. persistant.counter |
|||
⚫ | |||
local id_prefix = 'LOC_' |
|||
⚫ | |||
⚫ | |||
id_prefix = id_prefix .. loc_version .. '_' |
|||
⚫ | |||
local loc_json = {} |
|||
⚫ | |||
for i = 1, 9007199254740992 do |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if not loc then |
|||
⚫ | |||
break |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local id = id_prefix .. loc |
|||
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() |
|||
⚫ | |||
function p.bottom(frame) |
|||
⚫ | |||
assert(persistant.in_table, '{{LocTableBottom}} when not in a location table (Missing {{LocTableHead}}?)') |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
if |
if persistant.version then |
||
mw.smw.subobject({ ['Location JSON'] = mw.text.jsonEncode( |
mw.smw.subobject({ ['Location JSON'] = mw.text.jsonEncode(persistant.json) }, persistant.version) |
||
else |
else |
||
mw.smw.set{ ['Location JSON'] = mw.text.jsonEncode( |
mw.smw.set{ ['Location JSON'] = mw.text.jsonEncode(persistant.json) } |
||
end |
end |
||
persistant.in_table = nil |
|||
return tbl |
|||
persistant.json = nil |
|||
persistant.version = nil |
|||
persistant.location_object = nil |
|||
end |
end |
||