Пример #1
0
        public BuildCommand(string name, string description = null) : base(name, description)
        {
            AddArgument(new Argument <FileInfo>("project", null)
            {
                Description = "A project file to use."
            });

            Handler = CommandHandler.Create((ParseResult parseResult, IConsole console) =>
            {
                var project = parseResult.ValueForOption <FileInfo>("project");

                if (project == null)
                {
                    project = FindFileOfType(".bproj");
                }
                var importPipeline = new ImportPipeline();

                var projectExplorer = ProjectExplorer.Load(project.DirectoryName, importPipeline);

                string exportDirectory = "./bin/";
                Directory.CreateDirectory(exportDirectory);

                var consoleRenderer = new BuildConsoleRenderer();

                var buildPipeline = new BuildPipeline()
                {
                    BuildActions = new List <IBuildAction>()
                    {
                        consoleRenderer
                    }
                };
                consoleRenderer.DrawProgressBar(32);
                projectExplorer.Export(buildPipeline, exportDirectory);
            });
        }
Пример #2
0
        public void ModifyNameAndVersion()
        {
            var createExplorer = ProjectExplorer.CreateProject(FileName("project"), new ImportPipeline());

            createExplorer.Definition.Properties.Name    = "TestName1";
            createExplorer.Definition.Properties.Version = "1.0.0";

            createExplorer.Definition.SaveChanges();

            var loadExplorer = ProjectExplorer.Load(FileName("project"), new ImportPipeline());

            Assert.That(loadExplorer.Definition.Properties.Name, Is.EqualTo("TestName1"));
            Assert.That(loadExplorer.Definition.Properties.Version, Is.EqualTo("1.0.0"));

            loadExplorer.Export(new BuildPipeline()
            {
                ImportPipeline = new ImportPipeline(),
            }, FileName("export"));

            var packageImport = PackageExplorer.Load(
                Path.Combine(FileName("export"), "TestName1.bpkg"));

            Assert.That(packageImport.Definition.Properties.Name, Is.EqualTo("TestName1"));
            Assert.That(packageImport.Definition.Properties.Version, Is.EqualTo("1.0.0"));
        }
Пример #3
0
        public void ModifyNameAndVersion()
        {
            var importPipeline = ImportPipeline.Create().Build();

            var createExplorer = ProjectExplorer.CreateProject(FileName("project"), importPipeline);

            createExplorer.Definition.Properties.Name    = "TestName1";
            createExplorer.Definition.Properties.Version = "1.0.0";

            createExplorer.Definition.SaveChanges();

            var loadExplorer = ProjectExplorer.Load(FileName("project"), importPipeline);

            Assert.That(loadExplorer.Definition.Properties.Name, Is.EqualTo("TestName1"));
            Assert.That(loadExplorer.Definition.Properties.Version, Is.EqualTo("1.0.0"));

            loadExplorer.ExportZippedToDirectory(new BuildPipeline()
            {
                ImportPipeline = importPipeline,
            }, FileName("export"));

            var packageImport = PackageExplorer.LoadFromFileAsync(
                Path.Combine(FileName("export"), "TestName1.bpkg")).Result;

            Assert.That(packageImport.Definition.Properties.Name, Is.EqualTo("TestName1"));
            Assert.That(packageImport.Definition.Properties.Version, Is.EqualTo("1.0.0"));
        }
Пример #4
0
        public void ModifyVersion()
        {
            var    importPipeline = ImportPipeline.Create().Build();
            string projectPath    = TestUtilities.CreateFilePath("project");
            string exportPath     = Path.Combine(TestUtilities.CreateFilePath("export"), "project.bpkg");

            using (var explorer = ProjectExplorer.CreateProject(projectPath, importPipeline))
            {
                explorer.Definition.Properties.Version = "1.0.0";
                explorer.Definition.SaveChanges();
            }

            using (var explorer = ProjectExplorer.Load(projectPath, importPipeline))
            {
                Assert.That(explorer.Definition.Properties.Version, Is.EqualTo("1.0.0"));

                explorer.ExportZippedToDirectory(new BuildPipeline()
                {
                    ImportPipeline = importPipeline,
                }, TestUtilities.CreateFilePath("export"));
            }

            using (var explorer = PackageExplorer.LoadFromFileAsync(exportPath).Result)
            {
                Assert.That(explorer.Definition.Properties.Version, Is.EqualTo("1.0.0"));
            }
        }
