Skip to content

Commit 4f6780a

Browse files
committed
move GVAR(points) from CBA hash to HashMap
1 parent d040291 commit 4f6780a

6 files changed

+17
-19
lines changed

functions/points/fn_addPoints.sqf

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ if (_side isEqualTo sideUnknown) exitWith {
1313
false
1414
};
1515

16-
private _sidePoints = [GVAR(points), _side] call CBA_fnc_hashGet;
17-
private _oldSidePointsForCategory = [_sidePoints, _category] call CBA_fnc_hashGet;
18-
[_sidePoints, _category, _oldSidePointsForCategory + _points] call CBA_fnc_hashSet;
19-
[GVAR(points), _side, _sidePoints] call CBA_fnc_hashSet; // returning the default value does *not* imply setting it - so we need to explicitly set this at least once.
16+
private _sidePoints = GVAR(points) getOrDefault [_side, createHashMap];
17+
private _oldSidePointsForCategory = _sidePoints getOrDefault [_category, 0];
18+
_sidePoints set [_category, _oldSidePointsForCategory + _points];
19+
GVAR(points) set [_side, _sidePoints]; // returning the default value does *not* imply setting it - so we need to explicitly set this at least once.
2020

2121
publicVariable QGVAR(points);
2222
true

functions/points/fn_getPoints.sqf

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ params [
44
["_side", sideUnknown, [sideUnknown]]
55
];
66

7-
private _categorizedPoints = [[GVAR(points), _side] call CBA_fnc_hashGet] call CBA_fnc_hashValues;
7+
private _categorizedPoints = [
8+
GVAR(points) getOrDefault [_side, createHashMap]
9+
] call CBA_fnc_hashValues;
810

911
private _sum = 0;
10-
{ _sum = _sum + _x } forEach _categorizedPoints;
12+
{ _sum = _sum + _y } forEach _categorizedPoints;
1113

1214
_sum

functions/points/fn_getPointsCategorized.sqf

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ params [
55
];
66

77
private _pairs = [];
8-
[
9-
[GVAR(points), _side] call CBA_fnc_hashGet,
10-
{ _pairs pushBack [_key, _value] }
11-
] call CBA_fnc_hashEachPair;
8+
{
9+
_pairs pushBack [_x, _y];
10+
} forEach (GVAR(points) getOrDefault [_side, createHashMap]);
1211

1312
_pairs

functions/points/fn_getPointsCategory.sqf

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@ params [
55
["_category", "Other", [""]]
66
];
77

8-
[
9-
[GVAR(points), _side] call CBA_fnc_hashGet,
10-
_category
11-
] call CBA_fnc_hashGet
8+
(GVAR(points) getOrDefault [_side, createHashMap]) getOrDefault [_category, 0]

functions/points/fn_initPoints.sqf

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ ISNILS(GVAR(bounties), [ARR_2([], [ARR_2([], 0)] call CBA_fnc_hashCreate)] call
2626
];
2727

2828
// this is a map<side:SIDE,map<category:STRING,points:SCALAR>>
29-
ISNILS(GVAR(points), [ARR_2([], [ARR_2([], 0)] call CBA_fnc_hashCreate)] call CBA_fnc_hashCreate);
29+
ISNILS(GVAR(points), createHashMap);
3030

3131
[] call grad_points_fnc_addKilledEH;

functions/points/fn_setPoints.sqf

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ if (_side isEqualTo sideUnknown) exitWith {
1111
false
1212
};
1313

14-
private _sidePoints = [GVAR(points), _side] call CBA_fnc_hashGet;
15-
private _oldSidePointsForCategory = [_sidePoints, _category] call CBA_fnc_hashGet;
16-
[_sidePoints, _category, _points] call CBA_fnc_hashSet;
17-
[GVAR(points), _side, _sidePoints] call CBA_fnc_hashSet; // returning the default value does *not* imply setting it - so we need to explicitly set this at least once.
14+
private _sidePoints = GVAR(points) getOrDefault [_side, createHashMap];
15+
private _oldSidePointsForCategory = _sidePoints getOrDefault [_category, 0];
16+
_sidePoints set [_category, _points];
17+
GVAR(points) set [_side, _sidePoints]; // returning the default value does *not* imply setting it - so we need to explicitly set this at least once.
1818

1919
publicVariable QGVAR(points);
2020
true

0 commit comments

Comments
 (0)