Module
World
From Dogcraft Wiki
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