Module

World

From Dogcraft Wiki

(Created meta module for keeping track of current and past worlds and subworlds and performing the tasks of extracting the world/subworld name from a string, and getting the associated "parent" world for a given extracted subworld string. This module is meant for use with other modules (such as WorldPills or WorldSwitch))
 
m (Added Mall)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


-- table of all past and current world names
-- table of all past and current world names
Line 6: Line 5:




-- table of all past and current subworld names with associated "parent" worlds
-- table of all past and current subworld names with associated "parent" worlds.
p.subworldsWithWorlds = {
p.subworldsWithWorlds = {
["husky"] = p.worlds[4],
["husky"] = p.worlds[4],
Line 17: Line 16:
["retriever"] = p.worlds[6],
["retriever"] = p.worlds[6],
["streamtown"] = p.worlds[6],
["streamtown"] = p.worlds[6],
["D.E.P.3"] = p.worlds[8],
["D.E.P.4"] = p.worlds[8],
["mall"] = p.worlds[6], -- this is not perfect, sur4, 5 and 6 all have a mall subworld
}
}


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




-- function which returns the first world name found in a string
-- function which returns the first world name found in a string
function p.extractWorld(input)
function p.extractWorld(input, start)
start = start or 1
input = mw.ustring.lower(input)
input = mw.ustring.lower(input)
worlds = p.worlds
worlds = p.worlds
for key,value in ipairs(worlds) do  
for key,value in ipairs(worlds) do  
if (mw.ustring.find(input, value, 1, true) ~= nil) then
if (mw.ustring.find(input, value, start, true) ~= nil) then
return value
return value
end
end
Line 57: Line 60:
end
end
return ''
return ''
end
-- function which returns a table of all world name found in a string, can return an empty table
function p.extractAllWorlds(input, start)
start = start or 1
input = mw.ustring.lower(input)
worlds = p.worlds
out = {}
index = 1
for key,value in ipairs(worlds) do
if (mw.ustring.find(input, value, start, true) ~= nil) then
out[index] = value
index = index + 1
end
end
-- this covers an edge case where the only thing in the string is "survival"
-- however, it doesn't cover the case where the string has for eg. "survival survival 2 survival 3", that will return only survival 2 and survival 3 in the table
if (#out == 0 and mw.ustring.find(input, 'survival', 1, true) ~= nil) then
out[index] = 'survival 1'
index = index + 1
end
return out
end
end


-- function which returns the first subworld name found in a string
-- function which returns the first subworld name found in a string
function p.extractSubworld(input)
function p.extractSubworld(input, start)
start = start or 1
input = mw.ustring.lower(input)
input = mw.ustring.lower(input)
subworlds = p.subworlds
subworlds = p.subworlds
Line 70: Line 99:
end
end
return ''--return 'not found'
return ''--return 'not found'
end
-- function which returns a table of all subworld name found in a string, can return an empty table
function p.extractAllSubworlds(input, start)
start = start or 1
input = mw.ustring.lower(input)
subworlds = p.subworlds
out = {}
index = 1
for key,value in ipairs(subworlds) do
if (mw.ustring.find(input, value, start, true) ~= nil) then
out[index] = value
index = index + 1
end
end
return out
end
end



Latest revision as of 13:44, 29 July 2024

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],
	["D.E.P.3"]		= p.worlds[8],
	["D.E.P.4"]		= p.worlds[8],
	["mall"]		= p.worlds[6], -- this is not perfect, sur4, 5 and 6 all have a mall subworld
}


-- 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", "mall"},
-- 	["survival 5"] = {"akita", "corgi", "labrador", "shepherd", "mall"},
-- 	["survival 6"] = {"sheltie", "retriever", "streamtown", "mall"},
-- }


-- 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 a table of all world name found in a string, can return an empty table
function p.extractAllWorlds(input, start)
	start = start or 1
	input = mw.ustring.lower(input)
	worlds = p.worlds
	out = {}
	index = 1
	
	for key,value in ipairs(worlds) do 
		if (mw.ustring.find(input, value, start, true) ~= nil) then
			out[index] = value
			index = index + 1
		end
	end
	
	-- this covers an edge case where the only thing in the string is "survival"
	-- however, it doesn't cover the case where the string has for eg. "survival survival 2 survival 3", that will return only survival 2 and survival 3 in the table
	if (#out == 0 and mw.ustring.find(input, 'survival', 1, true) ~= nil) then
		out[index] = 'survival 1'
		index = index + 1
	end
	return out
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 a table of all subworld name found in a string, can return an empty table
function p.extractAllSubworlds(input, start)
	start = start or 1
	input = mw.ustring.lower(input)
	subworlds = p.subworlds
	out = {}
	index = 1
	
	for key,value in ipairs(subworlds) do 
		if (mw.ustring.find(input, value, start, true) ~= nil) then
			out[index] = value
			index = index + 1
		end
	end
	return out
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
Background SRN Opening by Montenator