Module:NameGenerator: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
(removed trailing spaces and added real hyphenation)
(don't need cargo)
 
(8 intermediate revisions by one other user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local cargo = mw.ext.cargo


function p.main(frame)
function p.main(frame)
local naming = require'Module:Sandbox/User:Illuminatiswag/namegen/NamingTable'
local namingtable = require'Module:NameGenerator/NamingTable'
local naming = namingtable.naming
local defaultvars = namingtable.defaultvars
local prefixes = ""
local prefixes = ""
local infixes = ""
local infixes = ""
Line 27: Line 28:
local hyphenationchance = naming[style]['HyphenationChance'] or 0
local hyphenationchance = naming[style]['HyphenationChance'] or 0
local twonamechance = naming[style]['TwoNameChance'] or 0
local twonamechance = naming[style]['TwoNameChance'] or 0
minprefix=naming[style]['MinPrefixAmount']
maxprefix=naming[style]['MaxPrefixAmount']
local namecount
local namecount
if math.random(0, 100) < twonamechance then
if math.random(0, 100) < twonamechance then
Line 35: Line 38:
local heroname = ''
local heroname = ''
for i = 1,namecount do
for i = 1,namecount do
prefixes = ''
infixes = ''
postfixes = ''
  --[get min/maxprefix stuff]--
  --[get min/maxprefix stuff]--
minprefix=naming[style]['MinPrefixAmount']
maxprefix=naming[style]['MaxPrefixAmount']
  for i=1,math.random(minprefix,maxprefix) do
  for i=1,math.random(minprefix,maxprefix) do
   prefixes = prefixes.. prefixtable[math.random(table.getn(prefixtable))]
   prefixes = prefixes.. prefixtable[math.random(table.getn(prefixtable))]
Line 66: Line 70:
  heroname = heroname .. ((prefixes..infixes..postfixes):gsub("^%l", string.upper):gsub("-$", '')) .. ' '
  heroname = heroname .. ((prefixes..infixes..postfixes):gsub("^%l", string.upper):gsub("-$", '')) .. ' '
end
end
heroname = heroname:gsub("\s*$", '')
heroname = heroname:gsub("%s*$", '')
--[title template]--
--[title template]--
-- titletemplate=result[1]['TitleTemplate']
 
-- local a = string.gsub(titletemplate,'NAME',tostring(heroname))
local b
-- local b = string.gsub(a,('BASETYPE'), style)
local templatetable = naming[style]['TitleTemplates']
local b = heroname
if templatetable ~= nil then
local titletemplate = templatetable[math.random(table.getn(templatetable))]
local varstable = defaultvars
if naming[style]['TemplateVars'] ~= nil then
  for k,v in pairs(naming[style]['TemplateVars']) do
  varstable[k] = v
  end
end
if varstable == nil then
  varstable = {}
end
varstable['%*Name%*'] = { heroname }
varstable['%*Rings%*'] = { 'Three-ringed', 'Four-ringed', 'Five-ringed', 'Seven-ringed', 'Eight-ringed', 'Nine-ringed', 'Twelve-ringed'}
-- not gonna bother doing every number in the 1d10+2 range and don't know how to handle that automatically
for var, values in pairs(varstable) do
  titletemplate = titletemplate:gsub(var, values[math.random(table.getn(values))])
end
b = titletemplate
else
b = heroname
end


return b
return b

Latest revision as of 16:52, 19 January 2023

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

local p = {}

function p.main(frame)
local namingtable = require'Module:NameGenerator/NamingTable'
local naming = namingtable.naming
local defaultvars = namingtable.defaultvars
local prefixes = ""
local infixes = ""
local postfixes = ""
local maxprefix
local minprefix
local maxinfix
local mininfix
local maxpostfix
local minpostfix
local titletemplate
local result = {}
local seed = frame.args.seed
local style = frame.args.style:lower()

if seed ~= nil and seed ~= ''then
 math.randomseed(seed:gsub("%w",string.byte))
end

local prefixtable = naming[style]['Prefixes']
local infixtable = naming[style]['Infixes']
local postfixtable = naming[style]['Postfixes']
local hyphenationchance = naming[style]['HyphenationChance'] or 0
local twonamechance = naming[style]['TwoNameChance'] or 0
minprefix=naming[style]['MinPrefixAmount']
maxprefix=naming[style]['MaxPrefixAmount']
local namecount
if math.random(0, 100) < twonamechance then
 namecount = 2
else
 namecount = 1
end
local heroname = ''
for i = 1,namecount do
 prefixes = ''
 infixes = ''
 postfixes = ''
 --[get min/maxprefix stuff]--
 for i=1,math.random(minprefix,maxprefix) do
   prefixes = prefixes.. prefixtable[math.random(table.getn(prefixtable))]
   if math.random(0, 100) < hyphenationchance then
    prefixes = prefixes .. '-'
   end
 end

 mininfix=naming[style]['MinInfixAmount']
 maxinfix=naming[style]['MaxInfixAmount']
 for i=1,math.random(mininfix,maxinfix) do
   infixes = infixes.. infixtable[math.random(table.getn(infixtable))]
   if math.random(0, 100) < hyphenationchance then
    infixes = infixes .. '-'
   end
 end
 minpostfix=naming[style]['MinPostfixAmount']
 maxpostfix=naming[style]['MaxPostfixAmount']
 for i=1,math.random(minpostfix,maxpostfix) do
   postfixes = postfixes.. postfixtable[math.random(table.getn(postfixtable))]
   if math.random(0, 100) < hyphenationchance then
    postfixes = postfixes .. '-'
   end
 end


 --[name fitting]--
 heroname = heroname .. ((prefixes..infixes..postfixes):gsub("^%l", string.upper):gsub("-$", '')) .. ' '
end
heroname = heroname:gsub("%s*$", '')
--[title template]--

local b
local templatetable = naming[style]['TitleTemplates']
if templatetable ~= nil then
 local titletemplate = templatetable[math.random(table.getn(templatetable))]
 local varstable = defaultvars
 if naming[style]['TemplateVars'] ~= nil then
  for k,v in pairs(naming[style]['TemplateVars']) do
   varstable[k] = v
  end
 end
 if varstable == nil then
  varstable = {}
 end
 varstable['%*Name%*'] = { heroname }
 varstable['%*Rings%*'] = { 'Three-ringed', 'Four-ringed', 'Five-ringed', 'Seven-ringed', 'Eight-ringed', 'Nine-ringed', 'Twelve-ringed'}
 -- not gonna bother doing every number in the 1d10+2 range and don't know how to handle that automatically
 
 for var, values in pairs(varstable) do
  titletemplate = titletemplate:gsub(var, values[math.random(table.getn(values))])
 end
 b = titletemplate
else
 b = heroname
end 

return b
end

return p