Added cse_f_modules source

This commit is contained in:
Thomas Kooi 2015-01-12 23:22:54 +01:00
parent efbe49d904
commit 770230a64f
17 changed files with 484 additions and 0 deletions

View File

@ -0,0 +1,22 @@
class CfgFunctions
{
class CSE
{
class Modules
{
file = "cse\cse_f_modules\functions";
class initalizeModule_F { recompile = 1; };
class isModuleEnabled_F { recompile = 1; };
class getModule_f { recompile = 1; };
class getModuleCondition_f { recompile = 1; };
class getModules_f { recompile = 1; };
class initalizeModuleObjEH { recompile = 1; };
class moduleIsActive_f { recompile = 1; };
class enableModule_f { recompile = 1; };
class getCfgModuleInits_f { recompile = 1; };
class getCfgModuleArguments_f { recompile = 1; };
class remoteModuleInit { recompile = 1; };
};
};
};

View File

@ -0,0 +1,21 @@
class Combat_Space_Enhancement {
class EventHandlers {
class PreInit_EventHandlers {
class cse_f_modules {
init = " call compile preprocessFile 'cse\cse_f_modules\init.sqf';";
};
};
class PostInit_EventHandlers {
class cse_f_modules {
init = " call compile preprocessFile 'cse\cse_f_modules\post-init.sqf';";
};
};
};
class CustomEventHandlers {
/**
* Called when the enableModule_f function is called. Third argument is whatever or not the module has initalized.
*/
class moduleEnabled_f; // [moduleName, arguments, enabled]
};
};

View File

@ -0,0 +1,23 @@
class CfgPatches
{
class cse_f_modules
{
units[] = {};
weapons[] = {};
requiredVersion = 0.1;
requiredAddons[] = {"cse_main"};
version = "0.10.0_rc";
author[] = {"Combat Space Enhancement"};
authorUrl = "http://csemod.com";
};
};
class CfgAddons {
class PreloadAddons {
class cse_f_modules {
list[] = {"cse_f_modules"};
};
};
};
#include "CfgFunctions.h"
#include "Combat_Space_Enhancement.h"

View File

@ -0,0 +1,36 @@
/**
* fn_enableModule_f.sqf
* @Descr: Enable a CSE Module
* @Author: Glowbal
*
* @Arguments: [moduleName STRING, arguments ARRAY (Format: [[name STRING, value ANY]])]
* @Return: void
* @PublicAPI: true
*/
private ["_moduleName", "_arguments", "_moduleInfo"];
_moduleName = _this select 0;
_arguments = _this select 1;
[format["enableModule_f %1 %2",_this, ([_moduleName] call cse_fnc_isModuleEnabled_F)]] call cse_fnc_debug;
if ([_moduleName] call cse_fnc_isModuleEnabled_F) exitwith {
[[_moduleName, _arguments, false],"moduleEnabled_f"] call cse_fnc_customEventHandler_F;
};
if (isnil "CSE_F_MODULE_OBJ_EH") then {
CSE_F_MODULE_OBJ_EH = [];
};
CSE_F_MODULE_OBJ_EH pushback _moduleName;
_initField = getText(ConfigFile >> "Combat_Space_Enhancement" >> "CfgModules" >> _moduleName >> "init");
_arguments call compile _initField;
if !(isnil "cse_f_eventhandlers_collection") then {
{
missionNamespace setvariable [_x, nil]; // clear all eventhandlers.
}foreach cse_f_eventhandlers_collection;
};
[_moduleName] call cse_fnc_parseModuleForConfigurations;
[[_moduleName, _arguments, true],"moduleEnabled_f"] call cse_fnc_customEventHandler_F;
[format["Initalize module: %1 COMPLETED. Arguments: %2", _moduleName, _arguments], 3] call cse_fnc_debug;

View File

