Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashes - Add parameter to prevent removing default values #1383

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions addons/hashes/fnc_hashCreate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Description:
Parameters:
_array - Array of key-value pairs to create Hash from [Array, defaults to []]
_defaultValue - Default value. Used when key doesn't exist. A key is also removed from the hash if the value is set to this default [Any, defaults to nil]
_clearOnDefault - Setting default value behaves like a remove

Returns:
Newly created Hash [Hash]
Expand All @@ -31,10 +32,10 @@ Author:
SCRIPT(hashCreate);

// -----------------------------------------------------------------------------
params [["_array", [], [[]]], "_defaultValue"];
params [["_array", [], [[]]], "_defaultValue", ["_clearOnDefault", true]];

private _keys = _array apply {_x select 0};
private _values = _array apply {_x select 1};

// Return.
[TYPE_HASH, _keys, _values, if (isNil "_defaultValue") then {nil} else {_defaultValue}];
[TYPE_HASH, _keys, _values, if (isNil "_defaultValue") then {nil} else {_defaultValue}, _clearOnDefault];
2 changes: 1 addition & 1 deletion addons/hashes/fnc_hashSet.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private _default = _hash select HASH_DEFAULT_VALUE;
if (isNil "_default") then {
_isDefault = isNil "_value";
} else {
if (!isNil "_value") then {
if (!isNil "_value" && {_hash param [HASH_CLEARONDEFAULT, true]}) then {
_isDefault = _value isEqualTo _default;
};
};
Expand Down
2 changes: 1 addition & 1 deletion addons/hashes/fnc_isHash.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ SCRIPT(isHash);
// -----------------------------------------------------------------------------
params ["_hash"];

_hash isEqualType [] && {count _hash == 4} && {(_hash select HASH_ID) isEqualTo TYPE_HASH}
_hash isEqualType [] && {(count _hash) in [4, 5]} && {(_hash select HASH_ID) isEqualTo TYPE_HASH}
1 change: 1 addition & 0 deletions addons/hashes/script_hashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define HASH_KEYS 1
#define HASH_VALUES 2
#define HASH_DEFAULT_VALUE 3
#define HASH_CLEARONDEFAULT 4

#define TYPE_HASH "#CBA_HASH#"