From 3d74c25c977fff2d9cc3036cd8a164abde8d849a Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sun, 15 May 2016 19:38:24 +0200 Subject: [PATCH 1/4] Add deprecate component solution --- addons/common/XEH_PREP.hpp | 1 + .../functions/fnc_deprecateComponent.sqf | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 addons/common/functions/fnc_deprecateComponent.sqf diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 3dea56a98d..d8a25211b3 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -24,6 +24,7 @@ PREP(debugModule); PREP(defineVariable); PREP(deviceKeyFindValidIndex); PREP(deviceKeyRegisterNew); +PREP(deprecateComponent); PREP(disableAI); PREP(disableUserInput); PREP(displayIcon); diff --git a/addons/common/functions/fnc_deprecateComponent.sqf b/addons/common/functions/fnc_deprecateComponent.sqf new file mode 100644 index 0000000000..fc23b0e57f --- /dev/null +++ b/addons/common/functions/fnc_deprecateComponent.sqf @@ -0,0 +1,40 @@ +/* + * Author: Glowbal + * Mark a component as deprecated and switches it to a new component if that is available + * + * Arguments: + * 0: Component + * 1: New component + * 2: Version when the compent will be removed + * + * Return Value: + * Replaced by new component + * + * Public: No + * + * Example: + * [["ace_sitting", "ace_sitting_enabled"], ["acex_sitting", "acex_sitting_enabled"], "3.7.0"] call ace_common_fnc_deprecateComponent; + */ +#include "script_component.hpp" + +params ["_oldComponent", "_newComponent", "_version"]; + +_oldComponent params ["_oldComponentName", "_oldSettingName"]; +_newComponent params ["_newComponentName", "_newSettingName"]; + +private _isReplacementAvailable = isClass (configFile >> "CfgPatches" >> _newComponentName); +private _isDeprecatedLoaded = missionNamespace getvariable [_oldSettingName, false]; +private _isReplacementLoaded = missionNamespace getvariable [_newSettingName, false]; + +if (_isDeprecatedLoaded && {_isReplacementAvailable} && {!_isReplacementLoaded}) then { + [_newSettingName, true, true, true] call FUNC(setSetting); +}; + +if (_isDeprecatedLoaded && {!_isReplacementLoaded}) then { + // Log deprecated component is loaded + private _message = format["Component %1 is deprecated. It is replaced by %2. Please disable %1 and make use of %2. The component (%1) will no longer be available from version %3 and later.", _oldComponentName, _newComponentName, _version]; + systemChat format["ACE [WARNING] - %1", _message]; + ACE_LOGWARNING(_message); +}; + +_isReplacementAvailable; From 7a7e930024499a071bb3566d7de74eec3a040ca9 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sun, 15 May 2016 19:38:37 +0200 Subject: [PATCH 2/4] Add deprecate sitting component --- addons/sitting/CfgVehicles.hpp | 2 +- addons/sitting/XEH_clientInit.sqf | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/sitting/CfgVehicles.hpp b/addons/sitting/CfgVehicles.hpp index d92d92fc49..f7b1c9c197 100644 --- a/addons/sitting/CfgVehicles.hpp +++ b/addons/sitting/CfgVehicles.hpp @@ -8,7 +8,7 @@ class CfgVehicles { category = "ACE"; displayName = CSTRING(ModuleDisplayName); function = QFUNC(moduleInit); - scope = 2; + scope = 1; isGlobal = 1; isSingular = 1; icon = QUOTE(PATHTOF(UI\Icon_Module_Sitting_ca.paa)); diff --git a/addons/sitting/XEH_clientInit.sqf b/addons/sitting/XEH_clientInit.sqf index e15017d715..f681a3df8d 100644 --- a/addons/sitting/XEH_clientInit.sqf +++ b/addons/sitting/XEH_clientInit.sqf @@ -3,11 +3,12 @@ // Exit on Headless if (!hasInterface) exitWith {}; +GVAR(isEnabled) = false; ["SettingsInitialized", { - TRACE_1("SettingInit", GVAR(enable)); - + if ([[QUOTE(ADDON), QGVAR(enable)], ["acex_sitting", "acex_sitting_enable"], "3.7.0"] call EFUNC(common,deprecateComponent)) exitwith {}; //If not enabled, then do not add CanInteractWith Condition or event handlers: - if (!GVAR(enable)) exitWith {}; + if (!GVAR(enable) || GVAR(isEnabled)) exitWith {}; + GVAR(isEnabled) = true; // Add interaction menu exception ["isNotSitting", {isNil {(_this select 0) getVariable QGVAR(isSitting)}}] call EFUNC(common,addCanInteractWithCondition); From 487400b14248845b1e566ab23ec4cc3c38b6ea70 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sun, 15 May 2016 20:13:10 +0200 Subject: [PATCH 3/4] Add different warning messages based on current version of component --- .../functions/fnc_deprecateComponent.sqf | 31 ++++++++++++++++--- addons/sitting/XEH_clientInit.sqf | 2 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/addons/common/functions/fnc_deprecateComponent.sqf b/addons/common/functions/fnc_deprecateComponent.sqf index fc23b0e57f..21905e8e4e 100644 --- a/addons/common/functions/fnc_deprecateComponent.sqf +++ b/addons/common/functions/fnc_deprecateComponent.sqf @@ -31,10 +31,33 @@ if (_isDeprecatedLoaded && {_isReplacementAvailable} && {!_isReplacementLoaded}) }; if (_isDeprecatedLoaded && {!_isReplacementLoaded}) then { - // Log deprecated component is loaded - private _message = format["Component %1 is deprecated. It is replaced by %2. Please disable %1 and make use of %2. The component (%1) will no longer be available from version %3 and later.", _oldComponentName, _newComponentName, _version]; - systemChat format["ACE [WARNING] - %1", _message]; - ACE_LOGWARNING(_message); + private _componentVersion = getText (configFile >> "CfgPatches" >> _oldComponentName >> "version"); + ((_componentVersion splitString ".") apply {parseNumber _x}) params ["_componentMajor", "_componentMinor", "_componentPatch"]; + ((_version splitString ".") apply {parseNumber _x}) params ["_major", "_minor", "_patch"]; + + switch (true) do { + case (_componentMajor >= _major && {_componentMinor >= _minor} && {_componentPatch >= _patch}): { // Removed from this version + private _message = format[ + "Component %1 is deprecated. It has been replaced by %2. The component %1 is no longer usable on this version. ", _oldComponentName, _newComponentName, _version]; + systemChat format["ACE [ERROR] - %1", _message]; + ACE_LOGERROR(_message); + }; + case (_componentMajor >= _major && {_componentMinor >= _minor-1}): { // Removed the next this version + private _message = format[ + "Component %1 is deprecated. It is replaced by %2. Please disable %1 and make use of %2. " + + "The component (%1) will no longer be available from version %3 and later.", _oldComponentName, _newComponentName, _version]; + systemChat format["ACE [WARNING] - %1", _message]; + ACE_LOGWARNING(_message); + }; + case (_componentMajor == _major && {_componentMinor >= _minor - 2}): { // we are in a version leading up to removal + private _message = format[ + "Component %1 is deprecated. It is replaced by %2. Please disable %1 and make use of %2. " + + "The component (%1) will no longer be available from version %3 and later.", _oldComponentName, _newComponentName, _version]; + ACE_LOGWARNING(_message); + }; + default { + }; + }; }; _isReplacementAvailable; diff --git a/addons/sitting/XEH_clientInit.sqf b/addons/sitting/XEH_clientInit.sqf index f681a3df8d..60b50c4d09 100644 --- a/addons/sitting/XEH_clientInit.sqf +++ b/addons/sitting/XEH_clientInit.sqf @@ -5,7 +5,7 @@ if (!hasInterface) exitWith {}; GVAR(isEnabled) = false; ["SettingsInitialized", { - if ([[QUOTE(ADDON), QGVAR(enable)], ["acex_sitting", "acex_sitting_enable"], "3.7.0"] call EFUNC(common,deprecateComponent)) exitwith {}; + if ([[QUOTE(ADDON), QGVAR(enable)], ["acex_sitting", "acex_sitting_enable"], "3.8.0"] call EFUNC(common,deprecateComponent)) exitwith {}; //If not enabled, then do not add CanInteractWith Condition or event handlers: if (!GVAR(enable) || GVAR(isEnabled)) exitWith {}; GVAR(isEnabled) = true; From dd60ac8170aeb7e61cff4b95b5fe97d1daaa9b0d Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sat, 21 May 2016 00:41:49 +0200 Subject: [PATCH 4/4] Remove isEnabled check in sitting IsEnabled check is not necessary here. It should not have been included, as it was a left over from testing for migrating sitting to ACEX. --- addons/sitting/XEH_clientInit.sqf | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/sitting/XEH_clientInit.sqf b/addons/sitting/XEH_clientInit.sqf index 60b50c4d09..7efb38d41e 100644 --- a/addons/sitting/XEH_clientInit.sqf +++ b/addons/sitting/XEH_clientInit.sqf @@ -3,12 +3,10 @@ // Exit on Headless if (!hasInterface) exitWith {}; -GVAR(isEnabled) = false; ["SettingsInitialized", { if ([[QUOTE(ADDON), QGVAR(enable)], ["acex_sitting", "acex_sitting_enable"], "3.8.0"] call EFUNC(common,deprecateComponent)) exitwith {}; //If not enabled, then do not add CanInteractWith Condition or event handlers: - if (!GVAR(enable) || GVAR(isEnabled)) exitWith {}; - GVAR(isEnabled) = true; + if (!GVAR(enable)) exitWith {}; // Add interaction menu exception ["isNotSitting", {isNil {(_this select 0) getVariable QGVAR(isSitting)}}] call EFUNC(common,addCanInteractWithCondition);