Exemplo n.º 1
0
        public void ExportGame()
        {
            var builder = new PackageBuilder()
            {
                Id          = Game.Id.ToString(),
                Description = Game.Description,
                ProjectUrl  = new Uri(Game.GameUrl),
                Version     = new NuGetVersion(Game.Version),
                Title       = Game.Name,
                IconUrl     = new Uri(Game.IconUrl),
            };

            foreach (var a in Game.Authors)
            {
                builder.Authors.Add(a);
            }
            foreach (var t in Game.Tags)
            {
                builder.Authors.Add(t);
            }

            var g = new GameSerializer();

            g.Serialize(Game);


            var feedPath   = Path.Combine(GamePath, Game.Name + '-' + Game.Version + ".nupkg");
            var filestream = File.Open(feedPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);

            builder.Save(filestream);
            filestream.Flush(true);
            filestream.Close();
        }
Exemplo n.º 2
0
        public void GameCanBeSerializedAndDeserialized()
        {
            var gs = new GameSerializer();
            var h  = new GameHistory(new[] { BoardState.ClassicInitialState }, Array.Empty <Turn>());

            string s = gs.Serialize(h, Color.White);

            Assert.Contains("King", s);
            Assert.Contains("White", s);

            var(dh, _) = gs.Deserialize(s);

            Assert.Equal((Figure.Pawn, Color.White), dh.States.Single()[Cell.At('E', 2)]);
        }
Exemplo n.º 3
0
        public bool SerializeXmlAssets()
        {
            try
            {
                var gameTempPath = Path.Combine(ViewModelLocator.AssetsTabViewModel.AssetTempDirectory.FullName, Guid.NewGuid().ToString() + ".xml");

                var gameSerializer = new GameSerializer();
                gameSerializer.OutputPath = gameTempPath;
                gameSerializer.Serialize(Game);
                Asset.SelectedAsset.SafeFile = new FileInfo(gameTempPath);

                var setSerializer = new SetSerializer()
                {
                    Game = Game
                };
                foreach (SetModel set in ViewModelLocator.SetTabViewModel.Items)
                {
                    var setTempPath = Path.Combine(ViewModelLocator.AssetsTabViewModel.AssetTempDirectory.FullName, Guid.NewGuid().ToString() + ".xml");
                    setSerializer.OutputPath = setTempPath;
                    setSerializer.Serialize(set._set);
                    set.Asset.SelectedAsset.SafeFile = new FileInfo(setTempPath);
                }
                var scriptSerializer = new GameScriptSerializer(Game.Id)
                {
                    Game = Game
                };
                foreach (ScriptItemModel script in ViewModelLocator.ScriptsTabViewModel.Scripts)
                {
                    scriptSerializer.OutputPath = script.Asset.SafePath;
                    scriptSerializer.Serialize(script._script);
                }

                var proxyTempPath = Path.Combine(ViewModelLocator.AssetsTabViewModel.AssetTempDirectory.FullName, Guid.NewGuid().ToString() + ".xml");

                var proxySerializer = new ProxyGeneratorSerializer(Game.Id)
                {
                    Game = Game
                };
                proxySerializer.OutputPath = proxyTempPath;
                proxySerializer.Serialize(ViewModelLocator.ProxyTabViewModel._proxydef);
                ViewModelLocator.ProxyTabViewModel.Asset.SelectedAsset.SafeFile = new FileInfo(proxyTempPath);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        private async Task ConfigureTemplate(string plugin_directory)
        {
            StatusText.Text = "Configuring Template...";

            var def_path = Path.Combine(plugin_directory, "definition.xml");

            // Correct anything making it unreadable by the serializer
            await Task.Run(() => {
                var def_contents = File.ReadAllText(def_path);

                var empty_guid = Guid.Empty.ToString().ToUpper();
                def_contents   = def_contents.Replace("SAMPLEID-GUID-0000-0000-00000000GAME", empty_guid);

                File.WriteAllText(def_path, def_contents);
            });

            var serializer = new GameSerializer();

            var game = await Task.Run(() => (Game)serializer.Deserialize(def_path));

            game.Id               = Guid.Parse(Game.Id);
            game.Name             = Game.Name;
            game.Description      = Game.Description;
            game.Authors          = Game.Authors.Split(',').ToList();
            game.GameUrl          = Game.Url;
            game.IconUrl          = Game.ImageUrl;
            game.UseTwoSidedTable = Game.IsDualSided;
            game.Version          = new Version(Game.Version);

            await Task.Run(() => {
                var game_bytes = serializer.Serialize(game);

                File.WriteAllBytes(def_path, game_bytes);
            });

            // Correcting set.xml
            var set_path = Path.Combine(plugin_directory, "Sets", "Base-Set", "set.xml");
            await Task.Run(() => {
                var set_contents = File.ReadAllText(set_path);

                set_contents = set_contents.Replace("SAMPLEID-GUID-0000-0000-00000000GAME", game.Id.ToString().ToUpper());
                set_contents = set_contents.Replace("SAMPLEID-GUID-0000-0000-000000000SET", Guid.NewGuid().ToString().ToUpper());
                set_contents = set_contents.Replace("SAMPLEID-GUID-0000-0000-0000000CARD1", Guid.NewGuid().ToString().ToUpper());

                File.WriteAllText(set_path, set_contents);
            });
        }
Exemplo n.º 5
0
        public void SaveGame(string name = "Quick")
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var path = $"{Application.persistentDataPath}/Saved Games/{name}.sav";

            try {
                ITypeModelBuilder builder = new AttributeBasedTypeModelBuilder();
                var      serializer       = new GameSerializer(GetPrefabs(), builder);
                SaveGame saveGame         = SaveGamePacker.PackSaveGame(GetSavables(), builder.GetSavableMonobehaviours());

                using (var stream = new FileStream(path, FileMode.Create)) {
                    serializer.Serialize(stream, saveGame);
                }
            }
            catch (Exception e) {
                Debug.Log(e);
            }
        }
        private SaveGame SerializeAndUnserialize(SaveGame saveGame, ITypeModelBuilder builder, IEnumerable <GameObject> prefabs)
        {
            var serializer = new GameSerializer(prefabs, builder);

            byte[] output;
            using (var s = new MemoryStream()) {
                serializer.Serialize(s, saveGame);
                output = s.ToArray();
            }

            foreach (var gameObject in saveGame.GameObjects)
            {
                Object.DestroyImmediate(gameObject);
            }

            SaveGame deserialized;

            using (var s = new MemoryStream(output)) {
                deserialized = serializer.Deserialize <SaveGame>(s);
            }

            Assert.NotNull(deserialized);
            return(deserialized);
        }
Exemplo n.º 7
0
    public void DoTest1()
    {
        var message = GameSerializer.Serialize(Game.game);

        System.IO.File.WriteAllText("C:/Users/sampp/Desktop/output.json", message);
    }
Exemplo n.º 8
0
 public static void Save(string path)
 {
     GameSerializer.Serialize(player, path);
 }