Ejemplo n.º 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);
            });
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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;
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                string 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);

                var consoleRenderer = new BuildConsoleRenderer();

                var buildPipeline = new BuildPipeline()
                {
                    BuildActions = new List <IBuildAction> ()
                    {
                        consoleRenderer
                    }
                };
                consoleRenderer.DrawProgressBar(32);
                project.Export(buildPipeline, exportDirectory);
            }
            else if (command.Equals("format", StringComparison.InvariantCultureIgnoreCase))
            {
                if (subCommand == "all")
                {
                    var files = FindFilesOfType(".csproj", SearchOption.AllDirectories);

                    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);
        }