Пример #5
0
        public FormatCommand(string name, string description = null) : base(name, description)
        {
            AddArgument(new Argument <FileInfo>("project", null)
            {
                Description = "A project file to use."
            });

            Handler = CommandHandler.Create((ParseResult parseResult, IConsole console) =>
            {
                var project = parseResult.ValueForOption <FileInfo>("project");

                if (project == null)
                {
                    project = FindFileOfType(".bproj");
                }
                var importPipeline = new ImportPipeline();

                var projectExplorer = ProjectExplorer.Load(project.DirectoryName, importPipeline);

                projectExplorer.Definition.SaveChanges();
            });
        }
Пример #6
0
        public void Start()
        {
            var nodes = NodeManifest.Construct(
                new Type[] {
                typeof(AddNode),
                typeof(RollNode),
                typeof(OutputValueNode),
                typeof(ItemInputNode),
                typeof(GetStatNode),
                typeof(IterateNode),
            }
                );
            var types = TypeManifest.ConstructBaseTypes();

            var manifest = new BehaviourManifest()
            {
                Nodes = nodes,
                Types = types
            };

            File.WriteAllText("Content/RPGCoreMath.bmfst", manifest.ToString());

            Console.WriteLine("Importing Graph...");

            var proj = ProjectExplorer.Load("Content/Tutorial");

            Console.WriteLine(proj.Name);
            Console.WriteLine("\t\"" + proj.Name + "\"");
            foreach (var resource in ((IPackageExplorer)proj).Resources)
            {
                Console.WriteLine("\t" + resource.FullName);
            }

            var editorTargetResource = proj.Resources["Tutorial Gamerules/Main.bhvr"];
            var editorTargetData     = editorTargetResource.LoadStream();

            JObject editorTarget;

            var serializer = new JsonSerializer();

            using (var sr = new StreamReader(editorTargetData))
                using (var reader = new JsonTextReader(sr))
                {
                    editorTarget = JObject.Load(reader);
                }

            var editor = new EditorSession(manifest, editorTarget, "SerializedGraph", serializer);

            foreach (var node in editor.Root["Nodes"])
            {
                var nodeData = node["Data"];

                foreach (var field in nodeData)
                {
                    Console.WriteLine($"{field}");
                    if (field.Name == "MaxValue")
                    {
                        field.SetValue(field.GetValue <int> () + 10);
                        field.ApplyModifiedProperties();

                        field.SetValue(field.GetValue <int> ());
                        field.ApplyModifiedProperties();
                    }
                    else if (field.Name == "ValueB")
                    {
                        Console.WriteLine(field.GetValue <LocalPropertyId> ());
                    }
                }
            }

            using (var file = editorTargetResource.WriteStream())
                using (var jsonWriter = new JsonTextWriter(file)
                {
                    Formatting = Formatting.Indented
                })
                {
                    serializer.Serialize(jsonWriter, editorTarget);
                }

            Console.WriteLine(new DirectoryInfo("Content/Temp").FullName);

            var consoleRenderer = new BuildConsoleRenderer();

            var buildPipeline = new BuildPipeline()
            {
                Exporters = new List <ResourceExporter> ()
                {
                    new BhvrExporter()
                },
                BuildActions = new List <IBuildAction> ()
                {
                    consoleRenderer
                }
            };

            consoleRenderer.DrawProgressBar(32);
            proj.Export(buildPipeline, "Content/Temp");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.Load("Content/Temp/Core.bpkg");

            var fireballAsset = exportedPackage.Resources["Fireball/Main.bhvr"];
            var data          = fireballAsset.LoadStream();

            SerializedGraph packageItem;

            using (var sr = new StreamReader(data))
                using (var reader = new JsonTextReader(sr))
                {
                    packageItem = serializer.Deserialize <SerializedGraph> (reader);
                }

            Console.WriteLine("Imported: " + packageItem.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new DemoPlayer();

            IGraphInstance instancedItem = unpackedGraph.Create();

            instancedItem.Setup();
            instancedItem.SetInput(player);
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 10;
            }
            instancedItem.Remove();

            var    packedInstance  = ((GraphInstance)instancedItem).Pack();
            string serializedGraph = packedInstance.AsJson();

            Console.WriteLine(serializedGraph);

            var deserialized     = JsonConvert.DeserializeObject <SerializedGraphInstance> (serializedGraph);
            var unpackedInstance = deserialized.Unpack(unpackedGraph);

            unpackedInstance.SetInput(player);
            unpackedInstance.Setup();
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            unpackedInstance.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }
Пример #7
0
        public void Start()
        {
            var nodes = NodeManifest.Construct(new Type[] { typeof(AddNode), typeof(RollNode) });
            var types = TypeManifest.ConstructBaseTypes();

            var manifest = new BehaviourManifest()
            {
                Nodes = nodes,
                Types = types
            };

            File.WriteAllText("Content/RPGCoreMath.bmfst", manifest.ToString());

            Console.WriteLine("Importing Graph...");

            var proj = ProjectExplorer.Load("Content/Tutorial");

            Console.WriteLine(proj.Name);
            Console.WriteLine("\t\"" + proj.Name + "\"");
            foreach (var resource in ((IPackageExplorer)proj).Resources)
            {
                Console.WriteLine("\t" + resource.FullName);
            }

            var editorTargetResource = proj.Resources["Tutorial Gamerules/Main.bhvr"];
            var editorTargetData     = editorTargetResource.LoadStream();

            JObject editorTarget;

            var serializer = new JsonSerializer();

            using (var sr = new StreamReader(editorTargetData))
                using (var reader = new JsonTextReader(sr))
                {
                    editorTarget = JObject.Load(reader);
                }

            //var editNode = editorTarget.Nodes.First ();

            var editor = new EditorSession(manifest, editorTarget, "SerializedGraph");

            /*foreach (var field in editor.Root)
             * {
             *      Console.WriteLine ($"{field.Name}: {field.Json} ({field.Field.Type})");
             *      if (field.Name == "MaxValue")
             *      {
             *              var newObject = JToken.FromObject (field.Json.ToObject<int> () + 10);
             *              field.Json.Replace (newObject);
             *      }
             * }*/

            using (var file = editorTargetResource.WriteStream())
            {
                serializer.Serialize(new JsonTextWriter(file)
                {
                    Formatting = Formatting.Indented
                }, editorTarget);
            }


            Console.WriteLine(new DirectoryInfo("Content/Temp").FullName);

            var consoleRenderer = new BuildConsoleRenderer();

            var buildPipeline = new BuildPipeline()
            {
                Exporters = new List <ResourceExporter> ()
                {
                    new BhvrExporter()
                },
                BuildActions = new List <IBuildAction> ()
                {
                    consoleRenderer
                }
            };

            consoleRenderer.DrawProgressBar(32);
            proj.Export(buildPipeline, "Content/Temp");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.Load("Content/Temp/Core.bpkg");

            var fireballAsset = exportedPackage.Resources["Fireball/Main.bhvr"];
            var data          = fireballAsset.LoadStream();

            SerializedGraph packageItem;

            using (var sr = new StreamReader(data))
                using (var reader = new JsonTextReader(sr))
                {
                    packageItem = serializer.Deserialize <SerializedGraph> (reader);
                }

            Console.WriteLine("Imported: " + packageItem.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new Actor();

            IBehaviour instancedItem = unpackedGraph.Setup(player);

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            instancedItem.Remove();

            var    packedInstance  = ((GraphInstance)instancedItem).Pack();
            string serializedGraph = packedInstance.AsJson();

            Console.WriteLine(serializedGraph);

            var deserialized     = JsonConvert.DeserializeObject <SerializedGraphInstance> (serializedGraph);
            var unpackedInstance = deserialized.Unpack(unpackedGraph);

            unpackedInstance.Setup(player);
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            unpackedInstance.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }
Пример #8
0
        public static void Run()
        {
            var manifest = BehaviourManifest.CreateFromAppDomain(AppDomain.CurrentDomain);

            File.WriteAllText("Content/RPGCoreMath.bmfst", manifest.ToString());

            Console.WriteLine("Importing Graph...");

            var importPipeline = ImportPipeline.Create().Build();

            var proj = ProjectExplorer.Load("Content/Core", importPipeline);

            Console.WriteLine(proj.Definition.Properties.Name);
            Console.WriteLine($"\t\"{proj.Definition.Properties.Name}\"");
            foreach (var resource in ((IExplorer)proj).Resources)
            {
                Console.WriteLine($"\t{resource.FullName}");
            }

            var editorTargetResource = proj.Resources["Fireball/Main.json"];
            var editorTargetData     = editorTargetResource.Content.LoadStream();

            JObject editorTarget;

            var serializer = new JsonSerializer();

            using (var sr = new StreamReader(editorTargetData))
                using (var reader = new JsonTextReader(sr))
                {
                    editorTarget = JObject.Load(reader);
                }

            var editor = new EditorSession(manifest, editorTarget, "SerializedGraph", serializer);

            foreach (var node in (editor.Root.Fields["Nodes"].Value as EditorObject).Fields.Values)
            {
                var nodeData = (node.Value as EditorObject).Fields["Data"];

                foreach (var field in (nodeData.Value as EditorObject).Fields.Values)
                {
                    var editableValue = field.Value as EditorValue;

                    Console.WriteLine($"{field}");
                    if (field.Field.Name == "MaxValue")
                    {
                        editableValue.SetValue(editableValue.GetValue <int>() + 10);
                        editableValue.ApplyModifiedProperties();

                        editableValue.SetValue(editableValue.GetValue <int>());
                        editableValue.ApplyModifiedProperties();
                    }
                    else if (field.Field.Name == "ValueB")
                    {
                        Console.WriteLine(editableValue.GetValue <LocalPropertyId>());
                    }
                }
            }

            using (var file = editorTargetResource.Content.OpenWrite())
                using (var sr = new StreamWriter(file))
                    using (var jsonWriter = new JsonTextWriter(sr)
                    {
                        Formatting = Formatting.Indented
                    })
                    {
                        serializer.Serialize(jsonWriter, editorTarget);
                    }

            Console.WriteLine(new DirectoryInfo("Content/Temp").FullName);

            var consoleRenderer = new BuildConsoleRenderer();

            var buildPipeline = new BuildPipeline();

            buildPipeline.Exporters.Add(new BhvrExporter());
            buildPipeline.BuildActions.Add(consoleRenderer);

            consoleRenderer.DrawProgressBar(32);
            proj.ExportZippedToDirectory(buildPipeline, "Content/Temp");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.LoadFromFileAsync("Content/Temp/Core.bpkg").Result;

            var fireballAsset = exportedPackage.Resources["Fireball/Main.json"];
            var data          = fireballAsset.Content.LoadStream();

            SerializedGraph packageItem;

            using (var sr = new StreamReader(data))
                using (var reader = new JsonTextReader(sr))
                {
                    packageItem = serializer.Deserialize <SerializedGraph>(reader);
                }

            Console.WriteLine("Imported: " + fireballAsset.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new DemoPlayer();

            IGraphInstance instancedItem = unpackedGraph.Create();

            instancedItem.Setup();
            instancedItem.SetInput(player);
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 10;
            }
            instancedItem.Remove();

            var settings = new JsonSerializerSettings();

            settings.Converters.Add(new LocalIdJsonConverter());
            settings.Converters.Add(new SerializedGraphInstanceProxyConverter(null));

            string serializedGraph = JsonConvert.SerializeObject(instancedItem, settings);

            // var packedInstance = ((GraphInstance)instancedItem).Pack ();
            // string serializedGraph = packedInstance.AsJson ();
            Console.WriteLine(serializedGraph);

            var deserialized     = JsonConvert.DeserializeObject <SerializedGraphInstance>(serializedGraph);
            var unpackedInstance = deserialized.Unpack(unpackedGraph);

            unpackedInstance.SetInput(player);
            unpackedInstance.Setup();
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            unpackedInstance.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }
Пример #9
0
        public void Start()
        {
            // Import the project
            var importPipeline = new ImportPipeline();

            importPipeline.ImportProcessors.Add(new BoardGameResourceImporter());
            var projectExplorer = ProjectExplorer.Load("Content/BoardGame", importPipeline);

            // Build the project to a package.
            var consoleRenderer = new BuildConsoleRenderer();

            var buildPipeline = new BuildPipeline();

            buildPipeline.Exporters.Add(new BhvrExporter());
            buildPipeline.BuildActions.Add(consoleRenderer);

            consoleRenderer.DrawProgressBar(32);
            projectExplorer.Export(buildPipeline, "BoardGame/Temp");
            Console.WriteLine("Exported package...");

            Step();

            var gameServer = new GameServer();

            gameServer.StartHosting(projectExplorer);

            var playerA = LocalId.NewShortId();
            var playerB = LocalId.NewShortId();

            gameServer.OnClientConnected(playerA, "Player A");
            gameServer.OnClientConnected(playerB, "Player B");
            DrawGameState(gameServer.Lobby);
            Step();

            gameServer.AcceptInput(playerA, new StartGameCommand()
            {
            });
            DrawGameState(gameServer.Lobby);
            Step();

            gameServer.AcceptInput(playerA, new DeclareResourceCommand()
            {
                ResourceIdentifier = "x"
            });
            DrawGameState(gameServer.Lobby);
            Step();

            gameServer.AcceptInput(playerA, new PlaceResourceCommand()
            {
                ResourceIdentifier = "x",
                ResourcePosition   = new Integer2(2, 2)
            });
            DrawGameState(gameServer.Lobby);
            Step();

            gameServer.AcceptInput(playerB, new PlaceResourceCommand()
            {
                ResourceIdentifier = "x",
                ResourcePosition   = new Integer2(3, 1)
            });
            DrawGameState(gameServer.Lobby);
            Step();

            gameServer.AcceptInput(playerB, new EndTurnCommand());
            DrawGameState(gameServer.Lobby);
        }
Пример #10
0
        public void Start()
        {
            var nodes = NodeManifest.Construct(new Type[] { typeof(StatsNode), typeof(RollNode) });
            var types = TypeManifest.ConstructBaseTypes();

            var manifest = new BehaviourManifest()
            {
                Nodes = nodes,
                Types = types
            };

            File.WriteAllText("Content/RPGCoreMath.bmfst", manifest.ToString());

            Console.WriteLine("Importing Graph...");

            var proj = ProjectExplorer.Load("Content/Tutorial");

            Console.WriteLine(proj.Name);
            Console.WriteLine("\t\"" + proj.Name + "\"");
            foreach (var asset in proj.Assets)
            {
                Console.WriteLine("\t" + asset.Archive.Name);
                foreach (var resource in asset.ProjectResources)
                {
                    Console.WriteLine("\t\t" + resource);
                }
            }

            proj.Export("Content/Temp");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.Load("Content/Temp/Core.bpkg");

            foreach (var asset in exportedPackage.Assets)
            {
                Console.WriteLine(asset.Root);
                foreach (var resource in asset.PackageResources)
                {
                    Console.WriteLine("\t" + resource.ToString());
                }
            }

            var fireballAsset = exportedPackage.Assets["Fireball"];
            var data          = fireballAsset.GetResource("Main.bhvr").LoadStream();

            SerializedGraph packageItem;

            using (var sr = new StreamReader(data))
                using (var reader = new JsonTextReader(sr))
                {
                    var serializer = new JsonSerializer();
                    packageItem = serializer.Deserialize <SerializedGraph>(reader);
                }

            Console.WriteLine("Imported: " + packageItem.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new Actor();

            IBehaviour instancedItem = unpackedGraph.Setup(player);

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            instancedItem.Remove();

            var    packedInstance  = ((GraphInstance)instancedItem).Pack();
            string serializedGraph = packedInstance.AsJson();

            Console.WriteLine(serializedGraph);

            var deserialized     = JsonConvert.DeserializeObject <SerializedGraphInstance>(serializedGraph);
            var unpackedInstance = deserialized.Unpack(unpackedGraph);

            unpackedInstance.Setup(player);
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            unpackedInstance.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }
Пример #11
0
        public void Start()
        {
            var serializer = new JsonSerializer();

            Console.WriteLine("Importing Graph...");

            var importPipeline = ImportPipeline.Create()
                                 .UseProcessor(new TagAllProjectResourceImporter())
                                 .Build();

            var projectExplorer = ProjectExplorer.Load("Content/Core", importPipeline);

            Console.WriteLine("Building project files...");
            RenderDirectory(projectExplorer.Archive.RootDirectory);

            var consoleRenderer = new BuildConsoleRenderer();

            var buildPipeline = new BuildPipeline();

            buildPipeline.BuildActions.Add(consoleRenderer);

            consoleRenderer.DrawProgressBar(32);
            projectExplorer.ExportZippedToDirectory(buildPipeline, "Content/Temp");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.LoadFromFileAsync("Content/Temp/Core.bpkg").Result;

            RenderDirectory(exportedPackage.Source);

            var fireballAsset = exportedPackage.Resources["Fireball/Main.json"];
            var data          = fireballAsset.Content.OpenRead();

            SerializedGraph packageItem;

            using (var sr = new StreamReader(data))
                using (var reader = new JsonTextReader(sr))
                {
                    packageItem = serializer.Deserialize <SerializedGraph>(reader);
                }

            Console.WriteLine("Imported: " + fireballAsset.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new DemoPlayer();

            IGraphInstance instancedItem = unpackedGraph.Create();

            instancedItem.Setup();
            instancedItem.SetInput(player);
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 10;
            }
            instancedItem.Remove();

            var settings = new JsonSerializerSettings();

            settings.Converters.Add(new LocalIdJsonConverter());
            settings.Converters.Add(new SerializedGraphInstanceProxyConverter(null));

            string serializedGraph = JsonConvert.SerializeObject(instancedItem, settings);

            Console.WriteLine(serializedGraph);

            var deserialized     = JsonConvert.DeserializeObject <SerializedGraphInstance>(serializedGraph);
            var unpackedInstance = deserialized.Unpack(unpackedGraph);

            unpackedInstance.SetInput(player);
            unpackedInstance.Setup();
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            unpackedInstance.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }
Пример #12
0
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                var versionString = Assembly.GetEntryAssembly()
                                    .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                    .InformationalVersion
                                    .ToString();

                Console.WriteLine($"bpack v{versionString}");
                Console.WriteLine("Usage:");
                Console.WriteLine("  bpack build [path]");
                Console.WriteLine("    Builds the .bproj at the active directory.");
                return((int)ExitCode.Success);
            }

            string command    = args[0];
            string subCommand = args.Length > 1 ? args[1] : "";

            if (command.Equals("build", StringComparison.InvariantCultureIgnoreCase))
            {
                FileInfo file;
                if (subCommand == "")
                {
                    file = FindFileOfType(".bproj");
                }
                else
                {
                    file = new FileInfo(subCommand);
                }

                var project = ProjectExplorer.Load(file.DirectoryName);

                string exportDirectory = "./bin/";
                Directory.CreateDirectory(exportDirectory);

                project.Export(exportDirectory);
            }
            else if (command.Equals("format", StringComparison.InvariantCultureIgnoreCase))
            {
                if (subCommand == "all")
                {
                    var files = FindFilesOfType(".csproj");

                    foreach (var file in files)
                    {
                        var projectFile = XmlProjectFile.Load(file.FullName);

                        projectFile.Format();

                        projectFile.Save(file.FullName);
                    }
                }
                else
                {
                    var file = FindFileOfType(".bproj");
                    if (file != null)
                    {
                        var project = ProjectExplorer.Load(file.DirectoryName);

                        project.Definition.Format();

                        project.Definition.Save(file.FullName);
                    }
                    else
                    {
                        file = FindFileOfType(".csproj");

                        var projectFile = XmlProjectFile.Load(file.FullName);

                        projectFile.Format();

                        projectFile.Save(file.FullName);
                    }
                }
            }

            return((int)ExitCode.Success);
        }
