m (Add linking of skills) |
(Adding health and armour wright calculations.) |
||
Line 1: | Line 1: | ||
p = {} -- p stands for package | |||
local headers = '!Level\ | local headers = '!Level\ | ||
Line 18: | Line 18: | ||
end | end | ||
function p.makeRows( text, start ) | function p.makeHealth( health, count ) | ||
local count, row, rows | if health == nil then return "" end | ||
return p.makeIncrement( health['inc'], count ) | |||
end | |||
function p.makeIncrement( incremental, multiplier) | |||
return tostring( math.floor( incremental * multiplier )) .. " (+" .. tostring( incremental ) .. ")" | |||
end | |||
function p.makeRows( text, start, hp, aw ) | |||
local buffer, count, row, rows | |||
local health = { values } | |||
local weight = {} | |||
rows = p.splitTextWithNulls( text ) | rows = p.splitTextWithNulls( text ) | ||
Line 33: | Line 45: | ||
end | end | ||
if hp == nil then | |||
health = nil | |||
else | |||
for min, max in hp:gmatch "(%d+)-%s*(%d+)" do | |||
health['min'] = tonumber( min ) | |||
health['max'] = tonumber( max ) | |||
--print("min: " .. min .. ", max: " .. max) | |||
end | |||
if health['min'] > 0 then | |||
health['max'] = health['max'] - health['min'] | |||
health['min'] = 0 | |||
end | |||
end | |||
if aw == nil then | |||
weight = nil | |||
else | |||
for min, max in aw:gmatch "(%d+)-%s*(%d+)" do | |||
weight['min'] = tonumber( min ) | |||
weight['max'] = tonumber( max ) | |||
--print("min: " .. min .. ", max: " .. max) | |||
end | |||
if weight['min'] > 0 then | |||
weight['max'] = weight['max'] - weight['min'] | |||
weight['min'] = 0 | |||
end | |||
end | |||
health['inc'] = health['max'] / (#rows - 1) | |||
weight['inc'] = weight['max'] / (#rows - 1) | |||
buffer = "" | buffer = "" | ||
count = 0 | |||
for _, v in ipairs(rows) do | for _, v in ipairs(rows) do | ||
buffer = buffer .. '|-' .. "\n" | buffer = buffer .. '|-' .. "\n" .. '|' .. tostring(row) .. "\n" | ||
buffer = buffer .. '|' .. p.makeHealth( health, count ) .. "\n" | |||
buffer = buffer .. '|' .. "\n" | buffer = buffer .. '|' .. p.makeWeight( weight, count ) .. "\n" | ||
buffer = buffer .. '|' .. "\n" | |||
buffer = buffer .. '|' .. p.makeSkills(v) .. "\n" | buffer = buffer .. '|' .. p.makeSkills(v) .. "\n" | ||
count = count + 1 | |||
row = row + 1 | row = row + 1 | ||
end | end | ||
Line 64: | Line 109: | ||
if frame.args['start'] == nil then | if frame.args['start'] == nil then | ||
start = nil | start = nil | ||
if frame.args['type'] ~= nil then | if ( frame.args['type'] ~= nil ) and ( frame.args['type'] ~= '' ) then | ||
if string.lower(frame.args['type']) == 'base' then | if string.lower(frame.args['type']) == 'base' then | ||
start = 1 | start = 1 | ||
Line 81: | Line 126: | ||
end | end | ||
buffer = buffer .. p.makeRows( frame['args'][' | buffer = buffer .. p.makeRows( frame.args['rows'], start, frame.args['health'], frame.args['weight'] ) .. tableEnd | ||
return buffer | return buffer | ||
end | |||
function p.makeWeight( weight, count ) | |||
if weight == nil then return "" end | |||
return p.makeIncrement( weight['inc'], count ) | |||
end | end | ||
Revision as of 18:29, 31 October 2022
Documentation for this module may be created at Module:Role Advancement Table/doc
p = {} -- p stands for package
local headers = '!Level\
![[Health]]\
![[Armor Weight|A.W.]]\
![[Skills]]\
'
local tableBegin = '{| class="wikitable"\
|+ {{{name|{{PAGENAME}} Level Advancement}}}\
'
local tableEnd = '|}\
'
function p.makeHeaders( frame )
return "Not Implemented Yet!!"
end
function p.makeHealth( health, count )
if health == nil then return "" end
return p.makeIncrement( health['inc'], count )
end
function p.makeIncrement( incremental, multiplier)
return tostring( math.floor( incremental * multiplier )) .. " (+" .. tostring( incremental ) .. ")"
end
function p.makeRows( text, start, hp, aw )
local buffer, count, row, rows
local health = { values }
local weight = {}
rows = p.splitTextWithNulls( text )
if start == nil then
if #rows > 6 then
row = 6
else
row = 1
end
else
row = start
end
if hp == nil then
health = nil
else
for min, max in hp:gmatch "(%d+)-%s*(%d+)" do
health['min'] = tonumber( min )
health['max'] = tonumber( max )
--print("min: " .. min .. ", max: " .. max)
end
if health['min'] > 0 then
health['max'] = health['max'] - health['min']
health['min'] = 0
end
end
if aw == nil then
weight = nil
else
for min, max in aw:gmatch "(%d+)-%s*(%d+)" do
weight['min'] = tonumber( min )
weight['max'] = tonumber( max )
--print("min: " .. min .. ", max: " .. max)
end
if weight['min'] > 0 then
weight['max'] = weight['max'] - weight['min']
weight['min'] = 0
end
end
health['inc'] = health['max'] / (#rows - 1)
weight['inc'] = weight['max'] / (#rows - 1)
buffer = ""
count = 0
for _, v in ipairs(rows) do
buffer = buffer .. '|-' .. "\n" .. '|' .. tostring(row) .. "\n"
buffer = buffer .. '|' .. p.makeHealth( health, count ) .. "\n"
buffer = buffer .. '|' .. p.makeWeight( weight, count ) .. "\n"
buffer = buffer .. '|' .. p.makeSkills(v) .. "\n"
count = count + 1
row = row + 1
end
return buffer
end
function p.makeSkills( text )
local buffer = ""
local skills = p.splitTextWithNulls( text, "," )
for _, v in ipairs(skills) do
buffer = buffer .. "[[" .. v .. "]]</br>\n"
end
return string.sub(buffer, 1, -7)
end
function p.makeTable( frame )
local buffer = tableBegin
local start
if frame.args['start'] == nil then
start = nil
if ( frame.args['type'] ~= nil ) and ( frame.args['type'] ~= '' ) then
if string.lower(frame.args['type']) == 'base' then
start = 1
elseif string.lower(frame.args['type']) == 'spec' then
start = 6
end
end
else
start = tonumber( frame.args['start'] )
end
if frame['args']['headers'] == nil then
buffer = buffer .. headers
else
buffer = buffer .. makeHeaders( frame['args']['headers'] )
end
buffer = buffer .. p.makeRows( frame.args['rows'], start, frame.args['health'], frame.args['weight'] ) .. tableEnd
return buffer
end
function p.makeWeight( weight, count )
if weight == nil then return "" end
return p.makeIncrement( weight['inc'], count )
end
function p.splitTextWithNulls( text, seperator )
local buffer = ''
local length = string.len(text)
local pos = 1
local results = {}
if length > 0 then
if seperator == nil then
seperator = "|"
end
while pos <= length do
local char = string.sub(text, pos, pos)
if (char ~= seperator) then
buffer = buffer .. char
else
table.insert(results, buffer)
buffer = ""
end
if (pos == length) then
table.insert(results, buffer)
end
pos = pos + 1
end
end
return results
end
return p