public void WriteTest() => File.OpenRead(FileName).Using(x => Helpers.AssertStream(x, stream => { var outStream = new MemoryStream(); AreaDataScript.Write(outStream, AreaDataScript.Read(stream)); return outStream; }));
protected int OnExecute(CommandLineApplication app) { OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.spawnscript"); var spawnScript = AreaDataScript.Compile(File.ReadAllText(InputPath)); File.Create(OutputPath).Using(stream => AreaDataScript.Write(stream, spawnScript)); return(0); }
protected int OnExecute(CommandLineApplication app) { OutputPath ??= Path.Combine(Path.GetDirectoryName(InputPath), $"{Path.GetFileNameWithoutExtension(InputPath)}.txt"); var spawnScript = File.OpenRead(InputPath).Using(AreaDataScript.Read); File.WriteAllText(OutputPath, AreaDataScript.Decompile(spawnScript)); return(0); }
public void CompileAreaSettings() => Helpers.AssertStream(new MemoryStream(SampleScript), _ => { var dstStream = new MemoryStream(); var scripts = AreaDataScript.Compile(SampleScriptDecompiled); AreaDataScript.Write(dstStream, scripts); return dstStream; });
public void WriteAreaSettings() => Helpers.AssertStream(new MemoryStream(SampleScript), stream => { var dstStream = new MemoryStream(); var scripts = AreaDataScript.Read(stream); AreaDataScript.Write(dstStream, scripts); return dstStream; });
public void ParseTextAsScript(string input) { var code = $"Program 0x00\n{input}"; var scripts = AreaDataScript.Compile(code).ToArray(); Assert.Single(scripts); var decompiled = scripts.First().ToString(); Assert.Equal(code, decompiled); }
public static SpawnScriptModel Create(List <Bar.Entry> entries, string name) { var entry = entries .FirstOrDefault(x => x.Name == name && x.Type == Bar.EntryType.AreaDataScript); if (entry == null) { return(null); } return(new SpawnScriptModel(name, AreaDataScript.Read(entry.Stream))); }
public IEnumerable <Bar.Entry> SaveToBar(IEnumerable <Bar.Entry> entries) { var memStream = new MemoryStream(); AreaDataScript.Write(memStream, _spawnScripts); return(entries.AddOrReplace(new Bar.Entry { Name = _name, Type = Bar.EntryType.AreaDataScript, Stream = memStream })); }
public void Batch_CompileAllScripts(string ardFile, string scriptSet) { Skip.If(ardFile == string.Empty, "No ARD files found"); var binarcEntry = File.OpenRead(ardFile).Using(Bar.Read) .FirstOrDefault(x => x.Name == scriptSet && x.Type == Bar.EntryType.AreaDataScript); if (binarcEntry == null) return; var expected = AreaDataScript.Decompile(AreaDataScript.Read(binarcEntry.Stream)); var actual = AreaDataScript.Decompile(AreaDataScript.Compile(expected)); Assert.Equal(expected, actual); }
public void Compile() { try { IsError = false; LastError = "Success!"; _spawnScripts = AreaDataScript.Compile(Decompiled).ToList(); } catch (SpawnScriptParserException ex) { IsError = true; LastError = ex.Message; } }
public void Batch_WriteAllScripts(string ardFile, string scriptSet) { Skip.If(ardFile == string.Empty, "No ARD files found"); var binarcEntry = File.OpenRead(ardFile).Using(Bar.Read) .FirstOrDefault(x => x.Name == scriptSet && x.Type == Bar.EntryType.AreaDataScript); if (binarcEntry == null) return; Helpers.AssertStream(binarcEntry.Stream, stream => { var memStream = new MemoryStream(); AreaDataScript.Write(memStream, AreaDataScript.Read(stream)); return memStream; }); }
public void CreateProgramsCorrectly() { const string Input = @" # This is a comment! Program 123 # This is our program entry StatusFlag3 Program 0x123 StatusFlag5"; var script = AreaDataScript.Compile(Input).ToArray(); Assert.Equal(2, script.Length); Assert.Equal(123, script[0].ProgramId); Assert.Single(script[0].Functions); Assert.Equal(0x123, script[1].ProgramId); Assert.Single(script[1].Functions); }
public void ParseScriptAsText(string expected, int operation, params int[] parameters) { const int ProgramId = 0; var writer = new BinaryWriter(new MemoryStream()); writer.Write((short)ProgramId); writer.Write((short)(parameters.Length * 4 + 8)); writer.Write((short)operation); writer.Write((short)parameters.Length); foreach (var item in parameters) writer.Write(item); writer.BaseStream.Position = 0; writer.BaseStream.Flush(); var command = AreaDataScript.Read(writer.BaseStream, ProgramId).First(); Assert.Equal(expected, command.ToString()); }
private void RunSpawnScript( IEnumerable <Bar.Entry> barEntries, string spawnScriptName, int programId) { var script = barEntries.ForEntry(spawnScriptName, Bar.EntryType.AreaDataScript, stream => AreaDataScript.Read(stream, programId)); if (script == null) { return; } foreach (var function in script) { switch (function) { case AreaDataScript.Spawn spawn: Log.Info("Loading spawn {0}", spawn.SpawnSet); var spawnPoints = barEntries.ForEntry(spawn.SpawnSet, Bar.EntryType.AreaDataSpawn, SpawnPoint.Read); if (spawnPoints != null) { foreach (var spawnPoint in spawnPoints) { foreach (var desc in spawnPoint.Entities) { if (desc.SpawnType == 0 || desc.SpawnArgument == _kernel.Entrance) { AddActor(desc); } } } } else { Log.Warn("Unable to find spawn \"{0}\".", spawn); } break; } } }
SpawnScriptModel(string name, List <AreaDataScript> spawnScripts) { _name = name; _spawnScripts = spawnScripts; Decompiled = AreaDataScript.Decompile(spawnScripts); }
public void DecompileAreaSettings() { var scripts = AreaDataScript.Read(new MemoryStream(SampleScript)); Assert.Equal(SampleScriptDecompiled, scripts.First().ToString()); }