@ -0,0 +1,98 @@
/**
* fn_getCfgModuleArguments_f.sqf
* @Descr: Grab Module arguments for a specific module in a config file.
* @Author: Glowbal
*
* @Arguments: [moduleName STRING (The classname of the CSE module), configPath CONFIG (Path to the module Config)]
* @Return: ARRAY An array with parameters for given module. If the parameters for the provided module have not been found within the config, default values will be used.
* @PublicAPI: true
*/
private ["_configOfModule","_collectedInits","_cfgRoot","_amountOfClasses","_i","_arguments","_moduleName","_CfgVehEntry","_CfgModuleEntry","_moduleArguments","_j","_cfg","_value","_typeNameArgument", "_return"];
_moduleName = _this select 0;
_configOfModule = _this select 1;
_return = [];
// Array for collection all initalization arguments for the given module.
_arguments = [];
// Grab necessary config entries
_CfgVehEntry = (ConfigFile >> "CfgVehicles" >> _moduleName);
_CfgModuleEntry = (ConfigFile >> "Combat_Space_Enhancement" >> "CfgModules" >> _moduleName);
if (isClass _CfgModuleEntry) then {
if (isClass _CfgVehEntry) then {
// init with parameters
_moduleArguments = (_CfgVehEntry >> "Arguments");
if (isClass _moduleArguments) then {
// Looping through the expected arguments, based on what is defined in the module Argument Class in CfgVehicles.
for [{_j=0}, {_j < (count _moduleArguments)}, {_j=_j+1}] do {
// if the argument is a class, parse it. Otherwise we will be ignoring it.
if (isClass (_moduleArguments select _j)) then {
// Grab the value from the argument defined in the description.ext and current class.
_value = 0; // (_configOfModule >> configName(_moduleArguments select _j)) call bis_fnc_getCfgData;
// This will be used to validate the retrieved value for a proper value.
_typeNameArgument = getText((_moduleArguments select _j) >> "typeName");
call {
if (_typeNameArgument == "BOOL") exitwith {
_value = getNumber(_configOfModule >> configName(_moduleArguments select _j)) == 1;
};
if (_typeNameArgument == "NUMBER") exitwith {
_value = getNumber(_configOfModule >> configName(_moduleArguments select _j));
};
if (_typeNameArgument == "STRING") exitwith {
_value = getText(_configOfModule >> configName(_moduleArguments select _j));
};
};
// If the argument is defined in the description.ext, we will validate the typeName of the argument and store it in the argument array.
if (!isnil "_value") then {
if (typeName _value == _typeNameArgument || TRUE) then { // lets assume the values are correct until we write a function to properly compare the typeNames.
_arguments pushback [(ConfigName (_moduleArguments select _j)), _value];
} else {
// Incase the typeName is invalid, we will set a default value and store this instead.
call {
if (_typeNameArgument == "BOOL") exitwith {
_value = getNumber((_moduleArguments select _j) >> "defaultValue") == 1;
};
if (_typeNameArgument == "NUMBER") exitwith {
_value = getNumber((_moduleArguments select _j) >> "defaultValue");
};
if (_typeNameArgument == "STRING") exitwith {
_value = getText((_moduleArguments select _j) >> "defaultValue");
};
};
[format["Module Argument has not been set %1 %2. Module need to be replaced. Value used: %4", _moduleName, (ConfigName (_moduleArguments select _j)), _typeNameArgument, _value], 1] call cse_fnc_debug;
_arguments pushback [(ConfigName (_moduleArguments select _j)), _value];
};
} else {
[format["Value is nil for %1 %2", _moduleName, (ConfigName (_moduleArguments select _j))], 1] call cse_fnc_debug;
// Because the value has not been defined, we will use a default value instead.
// TODO implement defaultValue retrieval for non defined arguments.
_value = "";
if (_typeNameArgument != "") then {
call {
if (_typeNameArgument == "BOOL") exitwith {
_value = getNumber((_moduleArguments select _j) >> "defaultValue") == 1;
};
if (_typeNameArgument == "NUMBER") exitwith {
_value = getNumber((_moduleArguments select _j) >> "defaultValue");
};
if (_typeNameArgument == "STRING") exitwith {
_value = getText((_moduleArguments select _j) >> "defaultValue");
};
};
[format["Module Argument has not been set %1 %2. Module need to be replaced. Value used: %4", _moduleName, (ConfigName (_moduleArguments select _j)), _typeNameArgument, _value], 1] call cse_fnc_debug;
_arguments pushback [(ConfigName (_moduleArguments select _j)), _value];
};
};
};
};
};
} else {
// init with no parameters. We do not have to collect anything for this.
};
};
_arguments

