Module

WorldSwitch

From Dogcraft Wiki

m (Removing unused commented out functions (its still in the history if needed))
m (Added function for categorizing a page with multiple world categories (primarily for groups and projects))
Line 4: Line 4:


-- get the parent world for a specific subworld
-- get the parent world for a specific subworld
-- @return the world or an empty string when it doesn't find anything
function p.parentWorld(frame)
function p.parentWorld(frame)
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
Line 11: Line 12:
-- get the subworld  
-- get the subworld  
-- (usually would expect a world + subworld combo as the first two #invoke args, but works with any setup as long as either the first or the second arg has a string)
-- usually would expect a world + subworld combo as the first two #invoke args, but works with any setup as long as either the first or the second arg has a string
-- returns an empty string when it doesn't find anything
-- @return the subworld or an empty string when it doesn't find anything
function p.subworld(frame)
function p.subworld(frame)
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
Line 20: Line 21:


-- get the world  
-- get the world  
-- (usually would expect a world + subworld combo as the first two #invoke args, but works with any setup as long as either the first or the second arg has a string)
-- usually would expect a world + subworld combo as the first two #invoke args, but works with any setup as long as either the first or the second arg has a string
-- returns an empty string when it doesn't find anything
-- @return the world or an empty string when it doesn't find anything
function p.world(frame)
function p.world(frame)
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
return worldTools.extractWorld(input)
return worldTools.extractWorld(input)
end
-- get all world-related categories
-- usually meant for pages with multiple worlds, like groups or projects
-- @return a custom string or an empty string when it doesn't find anything
function p.multicat(frame)
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
worlds = worldTools.extractAllWorlds(input)
cats = ""
for i, cat in pairs(world) do
cats = cats .. " [[Category:" ..  mw.getContentLanguage():ucfirst( cat ) .. "]]"
index = index + 1
end
return cats
end
end


return p
return p

Revision as of 15:49, 29 July 2024

{{#invoke:WorldSwitch|subworld|Survial 4|Husky}} generates: husky

{{#invoke:WorldSwitch|world|Survial 4|Husky}} generates: survival 4


local p = {} --p stands for package
local worldTools = require('Module:World')


-- get the parent world for a specific subworld
-- @return the world or an empty string when it doesn't find anything
function p.parentWorld(frame)
	input = mw.ustring.lower(frame.args[1] .. frame.args[2])
	return worldTools.getParentWorld(input)
end
	
	
-- get the subworld 
-- usually would expect a world + subworld combo as the first two #invoke args, but works with any setup as long as either the first or the second arg has a string
-- @return the subworld or an empty string when it doesn't find anything
function p.subworld(frame)
	input = mw.ustring.lower(frame.args[1] .. frame.args[2])
	return worldTools.extractSubworld(input)
end


-- get the world 
-- usually would expect a world + subworld combo as the first two #invoke args, but works with any setup as long as either the first or the second arg has a string
-- @return the world or an empty string when it doesn't find anything
function p.world(frame)
	input = mw.ustring.lower(frame.args[1] .. frame.args[2])
	return worldTools.extractWorld(input)
end


-- get all world-related categories
-- usually meant for pages with multiple worlds, like groups or projects
-- @return a custom string or an empty string when it doesn't find anything
function p.multicat(frame)
	input = mw.ustring.lower(frame.args[1] .. frame.args[2])
	worlds = worldTools.extractAllWorlds(input)
	
	cats = ""
	for i, cat in pairs(world) do
			cats = cats .. " [[Category:" ..  mw.getContentLanguage():ucfirst( cat ) .. "]]"
	 		index = index + 1
	end
	
	return cats
end

return p
This page was last modified on 29 July 2024, at 15:49. (3 months ago)
Background Valentine's Day Event 2024 by TheWhiteTigerNL