From 937e9b289abfd432d437dbd6caa9d19b74f84e98 Mon Sep 17 00:00:00 2001 From: Jonas Hoffmann Date: Wed, 14 Oct 2020 23:06:11 +0200 Subject: [PATCH 1/2] possible fix for #1358 --- addons/hashes/fnc_hashCreate.sqf | 5 +++-- addons/hashes/fnc_hashSet.sqf | 2 +- addons/hashes/fnc_isHash.sqf | 2 +- addons/hashes/script_hashes.hpp | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/hashes/fnc_hashCreate.sqf b/addons/hashes/fnc_hashCreate.sqf index 0052466b2..03b76f40e 100644 --- a/addons/hashes/fnc_hashCreate.sqf +++ b/addons/hashes/fnc_hashCreate.sqf @@ -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] @@ -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]; diff --git a/addons/hashes/fnc_hashSet.sqf b/addons/hashes/fnc_hashSet.sqf index 4b483d96b..f5c3a9a5f 100644 --- a/addons/hashes/fnc_hashSet.sqf +++ b/addons/hashes/fnc_hashSet.sqf @@ -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; }; }; diff --git a/addons/hashes/fnc_isHash.sqf b/addons/hashes/fnc_isHash.sqf index 3f713f2ec..c1cbb1ebd 100644 --- a/addons/hashes/fnc_isHash.sqf +++ b/addons/hashes/fnc_isHash.sqf @@ -23,4 +23,4 @@ SCRIPT(isHash); // ----------------------------------------------------------------------------- params ["_hash"]; -_hash isEqualType [] && {count _hash == 4} && {(_hash select HASH_ID) isEqualTo TYPE_HASH} +_hash isEqualType [] && {count _hash == 5} && {(_hash select HASH_ID) isEqualTo TYPE_HASH} diff --git a/addons/hashes/script_hashes.hpp b/addons/hashes/script_hashes.hpp index 7abf8ade7..3c0c9cc01 100644 --- a/addons/hashes/script_hashes.hpp +++ b/addons/hashes/script_hashes.hpp @@ -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#" From b3600ab9ee7f0918a3c84b7403940b92218a8119 Mon Sep 17 00:00:00 2001 From: Jonas Hoffmann Date: Thu, 15 Oct 2020 14:11:58 +0200 Subject: [PATCH 2/2] fix old Hashes not being valid. --- addons/hashes/fnc_isHash.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hashes/fnc_isHash.sqf b/addons/hashes/fnc_isHash.sqf index c1cbb1ebd..02037de6a 100644 --- a/addons/hashes/fnc_isHash.sqf +++ b/addons/hashes/fnc_isHash.sqf @@ -23,4 +23,4 @@ SCRIPT(isHash); // ----------------------------------------------------------------------------- params ["_hash"]; -_hash isEqualType [] && {count _hash == 5} && {(_hash select HASH_ID) isEqualTo TYPE_HASH} +_hash isEqualType [] && {(count _hash) in [4, 5]} && {(_hash select HASH_ID) isEqualTo TYPE_HASH}