Code cleanup of slideshow module

This commit is contained in:
Michael Braun 2015-08-07 12:11:34 +02:00
parent d636b4b5c7
commit fa56196fe3
5 changed files with 27 additions and 32 deletions

View File

@ -10,19 +10,19 @@
* 4: Current Slideshow <NUMBER> * 4: Current Slideshow <NUMBER>
* *
* Return Value: * Return Value:
* None * List of actions <ARRAY>
* *
* Example: * Example:
* [[object], ["image"], ["name"], controller, 1] call ace_slideshow_fnc_addSlideActions * [[object], ["image"], ["name"], controller, 1] call ace_slideshow_fnc_addSlideActions
* *
* Public: No * Public: No
*/ */
//#define DEBUG_MODE_FULL
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_5(_objects,_images,_names,_controller,_currentSlideshow); private "_actions";
params ["_objects", "_images", "_names", "_controller", "_currentSlideshow"];
private ["_actions"];
_actions = []; _actions = [];
{ {
_actions pushBack _actions pushBack
@ -32,10 +32,10 @@ _actions = [];
_names select _forEachIndex, _names select _forEachIndex,
"", "",
{ {
EXPLODE_2_PVT(_this select 2,_objects,_image); (_this select 2) params ["_objects", "_image"];
{ {
_x setObjectTextureGlobal [0, _image] _x setObjectTextureGlobal [0, _image]
} forEach _objects; } count _objects;
}, },
{true}, {true},
{}, {},

View File

@ -4,25 +4,23 @@
* *
* Arguments: * Arguments:
* 0: Objects <ARRAY> * 0: Objects <ARRAY>
* 1: Controller Objects <ARRAY>
* 2: Image Paths <ARRAY> * 2: Image Paths <ARRAY>
* 3: Action Names <ARRAY> * 3: State Variable Name <ARRAY>
* 4: Duration <NUMBER> (0 disables automatic transitions) * 4: Duration <NUMBER> (0 disables automatic transitions)
* *
* Return Value: * Return Value:
* Parsed List <ARRAY> * None
* *
* Example: * Example:
* [objects, controllers, images, actionNames, duration] call ace_slideshow_fnc_autoTransition * [objects, images, "ace_slideshow_slideshow1", duration] call ace_slideshow_fnc_autoTransition
* *
* Public: No * Public: No
*/ */
//#define DEBUG_MODE_FULL
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_4(_objects,_images,_varString,_duration); private "_currentSlide";
private ["_currentSlide"]; params ["_objects", "_images", "_varString", "_duration"];
// Get current slide number of this slideshow // Get current slide number of this slideshow
_currentSlide = missionNamespace getVariable [_varString, 0]; _currentSlide = missionNamespace getVariable [_varString, 0];
@ -40,6 +38,5 @@ missionNamespace setVariable [_varString, _currentSlide];
TRACE_4("Auto-transition",_images select _currentSlide,_currentSlide,count _images,_duration); TRACE_4("Auto-transition",_images select _currentSlide,_currentSlide,count _images,_duration);
// Next slide // Next slide
[FUNC(autoTransition), [_objects, _images, _varString, _duration], _duration] call EFUNC(common,waitAndExecute); [FUNC(autoTransition), [_objects, _images, _varString, _duration], _duration] call EFUNC(common,waitAndExecute);

View File

@ -17,10 +17,11 @@
* *
* Public: Yes * Public: Yes
*/ */
//#define DEBUG_MODE_FULL
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_5(_objects,_controllers,_images,_names,_duration); private ["_currentSlideshow", "_actionsObject", "_actionsClass", "_mainAction", "_slidesAction", "_varString"];
params ["_objects", "_controllers", "_images", "_names", "_duration"];
// Verify data // Verify data
if (count _images != count _names || {count _images == 0} || {count _names == 0}) exitWith { if (count _images != count _names || {count _images == 0} || {count _names == 0}) exitWith {
@ -30,7 +31,8 @@ if (count _images != count _names || {count _images == 0} || {count _names == 0}
// Objects synced to the module // Objects synced to the module
{ {
_objects pushBack _x; _objects pushBack _x;
} forEach (synchronizedObjects _logic); nil
} count (synchronizedObjects _logic);
// If no controllers use objects as controllers // If no controllers use objects as controllers
if (count _controllers == 0) then { if (count _controllers == 0) then {
@ -42,16 +44,14 @@ TRACE_4("Information",_objects,_controllers,_images,_names);
// Default images on whiteboards (first image) // Default images on whiteboards (first image)
{ {
_x setObjectTextureGlobal [0, _images select 0]; _x setObjectTextureGlobal [0, _images select 0];
} forEach _objects; } count _objects;
// Number of slideshows (multiple modules support) // Number of slideshows (multiple modules support)
GVAR(slideshows) = GVAR(slideshows) + 1; GVAR(slideshows) = GVAR(slideshows) + 1;
private ["_currentSlideshow"];
_currentSlideshow = GVAR(slideshows); // Local variable in case GVAR gets changed during execution of below code _currentSlideshow = GVAR(slideshows); // Local variable in case GVAR gets changed during execution of below code
// Add interactions if automatic transitions are disabled, else setup automatic transitions // Add interactions if automatic transitions are disabled, else setup automatic transitions
if (_duration == 0) then { if (_duration == 0) then {
private ["_actionsObject", "_actionsClass", "_mainAction", "_slidesAction"];
{ {
// Add MainAction if one does not already exist // Add MainAction if one does not already exist
_actionsObject = _x getVariable [QEGVAR(interact_menu,actions), []]; _actionsObject = _x getVariable [QEGVAR(interact_menu,actions), []];
@ -65,10 +65,10 @@ if (_duration == 0) then {
// Add Slides sub-action and populate with images // Add Slides sub-action and populate with images
_slidesAction = [QGVAR(Slides), localize LSTRING(Interaction), "", {}, {true}, {(_this select 2) call FUNC(addSlideActions)}, [_objects,_images,_names,_x,_currentSlideshow], [0,0,0], 2] call EFUNC(interact_menu,createAction); _slidesAction = [QGVAR(Slides), localize LSTRING(Interaction), "", {}, {true}, {(_this select 2) call FUNC(addSlideActions)}, [_objects,_images,_names,_x,_currentSlideshow], [0,0,0], 2] call EFUNC(interact_menu,createAction);
[_x, 0, ["ACE_MainActions"], _slidesAction] call EFUNC(interact_menu,addActionToObject); [_x, 0, ["ACE_MainActions"], _slidesAction] call EFUNC(interact_menu,addActionToObject);
} forEach _controllers; nil
} count _controllers;
} else { } else {
// Formatted GVAR string (multiple modules support) // Formatted GVAR string (multiple modules support)
private ["_varString"];
_varString = format [QGVAR(slideshow%1), _currentSlideshow]; _varString = format [QGVAR(slideshow%1), _currentSlideshow];
TRACE_1("Current Slide",_varString); TRACE_1("Current Slide",_varString);

View File

@ -18,7 +18,7 @@
//#define DEBUG_MODE_FULL //#define DEBUG_MODE_FULL
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_3(_list,_removeWhitespace,_checkNil); params ["_list", "_removeWhitespace", "_checkNil"];
private ["_splittedList", "_listNoWhitespace", "_nilCheckPassedList"]; private ["_splittedList", "_listNoWhitespace", "_nilCheckPassedList"];
@ -30,7 +30,8 @@ _listNoWhitespace = [];
if (_removeWhitespace) then { if (_removeWhitespace) then {
{ {
_listNoWhitespace pushBack ([_x] call EFUNC(common,stringRemoveWhiteSpace)); _listNoWhitespace pushBack ([_x] call EFUNC(common,stringRemoveWhiteSpace));
} forEach _splittedList; nil
} count _splittedList;
_list = _listNoWhitespace; _list = _listNoWhitespace;
}; };
@ -45,7 +46,7 @@ if (_checkNil) then {
_nilCheckPassedList = _nilCheckPassedList + "," + _x; _nilCheckPassedList = _nilCheckPassedList + "," + _x;
}; };
}; };
} forEach _list; } count _list;
// Add Array characters and parse into array // Add Array characters and parse into array
_list = "[" + _nilCheckPassedList + "]"; _list = "[" + _nilCheckPassedList + "]";
@ -54,4 +55,4 @@ if (_checkNil) then {
TRACE_4("Lists",_splittedList,_listNoWhitespace,_nilCheckPassedList,_list); TRACE_4("Lists",_splittedList,_listNoWhitespace,_nilCheckPassedList,_list);
_list _list // return

View File

@ -12,18 +12,15 @@
* *
* Public: No * Public: No
*/ */
//#define DEBUG_MODE_FULL
#include "script_component.hpp" #include "script_component.hpp"
if !(isServer) exitWith {}; if !(isServer) exitWith {};
PARAMS_3(_logic,_units,_activated);
if !(_activated) exitWith {};
private ["_objects", "_controllers", "_images", "_names", "_duration"]; private ["_objects", "_controllers", "_images", "_names", "_duration"];
_logic = [_this, 0, objNull, [objNull]] call BIS_fnc_param; params [["_logic", objNull, [objNull]], "_units", "_activated"];
if !(_activated) exitWith {};
if (isNull _logic) exitWith {}; if (isNull _logic) exitWith {};
// Extract variables from logic // Extract variables from logic