View File

@ -0,0 +1,28 @@
/**
* fn_getCfgModuleInits_f.sqf
* @Descr: Grab all defined modules in the given config space, collect their arguments and return them.
* @Author: Glowbal
*
* @Arguments: [config CONFIG (For example: MissionConfigFile or ConfigFile)]
* @Return: ARRAY Array with format: [[moduleName STRING, moduleArgs ARRAY (Format: [argumentName STRING, value ANY])], ...]
* @PublicAPI: false
*/
private ["_config","_collectedInits","_cfgRoot","_amountOfClasses","_i","_arguments","_moduleName","_CfgVehEntry","_CfgModuleEntry","_moduleArguments","_j","_cfg","_value","_moduleArgs"];
_config = [_this, 0, MissionConfigFile, [MissionConfigFile]] call BIS_fnc_Param;
_collectedInits = [];
_cfgRoot = (_config >> "Combat_Space_Enhancement" >> "Modules");
_amountOfClasses = count _cfgRoot;
for [{_i=0}, {_i < _amountOfClasses}, {_i=_i+1}] do {
if (isClass (_cfgRoot select _i)) then {
_moduleName = ConfigName (_cfgRoot select _i);
_disableConfigExecution = getNumber (ConfigFile >> "Combat_Space_Enhancement" >> "CfgModules" >> _moduleName >> "disableConfigExecution");
if (_disableConfigExecution > 0) exitwith {};
if (!([_moduleName] call cse_fnc_isModuleEnabled_f)) then {
_moduleArgs = [_moduleName, (_cfgRoot select _i)] call cse_fnc_getCfgModuleArguments_f;
_collectedInits pushback [_moduleName, _moduleArgs];
};
};
};
_collectedInits

View File

@ -0,0 +1,20 @@
/**
* fn_getModuleCondition_f.sqf
* @Descr: N/A DEPRECATED
* @Author: Glowbal
*
* @Arguments: []
* @Return:
* @PublicAPI: false
*/
private ["_moduleName","_condition","_return","_cfgFile"];
_moduleName = _this select 0;
_return = "";
_cfgFile = (ConfigFile >> "Combat_Space_Enhancement" >> "CfgModules" >> _moduleName);
if (isClass _cfgFile) then {
_return = format["CSE_MODULE_CONDITION_%1",_moduleName];
};
_return

View File

@ -0,0 +1,22 @@
/**
* fn_getModule_f.sqf
* @Descr: Gets module information. DEPRECATED
* @Author: Glowbal
*
* @Arguments: [ModuleName STRING]
* @Return: ARRAY Returns an array with [ModuleName STRING, initLine STRING]
* @PublicAPI: false
*/
private ["_module","_cfg","_init","_name"];
_moduleName = _this select 0;
_cfg = (ConfigFile >> "Combat_Space_Enhancement" >> "CfgModules" >> _moduleName);
_module = [];
if (isClass _cfg) then {
_init = getText (_cfg >> "init");
_name = getText (_cfg >> "name");
//_module set [count _module,[_name,_init]];
_module = [_name,_init];
};
_module

View File

@ -0,0 +1,15 @@
/**
* fn_getModules_f.sqf
* @Descr: Returns all current active CSE Modules
* @Author: Glowbal
*
* @Arguments: []
* @Return: ARRAY List of all current Modules [moduleName STRING (Module classname), ...]
* @PublicAPI: true
*/
if (isnil "CSE_F_MODULE_OBJ_EH") then {
CSE_F_MODULE_OBJ_EH = [];
};
CSE_F_MODULE_OBJ_EH;

