program xml2level;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  janxmlparser2,
  Classes,
  PropsList in 'PropsList.pas';

var
 LogLevel:byte;


procedure LogMsg(Msg:string; Level:byte=0);
begin
 Writeln(Msg);
end;

procedure InitPropsList(var obj:TPropsList);
begin
 obj := TPropsList.Create;
end;

procedure ParseMainNode(MainNode:TjanXMLNode2; Output:TStringList);
var
 sNaming, sAmbient, sTerrain, sObjects, sLights, sMap, sResearches, sMission: TPropsList;
begin
 LogMsg('Parsing function call successful.');
 InitPropsList(sNaming);
 InitPropsList(sAmbient);
 InitPropsList(sTerrain);
 InitPropsList(sObjects);
 InitPropsList(sLights);
 InitPropsList(sMap);
 InitPropsList(sResearches);
 InitPropsList(sMission);
end;

var
  InputFile, OutputFile:string;
  Parser:TjanXMLParser2;
  MainNode:TjanXMLNode2;
  Output:TStringList;

begin
 Writeln('xml2level - XML to Colobot level converter');
 Writeln('by LolSoft');
 Writeln('');
 Writeln('Preparing...');
 InputFile := ParamStr(1);
 OutputFile := ParamStr(2);
 Parser := TjanXMLParser2.Create;
 Output := TStringList.Create;

 Writeln('Loading file '+InputFile);

 Parser.LoadXML(InputFile);
 MainNode := Parser.getChildByName('XMLColobotLevel');
 Writeln('');
 Writeln('PARSING START.');
 ParseMainNode(MainNode, Output);
 Writeln('PARSING DONE.');
 Writeln('Writing output to file '+OutputFile);
 Output.SaveToFile(OutputFile);
 Writeln('');
 Writeln('Cleaning up memory...');
 Output.Free;
 Parser.Free;
 Writeln('Done.');

end.
