ModGuy
Content Creator
- Joined
- Feb 17, 2011
In an attempt to empower mod developers, a need for communication between mods became apparent.
Here's the current idea behind the implementation:
You create some dictionary that contains methods and properties you wish to expose to other mods.
This is then passed to registerAPI("SOME_ID", THE_DICT, PERSISTS);
After the dictionary is registered, all other registered dicts are queried for the "apiRegister" method. If it exists it is called. This basically means that already loaded mods will be aware that this new mod has been loaded.
In the same way, if a mod contains the method "apiNotify" it is called after init or initl. Not sure what params should be passed in here tbh.
Registered dicts or "APIs" can be unregistered using resetAPIs. This ignores persistent entries unless the boolean value true is passed in.
You can freely check and request APIs using the ID string.
Now on to actual discussion. What else does this need?
I'm sure version info is important but that's a trivial addition to the registered dictionary and needs no action on my part.
Here's the current idea behind the implementation:
Code:
var api:Dictionary = new Dictionary();
const propPersists:String = "apiPersists";
const propReset:String = "apiReset";
const propRegister:String = "apiRegister";
const propNotify:String = "apiNotify";
function registerAPI(apiName:String, apiDict:Dictionary, persists:Boolean = false):void
{
api[apiName] = apiDict;
api[apiName][propPersists] = persists;
for (var key:String in api)
if (key != apiName && api[key][propRegister])
api[key][propRegister](apiName, apiDict);
}
function resetAPIs(force:Boolean = false):void
{
for (var key:String in api)
if (!api[key][propPersists] || force)
{
if(api[key][propReset])
api[key][propReset]();
delete api[key];
}
}
function checkAPI(apiName:String):Boolean
{
if(api[apiName]) return true;
return false;
}
function getAPI(apiName:String):Dictionary
{
if(checkAPI(apiName))
return api[apiName];
return null;
}
...
if (modRef.hasOwnProperty("init"))
modRef.init();
if (modRef.hasOwnProperty("initl"))
modRef.initl(this);
if (modRef.hasOwnProperty(propNotify))
modRef[propNotify]();
...
You create some dictionary that contains methods and properties you wish to expose to other mods.
This is then passed to registerAPI("SOME_ID", THE_DICT, PERSISTS);
After the dictionary is registered, all other registered dicts are queried for the "apiRegister" method. If it exists it is called. This basically means that already loaded mods will be aware that this new mod has been loaded.
In the same way, if a mod contains the method "apiNotify" it is called after init or initl. Not sure what params should be passed in here tbh.
Registered dicts or "APIs" can be unregistered using resetAPIs. This ignores persistent entries unless the boolean value true is passed in.
You can freely check and request APIs using the ID string.
Now on to actual discussion. What else does this need?
I'm sure version info is important but that's a trivial addition to the registered dictionary and needs no action on my part.