From fba423e38daaca9976d32c12dd059aec8669f718 Mon Sep 17 00:00:00 2001 From: IndigoFox Date: Thu, 8 Feb 2024 12:47:51 -0800 Subject: [PATCH] update mapcopy module with CBA events --- README.md | 2 +- framework/CfgFunctions.hpp | 23 ++++----- framework/init/functions/fn_initClient.sqf | 1 + framework/map/fn_copyMapFromPlayer.sqf | 5 -- framework/map/fn_getPlayerMapMarkers.sqf | 16 ------- framework/map/fn_initMapCopy.sqf | 17 ------- framework/map/fn_loadMapMarkers.sqf | 10 ---- .../mapcopy/functions/fn_addCBASettings.sqf | 24 ++++++++++ .../mapcopy/functions/fn_getMapMarkers.sqf | 15 ++++++ framework/mapcopy/functions/fn_initClient.sqf | 48 +++++++++++++++++++ .../mapcopy/functions/fn_loadMapMarkers.sqf | 8 ++++ .../functions}/fn_mapMarkerToString.sqf | 0 .../functions}/fn_stringToMapMarker.sqf | 0 framework/mapcopy/script_component.hpp | 3 ++ 14 files changed, 112 insertions(+), 60 deletions(-) delete mode 100644 framework/map/fn_copyMapFromPlayer.sqf delete mode 100644 framework/map/fn_getPlayerMapMarkers.sqf delete mode 100644 framework/map/fn_initMapCopy.sqf delete mode 100644 framework/map/fn_loadMapMarkers.sqf create mode 100644 framework/mapcopy/functions/fn_addCBASettings.sqf create mode 100644 framework/mapcopy/functions/fn_getMapMarkers.sqf create mode 100644 framework/mapcopy/functions/fn_initClient.sqf create mode 100644 framework/mapcopy/functions/fn_loadMapMarkers.sqf rename framework/{map => mapcopy/functions}/fn_mapMarkerToString.sqf (100%) rename framework/{map => mapcopy/functions}/fn_stringToMapMarker.sqf (100%) create mode 100644 framework/mapcopy/script_component.hpp diff --git a/README.md b/README.md index 8587393..b3279a5 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ This directory contains a number of hpp files used to define constants throughou - A subcomponent of `fbcb2_main`. Used to gather, display, and manage diary records as intel for assets near known bases. - `init`: - Contains core initialization functions. Both server and client inits across all modules are managed here. -- `map`: +- `mapcopy`: - Gives players the ability to copy each other's maps. - `performance`: - Contains functionality for monitoring and logging performance data. diff --git a/framework/CfgFunctions.hpp b/framework/CfgFunctions.hpp index d9e5f96..997f002 100644 --- a/framework/CfgFunctions.hpp +++ b/framework/CfgFunctions.hpp @@ -20,16 +20,6 @@ class CfgFunctions { class flakInitVehicle {}; class flakEH {}; }; - - class map { - file = "framework\map"; - class initMapCopy { postInit = 1; }; - class copyMapFromPlayer {}; //needs refactor - class getPlayerMapMarkers {}; //needs refactor - class loadMapMarkers {}; //needs refactor - class mapMarkerToString {}; //needs refactor - class stringToMapMarker {}; //needs refactor - }; }; class DOUBLES(PREFIX,client) { @@ -42,7 +32,6 @@ class CfgFunctions { }; }; - class DOUBLES(PREFIX,common) { class functions { file = "framework\common\functions"; @@ -101,6 +90,18 @@ class CfgFunctions { }; }; + class DOUBLES(PREFIX,mapcopy) { + class functions { + file = "framework\mapcopy\functions"; + class addCBASettings {preInit=1;}; + class initClient {}; + class getMapMarkers {}; + class loadMapMarkers {}; + class mapMarkerToString {}; + class stringToMapMarker {}; + }; + }; + class DOUBLES(PREFIX,performance) { class functions { file = "framework\performance\functions"; diff --git a/framework/init/functions/fn_initClient.sqf b/framework/init/functions/fn_initClient.sqf index a7d106a..14259f6 100644 --- a/framework/init/functions/fn_initClient.sqf +++ b/framework/init/functions/fn_initClient.sqf @@ -16,6 +16,7 @@ waitUntil {!isNil QGVARMAIN(complete)}; // initialize other modules +call EFUNC(mapcopy,initClient); call EFUNC(reinsert,initClient); call EFUNC(resupply,initClient); call EFUNC(triageIcons,initClient); diff --git a/framework/map/fn_copyMapFromPlayer.sqf b/framework/map/fn_copyMapFromPlayer.sqf deleted file mode 100644 index 16d988e..0000000 --- a/framework/map/fn_copyMapFromPlayer.sqf +++ /dev/null @@ -1,5 +0,0 @@ -params ["_sourcePlayer","_destinationPlayer"]; - -hint format["Copying map markers from %1", name _sourcePlayer]; - -[_destinationPlayer] remoteExecCall ["milsim_fnc_getPlayerMapMarkers",_sourcePlayer]; diff --git a/framework/map/fn_getPlayerMapMarkers.sqf b/framework/map/fn_getPlayerMapMarkers.sqf deleted file mode 100644 index 299985c..0000000 --- a/framework/map/fn_getPlayerMapMarkers.sqf +++ /dev/null @@ -1,16 +0,0 @@ -params ["_destinationPlayer"]; - -_markerData = []; - -hint format["Your map is being copied by %1", name _destinationPlayer]; - -{ - _marker = toArray _x; - _marker resize 15; - if ( toString _marker == "_USER_DEFINED #" ) then { - _marker = _x call milsim_fnc_mapMarkerToString; - _markerData pushBack _marker; - }; -} forEach allMapMarkers; - -[_markerData] remoteExecCall ["milsim_fnc_loadMapMarkers",_destinationPlayer]; diff --git a/framework/map/fn_initMapCopy.sqf b/framework/map/fn_initMapCopy.sqf deleted file mode 100644 index 7e60c51..0000000 --- a/framework/map/fn_initMapCopy.sqf +++ /dev/null @@ -1,17 +0,0 @@ -_map_copy_condition = -{ - ('ItemMap' in (assignedItems _player)) && ('ItemMap' in (assignedItems _target)) && ([_player, _target, []] call ace_common_fnc_canInteractWith) -}; - -_map_copy_action = -[ - "MilSimCopyMap", - "Copy Map", - "\a3\ui_f\data\igui\cfg\actions\talk_ca.paa", - { - [_target,_player] call milsim_fnc_copyMapFromPlayer - }, - _map_copy_condition -] call ace_interact_menu_fnc_createAction; - -["Man", 0, ["ACE_MainActions"], _map_copy_action, true] call ace_interact_menu_fnc_addActionToClass; \ No newline at end of file diff --git a/framework/map/fn_loadMapMarkers.sqf b/framework/map/fn_loadMapMarkers.sqf deleted file mode 100644 index d01989b..0000000 --- a/framework/map/fn_loadMapMarkers.sqf +++ /dev/null @@ -1,10 +0,0 @@ -params ["_markerList"]; - -if ('ItemMap' in (assignedItems player)) then { - { - _x call milsim_fnc_stringToMapMarker; - } foreach _markerList; - hint format["Map copied!"]; -} else { - hint format["You need a map to copy onto!"]; -}; diff --git a/framework/mapcopy/functions/fn_addCBASettings.sqf b/framework/mapcopy/functions/fn_addCBASettings.sqf new file mode 100644 index 0000000..6e299a3 --- /dev/null +++ b/framework/mapcopy/functions/fn_addCBASettings.sqf @@ -0,0 +1,24 @@ +#include "..\script_component.hpp" + +[ + QGVAR(setting_enable), + "CHECKBOX", + "Allow Map Copying", + [QUOTE(SETTINGS_GROUP_NAME), QUOTE(COMPONENT_BEAUTIFIED)], + true, // default value + true, // is global + { + params ["_value"]; + [ + QGVAR(setting_enable), + _value + ] call EFUNC(common,logSettingChanged); + } +] call CBA_fnc_addSetting; + +[ + LEVEL_INFO, + QUOTE(COMPONENT), + "CREATED SETTINGS", + [] +] call EFUNC(common,log); \ No newline at end of file diff --git a/framework/mapcopy/functions/fn_getMapMarkers.sqf b/framework/mapcopy/functions/fn_getMapMarkers.sqf new file mode 100644 index 0000000..2764dd4 --- /dev/null +++ b/framework/mapcopy/functions/fn_getMapMarkers.sqf @@ -0,0 +1,15 @@ +#include "..\script_component.hpp" +// serializes markers on local machine and returns them as array + +_markerData = []; + +{ + _marker = toArray _x; + _marker resize 15; + if ( toString _marker == "_USER_DEFINED #" ) then { + _marker = _x call FUNC(mapMarkerToString); + _markerData pushBack _marker; + }; +} forEach allMapMarkers; + +_markerData; \ No newline at end of file diff --git a/framework/mapcopy/functions/fn_initClient.sqf b/framework/mapcopy/functions/fn_initClient.sqf new file mode 100644 index 0000000..c7eaa22 --- /dev/null +++ b/framework/mapcopy/functions/fn_initClient.sqf @@ -0,0 +1,48 @@ +#include "..\script_component.hpp" + +//////////////////////////////////////////////////////////////////// +// Create action to copy map markers on all inheritors of CAManBase +//////////////////////////////////////////////////////////////////// +private _mapCopyAction = +[ + QGVAR(actionID), + "Copy Map", + "\a3\ui_f\data\igui\cfg\actions\talk_ca.paa", + { + params ["_target", "_player", "_params"]; + format["Copying map markers from %1", name _target] call CBA_fnc_notify; + [QGVAR(mapCopyRequest), _this, _target] call CBA_fnc_targetEvent; + }, + { + params ["_target", "_player", "_params"]; + [QGVAR(setting_enable)] call CBA_settings_fnc_get && { + ('ItemMap' in (assignedItems _player)) && + ('ItemMap' in (assignedItems _target)) && + ([_player, _target, []] call ace_common_fnc_canInteractWith) + }; + } +] call ace_interact_menu_fnc_createAction; +["CAManBase", 0, ["ACE_MainActions"], _mapCopyAction, true] call ace_interact_menu_fnc_addActionToClass; + +//////////////////////////////////////////////////////////////////// +// Create CBA event to receive requests +//////////////////////////////////////////////////////////////////// +[QGVAR(mapCopyRequest), { + params ["_me", "_requester", "_params"]; + format["Your map is being copied by %1", name _requester] call CBA_fnc_notify; + private _myMarkers = _this call FUNC(getMapMarkers); + [QGVAR(mapCopyResponse), [_me, _myMarkers], _requester] call CBA_fnc_targetEvent; +}] call CBA_fnc_addEventHandler; + +//////////////////////////////////////////////////////////////////// +// Create CBA event to receive responses +//////////////////////////////////////////////////////////////////// +[QGVAR(mapCopyResponse), { + params [["_responder", objNull, [objNull]], ["_markerList", [], [[]]]]; + if ('ItemMap' in (assignedItems player)) then { + [_markerList] call FUNC(loadMapMarkers); + format["Copied %1 markers from %2", count _markerList, name _responder] call CBA_fnc_notify; + } else { + format["You need a map to copy onto!"] call CBA_fnc_notify; + }; +}] call CBA_fnc_addEventHandler; \ No newline at end of file diff --git a/framework/mapcopy/functions/fn_loadMapMarkers.sqf b/framework/mapcopy/functions/fn_loadMapMarkers.sqf new file mode 100644 index 0000000..804bc82 --- /dev/null +++ b/framework/mapcopy/functions/fn_loadMapMarkers.sqf @@ -0,0 +1,8 @@ +#include "..\script_component.hpp" +// accepts an array of serialized markers and adds them to local map + +params [["_markerList", [], [[]]]]; + +{ + _x call FUNC(stringToMapMarker); +} foreach _markerList; \ No newline at end of file diff --git a/framework/map/fn_mapMarkerToString.sqf b/framework/mapcopy/functions/fn_mapMarkerToString.sqf similarity index 100% rename from framework/map/fn_mapMarkerToString.sqf rename to framework/mapcopy/functions/fn_mapMarkerToString.sqf diff --git a/framework/map/fn_stringToMapMarker.sqf b/framework/mapcopy/functions/fn_stringToMapMarker.sqf similarity index 100% rename from framework/map/fn_stringToMapMarker.sqf rename to framework/mapcopy/functions/fn_stringToMapMarker.sqf diff --git a/framework/mapcopy/script_component.hpp b/framework/mapcopy/script_component.hpp new file mode 100644 index 0000000..1011914 --- /dev/null +++ b/framework/mapcopy/script_component.hpp @@ -0,0 +1,3 @@ +#define COMPONENT mapcopy +#define COMPONENT_BEAUTIFIED Map Copy +#include "../script_mod.hpp" \ No newline at end of file