From 9f0415b9fa32fa319e0ba7194756362563c45ed6 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Tue, 21 Jul 2015 21:51:32 +0100 Subject: [PATCH] Safeguard against removal of all modes --- .../functions/fnc_transitionCamera.sqf | 9 ++++-- .../functions/fnc_updateCameraModes.sqf | 27 ++++++++++++----- .../functions/fnc_updateVisionModes.sqf | 30 +++++++++++++------ addons/spectator/stringtable.xml | 2 +- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/addons/spectator/functions/fnc_transitionCamera.sqf b/addons/spectator/functions/fnc_transitionCamera.sqf index 65b4aa3456..198929af66 100644 --- a/addons/spectator/functions/fnc_transitionCamera.sqf +++ b/addons/spectator/functions/fnc_transitionCamera.sqf @@ -27,9 +27,9 @@ params [["_newMode",GVAR(camMode)], ["_newUnit",GVAR(camUnit)], ["_newVision",GVAR(camVision)]]; -// If new mode isn't available then keep current +// If new mode isn't available then keep current (unless current also isn't) if !(_newMode in GVAR(availableModes)) then { - _newMode = GVAR(camMode); + _newMode = GVAR(availableModes) select ((GVAR(availableModes) find GVAR(camMode)) max 0); }; // When no units available to spectate, exit to freecam @@ -55,6 +55,11 @@ if (_newMode == 0) then { // Free showCinemaBorder false; cameraEffectEnableHUD false; + // If new vision isn't available then keep current (unless current also isn't) + if !(_newVision in GVAR(availableVisions)) then { + _newVision = GVAR(availableVisions) select ((GVAR(availableVisions) find GVAR(camVision)) max 0); + }; + // Vision mode only applies to free cam if (_newVision < 0) then { false setCamUseTi 0; diff --git a/addons/spectator/functions/fnc_updateCameraModes.sqf b/addons/spectator/functions/fnc_updateCameraModes.sqf index 7048297551..7ba6d6cf5e 100644 --- a/addons/spectator/functions/fnc_updateCameraModes.sqf +++ b/addons/spectator/functions/fnc_updateCameraModes.sqf @@ -22,16 +22,27 @@ #include "script_component.hpp" params [["_addModes",[],[[]]], ["_removeModes",[],[[]]]]; +private ["_newModes","_currentModes"]; + +_currentModes = GVAR(availableModes); // Restrict additions to only possible values -_addModes = _addModes arrayIntersect [0,1,2]; -_addModes sort true; +_newModes = _addModes arrayIntersect [0,1,2]; +_newModes append (_currentModes - _removeModes); -// Remove and add new modes -GVAR(availableModes) = GVAR(availableModes) - _removeModes; +_newModes arrayIntersect _newModes; +_newModes sort true; -GVAR(availableModes) append _addModes; -GVAR(availableModes) arrayIntersect GVAR(availableModes); -GVAR(availableModes) sort true; +// Can't become an empty array +if (_newModes isEqualTo []) then { + [["[ACE Spectator]","Cannot remove all camera modes"],true,10] call EFUNC(common,displayStructuredText); +} else { + GVAR(availableModes) = _newModes; +}; -GVAR(availableModes) +// Update camera in case of change +if !(isNil QGVAR(camera)) then { + [] call FUNC(transitionCamera); +}; + +_newModes diff --git a/addons/spectator/functions/fnc_updateVisionModes.sqf b/addons/spectator/functions/fnc_updateVisionModes.sqf index 4e8b02bce3..230b740058 100644 --- a/addons/spectator/functions/fnc_updateVisionModes.sqf +++ b/addons/spectator/functions/fnc_updateVisionModes.sqf @@ -9,9 +9,9 @@ * - 1: Black hot * - 2: Light Green Hot / Darker Green cold * - 3: Black Hot / Darker Green cold - * - 4: Light Red Hot /Darker Red Cold + * - 4: Light Red Hot / Darker Red Cold * - 5: Black Hot / Darker Red Cold - * - 6: White Hot . Darker Red Col + * - 6: White Hot / Darker Red Cold * - 7: Thermal (Shade of Red and Green, Bodies are white) * * Arguments: @@ -30,15 +30,27 @@ #include "script_component.hpp" params [["_addModes",[],[[]]], ["_removeModes",[],[[]]]]; +private ["_newModes","_currentModes"]; + +_currentModes = GVAR(availableVisions); // Restrict additions to only possible values -_addModes = _addModes arrayIntersect [-2,-1,0,1,2,3,4,5,6,7]; +_newModes = _addModes arrayIntersect [-2,-1,0,1,2,3,4,5,6,7]; +_newModes append (_currentModes - _removeModes); -// Remove and add new modes -GVAR(availableVisions) = GVAR(availableVisions) - _removeModes; +_newModes arrayIntersect _newModes; +_newModes sort true; -GVAR(availableVisions) append _addModes; -GVAR(availableVisions) arrayIntersect GVAR(availableVisions); -GVAR(availableVisions) sort true; +// Can't become an empty array +if (_newModes isEqualTo []) then { + [["[ACE Spectator]","Cannot remove all vision modes"],true,10] call EFUNC(common,displayStructuredText); +} else { + GVAR(availableVisions) = _newModes; +}; -GVAR(availableVisions) +// Update camera in case of change +if !(isNil QGVAR(camera)) then { + [] call FUNC(transitionCamera); +}; + +_newModes diff --git a/addons/spectator/stringtable.xml b/addons/spectator/stringtable.xml index 9970f2f2e2..d7d5cc7959 100644 --- a/addons/spectator/stringtable.xml +++ b/addons/spectator/stringtable.xml @@ -2,7 +2,7 @@ - Spectator Setings + Spectator Settings Configure how the spectator system will operate by default.