Module

World

From Dogcraft Wiki

Revision as of 01:57, 29 December 2023 by Domino (talk | contribs) (added an optional start parameter to extractSubworld and extractWorld)

Documentation for this module may be created at Module:World/doc

local p = {}

-- table of all past and current world names
p.worlds = {"survival 1", "survival 2", "survival 3", "survival 4", "survival 5", "survival 6", "creative", "patreon", "hub", "lobby", "amplified", "MCMMO", "skyblock"}


-- table of all past and current subworld names with associated "parent" worlds
p.subworldsWithWorlds = {
	["husky"]		= p.worlds[4],
	["beagle"]		= p.worlds[4],
	["akita"]		= p.worlds[5],
	["corgi"]		= p.worlds[5],
	["labrador"]	= p.worlds[5],
	["shepherd"]	= p.worlds[5],
	["sheltie"] 	= p.worlds[6],
	["retriever"]	= p.worlds[6],
	["streamtown"]	= p.worlds[6],
}


-- function to convert the subworldsWithWorlds table to a list of only subworld names
function p.subworlds()
	out = {}
	index = 1
	for subworld in pairs(p.subworldsWithWorlds) do
		out[index] = subworld
		index = index + 1
	end
	return out
end


-- table of only subworld names
p.subworlds = p.subworlds()


-- table of world names with associated subworlds (unused)
-- p.worldsWithSubworlds = {
-- 	["survival 4"] = {"husky", "beagle"},
-- 	["survival 5"] = {"akita", "corgi", "labrador", "shepherd"},
-- 	["survival 6"] = {"sheltie", "retriever", "streamtown"},
-- }


-- function which returns the first world name found in a string
function p.extractWorld(input, start)
	start = start or 1
	input = mw.ustring.lower(input)
	worlds = p.worlds
	for key,value in ipairs(worlds) do 
		if (mw.ustring.find(input, value, start, true) ~= nil) then
			return value
		end
	end
	if (mw.ustring.find(input, 'survival', 1, true) ~= nil) then
		return 'survival 1'
	end
	return ''
end
	

-- function which returns the first subworld name found in a string
function p.extractSubworld(input, start)
	start = start or 1
	input = mw.ustring.lower(input)
	subworlds = p.subworlds
	for key,value in ipairs(subworlds) do 
		if (mw.ustring.find(input, value, 1, true) ~= nil) then
			return value
		end
	end
	return ''--return 'not found'
end


-- function which returns the parent world for the first subworld found in a string
function p.getParentWorld(input)
	input = mw.ustring.lower(input)
	subworld = p.extractSubworld(input)
	return p.subworldsWithWorlds[subworld]
end

return p
This page was last modified on 29 December 2023, at 01:57. (3 months ago)