Skip to content

Instantly share code, notes, and snippets.

@X39
Last active October 4, 2015 10:13
Show Gist options
  • Save X39/0afe1477f33964321937 to your computer and use it in GitHub Desktop.
Save X39/0afe1477f33964321937 to your computer and use it in GitHub Desktop.
Prints ArmA Config class (+ its parents) to clipboard
//Example call:
//[configFile >> "CfgVehicles" >> "B_Soldier_F"] call _fnc_printClass;
_fnc_printClass = {
params [
"_class"
];
private [
"_fnc_getClass",
"_fnc_WriteToString",
"_classArr",
"_outString"
];
_fnc_getClass = {
params [
"_targetConfig"
];
private [
"_fnc_addSubclasses",
"_fnc_getParents",
"_arr"
];
_fnc_addSubclasses = {
params [
"_curClass",
"_curArray"
];
private [
"_name",
"_curClassCount",
"_sub",
"_subName",
"_index",
"_arr"
];
if(typeName _targetConfig != "CONFIG") exitWith
{
["Invalid param provided"] call BIS_fnc_HALT;
};
_name = _curArray select 0;
_curClassCount = count _curClass;
for "_i" from 0 to (_curClassCount - 1) do
{
_sub = _curClass select _i;
_subName = configName _sub;
_index = (_curArray select 1 select 0) find _subName;
if(isClass _sub) then
{
if(_index >= 0) then
{
_arr = _curArray select 1 select 1 select _index;
}
else
{
_arr = [_sub, [[], []]];
_curArray select 1 select 0 pushBack _subName;
_curArray select 1 select 1 pushBack _arr;
};
[_sub, _arr] call _fnc_addSubclasses;
}
else
{
if(_index >= 0) then
{
_arr = _curArray select 1 select 1 select _index;
_arr = _arr select 1;
_arr set [1, _sub call BIS_fnc_getCfgData];
}
else
{
_arr = [
_sub,
[
_subName,
_sub call BIS_fnc_getCfgData
]
];
_curArray select 1 select 0 pushBack _subName;
_curArray select 1 select 1 pushBack _arr;
};
};
};
};
_fnc_getParentTree = {
params [
"_class"
];
private [
"_arr"
];
_arr = [_class];
while {
_class = inheritsFrom _class;
configName _class != ""
} do
{
_arr pushBack _class;
};
reverse _arr;
_arr
};
if(typeName _targetConfig != "CONFIG") exitWith
{
["Invalid param provided"] call BIS_fnc_HALT;
};
_arr = [_class, [[], []]];
{
[_x, _arr] call _fnc_addSubclasses;
false
} count (_targetConfig call _fnc_getParentTree);
_arr
};
_fnc_WriteToString = {
params [
"_classArray",
"_tabCount"
];
private [
"_fnc_printTabs",
"_str",
"_lVal",
"_rVal"
];
_fnc_printTabs = {
private [
"_str"
];
_str = "";
for "_i" from 0 to _this do
{
_str = _str + toString [9];
};
_str
};
_str = "";
_lVal = _classArray select 1 select 0;
_rVal = _classArray select 1 select 1;
if(typeName _lVal == "ARRAY") then
{
_str = _str +
(_tabCount call _fnc_printTabs) +
"class " +
configName (_classArray select 0) +
toString [13, 10] +
(_tabCount call _fnc_printTabs) +
"{" +
toString [13, 10];
{
_str = _str + (
[_x, _tabCount + 1] call _fnc_WriteToString
);
false
} count _rVal;
_str = _str +
toString [13, 10] +
(_tabCount call _fnc_printTabs) +
"};" +
toString [13, 10];
}
else
{
_str = _str +
(_tabCount call _fnc_printTabs) +
_lVal +
" = " +
str _rVal +
";" +
toString [13, 10];
};
_str
};
_classArr = [_class] call _fnc_getClass;
_outString = [_classArr, 0] call _fnc_WriteToString;
copyToClipboard _outString;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment