protected int OnExecute(CommandLineApplication app) { OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.spawnscript"); var spawnScript = SpawnScriptParser.Compile(File.ReadAllText(InputPath)); File.Create(OutputPath).Using(stream => Kh2.Ard.SpawnScript.Write(stream, spawnScript)); return(0); }
public void Compile() { try { IsError = false; LastError = "Success!"; _spawnScripts = SpawnScriptParser.Compile(Decompiled).ToList(); } catch (SpawnScriptParserException ex) { IsError = true; LastError = ex.Message; } }
public void ParseTextAsScript(string input, SpawnScript.Operation expectedOp, params int[] expectedParams) { var script = SpawnScriptParser.Compile($"Program 0\n{input}\n").ToArray(); Assert.Single(script); var program = script.First(); Assert.Single(program.Functions); var function = program.Functions.First(); Assert.Equal(expectedOp, function.Opcode); Assert.Equal(expectedParams, function.Parameters.ToArray()); }
public void CreateProgramsCorrectly() { const string Input = @" # This is a comment! Program 123 # This is our program entry Unk14 Program 0x123 Unk17"; var script = SpawnScriptParser.Compile(Input).ToArray(); Assert.Equal(2, script.Length); Assert.Equal(123, script[0].ProgramId); Assert.Single(script[0].Functions); Assert.Equal((SpawnScript.Operation) 0x14, script[0].Functions[0].Opcode); Assert.Equal(0x123, script[1].ProgramId); Assert.Single(script[1].Functions); Assert.Equal((SpawnScript.Operation) 0x17, script[1].Functions[0].Opcode); }