Xarxus
July 18th, 2022, 15:46
So here's my solution. It works, but I don't know if what I have done is correct or if it can create problems somewhere.
First of all, I will describe to you what the problem was. I have a ruleset and two (or more modules). Each module has a description of some skills, one of which exists on multiple modules.
When loading both modules nad opening the skill list, you see both versions, which may cause problems as players may be using the outdated version instead of the revised one.
My solution involves the generation of a LUA script which at the time of initialization registers a function (onEvent) to be called for these 5 events: onModuleLoad, onModuleUnload, onModuleAdded, onModuleUpdated and onModuleRemoved.
The function essentially does 3 things:
1. if both modules are loaded it makes a backup of the module skill with the original version (obviously it is tested that this backup is not already present);
2. if both modules are loaded delete the original skill (if it still exists);
3. if the original skill appears in the backups and the original module is loaded, while the one with the revised version is not, restore the original version (obviously testing that it does not already exist).
I would say everything happens very quickly. This solution implies that the ruleset must know which skill to look for and on which module. I am open to any suggestions.
This is added ti base.xml
<script name="SkillVersionManager" file="scripts/skill_version_manager.lua" />
This is part of skill_version_manager.lua - I don't show the search or existence check functions because they are trivial checks of the DB. I think in the end I will leave only the search ones (find), cleaning up the code a bit.
function onInit()
Interface.onDesktopInit = onDesktopInit;
end
function onDesktopInit()
Module.onModuleLoad = SkillVersionManager.onEvent;
Module.onModuleUnload = SkillVersionManager.onEvent;
Module.onModuleAdded = SkillVersionManager.onEvent;
Module.onModuleUpdated = SkillVersionManager.onEvent;
Module.onModuleRemoved = SkillVersionManager.onEvent;
end
function onEvent()
local nodeDest;
local nodeOrig;
if existsBackupVersion() == false
and ModuleManager.isModuleLoaded("Module A") == true
and ModuleManager.isModuleLoaded("ModuleB") == true then
nodeDest = DB.createChild('backup');
nodeOrig = findModuleA(); -- Finds the original verison on Module A
DB.copyNode(nodeOrig, nodeDest);
end
if existsBackupVersion() == true
and existsOriginalVersion() == true
and ModuleManager.isModuleLoaded("ModuleA") == true
and ModuleManager.isModuleLoaded("ModuleB") == true then
nodeOrig = findModuleA();
DB.deleteNode(nodeOrig);
end
if existsBackupVersion == true
and existsOriginalVersion == false
and ModuleManager.isModuleLoaded("ModuleA") == true
and ModuleManager.isModuleLoaded("ModuleB") == false then
nodeDest = DB.createChild('[ path on module A ]');
DB.copyNode(findBackupVersion(), nodeDest);
DB.setCategory(findOriginalVersion, "ModuleA");
end
end
First of all, I will describe to you what the problem was. I have a ruleset and two (or more modules). Each module has a description of some skills, one of which exists on multiple modules.
When loading both modules nad opening the skill list, you see both versions, which may cause problems as players may be using the outdated version instead of the revised one.
My solution involves the generation of a LUA script which at the time of initialization registers a function (onEvent) to be called for these 5 events: onModuleLoad, onModuleUnload, onModuleAdded, onModuleUpdated and onModuleRemoved.
The function essentially does 3 things:
1. if both modules are loaded it makes a backup of the module skill with the original version (obviously it is tested that this backup is not already present);
2. if both modules are loaded delete the original skill (if it still exists);
3. if the original skill appears in the backups and the original module is loaded, while the one with the revised version is not, restore the original version (obviously testing that it does not already exist).
I would say everything happens very quickly. This solution implies that the ruleset must know which skill to look for and on which module. I am open to any suggestions.
This is added ti base.xml
<script name="SkillVersionManager" file="scripts/skill_version_manager.lua" />
This is part of skill_version_manager.lua - I don't show the search or existence check functions because they are trivial checks of the DB. I think in the end I will leave only the search ones (find), cleaning up the code a bit.
function onInit()
Interface.onDesktopInit = onDesktopInit;
end
function onDesktopInit()
Module.onModuleLoad = SkillVersionManager.onEvent;
Module.onModuleUnload = SkillVersionManager.onEvent;
Module.onModuleAdded = SkillVersionManager.onEvent;
Module.onModuleUpdated = SkillVersionManager.onEvent;
Module.onModuleRemoved = SkillVersionManager.onEvent;
end
function onEvent()
local nodeDest;
local nodeOrig;
if existsBackupVersion() == false
and ModuleManager.isModuleLoaded("Module A") == true
and ModuleManager.isModuleLoaded("ModuleB") == true then
nodeDest = DB.createChild('backup');
nodeOrig = findModuleA(); -- Finds the original verison on Module A
DB.copyNode(nodeOrig, nodeDest);
end
if existsBackupVersion() == true
and existsOriginalVersion() == true
and ModuleManager.isModuleLoaded("ModuleA") == true
and ModuleManager.isModuleLoaded("ModuleB") == true then
nodeOrig = findModuleA();
DB.deleteNode(nodeOrig);
end
if existsBackupVersion == true
and existsOriginalVersion == false
and ModuleManager.isModuleLoaded("ModuleA") == true
and ModuleManager.isModuleLoaded("ModuleB") == false then
nodeDest = DB.createChild('[ path on module A ]');
DB.copyNode(findBackupVersion(), nodeDest);
DB.setCategory(findOriginalVersion, "ModuleA");
end
end