Exemplo n.º 1
0
        public void LoadGame(FileInfo path)
        {
            NeedsSave = false;

            _workingDirectory = path.Directory;

            var files = WorkingDirectory.GetFiles("*.*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var asset = ViewModelLocator.AssetsTabViewModel.LoadAsset(file);
                if (file.FullName == path.FullName)
                {
                    // registers the game definition asset

                    var gameSerializer = new GameSerializer();
                    Game                   = (Game)gameSerializer.Deserialize(path.FullName);
                    Asset                  = new AssetController(AssetType.Xml);
                    asset.LockName         = true;
                    asset.IsReserved       = true;
                    Asset.SelectedAsset    = asset;
                    Asset.PropertyChanged += AssetUpdated;
                    {
                    };
                }
            }
        }
Exemplo n.º 2
0
        private Guid GetGameId()
        {
            var xmlPath = Details.Path;

            var serializer = new GameSerializer();

            var game = (Game)serializer.Deserialize(xmlPath);

            return(game.Id);
        }
Exemplo n.º 3
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.º 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 LoadGame(string name = "Quick")
        {
            GameObject oldRoot = GameController.Instance.gameObject;

            DestroyImmediate(oldRoot); // this is generally a bad idea, but it's necessary for our dependency injection to work

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

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

            if (string.IsNullOrEmpty(LoadIntoScene))
            {
                ITypeModelBuilder builder = new AttributeBasedTypeModelBuilder();
                var serializer            = new GameSerializer(GetPrefabs(), builder);

                using (var stream = new FileStream(path, FileMode.Open)) {
                    serializer.Deserialize <SaveGame>(stream);
                }

                GameObject newRoot = GameController.Instance.gameObject;
                IEnumerable <GameObject> prefabChildObjectsNotRestored = newRoot
                                                                         .GetComponentsInChildren <Savable>()
                                                                         .Where(savable => !savable.WasRestored)
                                                                         .Select(savable => savable.gameObject);

                foreach (var gameObject in prefabChildObjectsNotRestored)
                {
                    Destroy(gameObject);
                }

                // It is necessary to call this here even though GameController attempts to do injection because
                // the whole scene graph may not have been fully instantiated yet when GameController does the injection
                GameController.Instance.InjectAllObjects();
            }
            else
            {
                GameObject go         = new GameObject();
                var        transition = go.AddComponent <GameSceneTransitioner>();
                transition.InitLoadGame(name);
                SceneManager.LoadScene(LoadIntoScene);
            }
        }
        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 LoadGame(string filename)
        {
            var file           = new FileInfo(filename);
            var gameSerializer = new GameSerializer();
            var setSerializer  = new SetSerializer();

            try {
                Game     = (Game)gameSerializer.Deserialize(filename);
                GamePath = Game.InstallPath;

                /// Associate any <see cref="Octgn.DataNew.Entities.Set"/>s deserialized with this serializer with the <see cref="Octgn.DataNew.Entities.Game"/>
                /// we just deserialized
                setSerializer.Game = Game;

                Sets = file.Directory
                       .EnumerateFiles("set.xml", SearchOption.AllDirectories)
                       .Select(setFile => (Set)setSerializer.Deserialize(setFile.FullName))
                       .ToArray();
            } catch (Exception) {
                Game     = null;
                GamePath = string.Empty;
                Sets     = null;
            }
        }
Exemplo n.º 8
0
    public void DoTest2()
    {
        var json = System.IO.File.ReadAllText("C:/Users/sampp/Desktop/output.json");

        GameSerializer.Deserialize(json, Game.game);
    }
Exemplo n.º 9
0
 public static void Load(string path)
 {
     player = GameSerializer.Deserialize <Player>(path);
 }