public void PackageModules() { var package = new RantPackage(); var pattern = RantPattern.FromString("[$[.hello_world]:Hello World]"); pattern.Name = "pkg_test"; package.AddPattern(pattern); rant.LoadPackage(package); Assert.AreEqual("Hello World", rant.Do("[use:pkg_test][$pkg_test.hello_world]").Main); }
public void PackageModules() { var package = new RantPackage(); var pattern = RantPattern.FromString("[$[.hello_world]:Hello World]"); pattern.Name = "pkg_test"; package.AddPattern(pattern); rant.LoadPackage(package); Assert.AreEqual("Hello World", rant.Do("[use:pkg_test][$pkg_test.hello_world]").Main); }
public Rant_Generator() { rant = new RantEngine(); rng = new RNG(Seed); Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); var package = RantPackage.Load(Package); rant.LoadPackage(package); }
private static void Pack(RantPackage package, string contentPath) { foreach (var path in Directory.EnumerateFiles(contentPath, "*.*", SearchOption.AllDirectories) .Where(p => p.EndsWith(".rant") || p.EndsWith(".rants"))) { var pattern = RantPattern.FromFile(path); string relativePath; TryGetRelativePath(contentPath, path, out relativePath, true); pattern.Name = relativePath; package.AddPattern(pattern); Console.WriteLine("+ " + pattern.Name); } foreach (var path in Directory.GetFiles(contentPath, "*.dic", SearchOption.AllDirectories)) { Console.WriteLine("+ " + path); var table = RantDictionaryTable.FromFile(path); package.AddTable(table); } }
private static void Pack(RantPackage package, string contentPath) { foreach (string path in Directory.EnumerateFiles(contentPath, "*.*", SearchOption.AllDirectories) .Where(p => p.EndsWith(".rant") || p.EndsWith(".rants"))) { var pattern = RantProgram.CompileFile(path); string relativePath; TryGetRelativePath(contentPath, path, out relativePath, true); pattern.Name = relativePath; package.AddResource(pattern); Console.WriteLine("+ " + pattern.Name); } foreach (string path in Directory.GetFiles(contentPath, "*.table", SearchOption.AllDirectories)) { Console.WriteLine("+ " + path); var table = RantDictionaryTable.FromStream(Path.GetFileNameWithoutExtension(path), File.Open(path, FileMode.Open)); package.AddResource(table); } }
public void SaveLoadRun() { var package = new RantPackage { ID = "TestPackage", Description = "This is a test.", Title = "Test Package?!", Version = new RantPackageVersion(1, 1, 0) }; package.AddResource(RantDictionaryTable.FromStream("nouns", File.Open("Tables/nouns.table", FileMode.Open))); package.AddResource(RantProgram.CompileString("TestProgram", @"[case:title]<noun-food-fruit-yellow> [rs:5;,\s]{[rn]}")); package.Save("TestPackage.rantpkg"); package = RantPackage.Load("TestPackage.rantpkg"); rant.LoadPackage(package); Assert.AreEqual("Banana 1, 2, 3, 4, 5", rant.DoName("TestProgram").Main); Assert.AreEqual("TestPackage", package.ID); Assert.AreEqual("This is a test.", package.Description); Assert.AreEqual("Test Package?!", package.Title); Assert.AreEqual("1.1.0", package.Version.ToString()); }
public static void Run() { var pkg = new RantPackage(); var paths = GetPaths(); var compress = Property("compression", "true") == "true"; var stringTableMode = int.Parse(Property("string-table", "1")); if (stringTableMode < 0 || stringTableMode > 2) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid string table mode."); Console.ResetColor(); return; } var modeEnum = (BsonStringTableMode)stringTableMode; Console.WriteLine("Packing..."); var contentDir = Path.GetFullPath(paths.Length == 0 ? Environment.CurrentDirectory : paths[0]); Pack(pkg, contentDir); string outputPath; if (!Flag("old")) { var infoPath = Path.Combine(contentDir, "rantpkg.json"); if (!File.Exists(infoPath)) { throw new FileNotFoundException("rantpkg.json missing from root directory."); } var info = JsonConvert.DeserializeObject <PackInfo>(File.ReadAllText(infoPath)); pkg.Title = info.Title; pkg.Authors = info.Authors; pkg.Version = RantPackageVersion.Parse(!String.IsNullOrWhiteSpace(Property("version")) ? Property("version") : info.Version); pkg.Description = info.Description; pkg.ID = info.ID; pkg.Tags = info.Tags; foreach (var dep in info.Dependencies) { pkg.AddDependency(dep); } if (!String.IsNullOrWhiteSpace(info.OutputPath)) { outputPath = Path.Combine(contentDir, info.OutputPath, $"{pkg.ID}-{pkg.Version}.rantpkg"); Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } else { outputPath = Path.Combine(Directory.GetParent(contentDir).FullName, $"{pkg.ID}-{pkg.Version}.rantpkg"); } Console.WriteLine($"String table mode: {modeEnum}"); Console.WriteLine($"Compression: {(compress ? "yes" : "no")}"); Console.WriteLine(compress ? "Compressing and saving..." : "Saving..."); pkg.Save(outputPath, compress, modeEnum); } else { outputPath = Property("out", Path.Combine( Directory.GetParent(Environment.CurrentDirectory).FullName, Path.GetFileName(Environment.CurrentDirectory) + ".rantpkg")); Console.WriteLine("Saving..."); pkg.SaveOld(outputPath); } Console.WriteLine("\nPackage saved to " + outputPath); Console.ResetColor(); }
protected override void OnRun() { var pkg = new RantPackage(); var paths = CmdLine.GetPaths(); bool compress = !CmdLine.Flag("no-compress"); Console.WriteLine("Packing..."); string contentDir = Path.GetFullPath(paths.Length == 0 ? Environment.CurrentDirectory : paths[0]); Pack(pkg, contentDir); string outputPath; string infoPath = Path.Combine(contentDir, "rantpkg.json"); if (!File.Exists(infoPath)) { throw new FileNotFoundException("rantpkg.json missing from root directory."); } var info = JsonConvert.DeserializeObject <PackInfo>(File.ReadAllText(infoPath)); pkg.Title = info.Title; pkg.Authors = info.Authors; pkg.Version = RantPackageVersion.Parse(!string.IsNullOrWhiteSpace(CmdLine.Property("version")) ? CmdLine.Property("version") : info.Version); pkg.Description = info.Description; pkg.ID = info.ID; pkg.Tags = info.Tags; foreach (var dep in info.Dependencies) { pkg.AddDependency(dep); } // -out property overrides rantpkg.json's output path if (!string.IsNullOrWhiteSpace(CmdLine.Property("out"))) { outputPath = Path.Combine(CmdLine.Property("out"), $"{pkg.ID}-{pkg.Version}.rantpkg"); Directory.CreateDirectory(CmdLine.Property("out")); } // Otherwise, use rantpkg.json's "out" property else if (!string.IsNullOrWhiteSpace(info.OutputPath)) { outputPath = Path.Combine(contentDir, info.OutputPath, $"{pkg.ID}-{pkg.Version}.rantpkg"); Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } // If it doesn't have one, put it in the package content directory else { outputPath = Path.Combine(Directory.GetParent(contentDir).FullName, $"{pkg.ID}-{pkg.Version}.rantpkg"); } Console.WriteLine($"Compression: {(compress ? "yes" : "no")}"); Console.WriteLine(compress ? "Compressing and saving..." : "Saving..."); pkg.Save(outputPath, compress); Console.WriteLine("\nPackage saved to " + outputPath.Replace('\\', '/')); Console.ResetColor(); }