PDA

View Full Version : "Decorating" or extending functionality in CoreRPG



Varsuuk
December 29th, 2020, 00:22
So far, in a simple character sheet I am working on, I just want to do everything MoreCore/CoreRPG does when adding a PC to the CT plus add a pair of other fields.

I was trying to look at my best option for minimal upkeep as Core or MoreCore changed. If folks have suggestions for this - feel free please to advise me. For now, I will simply call the setCustomAddPC() and copy the "base" behavior from CoreRPG into MY addPC() method.


Some other thoughts:

One simple way that might work is instead of (in CoreRPG):


function addPC(nodePC)
if fCustomAddPC then
return fCustomAddPC(nodePC);
end

-- Parameter validation
if not nodePC then
return;
end

-- Create a new combat tracker window
local nodeEntry = DB.createChild(CT_LIST);
if not nodeEntry then
return;
end

-- Set up the CT specific information
DB.setValue(nodeEntry, "link", "windowreference", "charsheet", nodePC.getNodeName());
DB.setValue(nodeEntry, "friendfoe", "string", "friend");

local sToken = DB.getValue(nodePC, "token", nil);
if not sToken or sToken == "" then
sToken = "portrait_" .. nodePC.getName() .. "_token"
end
DB.setValue(nodeEntry, "token", "token", sToken);
end



Do:


function addPC(nodePC)
if fCustomAddPC then
return fCustomAddPC(nodePC);
end

function doAddPC(nodePC) -- Yeah, I didn't spend time on a better name - figure keep original name for the "outer" call.
-- Parameter validation
if not nodePC then
return;
end

-- Create a new combat tracker window
local nodeEntry = DB.createChild(CT_LIST);
if not nodeEntry then
return;
end

-- Set up the CT specific information
DB.setValue(nodeEntry, "link", "windowreference", "charsheet", nodePC.getNodeName());
DB.setValue(nodeEntry, "friendfoe", "string", "friend");

local sToken = DB.getValue(nodePC, "token", nil);
if not sToken or sToken == "" then
sToken = "portrait_" .. nodePC.getName() .. "_token"
end
DB.setValue(nodeEntry, "token", "token", sToken);
end



Then a later ruleset can call:



function onInit()
CombatManager.setCustomAddPC(addPC);
end

function addPC(nodePC)
-- Perform work CoreRPG does if you just want to add to it:
if super and super.doAddPC then
super.doAddPC(nodePC)
end

-- Parameter validation
if not nodePC then
return;
end

-- Now add your extra behavior...
...
end


This "automagically" pics up quality of life / bug-fix changes in CoreRPG without the derived author have to scan for the differences. Of course if the new ruleset diverges greatly, this ends up adding nothing. But unless the extra call in the addPC/doAddPC combo is a perf hit, seems an easy way to make maintenance easier in a subset of cases.