Module:GetRandomCreature: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
local p = {}
local p = {}
local colorparse = require'Module:ColorParse'
local cargo = mw.ext.cargo


function p.qudlook(frame)
function p.main(frame)
local prefixes = ""
local infixes = ""
local postfixes = ""
local maxprefix
local minprefix
local maxinfix
local mininfix
local maxpostfix
local minpostfix
local titletemplate
local result = {}


local bordercolor
--[get cargo row]--
local padding
local tables= 'HeroNames'
local bottomtext
local fields= 'Prefixes, MinPrefixAmount, MaxPrefixAmount,Infixes, MinInfixAmount,MaxInfixAmount,Postfixes ,MinPostfixAmount,MaxPostfixAmount,TitleTemplate'
local args= {
where= 'BaseType="Crab"'
}
result = cargo.query(tables,fields,args)
if not next(result) then
error('no base type of that kind found.')
end
--[get prefixes array]--
local resultstring = ''
resultstring = result[1]['Prefixes']
local prefixtable= {}
local i = 1
for j in string.gmatch(resultstring,"%s*(%w+),?%s*") do
prefixtable[i] = j
i= i+1
end
--[get infixes array]--
local resultstring = ''
resultstring = result[1]['Infixes']
local infixtable= {}
local i = 1
for j in string.gmatch(resultstring,"%s*(%w+),?%s*") do
infixtable[i] = j
i= i+1
end
--[get postfixes array]--
local resultstring = ''
resultstring = result[1]['Postfixes']
local postfixtable= {}
local i = 1
for j in string.gmatch(resultstring,"%s*(%w+),?%s*") do
postfixtable[i] = j
i= i+1
end


--[Determine border color]--
--[get min/maxprefix stuff]--
local bordercolorin = frame.args.bordercolor
minprefix=result[1]['MinPrefixAmount']
if bordercolorin == nil then
maxprefix=result[1]['MaxPrefixAmount']
  bordercolor = ''
for i=1,math.random(minprefix,maxprefix) do
elseif bordercolorin == 'c' then
   prefixes = prefixes.. prefixtable[math.random(table.getn(prefixtable))]
  bordercolor = ''
elseif bordercolorin == 'y' then
   bordercolor='white-border'
else
  error('bordercolor not set to either "c" or "y"',0)
end
end


--[Determine Title Color]--
mininfix=result[1]['MinInfixAmount']
local titlein= frame.args.title
maxinfix=result[1]['MaxInfixAmount']
local title = colorparse.moduleparse('&y'.. titlein)
for i=1,math.random(mininfix,maxinfix) do
 
  infixes = infixes.. infixtable[math.random(table.getn(infixtable))]
--[Determine qud text]--
end
local text = frame.args['text']
minpostfix=result[1]['MinPostfixAmount']
local qudtext = frame:extensionTag{ name='poem', content=colorparse.moduleparse('&y' .. text) }
maxpostfix=result[1]['MaxPostfixAmount']
 
for i=1,math.random(minpostfix,maxpostfix) do
--[Determine body padding]--
   postfixes = postfixes.. postfixtable[math.random(table.getn(postfixtable))]
local paddingin = frame.args.padding
if paddingin == nil or paddingin == '' then
  padding = '0'
else
   padding = paddingin
end
end


--[Determine bottomtext]--
--[title template]--
local bottomin = frame.args.bottomtext
titletemplate=result[1]['TitleTemplate']
if bottomin == nil or bottomin == '' then
  bottomtext= 'Perfect'
elseif bottomin == 'none' then
  bottomtext= ''
else
  bottomtext= bottomin
end
local a = {}
local parsedbottomtext=colorparse.moduleparse('&Y'..bottomtext)


--[Return html]--
--[name fitting]--
local html = {
local heroname= ((prefixes..infixes..postfixes):gsub("^%l", string.upper))
  '<div class="qud-box-wrapper ' ..bordercolor..'"><div class="qud-box"><span class="qud-box-header"><b>' .. title .. '</b></span><div class="qud-box-content" style="font-weight:bold; line-height:1.5em; padding:0em '..padding..'em;">'..qudtext..'</div><span class="qud-box-footer-left">'..parsedbottomtext..'</span></div></div>'
local a = string.gsub(titletemplate,'NAME',tostring(heroname))
  }
local b = string.gsub(a,('BASETYPE'), 'crab')


return table.concat(html , '\n')
return b
--return 'bordercolor: '.. bordercolor
end
end


return p
return p

Revision as of 16:58, 9 August 2019

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

local p = {}
local cargo = mw.ext.cargo

function p.main(frame)
local prefixes = ""
local infixes = ""
local postfixes = ""
local maxprefix
local minprefix
local maxinfix
local mininfix
local maxpostfix
local minpostfix
local titletemplate
local result = {}

--[get cargo row]--
local tables= 'HeroNames'
local fields= 'Prefixes, MinPrefixAmount, MaxPrefixAmount,Infixes, MinInfixAmount,MaxInfixAmount,Postfixes ,MinPostfixAmount,MaxPostfixAmount,TitleTemplate' 
local args= {
 where= 'BaseType="Crab"'
}
result = cargo.query(tables,fields,args)
if not next(result) then
 error('no base type of that kind found.')
end
--[get prefixes array]--
local resultstring = ''
resultstring = result[1]['Prefixes']
local prefixtable= {}
local i = 1
for j in string.gmatch(resultstring,"%s*(%w+),?%s*") do
prefixtable[i] = j
i= i+1
end
--[get infixes array]--
local resultstring = ''
resultstring = result[1]['Infixes']
local infixtable= {}
local i = 1
for j in string.gmatch(resultstring,"%s*(%w+),?%s*") do
infixtable[i] = j
i= i+1
end
--[get postfixes array]--
local resultstring = ''
resultstring = result[1]['Postfixes']
local postfixtable= {}
local i = 1
for j in string.gmatch(resultstring,"%s*(%w+),?%s*") do
postfixtable[i] = j
i= i+1
end

--[get min/maxprefix stuff]--
minprefix=result[1]['MinPrefixAmount']
maxprefix=result[1]['MaxPrefixAmount']
for i=1,math.random(minprefix,maxprefix) do
  prefixes = prefixes.. prefixtable[math.random(table.getn(prefixtable))]
end

mininfix=result[1]['MinInfixAmount']
maxinfix=result[1]['MaxInfixAmount']
for i=1,math.random(mininfix,maxinfix) do
  infixes = infixes.. infixtable[math.random(table.getn(infixtable))]
end
minpostfix=result[1]['MinPostfixAmount']
maxpostfix=result[1]['MaxPostfixAmount']
for i=1,math.random(minpostfix,maxpostfix) do
  postfixes = postfixes.. postfixtable[math.random(table.getn(postfixtable))]
end

--[title template]--
titletemplate=result[1]['TitleTemplate']

--[name fitting]--
local heroname= ((prefixes..infixes..postfixes):gsub("^%l", string.upper))
local a = string.gsub(titletemplate,'NAME',tostring(heroname))
local b = string.gsub(a,('BASETYPE'), 'crab')

return b
end

return p