Module:Sandbox/User:Artoire/1: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
(Created page with "return { main = function() mw.x = (mw.x or 0) + 1 return tostring(mw.x) end }")
 
mNo edit summary
Line 1: Line 1:
require('strict')
return {
local persistant = require('Module:Break Isolation').get_module_store('Module:Location Table')
main = function()
local parse = require('Module:Param Parse')
mw.x = (mw.x or 0) + 1
local edit = 'Unknown <span class="small plainlinks">' .. require('Module:Edit button')() .. '</span>'
return tostring(mw.x)

persistant.counter = persistant.counter or 0

local p = {}

function p.head(frame)
local args = frame.args
assert(not persistant.in_table, 'Second {{LocTableHead}} (Missing {{LocTableBottom}}?)')
persistant.in_table = true
persistant.json = {}
persistant.version = args.version
persistant.location_object = mw.title.getCurrentTitle().fullText
if args.version then
persistant.location_object = persistant.location_object .. '#' .. args.version
end
end
end
}

function p.line(frame)
assert(persistant.in_table, '{{LocLine}} when not in a location table (Missing {{LocTableHead}}?)')
local args = frame.args
local qty = args.quantity
qty = tonumber(qty or '')
persistant.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]

persistant.counter = persistant.counter + 1
local id = 'LOC_' .. persistant.counter

tbl:tag('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()

mw.smw.subobject({
['Location object'] = persistant.location_object,
['Located in'] = loc,
['Location quantity'] = qty or 'Unknown'
}, id)
end

function p.bottom(frame)
assert(persistant.in_table, '{{LocTableBottom}} when not in a location table (Missing {{LocTableHead}}?)')

if persistant.version then
mw.smw.subobject({ ['Location JSON'] = mw.text.jsonEncode(persistant.json) }, persistant.version)
else
mw.smw.set{ ['Location JSON'] = mw.text.jsonEncode(persistant.json) }
end

persistant.in_table = nil
persistant.json = nil
persistant.version = nil
persistant.location_object = nil
end

return p

Revision as of 16:25, 16 December 2024

Documentation for this module may be created at Module:Sandbox/User:Artoire/1/doc

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.head(frame)
	local args = frame.args
	assert(not persistant.in_table, 'Second {{LocTableHead}} (Missing {{LocTableBottom}}?)')
	persistant.in_table = true
	persistant.json = {}
	persistant.version = args.version
	persistant.location_object = mw.title.getCurrentTitle().fullText
	if args.version then
		persistant.location_object = persistant.location_object .. '#' .. args.version
	end
end

function p.line(frame)
	assert(persistant.in_table, '{{LocLine}} when not in a location table (Missing {{LocTableHead}}?)')
	local args = frame.args
	local qty = args.quantity
	qty = tonumber(qty or '')
	persistant.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]

	persistant.counter = persistant.counter + 1
	local id = 'LOC_' .. persistant.counter

	tbl:tag('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()

	mw.smw.subobject({
		['Location object'] = persistant.location_object,
		['Located in'] = loc,
		['Location quantity'] = qty or 'Unknown'
	}, id)
end

function p.bottom(frame)
	assert(persistant.in_table, '{{LocTableBottom}} when not in a location table (Missing {{LocTableHead}}?)')

	if persistant.version then
		mw.smw.subobject({ ['Location JSON'] = mw.text.jsonEncode(persistant.json) }, persistant.version)
	else
		mw.smw.set{ ['Location JSON'] = mw.text.jsonEncode(persistant.json) }
	end

	persistant.in_table = nil
	persistant.json = nil
	persistant.version = nil
	persistant.location_object = nil
end

return p