View File

@ -0,0 +1,59 @@
/**
* fn_initalizeModuleObjEH.sqf
* @Descr: initalize module Object init Eventhandlers. DEPRICATED. DO NOT USE.
* @Author: Glowbal
*
* @Arguments: [object OBJECT, eventhandler STRING]
* @Return: void
* @PublicAPI: false
*/
private ["_entity","_handle","_cfg","_ehCfg","_numberOfEH"];
_entity = (_this select 0) select 0;
_handle = _this select 1;
if (!local _entity) exitwith{};
if (isnil "cse_postInit") then {
_this spawn {
private ["_entity"];
_entity = (_this select 0) select 0;
_handle = _this select 1;
waituntil{(!isnil 'cse_postInit')};
{
_cfg = (ConfigFile >> "Combat_Space_Enhancement" >> "CfgModules" >> _x);
if (isClass _cfg) then {
if (isClass (_cfg >> "EventHandlers")) then {
_numberOfEH = count (_cfg >> "EventHandlers");
for [{_j=0}, {_j< _numberOfEH}, {_j=_j+1}] do {
_ehCfg = ((_cfg >> "EventHandlers") select _j);
if (isClass _ehCfg) then {
if (_entity isKindOf (ConfigName _ehCfg)) then {
(_this select 0) call (compile getText(_ehCfg >> _handle));
};
};
};
};
};
}foreach (call cse_fnc_getModules);
};
} else {
if (!local _entity) exitwith{};
{
_cfg = (ConfigFile >> "Combat_Space_Enhancement" >> "CfgModules" >> _x);
if (isClass _cfg) then {
if (isClass (_cfg >> "EventHandlers")) then {
_numberOfEH = count (_cfg >> "EventHandlers");
for [{_j=0}, {_j< _numberOfEH}, {_j=_j+1}] do {
_ehCfg = ((_cfg >> "EventHandlers") select _j);
if (isClass _ehCfg) then {
if (_entity isKindOf (ConfigName _ehCfg)) then {
(_this select 0) call (compile getText(_ehCfg >> _handle));
};
};
};
};
};
}foreach (call cse_fnc_getModules);
};

View File

@ -0,0 +1,59 @@
/**
* fn_initalizeModule_F.sqf
* @Descr: Initalize a CSE Module. To be called through the BI A3 Module Framework
* @Author: Glowbal
*
* @Arguments: []
* @Return: void
* @PublicAPI: true
*/
private ["_moduleName","_arguments","_logic","_units", "_activated","_cfg", "_moduleInfo", "_value", "_typeNameArgument"];
if (count _this > 1) then {
_moduleName = typeOf (_this select 0);
} else {
_moduleName = _this select 0;
};
[format["Initalize module: %1 IN QUE",_moduleName], 3] call cse_fnc_debug;
waituntil {(!isnil 'cse_f_modules')};
[format["Initalize module: %1 STARTED",_moduleName], 3] call cse_fnc_debug;
_arguments = [];
if (count _this >1) then {
_logic = [_this,0,objNull,[objNull]] call BIS_fnc_param;
_units = [_this,1,[],[[]]] call BIS_fnc_param;
_activated = [_this,2,true,[true]] call BIS_fnc_param;
_moduleName = typeOf _logic;
_cfg = (ConfigFile >> "CfgVehicles" >> _moduleName >> "Arguments");
if (isClass _cfg) then {
for [{_i=0}, {_i < (count _cfg)}, {_i=_i+1}] do {
if (isClass (_cfg select _i)) then {
_value = _logic getvariable (ConfigName (_cfg select _i));
if (!isnil "_value") then {
_arguments pushback [(ConfigName (_cfg select _i)), _value];
} else {
_typeNameArgument = getText ((_cfg select _i) >> "typeName");
_value = "";
if (_typeNameArgument != "") then {
call {
if (_typeNameArgument == "BOOL") exitwith {
_value = getNumber((_cfg select _i) >> "defaultValue") == 1;
};
if (_typeNameArgument == "NUMBER") exitwith {
_value = getNumber((_cfg select _i) >> "defaultValue");
};
if (_typeNameArgument == "STRING") exitwith {
_value = getText((_cfg select _i) >> "defaultValue");
};
};
[format["Module Argument has not been set %1 %2. Module need to be replaced. Value used: %4", _moduleName, (ConfigName (_cfg select _i)), _typeNameArgument, _value], 1] call cse_fnc_debug;
_arguments pushback [(ConfigName (_cfg select _i)), _value];
};
};
};
};
};
} else {
_moduleName = _this select 0;
};
[_moduleName, _arguments] call cse_fnc_enableModule_f;

