-
Notifications
You must be signed in to change notification settings - Fork 149
/
fnc_createFromConfig.sqf
65 lines (51 loc) · 2.28 KB
/
fnc_createFromConfig.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_statemachine_fnc_createFromConfig
Description:
Creates a state machine from a config class.
Parameters:
_config - config path that contains a valid state machine config
(check the example.hpp file for the required structure)
<CONFIG>
Returns:
_stateMachine - a state machine <LOCATION>
Examples:
(begin example)
_stateMachine = [configFile >> "MyAddon_Statemachine"] call CBA_statemachine_fnc_createFromConfig;
(end)
Author:
BaerMitUmlaut
---------------------------------------------------------------------------- */
SCRIPT(createFromConfig);
params [["_config", configNull, [configNull]]];
if (isNull _config) exitWith {};
private _list = compile getText (_config >> "list");
private _skipNull = (getNumber (_config >> "skipNull")) > 0;
private _stateMachine = [_list, _skipNull] call FUNC(create);
{
private _state = configName _x;
GET_FUNCTION(_onState,_x >> "onState");
GET_FUNCTION(_onStateEntered,_x >> "onStateEntered");
GET_FUNCTION(_onStateLeaving,_x >> "onStateLeaving");
[_stateMachine, _onState, _onStateEntered, _onStateLeaving, _state] call FUNC(addState);
} forEach (configProperties [_config, "isClass _x", true]);
// We need to add the transitions in a second loop to make sure the states exist already
{
private _state = configName _x;
{
private _transition = configName _x;
private _targetState = _transition;
if (isText (_x >> "targetState")) then {
_targetState = getText (_x >> "targetState");
};
GET_FUNCTION(_condition,_x >> "condition");
GET_FUNCTION(_onTransition,_x >> "onTransition");
private _events = getArray (_x >> "events");
if (_events isEqualTo []) then {
[_stateMachine, _state, _targetState, _condition, _onTransition, _transition] call FUNC(addTransition);
} else {
[_stateMachine, _state, _targetState, _events, _condition, _onTransition, _transition] call FUNC(addEventTransition);
};
} forEach (configProperties [_x, "isClass _x", true]);
} forEach (configProperties [_config, "isClass _x", true]);
_stateMachine