scriptName "fn_exportCfgPatches_POSEIDON";
/*
        Author: Karel Moricky, edited by Tom_48_97

        Description:
        Export list of addons for Poseidon
        http://poseidon.arma3.fr

        Parameter(s):
                None

        Returns:
        NOTHING
*/
#define __filename "fn_exportCfgPatches_POSEIDON"
#define writeRPT(VALUE) diag_log [format ["%1:LOG", __filename], format ["%1", VALUE]]
private ["_cfg", "_patches", "_this", "_fnc", "_param", "_foreachindex", "_allPatches", "_list", "_product", "_productShort", "_getItemPage", "_class", "_textAddons", "_textUnits", "_textWeapons", "_textSide", "_galleryUnits", "_galleryWeapons", "_units", "_weapons", "_sidetype", "_br", "_type", "_itemType", "_page", "_arrayPush", "_log", "_returnchildren", "_text"];
writeRPT("BEGIN");

_p2 = test;
startloadingscreen [""];
_cfg = "cfgVehicles";

_patches = [_this, 1, [], [ []]] call bis_fnc_param;
_patches = +_patches;
{
	_patches set [_foreachindex, tolower _x];
} foreach _patches;
_allPatches   = count _patches == 0;
_list	      = [];
_product      = productversion select 0;
_productShort = productversion select 1;

_fnc_getItemPage = {
	switch (_this) do {
		case "Weapon": {"CfgWeapons Weapons"};
		case "VehicleWeapon": {"CfgWeapons Vehicle Weapons"};
		case "Item": {"CfgWeapons Items"};
		case "Equipment": {"CfgWeapons Equipment"};
			default {"CfgWeapons"};
		};
};

{
	_class = configname _x;
	if (_allPatches || (tolower _class) in _patches) then {
			_textAddons	= "";
			_textUnits	= "";
			_textWeapons	= "";
			_textSide	= "";
			_galleryUnits	= "";
			_galleryWeapons = "";
			_units		= getarray (_x >> "units");
			if (_cfg == "cfgVehicles" && count _units == 0) exitwith {};
			_weapons = getarray (_x >> "weapons");
			if (_cfg != "cfgVehicles" && count _weapons == 0) exitwith {};


			{
				_textSide = if (_x iskindof "allvehicles") then {
						str ((getnumber (configfile >> "cfgvehicles" >> _x >> "side") min 3) call bis_fnc_sidetype)
					} else {
						"EMPTY"
					};
				_textUnits    = _textUnits + _br + format [":[[%1 CfgVehicles %4#%3|%3]]", _product, _productShort, _x, _textSide];
				_galleryUnits = _galleryUnits + format ["[[File:%2 CfgVehicles %3.jpg|150px|&nbsp;]]", _product, _productShort, _x, _textSide];
			} foreach _units;

			{
				if (isclass (configfile >> "cfgweapons" >> _x)) then {
						_type		= _x call bis_fnc_itemType;
						_page		= (_type select 0) call _fnc_getItemPage;
						_textWeapons	= _textWeapons + _br + format [":[[%1 %4#%3|%3]]", _product, _productShort, _x, _page];
						_galleryWeapons = _galleryWeapons + format ["[[File:%2 CfgWeapons %3.jpg|150px|&nbsp;]]", _productShort, _productShort, _x];
					};
			} foreach _weapons;

			[_list, _class] call bis_fnc_arrayPush;
			diag_log format ["		{ 'trigger': '%1', 'contents': '%1'},", _class];
		};
} foreach ((configfile >> "cfgpatches") call bis_fnc_returnchildren);

_text = "(";
{
	_text = _text + format ["%1|", _x];
} forEach _list;
_text = _text + ")";
copytoclipboard _text;
endloadingscreen;
writeRPT("END");