Пример #13
0
        public void Start()
        {
            IntEventField left  = new IntEventField(1);
            IntEventField right = new IntEventField(3);

            left += (int newValue) =>
            {
                Console.WriteLine("New Value: " + newValue);
            };

            left.Value += 5;

            Console.WriteLine($"{left.Value} + {right.Value} = " + (left + right).Calculate());

            IntEventField one = new IntEventField(1);

            IntEventField test = new IntEventField(left + right + one);

            left.Value++;
            right.Value++;

            Console.WriteLine($"{left.Value} + {right.Value} + {one.Value} = " + test.Value);


            var nodes = NodeManifest.Construct(new Type[] { typeof(StatsNode), typeof(RollNode) });
            var types = TypeManifest.ConstructBaseTypes();

            var manifest = new BehaviourManifest()
            {
                Nodes = nodes,
                Types = types
            };

            File.WriteAllText("Content/RPGCoreMath.bmfst", manifest.ToString());

            Console.WriteLine("Importing Graph...");

            var proj = ProjectExplorer.Load("Content/Core");

            Console.WriteLine(proj.Name);
            Console.WriteLine("\t\"" + proj.Name + "\"");
            foreach (var asset in proj.Assets)
            {
                Console.WriteLine("\t" + asset.Archive.Name);
                foreach (var resource in asset.Resources)
                {
                    Console.WriteLine("\t\t" + resource);
                }
            }

            proj.Export("Content/Core.bpkg");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.Load("Content/Core.bpkg");

            foreach (var asset in exportedPackage.Assets)
            {
                Console.WriteLine(asset.Root);
                foreach (var resource in asset.Resources)
                {
                    Console.WriteLine("\t" + resource.ToString());
                }
            }

            var packageItem = JsonConvert.DeserializeObject <PackageBehaviour> (File.ReadAllText("Content/Core/Longsword/Main.bhvr"));

            Console.WriteLine("Imported: " + packageItem.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new Actor();

            IBehaviour instancedItem = unpackedGraph.Setup(player);

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            instancedItem.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }
Пример #14
0
        public async Task StartAsync()
        {
            // Import the project
            var importPipeline = ImportPipeline.Create()
                                 .UseImporter(new BoardGameResourceImporter())
                                 .UseJsonMetaFiles(options =>
            {
                options.IsMetaFilesOptional = true;
            })
                                 .Build();

            var projectExplorer = ProjectExplorer.Load("Content/BoardGame", importPipeline);

            // Build the project to a package.
            var consoleRenderer = new BuildConsoleRenderer();

            var buildPipeline = new BuildPipeline();

            buildPipeline.BuildActions.Add(consoleRenderer);

            consoleRenderer.DrawProgressBar(32);

            projectExplorer.ExportZippedToDirectory(buildPipeline, "BoardGame/Temp");
            var packageExplorer = PackageExplorer.LoadFromFileAsync("BoardGame/Temp/BoardGame.bpkg").Result;

            var dest = new FileSystemArchive(new DirectoryInfo("BoardGame/Temp"));
            await packageExplorer.Source.CopyIntoAsync(dest.RootDirectory, "Fast");

            var cottage = packageExplorer.Resources["buildings/cottage.json"];

            foreach (var dep in cottage.Dependencies)
            {
                Console.WriteLine($"{dep.Key}: {dep.Resource?.Name}");
            }

            Step();

            var gameServer = new GameServer();

            gameServer.StartHosting(projectExplorer);

            var playerA = LocalId.NewShortId();
            var playerB = LocalId.NewShortId();

            gameServer.OnClientConnected(playerA, "Player A");
            gameServer.OnClientConnected(playerB, "Player B");
            DrawGameState(gameServer.Lobby);
            Step();

            gameServer.AcceptInput(playerA, new StartGameCommand()
            {
            });
            DrawGameState(gameServer.Lobby);
            Step();

            gameServer.AcceptInput(playerA, new DeclareResourceCommand()
            {
                ResourceIdentifier = "x"
            });
            DrawGameState(gameServer.Lobby);
            Step();

            gameServer.AcceptInput(playerA, new PlaceResourceCommand()
            {
                ResourceIdentifier = "x",
                ResourcePosition   = new Integer2(2, 2)
            });
            DrawGameState(gameServer.Lobby);
            Step();

            gameServer.AcceptInput(playerB, new PlaceResourceCommand()
            {
                ResourceIdentifier = "x",
                ResourcePosition   = new Integer2(3, 1)
            });
            DrawGameState(gameServer.Lobby);
            Step();



            gameServer.AcceptInput(playerA, new BuildBuildingCommand()
            {
                BuildingIdentifier = "cottage",
                BuildingPosition   = new Integer2(1, 1),
                Offset             = new Integer2(1, 1),
            });
            DrawGameState(gameServer.Lobby);
            Step();


            gameServer.AcceptInput(playerB, new EndTurnCommand());
            DrawGameState(gameServer.Lobby);
        }