Module:Beastie Bay
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Beastie Bay/doc
--<syntaxhighlight lang="lua">
local p = {}
local paramtest = require('Module:Paramtest')
local default_to = paramtest.default_to
local has_content = paramtest.has_content
-- Returns 5 squares, filled with a specific color based on the max fill num.
-- @param (pRange:String): Number of boxes to fill.
-- @returns: a mw.html Element
function p._monsterColorRange( pNum )
local MAX_CELLS = 5
local color = 'bbColorGreen';
local min = 0
local max = tonumber(pNum) or 0;
if(max >= 5) then
max = 5;
color = 'bbColorOrange';
end
local range_string = mw.html.create('span'):addClass('colorBoxCont'):addClass('bbColorGray')
for i=1,MAX_CELLS,1 do
range_string:tag('span'):addClass('colorBox'):addClass((i >= min and i <= max) and color or ''):done()
end
range_string:tag('span'):addClass('mobile-hide'):css({['display']="none"}):wikitext(pRange):done();
range_string:done();
return tostring(range_string)
end
-- Should be invoked directly, not through a template. {{#invoke:Beastie Bay|monsterColorRange|<num>}}
function p.monsterColorRange( pFrame )
local parameters = pFrame.args
return p._monsterColorRange(
default_to(parameters["1"], "0")
)
end
-- Takes a trait name, and returns an image of that trait followed by the name of the trait as passed into the function.
function p._trait(pTrait)
local tTraitLower = pTrait:lower()
if tTraitLower == "none"
or tTraitLower == "lightning"
or tTraitLower == "earth"
or tTraitLower == "fire"
or tTraitLower == "water"
or tTraitLower == "wind"
then
return '[[File:'..tTraitLower..' trait.png]] '..pTrait
elseif tTraitLower == "ice" then
return '[[File:water trait.png]] '..pTrait
else
return pTrait
end
end
-- Should be invoked directly, not through a template. {{#invoke:Beastie Bay|trait|<trait>}}
-- trait: none, lightning, earth, fire, water, wind, ice
function p.trait( pFrame )
local parameters = pFrame.args
return p._trait(
default_to(parameters["1"], "")
)
end
-- Creates a monster toc from and to specified values
-- Should be invoked directly, not through a template.
function p.bestiaryTOC( pFrame )
local parameters = pFrame.args;
local tFrom = tonumber(default_to(parameters["from"], 0))
local tTo = tonumber(default_to(parameters["to"], 100))
function tTocLink(pNum)
return '[[#'..pNum..'|<span style="padding:0 5px; background:#D5D0B5; border-radius:5px;">'..pNum..'</span>]]'
end
-- http://stackoverflow.com/questions/1405583/concatenation-of-strings-in-lua
local t = { } -- returnStringParts
t[#t+1] = '<div style="text-align:center; margin:0 6%; padding:1px 8px; background:#DFDBC3; border:1px solid #CFC8A2;">'
t[#t+1] = tTocLink(tFrom)
for i=tFrom+1,tTo,1 do
t[#t+1] = "•"
t[#t+1] = tTocLink(i)
end
t[#t+1] = '</div>'
return table.concat(t," ")
end
function p._bestiaryEntry(pID, pName, pName2, pImage, pLocations, pDescription, pDefeatMessage, pCriticalHitMessage, pTrait, pExp, pHP, pAtk, pDef, pSpd, pMP, pSkill1, pSkill2, pSkill3, pSkill4, pSkill5, pSkill6, pLevel1, pLevel2, pLevel3, pLevel4, pLevel5, pLevel6)
local tName2 = ''
if has_content(pName2) then
tName2 = ' <span id="'..pName2..'" title="'..pName..' appears as '..pName2..' in some versions of the game">\'\'('..pName2..')\'\'</span>'
end
local t = { } -- returnStringParts
t[#t+1] = '|- id="'..pName..'"'
t[#t+1] = '! id="'..pID..'" | '..pName..tName2..' [[#'..pID..']]'
t[#t+1] = '! colspan="2"| Location(s)'
t[#t+1] = '! colspan="2"| Description'
t[#t+1] = '! Defeat message'
t[#t+1] = '! Critical hit'
t[#t+1] = '|-'
t[#t+1] = '| style="text-align:center"|'..pImage
t[#t+1] = '| colspan="2"|'..pLocations
t[#t+1] = '| colspan="2"|'..pDescription
t[#t+1] = '|'..pDefeatMessage
t[#t+1] = '|'..pCriticalHitMessage
t[#t+1] = '|-'
t[#t+1] = '! Trait !! EXP !! HP !! Attack !! Defense !! Speed !! MP'
t[#t+1] = '|- style="text-align:center;"'
t[#t+1] = '|'..p._trait(pTrait)
t[#t+1] = '|'..p._monsterColorRange(pExp)
t[#t+1] = '|'..p._monsterColorRange(pHP)
t[#t+1] = '|'..p._monsterColorRange(pAtk)
t[#t+1] = '|'..p._monsterColorRange(pDef)
t[#t+1] = '|'..p._monsterColorRange(pSpd)
t[#t+1] = '|'..p._monsterColorRange(pMP)
t[#t+1] = '|-'
t[#t+1] = '! rowspan="2"| Skills'
t[#t+1] = '! Skill 1 !! Skill 2 !! Skill 3 !! Skill 4 !! Skill 5 !! Skill 6'
t[#t+1] = '|- style="text-align:center;"'
t[#t+1] = '|'..pSkill1
t[#t+1] = '|'..pSkill2
t[#t+1] = '|'..pSkill3
t[#t+1] = '|'..pSkill4
t[#t+1] = '|'..pSkill5
t[#t+1] = '|'..pSkill6
t[#t+1] = '|- style="text-align:center;"'
t[#t+1] = '! Level'
t[#t+1] = '|'..pLevel1
t[#t+1] = '|'..pLevel2
t[#t+1] = '|'..pLevel3
t[#t+1] = '|'..pLevel4
t[#t+1] = '|'..pLevel5
t[#t+1] = '|'..pLevel6
t[#t+1] = '|-'
t[#t+1] = '| colspan="8" style="height:4px; background:#9C9762" |'
t[#t+1] = '|-'
return table.concat(t,"\n")
end
function p.bestiaryEntryHeader( pFrame )
local t = { } -- returnStringParts
t[#t+1] = '{| class="wikitable"'
t[#t+1] = '|-'
t[#t+1] = '!#'
t[#t+1] = '!colspan="6" | Stats'
return table.concat(t,"\n")
end
function p.bestiaryEntry( pFrame )
--local parameters = pFrame.args
local parameters = pFrame:getParent().args
return p._bestiaryEntry(
tonumber(default_to(parameters["1"], "0")),
default_to(parameters["name"], "NAME REQUIRED"),
parameters["name2"],
has_content(parameters["img"]) and "[[File:"..parameters["img"].."]]" or "?",
default_to(parameters["loc"], "?"),
default_to(parameters["desc"], "?"),
default_to(parameters["dft"], "?"),
default_to(parameters["crit"], "?"),
default_to(parameters["trait"], "?"),
default_to(parameters["exp"], "?"),
default_to(parameters["hp"], "?"),
default_to(parameters["atk"], "?"),
default_to(parameters["spd"], "?"),
default_to(parameters["mp"], "?"),
default_to(parameters["def"], "?"),
default_to(parameters["s1"], "‑"),
default_to(parameters["s2"], "‑"),
default_to(parameters["s3"], "‑"),
default_to(parameters["s4"], "‑"),
default_to(parameters["s5"], "‑"),
default_to(parameters["s6"], "‑"),
default_to(parameters["l1"], "‑"),
default_to(parameters["l2"], "‑"),
default_to(parameters["l3"], "‑"),
default_to(parameters["l4"], "‑"),
default_to(parameters["l5"], "‑"),
default_to(parameters["l6"], "‑")
)
end
return p