Module

WorldPills

From Dogcraft Wiki

m (added streamtown)
(Switching to using Module:World)
Line 1: Line 1:
local p = {} --p stands for package
local p = {} --p stands for package
local worldTools = requite('Module:World')


local lang = mw.language.getContentLanguage()
local lang = mw.language.getContentLanguage()




function subworld(world, subworld)
-- function subworld(world, subworld)
input = mw.ustring.lower(world .. subworld)
-- input = mw.ustring.lower(world .. subworld)
subworlds = {"husky", "beagle", "akita", "corgi", "labrador", "shepherd", "sheltie", "retriever", "streamtown"}
-- subworlds = {"husky", "beagle", "akita", "corgi", "labrador", "shepherd", "sheltie", "retriever", "streamtown"}
for key,value in ipairs(subworlds) do  
-- for key,value in ipairs(subworlds) do  
if (mw.ustring.find(input, value, 1, true) ~= nil) then
-- if (mw.ustring.find(input, value, 1, true) ~= nil) then
return lang:ucfirst(value)
-- return lang:ucfirst(value)
end
-- end
end
-- end
return ''--return 'not found'
-- return ''--return 'not found'
end
-- end




function world(world, subworld)
-- function world(world, subworld)
input = mw.ustring.lower(world .. subworld)
-- input = mw.ustring.lower(world .. subworld)
worlds = {"survival 1", "survival 2", "survival 3", "survival 4", "survival 5", "survival 6", "creative", "patreon", "hub", "amplified", "MCMMO", "skyblock"}
-- worlds = {"survival 1", "survival 2", "survival 3", "survival 4", "survival 5", "survival 6", "creative", "patreon", "hub", "amplified", "MCMMO", "skyblock"}
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, 1, true) ~= nil) then
return lang:ucfirst(value)
-- return lang:ucfirst(value)
end
-- end
end
-- end
if (mw.ustring.find(input, 'survival', 1, true) ~= nil) then
-- if (mw.ustring.find(input, 'survival', 1, true) ~= nil) then
return 'Survival 1'
-- return 'Survival 1'
end
-- end
return ''--return 'not found'
-- return ''--return 'not found'
end
-- end


function pill (text, color)
function pill (text, color)
Line 38: Line 39:
function p.single(frame)
function p.single(frame)
color = frame.args[color] or 'lightslategray'
color = frame.args[color] or 'lightslategray'
world = world(frame.args[1], frame.args[2])
world= worldTools.extractWorld(frame.args[1] .. frame.args[2]) -- world(frame.args[1], frame.args[2])
subworld = subworld(frame.args[1], frame.args[2])
subworld = worldTools.extractSubworld(frame.args[1] .. frame.args[2]) -- subworld(frame.args[1], frame.args[2])
if (subworld ~= '') then
if (subworld ~= '') then
Line 55: Line 56:
frame.args[2] = frame.args[2] or ''
frame.args[2] = frame.args[2] or ''
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
worlds = {"survival 1", "survival 2", "survival 3", "survival 4", "survival 5", "survival 6", "creative", "patreon", "hub", "amplified", "MCMMO", "skyblock"}
-- worlds = {"survival 1", "survival 2", "survival 3", "survival 4", "survival 5", "survival 6", "creative", "patreon", "hub", "amplified", "MCMMO", "skyblock"}
out = ''
out = ''
for key,value in ipairs(worlds) do  
for key,value in ipairs(worldTools.worlds) do  
if (mw.ustring.find(input, value, 1, true) ~= nil) then
if (mw.ustring.find(input, value, 1, true) ~= nil) then
value = lang:ucfirst(value)
value = lang:ucfirst(value)

Revision as of 00:53, 29 December 2023

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

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

local lang = mw.language.getContentLanguage()


-- function subworld(world, subworld)
-- 	input = mw.ustring.lower(world .. subworld)
-- 	subworlds = {"husky", "beagle", "akita", "corgi", "labrador", "shepherd", "sheltie", "retriever", "streamtown"}
-- 	for key,value in ipairs(subworlds) do 
-- 		if (mw.ustring.find(input, value, 1, true) ~= nil) then
-- 			return lang:ucfirst(value)
-- 		end
-- 	end
-- 	return ''--return 'not found'
-- end


-- function world(world, subworld)
-- 	input = mw.ustring.lower(world .. subworld)
-- 	worlds = {"survival 1", "survival 2", "survival 3", "survival 4", "survival 5", "survival 6", "creative", "patreon", "hub", "amplified", "MCMMO", "skyblock"}
-- 	for key,value in ipairs(worlds) do 
-- 		if (mw.ustring.find(input, value, 1, true) ~= nil) then
-- 			return lang:ucfirst(value)
-- 		end
-- 	end
-- 	if (mw.ustring.find(input, 'survival', 1, true) ~= nil) then
-- 		return 'Survival 1'
-- 	end
-- 	return ''--return 'not found'
-- end

function pill (text, color)
	return ('[[' .. text .. '|<span class="world-pill" style="background:' .. color .. 
			'; padding: 3px 7px; color: white; font-weight: bold; border-radius: 7.5px; display: inline-block; margin-bottom:3px;">' .. text .. '</span>]]')
end


function p.single(frame)
	color = frame.args[color] or 'lightslategray'
	world= worldTools.extractWorld(frame.args[1] .. frame.args[2]) -- world(frame.args[1], frame.args[2])
	subworld = worldTools.extractSubworld(frame.args[1] .. frame.args[2]) -- subworld(frame.args[1], frame.args[2])
	
	if (subworld ~= '') then
		return (pill(world, color) .. ' ' .. pill(subworld, color))
	elseif (world ~= '') then
		return (pill(world, color))
	else 
		return ''
	end
end


function p.multi(frame)
	color = frame.args[color] or 'lightslategray'
	frame.args[2] = frame.args[2] or ''
	input = mw.ustring.lower(frame.args[1] .. frame.args[2])
	-- worlds = {"survival 1", "survival 2", "survival 3", "survival 4", "survival 5", "survival 6", "creative", "patreon", "hub", "amplified", "MCMMO", "skyblock"}
	out = ''
	
	for key,value in ipairs(worldTools.worlds) do 
		if (mw.ustring.find(input, value, 1, true) ~= nil) then
			value = lang:ucfirst(value)
			out = out .. pill(value, color) .. ' '
		end
	end
	
	return out
end


return p
This page was last modified on 29 December 2023, at 00:53. (2 months ago)