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

Add Deprecate components support #3795

Merged
merged 4 commits into from
May 31, 2016
Merged
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
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ PREP(debugModule);
PREP(defineVariable);
PREP(deviceKeyFindValidIndex);
PREP(deviceKeyRegisterNew);
PREP(deprecateComponent);
PREP(disableAI);
PREP(disableUserInput);
PREP(displayIcon);
Expand Down
63 changes: 63 additions & 0 deletions addons/common/functions/fnc_deprecateComponent.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Author: Glowbal
* Mark a component as deprecated and switches it to a new component if that is available
*
* Arguments:
* 0: Component <Array>
* 1: New component <Array>
* 2: Version when the compent will be removed <String>
*
* Return Value:
* Replaced by new component <Boolean>
*
* 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 {
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;
2 changes: 1 addition & 1 deletion addons/sitting/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions addons/sitting/XEH_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
if (!hasInterface) exitWith {};

["SettingsInitialized", {
TRACE_1("SettingInit", GVAR(enable));

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)) exitWith {};

Expand Down