Skip to content

Instantly share code, notes, and snippets.

@headswe
Created March 24, 2016 19:00
Show Gist options
  • Save headswe/6b41f3883a1a507a3ee5 to your computer and use it in GitHub Desktop.
Save headswe/6b41f3883a1a507a3ee5 to your computer and use it in GitHub Desktop.
#include "debug_console.hpp"
conClear();
_items = [];
#define TAB 9
#define BACKWARDSLASH 92
#define QUOTE 34
outlines = [];
#define PushbackLine(msg) outlines pushBack msg
KK_fnc_insert = {
private ["_arr", "_i", "_res"];
_arr = _this select 0;
_i = _this select 2;
_res = [];
_res append (_arr select [0, _i]);
_res append (_this select 1);
_res append (_arr select [_i, count _arr - _i]);
_res
};
_escape = {
private ["_index","_foreachindex"];
_newarr = [];
_arr = toArray _this;
{
if(_x == BACKWARDSLASH || _x == QUOTE) then
{
_newarr pushBack 92;
};
if(_x != TAB) then {
_newarr pushBack _x;
};
} foreach _arr;
toString _newarr
};
_parse = {
params ["_class"];
private ["_attributes","_children","_attrname","_data","_out","_class","_name"];
_name = configName _x;
_attributes = [];
_children = [];
{
_attrname = configName _x;
if(!isClass _x) then
{
_data = switch ( true ) do
{
case (isNumber _x): {getNumber _x};
case (isText _x): {(getText _x) call _escape};
case (isArray _x): {getArray _x};
default { nil };
};
_out = format ["%1 = %2 (%3)",_attrname,_data,_x];
_attributes pushBack [_attrname,_data];
}
else
{
_children pushBack ([_x] call _parse);
};
} foreach (configProperties [_class,"true",true]);
[_name,_attributes,_children]
};
{
_items pushBack ([_x] call _parse);
} foreach ("true" configClasses (configFile >> "CfgWeapons"));//
//[(configFile >> "CfgWeapons" >> "MMG_02_camo_F")];
//("true" configClasses (configFile >> "CfgWeapons"));
conWhite("Finished processing");
_printNode = {
private ["_attributes","_children","_d","_count","_dot","_attrName","_data","_foreachindex","_attrname","_totalChildren","_count"];
(_this select 0) params ["_name","_attributes","_children"];
_d = format ['{"title":"%1" ,"folder":true,', _name];
PushbackLine(_d);
PushbackLine('"children" : [');
_count = count _attributes;
for [{_i=0},{_i<_count},{_i=_i+1}] do {
_dot = ","; //herpderp
if(_i == (_count -1) && {count _children <= 0}) then {_dot = ""};
(_attributes select _i) params ["_attrName","_data"];
if(typeName _data == "STRING") then {_data = format ['"%1"', _data]};
if(typeName _data == "ARRAY") then {
{
if(typeName _x == "STRING") then
{
_data set [_foreachindex,(_x) call _escape];
};
} forEach _data;
_data = format ['%1', _data]
};
_d = format ['{"title" : "%1","artibute" : true, "children" : [ {"title" : %2 } ]} %3 ', _attrname,_data,_dot];
PushbackLine(_d);
};
_totalChildren = count _children;
{
[_x,(_totalChildren-1) == _foreachindex] call _printNode;
} foreach _children;
PushbackLine(']');
if(_this select 1) then
{
PushbackLine("}");
} else {
PushbackLine("} $ ");
};
};
_totalC = count _items;
PushbackLine('[');
{
[_x,_foreachindex == _totalC-1] call _printNode;
} foreach _items;
PushbackLine(']');
{
conFile(_x);
} foreach outlines;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment