more common code cleanup

This commit is contained in:
commy2 2015-09-19 20:17:38 +02:00
parent cbc7f961b2
commit 1636e3976d
7 changed files with 82 additions and 134 deletions

View File

@ -27,7 +27,6 @@ PREP(checkPBOs);
PREP(claim); PREP(claim);
PREP(codeToLetter); PREP(codeToLetter);
PREP(codeToString); PREP(codeToString);
PREP(convertKeyCode);
PREP(createOrthonormalReference); PREP(createOrthonormalReference);
PREP(currentChannel); PREP(currentChannel);
PREP(debug); PREP(debug);
@ -151,7 +150,6 @@ PREP(removeSpecificMagazine);
PREP(requestCallback); PREP(requestCallback);
PREP(resetAllDefaults); PREP(resetAllDefaults);
PREP(restoreVariablesJIP); PREP(restoreVariablesJIP);
PREP(revertKeyCodeLocalized);
PREP(runAfterSettingsInit); PREP(runAfterSettingsInit);
PREP(sanitizeString); PREP(sanitizeString);
PREP(sendRequest); PREP(sendRequest);

View File

@ -1,30 +0,0 @@
/*
* Author: commy2
* Get a key code used in AGM key input eh.
*
* Arguments:
* 0: Arma DIK code <NUMBER>
* 1: Key state for shift left and shift right key <BOOL>
* 2: Key state for ctrl left and ctrl right key <BOOL>
* 3: Key state for alt and alt gr key <BOOL>
*
* Return Value:
* Key code <NUMBER>
*
* Public: Yes
*
* Deprecated
*/
#include "script_component.hpp"
#define KEY_MODIFIERS [42, 54, 29, 157, 56, 184]
params ["_key", "_stateShift", "_stateCtrl", "_stateAlt"];
if (_key in KEY_MODIFIERS) exitWith {_key};
if (_stateShift) then {_key = _key + 0.1};
if (_stateCtrl) then {_key = _key + 0.2};
if (_stateAlt) then {_key = _key + 0.4};
_key

View File

@ -1,39 +0,0 @@
/*
* Author: commy2
*
* Revert a key code to a readible text.
*
* Argument:
* 0: Key code (Number)
*
* Return value:
* What input will result in the given key code? (String)
*/
#include "script_component.hpp"
private ["_key", "_alt", "_ctrl", "_shift"];
PARAMS_1(_keyCode);
_key = toString ((toArray keyName floor _keyCode) - [34]);
_keyCode = round ((_keyCode % 1) * 10);
switch (_keyCode) do {
case 8 : {format [localize QUOTE(DOUBLES(STR,GVAR(DoubleTapKey))), _key]};
case 9 : {format [localize QUOTE(DOUBLES(STR,GVAR(HoldKey))), _key]};
default {
_keyCode = toArray ([_keyCode, 3] call FUNC(toBin));
_alt = "1" == toString [_keyCode select 0];
_ctrl = "1" == toString [_keyCode select 1];
_shift = "1" == toString [_keyCode select 2];
format ["%1%2%3%4",
["", format ["%1 + ", localize QUOTE(DOUBLES(STR,GVAR(Alt)))]] select _alt,
["", format ["%1 + ", localize QUOTE(DOUBLES(STR,GVAR(Ctrl)))]] select _ctrl,
["", format ["%1 + ", localize QUOTE(DOUBLES(STR,GVAR(Shift)))]] select _shift,
_key
]
};
};

View File

@ -1,23 +1,22 @@
/* /*
* Author: esteldunedain, based on Killzone-Kid code * Author: esteldunedain, based on Killzone-Kid code
*
* Removes quotation marks to avoid exploits and optionally html tags from text to avoid conflicts with structured text. * Removes quotation marks to avoid exploits and optionally html tags from text to avoid conflicts with structured text.
* *
* Arguments: * Arguments:
* 0: Source string (String) * 0: Source string <STRING>
* 1: Remove html tags (Bool, optional) * 1: Remove html tags (optional) <BOOL>
* *
* Return Value: * Return Value:
* Sanitized string * Sanitized string
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params ["_string", ["_removeTags", false]];
private ["_array", "_arrayNew"]; private ["_array", "_arrayNew"];
PARAMS_2(_string,_removeTags);
if (isNil "_removeTags") then {_removeTags = false};
_array = toArray _string; _array = toArray _string;
_arrayNew = []; _arrayNew = [];
@ -37,6 +36,7 @@ _arrayNew = [];
_arrayNew = _arrayNew + [_x]; _arrayNew = _arrayNew + [_x];
}; };
}; };
} forEach _array; false
} count _array;
toString _arrayNew toString _arrayNew

View File

@ -1,47 +1,53 @@
/** /*
* fn_sendDisplayInformationTo.sqf * Author: Glowbal
* @Descr: Sends a display information hint to a receiver * Sends a display information hint to a receiver
* @Author: Glowbal
* *
* @Arguments: [receiver OBJECT, title STRING, content ARRAY (An array with strings), type NUMBER (Optional)] * Arguments:
* @Return: void * 0: receiver <OBJECT>
* @PublicAPI: true * 1: title <STRING>
* 2: content <ARRAY>
* 3: type (optional) <NUMBER>
*
* Return Value:
* None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_reciever","_title","_content","_type", "_parameters", "_localizationArray"]; params [["_reciever", objNull], ["_title", ""], ["_content", ""], ["_type", 0], ["_parameters", []]];
_reciever = [_this, 0, ObjNull,[ObjNull]] call BIS_fnc_Param;
_title = [_this, 1, "",[""]] call BIS_fnc_Param;
_content = [_this, 2, [""],[[""]]] call BIS_fnc_Param;
_type = [_this, 3, 0,[0]] call BIS_fnc_Param;
_parameters = [_this, 4, [], [[]]] call BIS_fnc_Param;
if (isPlayer _reciever) then { if (isPlayer _reciever) then {
if (!local _reciever) then { if (!local _reciever) then {
[_this, QUOTE(FUNC(sendDisplayInformationTo)), _reciever, false] call EFUNC(common,execRemoteFnc); [_this, QFUNC(sendDisplayInformationTo), _reciever, false] call FUNC(execRemoteFnc);
} else { } else {
if (isLocalized _title) then { if (isLocalized _title) then {
_title = localize _title; _title = localize _title;
}; };
private "_localizationArray";
_localizationArray = [_title]; _localizationArray = [_title];
{ {
_localizationArray pushback _x; _localizationArray pushback _x;
} forEach _parameters; false
} count _parameters;
_title = format _localizationArray; _title = format _localizationArray;
{ {
if (isLocalized _x) then { if (isLocalized _x) then {
_localizationArray = [localize _x]; _localizationArray = [localize _x];
{ {
_localizationArray pushback _x; _localizationArray pushBack _x;
} forEach _parameters; false
} count _parameters;
_content set [_foreachIndex, format _localizationArray]; _content set [_forEachIndex, format _localizationArray];
}; };
} forEach _content;
}foreach _content; [_title, _content, _type] call FUNC(displayInformation);
[_title,_content,_type] call EFUNC(common,displayInformation);
}; };
}; };

View File

@ -1,46 +1,53 @@
/** /*
* fn_sendDisplayMessageTo.sqf * Author: Glowbal
* @Descr: Displays a message on locality of receiver * Displays a message on locality of receiver
* @Author: Glowbal
* *
* @Arguments: [receiver OBJECT, title STRING, content STRING, type NUMBER (Optional)] * Arguments:
* @Return: void * 0: receiver <OBJECT>
* @PublicAPI: true * 1: title <STRING>
* 2: content <ARRAY>
* 3: type (optional) <NUMBER>
*
* Return Value:
* None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_reciever","_title","_content","_type", "_parameters", "_localizationArray"]; params [["_reciever", objNull], ["_title", ""], ["_content", ""], ["_type", 0], ["_parameters", []]];
_reciever = [_this, 0, ObjNull,[ObjNull]] call BIS_fnc_Param;
_title = [_this, 1, "",[""]] call BIS_fnc_Param;
_content = [_this, 2, "",[""]] call BIS_fnc_Param;
_type = [_this, 3, 0,[0]] call BIS_fnc_Param;
_parameters = [_this, 4, [], [[]]] call BIS_fnc_Param;
if (isPlayer _reciever) then { if (isPlayer _reciever) then {
if (!local _reciever) then { if (!local _reciever) then {
[_this, QUOTE(FUNC(sendDisplayMessageTo)), _reciever, false] call EFUNC(common,execRemoteFnc); [_this, QFUNC(sendDisplayMessageTo), _reciever, false] call FUNC(execRemoteFnc);
} else { } else {
if (isLocalized _title) then { if (isLocalized _title) then {
_title = localize _title; _title = localize _title;
}; };
if (isLocalized _content) then { if (isLocalized _content) then {
_content = localize _content; _content = localize _content;
}; };
private "_localizationArray";
_localizationArray = [_title]; _localizationArray = [_title];
{ {
_localizationArray pushback _x; _localizationArray pushBack _x;
}foreach _parameters; false
} count _parameters;
_title = format _localizationArray; _title = format _localizationArray;
_localizationArray = [_content]; _localizationArray = [_content];
{ {
_localizationArray pushback _x; _localizationArray pushBack _x;
}foreach _parameters; false
} count _parameters;
_content = format _localizationArray; _content = format _localizationArray;
[_title,_content,_type] call EFUNC(common,displayMessage); [_title, _content, _type] call FUNC(displayMessage);
}; };
}; };

View File

@ -1,20 +1,26 @@
/** /*
* fn_sendRequest_f.sqf * Author: Glowbal
* @Descr: Send a request to an unit and execute code based upon results. * Send a request to an unit and execute code based upon results.
* @Author: Glowbal
* *
* @Arguments: [caller OBJECT, target OBJECT, requestID STRING, requestMessage STRING (Will be localized for other target object), callback CODE (Code called upon accept or decline.)] * Arguments:
* @Return: void * 0: caller <OBJECT>
* @PublicAPI: true * 1: target <OBJECT>
* 2: requestID (STRING)
* 3: requestMessage Will be localized for other target object. (STRING)
* 4: callback Code called upon accept or decline. (CODE)
*
* Return Value:
* None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_5(_caller,_target,_requestID,_requestMessage,_callBack); params ["_caller", "_target", "_requestID", "_requestMessage", "_callBack"];
if (isPlayer _target) then { if (isPlayer _target) then {
// Pass request on to target locality for player accept/decline. // Pass request on to target locality for player accept/decline.
[[_caller, _target, _requestID, _requestMessage, _callBack], QUOTE(FUNC(receiveRequest)), _target, false] call EFUNC(common,execRemoteFnc); [[_caller, _target, _requestID, _requestMessage, _callBack], QFUNC(receiveRequest), _target, false] call FUNC(execRemoteFnc);
} else { } else {
// accept it, since it's an AI. // accept it, since it's an AI.
[_caller, _target, true] call compile _callBack; [_caller, _target, true] call compile _callBack;