Module:Room features: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
Line 13: Line 13:
}
}


function base_query(location, category)
function base_query(location)
return {
local ret = {
'[[Has subobject::<q>[[Located in::' .. location .. ']]</q>]]',
'[[Has subobject::<q>[[Located in::' .. location .. ']]</q>]]',
'[[Category:' .. category,
'?#-',
'?#-',
'?Name',
'?Name',
'?Image#-',
'?Image#-'
}
}
for _,cat in ipairs(categories) do
table.insert(ret, string.format('?Category:%s=%s', cat, cat))
end
return ret
end
end


Line 28: Line 31:
local location = args[1] or mw.title.getCurrentTitle()
local location = args[1] or mw.title.getCurrentTitle()
local query = mw.smw.ask(base_query(location))
for _,cat in ipairs(categories) do
if query ~= nil then
local query = mw.smw.ask(base_query(location, cat))
local results_by_type = {}
if query ~= nil then
for i,v in ipairs(query) do
ret = ret .. '===' .. cat .. '===\n'
for _,cat in ipairs(categories) do
if i == 1 then
local gallery = '<gallery>\n'
results_by_type[cat] = {}
for i,v in ipairs(query or {}) do
end
gallery = gallery .. (v.Image or 'File:Section anchor light.svg') .. '|' .. '[[' .. v[1] .. '|' .. v.Name .. ']]\n'
if v[cat] == true then
table.insert(results_by_type[cat], v)
end
end
end
for cat,v in pairs(results_by_type) do
if #v > 0 then
ret = ret .. '===' .. cat .. '===\n'
local gallery = '<gallery>\n'
for i,v in ipairs(query or {}) do
gallery = gallery .. (v.Image or 'File:Section anchor light.svg') .. '|' .. '[[' .. v[1] .. '|' .. v.Name .. ']]\n'
end
gallery = gallery .. '</gallery>\n\n'
mw.log(gallery)
ret = ret .. gallery
end
end
gallery = gallery .. '</gallery>\n\n'
mw.log(gallery)
ret = ret .. frame:preprocess(gallery)
end
end
end
end
return ret
return frame:preprocess(ret)
end
end



Revision as of 15:22, 3 November 2024

Module documentation
This documentation is transcluded from Module:Room features/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Room features/doc. [edit]
Module:Room features's function main is invoked by Template:Room features.

local p = {}

function p.main(frame)
	local args = frame:getParent().args
	return p._main(args)
end

local categories = {
	'Non-player characters',
	'Monsters',
	'Skill nodes',
	'Scenery'
}

function base_query(location)
	local ret = {
		'[[Has subobject::<q>[[Located in::' .. location .. ']]</q>]]',
		'?#-',
		'?Name',
		'?Image#-'
	}
	for _,cat in ipairs(categories) do
		table.insert(ret, string.format('?Category:%s=%s', cat, cat))
	end
	return ret
end

function p._main(args)
	local frame = mw.getCurrentFrame()
	local ret = ''
	local location = args[1] or mw.title.getCurrentTitle()
	
	local query = mw.smw.ask(base_query(location))
	if query ~= nil then
		local results_by_type = {}
		for i,v in ipairs(query) do
			for _,cat in ipairs(categories) do
				if i == 1 then
					results_by_type[cat] = {}
				end
				if v[cat] == true then
					table.insert(results_by_type[cat], v)
				end
			end
		end
		for cat,v in pairs(results_by_type) do
			if #v > 0 then
				ret = ret .. '===' .. cat .. '===\n'
				
				local gallery = '<gallery>\n'
				for i,v in ipairs(query or {}) do
					gallery = gallery .. (v.Image or 'File:Section anchor light.svg') .. '|' .. '[[' .. v[1] .. '|' .. v.Name .. ']]\n'
				end
				gallery = gallery .. '</gallery>\n\n'
				mw.log(gallery)
				
				ret = ret .. gallery
			end
		end
	end
	
	return frame:preprocess(ret)
end

return p