View File

@ -0,0 +1,14 @@
/**
* fn_isModuleEnabled_F.sqf
* @Descr: Check if given CSE Module class is enabled
* @Author: Glowbal
*
* @Arguments: [moduleName STRING]
* @Return: BOOL Returns true if module is currently enabled
* @PublicAPI: true
*/
if (isnil "CSE_F_MODULE_OBJ_EH") then {
CSE_F_MODULE_OBJ_EH = [];
};
((_this select 0) in CSE_F_MODULE_OBJ_EH);

View File

@ -0,0 +1,19 @@
/**
* fn_moduleIsActive_f.sqf
* @Descr: Check if given module name is active. DEPRICATED. DO NOT USE.
* @Author: Glowbal
*
* @Arguments: [moduleName STRING]
* @Return: BOOL Returns true if moduel is currently active
* @PublicAPI: false
*/
private ["_moduleName","_return","_condition"];
_moduleName = _this select 0;
_return = false;
_condition = [_moduleNAme] call cse_fnc_getModuleCondition_F;
if (!isnil "_condition") then {
call compile format["_return = %1;",_condition];
};
_return

View File

@ -0,0 +1,17 @@
/**
* fn_remoteModuleInit.sqf
* @Descr: Called by remote execution script to initialize modules.
* @Author: Glowbal
*
* @Arguments: [[moduleName STRING, arguments ARRAY (Format: [argumentName STRING, value ANY])], ...]
* @Return: nil
* @PublicAPI: false
*/
private ["_toinitalizeModules"];
_toinitalizeModules = _this select 0;
sleep 5;
{
[format["initalize module through Cfg REMOTE: %1",_x]] call cse_fnc_debug;
_x call cse_fnc_enableModule_f;
}foreach _toinitalizeModules;

View File

@ -0,0 +1,3 @@
cse_f_modules = true;

View File

@ -0,0 +1,21 @@
// Collect cfg modules and initalize them.
[] spawn {
// by waiting, we ensure that CSE Config modules aren't initalized before the modules have been.
sleep 5;
_toinitalizeModules = [MissionConfigFile] call cse_fnc_getCfgModuleInits_f;
{
[format["initalize module through cfg: %1",_x]] call cse_fnc_debug;
_x call cse_fnc_enableModule_f;
}foreach _toinitalizeModules;
// Check if we want to collect server side modules
_allowCfg = ((getNumber(MissionConfigFile >> "Combat_Space_Enhancement" >> "DisableModuleConfig")) == 0);
if (isServer && _allowCfg) then {
_toinitalizeModules = [configFile] call cse_fnc_getCfgModuleInits_f;
[format["initalize modules through server cfg: %1",_toinitalizeModules]] call cse_fnc_debug;
if !(_toinitalizeModules isEqualTo []) then {
[[_toinitalizeModules], "cse_fnc_remoteModuleInit", true, true] spawn BIS_fnc_MP;
};
};
};

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project name="Combat Space Enhancement">
<Package name="cse_f_modules">
<Container ID="Modules">
</Container>
</Package>
</Project>