Example #1
0
        public void testSerializationAndDeserialization()
        {
            // set up board
            Board board = new Board(5, 5, 4);

            for (int i = 0; i < 4; i++)
            {
                board.SetBombState(i, 0, 0, true);
            }

            board.SetBombState(0, 0, 0, false);
            board.SetBombState(2, 2, 2, false);
            board[0, 1, 2].Highlighted = true;

            // serialize Board
            string json = GameSerializer.serialize(new GameRepresentation(board, new PlayerStats()));

            // deserialize again and check if the values are still the same
            GameRepresentation grep = GameSerializer.deserialize(json);

            Assert.AreEqual(grep.board[0, 1, 2].PosX, 0);
            Assert.AreEqual(grep.board[0, 1, 2].PosY, 1);
            Assert.AreEqual(grep.board[0, 1, 2].PosZ, 2);//
            Assert.AreEqual(grep.board[0, 0, 0].IsBomb, false, "huh...");
            Assert.AreEqual(grep.board[1, 0, 0].IsBomb, true, "hmm...");
            Assert.AreEqual(grep.board[2, 2, 2].IsBomb, false, "heh.");
            Assert.AreEqual(grep.board[0, 1, 2].Highlighted, true, "huh...");
        }
Example #2
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();
        }
    public GameObject Load(LevelResAsset lightmapAsset)
    {
        GameObject result = null;

        if (lightmapAsset != null)
        {
            if (!(lightmapAsset.levelDom != null))
            {
                return(null);
            }
            TextAsset         levelDom = lightmapAsset.levelDom;
            BinaryDomDocument document = new BinaryDomDocument(levelDom.bytes);
            result = GameSerializer.Load(document);
            int            num   = lightmapAsset.lightmapFar.Length;
            LightmapData[] array = new LightmapData[num];
            for (int i = 0; i < num; i++)
            {
                array[i] = new LightmapData
                {
                    lightmapFar  = lightmapAsset.lightmapFar[i],
                    lightmapNear = lightmapAsset.lightmapNear[i]
                };
            }
            LightmapSettings.lightmaps = array;
        }
        return(result);
    }
 private static void InitComponets(BinaryNode domNode, GameObject go)
 {
     Component[] components = go.GetComponents(typeof(Component));
     for (int i = 0; i < domNode.GetChildNum(); i++)
     {
         BinaryNode child = domNode.GetChild(i);
         if (!(child.GetName() != "Cop"))
         {
             string    nodeAttr = GameSerializer.GetNodeAttr(child, "Type");
             Component x        = null;
             for (int j = 0; j < components.Length; j++)
             {
                 if (!GameSerializer.isNull(components[j]))
                 {
                     string pureType = GameSerializer.GetPureType(components[j].GetType().ToString());
                     if (pureType.Equals(nodeAttr))
                     {
                         x = components[j];
                         break;
                     }
                 }
             }
             if (x == null)
             {
                 x = go.AddComponent(GameSerializer.GetType(nodeAttr));
             }
         }
     }
 }
Example #5
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;
                    {
                    };
                }
            }
        }
Example #6
0
    public void ObjectDeserialize(ref object o, BinaryNode node)
    {
        byte[]     binaryAttribute = GameSerializer.GetBinaryAttribute(node, "Value");
        Quaternion quaternion      = (Quaternion)o;

        UnityBasetypeSerializer.BytesToQuaternion(ref quaternion, binaryAttribute);
        o = quaternion;
    }
Example #7
0
    public void ObjectDeserialize(ref object o, BinaryNode node)
    {
        byte[] binaryAttribute = GameSerializer.GetBinaryAttribute(node, "Value");
        Rect   rect            = (Rect)o;

        UnityBasetypeSerializer.BytesToRect(ref rect, binaryAttribute);
        o = rect;
    }
Example #8
0
    public void ObjectDeserialize(ref object o, BinaryNode node)
    {
        byte[]    binaryAttribute = GameSerializer.GetBinaryAttribute(node, "Value");
        Matrix4x4 matrix          = (Matrix4x4)o;

        UnityBasetypeSerializer.BytesToMatrix4x4(ref matrix, binaryAttribute);
        o = matrix;
    }
Example #9
0
    public void ObjectDeserialize(ref object o, BinaryNode node)
    {
        byte[] binaryAttribute = GameSerializer.GetBinaryAttribute(node, "Value");
        Bounds bounds          = (Bounds)o;

        UnityBasetypeSerializer.BytesToBounds(ref bounds, binaryAttribute);
        o = bounds;
    }
    public void ComponentDeserialize(Component cmp, BinaryNode node)
    {
        SphereCollider sphereCollider = cmp as SphereCollider;

        sphereCollider.center    = UnityBasetypeSerializer.BytesToVector3(GameSerializer.GetBinaryAttribute(node, "center"));
        sphereCollider.radius    = UnityBasetypeSerializer.BytesToFloat(GameSerializer.GetBinaryAttribute(node, "radius"));
        sphereCollider.isTrigger = bool.Parse(GameSerializer.GetAttribute(node, "trigger"));
    }
Example #11
0
    public void ObjectDeserialize(ref object o, BinaryNode node)
    {
        byte[] binaryAttribute = GameSerializer.GetBinaryAttribute(node, "Value");
        Color  color           = (Color)o;

        UnityBasetypeSerializer.BytesToColor(ref color, binaryAttribute);
        o = color;
    }
    public void ComponentDeserialize(Component cmp, BinaryNode node)
    {
        BoxCollider collider = cmp as BoxCollider;

        collider.center    = UnityBasetypeSerializer.BytesToVector3(GameSerializer.GetBinaryAttribute(node, "center"));
        collider.size      = UnityBasetypeSerializer.BytesToVector3(GameSerializer.GetBinaryAttribute(node, "size"));
        collider.isTrigger = bool.Parse(GameSerializer.GetAttribute(node, "trigger"));
    }
Example #13
0
    public void ObjectDeserialize(ref object o, BinaryNode node)
    {
        byte[]  binaryAttribute = GameSerializer.GetBinaryAttribute(node, "Value");
        Vector2 vector          = default(Vector2);

        UnityBasetypeSerializer.BytesToVector2(ref vector, binaryAttribute);
        o = vector;
    }
Example #14
0
        public static void DeleteSave()
        {
            var path = GameSerializer.GetPath();

            if (File.Exists(path))
            {
                File.Delete(path);
            }
        }
    private static void LoadRecursionTwice(GameObject parentGo, BinaryNode domNode, GameObject go)
    {
        if (domNode == domNode.OwnerDocument.Root)
        {
            GameSerializer.LoadComponets(domNode, go);
            int num = -1;
            for (int i = 0; i < domNode.GetChildNum(); i++)
            {
                BinaryNode child = domNode.GetChild(i);
                if (child.GetName() == "CHD")
                {
                    num++;
                    GameObject gameObject = go.transform.GetChild(num).gameObject;
                    if (!(gameObject == null))
                    {
                        GameSerializer.LoadRecursionTwice(null, child, gameObject);
                    }
                }
            }
        }
        else
        {
            BinaryNode parentNode = domNode.ParentNode;
            for (int j = 0; j < parentNode.GetChildNum(); j++)
            {
                BinaryNode child2 = parentNode.GetChild(j);
                if (!(child2.GetName() != "CHD"))
                {
                    string attribute = GameSerializer.GetAttribute(child2, "ON");
                    if (!(attribute != go.name))
                    {
                        GameSerializer.LoadComponets(child2, go);
                        if (child2.GetChildNum() > 0 && go.transform.childCount > 0)
                        {
                            BinaryNode child3 = child2.GetChild(0);
                            for (int k = 0; k < go.transform.childCount; k++)
                            {
                                GameObject gameObject2 = go.transform.GetChild(k).gameObject;
                                GameSerializer.LoadRecursionTwice(null, child3, gameObject2);
                            }
                        }
                        domNode = child2;
                    }
                }
            }
        }
        string nodeAttr = GameSerializer.GetNodeAttr(domNode, "DIS");

        if (nodeAttr != null)
        {
            go.SetActive(false);
        }
        else
        {
            go.SetActive(true);
        }
    }
Example #16
0
    public void ComponentDeserialize(Component o, BinaryNode node)
    {
        AstarPath astarPath = (AstarPath)o;

        astarPath.astarData = new AstarData();
        astarPath.astarData.cacheStartup       = bool.Parse(GameSerializer.GetNodeAttr(node, this.XML_ATTR_CACHE_AT_START_UP));
        ((AstarPath)o).logPathResults          = PathLog.OnlyErrors;
        astarPath.astarData.data_cachedStartup = node.GetValue();
        astarPath.astarData.cacheStartup       = true;
    }
    public void ComponentDeserialize(Component cmp, BinaryNode node)
    {
        CapsuleCollider capsuleCollider = cmp as CapsuleCollider;

        capsuleCollider.center    = UnityBasetypeSerializer.BytesToVector3(GameSerializer.GetBinaryAttribute(node, "center"));
        capsuleCollider.radius    = UnityBasetypeSerializer.BytesToFloat(GameSerializer.GetBinaryAttribute(node, "radius"));
        capsuleCollider.height    = UnityBasetypeSerializer.BytesToFloat(GameSerializer.GetBinaryAttribute(node, "height"));
        capsuleCollider.direction = UnityBasetypeSerializer.BytesToInt(GameSerializer.GetBinaryAttribute(node, "dir"));
        capsuleCollider.isTrigger = bool.Parse(GameSerializer.GetAttribute(node, "trigger"));
    }
Example #18
0
    public void ObjectDeserialize(ref object o, BinaryNode node)
    {
        IList list     = (IList)o;
        int   childNum = node.GetChildNum();

        for (int i = 0; i < childNum; i++)
        {
            list.Add(GameSerializer.GetObject(node.GetChild(i)));
        }
    }
Example #19
0
        public void BuildPgn_TestVariousPositionsAndVariations(PgnFormatterVariationTestCase testCase)
        {
            Console.WriteLine(testCase.ExpectedPgn);
            var            expected = string.Format(testCase.ExpectedPgn, options.NewLineIndicator);
            GameSerializer gs       = new GameSerializer(new PGNFormatterOptions());
            var            actual   = gs.SerializeToString(testCase.Game);

            Console.WriteLine(actual);
            Assert.AreEqual(expected, actual, testCase.ToString());
        }
Example #20
0
        public SerializableGameViewModel([NotNull] GameConfig config)
        {
            Assert.IsNotNull(config);
            _serializer = new GameSerializer();
            var model = _serializer.TryLoad();

            ViewModel = GameViewModel.Create(config, model);
            Observable.Timer(TimeSpan.FromSeconds(30))
            .Subscribe(_ => Save());
        }
Example #21
0
        private Guid GetGameId()
        {
            var xmlPath = Details.Path;

            var serializer = new GameSerializer();

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

            return(game.Id);
        }
Example #22
0
    public void ComponentDeserialize(Component o, BinaryNode node)
    {
        RectTransform rectTransform = o as RectTransform;

        rectTransform.localScale    = new Vector3(float.Parse(GameSerializer.GetAttribute(node, "SX")), float.Parse(GameSerializer.GetAttribute(node, "SY")), float.Parse(GameSerializer.GetAttribute(node, "SZ")));
        rectTransform.localRotation = new Quaternion(float.Parse(GameSerializer.GetAttribute(node, "RX")), float.Parse(GameSerializer.GetAttribute(node, "RY")), float.Parse(GameSerializer.GetAttribute(node, "RZ")), float.Parse(GameSerializer.GetAttribute(node, "RW")));
        rectTransform.anchorMin     = new Vector2(float.Parse(GameSerializer.GetAttribute(node, "anchorMinX")), float.Parse(GameSerializer.GetAttribute(node, "anchorMinY")));
        rectTransform.anchorMax     = new Vector2(float.Parse(GameSerializer.GetAttribute(node, "anchorMaxX")), float.Parse(GameSerializer.GetAttribute(node, "anchorMaxY")));
        rectTransform.offsetMin     = new Vector2(float.Parse(GameSerializer.GetAttribute(node, "offsetMinX")), float.Parse(GameSerializer.GetAttribute(node, "offsetMinY")));
        rectTransform.offsetMax     = new Vector2(float.Parse(GameSerializer.GetAttribute(node, "offsetMaxX")), float.Parse(GameSerializer.GetAttribute(node, "offsetMaxY")));
    }
Example #23
0
        private void saveExecute()
        {
            string playerSaveFile            = Path.Combine(dataDir, "players.elo");
            List <PlayerSerializer> pSerials = PlayerSerializer.SerializeList(Players);

            Serializer <PlayerSerializer> .Save(pSerials, playerSaveFile);

            string gameSaveFile            = Path.Combine(dataDir, "games.elo");
            List <GameSerializer> gSerials = GameSerializer.SerializeList(History.GameHistory);

            Serializer <GameSerializer> .Save(gSerials, gameSaveFile);
        }
Example #24
0
 /// <summary>
 /// Initializes the object and all control elements of the game.
 /// </summary>
 private GameObjectManager()
 {
     teamMgr        = new TeamManager();
     fightMgr       = new FightManager();
     objectCreator  = new ObjectCreator();
     moveMgr        = new MoveManager();
     groupMgr       = new GroupManager();
     propertyMgr    = new PropertyManager();
     hitTest        = new HitTest();
     solarSystemMgr = new SolarSystemManager();
     gameSerializer = new GameSerializer();
 }
 private static void LoadComponets(BinaryNode domNode, GameObject go)
 {
     for (int i = 0; i < domNode.GetChildNum(); i++)
     {
         BinaryNode child = domNode.GetChild(i);
         if (!(child.GetName() != "Cop"))
         {
             string    nodeAttr  = GameSerializer.GetNodeAttr(child, "Type");
             Component component = go.GetComponent(nodeAttr);
             if (!(component == null))
             {
                 string nodeAttr2 = GameSerializer.GetNodeAttr(child, "DIS");
                 if (nodeAttr2 != null && component is Behaviour)
                 {
                     Behaviour behaviour = (Behaviour)component;
                     behaviour.enabled = false;
                 }
                 ICustomizedComponentSerializer componentSerlizer = GameSerializer.GetComponentSerlizer(component.GetType());
                 if (componentSerlizer != null)
                 {
                     componentSerlizer.ComponentDeserialize(component, child);
                 }
                 else
                 {
                     MemberInfo[] members = component.GetType().GetMembers();
                     for (int j = 0; j < members.Length; j++)
                     {
                         if (GameSerializer.IsMINeedExport(members[j]))
                         {
                             BinaryNode binaryNode = child.SelectSingleNode(members[j].get_Name());
                             if (binaryNode != null)
                             {
                                 object @object = GameSerializer.GetObject(binaryNode);
                                 try
                                 {
                                     if (@object != null)
                                     {
                                         GameSerializer.SetMIValue(members[j], component, @object);
                                     }
                                 }
                                 catch (Exception var_11_F4)
                                 {
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #26
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)]);
        }
Example #27
0
    public bool Load(string name)
    {
        Debug.Log("Loading to {name}");

        Clear();

        bool res = GameSerializer.Load(name, (Vector3 pos) => CreateNode(pos),
                                       (GameObject f, GameObject t) => CreateEdge(f, t));

        current = graph.GetRoot();

        Start();

        return(res);
    }
Example #28
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);
            }
        }
Example #29
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            graphics.PreferredBackBufferWidth  = 800;
            graphics.PreferredBackBufferHeight = 600;
            RasterizerState customState = new RasterizerState();

            graphics.GraphicsDevice.RasterizerState = customState;

            graphics.ApplyChanges();

            ComponentRecord.RegisterAttribute <Sprite>("Sprite");
            ComponentRecord.RegisterAttribute <AnimatedSprite>("AnimatedSprite");
            ComponentRecord.RegisterAttribute <Transform>("Transform");
            ComponentRecord.RegisterAttribute <GUIButton>("GUIButton");
            ComponentRecord.RegisterAttribute <GUILabel>("GUILabel");
            ComponentRecord.RegisterAttribute <GUITextBox>("GUITextBox");
            ComponentRecord.RegisterAttribute <GUIImage>("GUIImage");
            ComponentRecord.RegisterAttribute <AABBCollider>("AABBCollider");
            ComponentRecord.RegisterAttribute <SATCollider>("SATCollider");
            ComponentRecord.RegisterAttribute <CharacterController>("CharacterController");

            Debug.InitializeDebug(GraphicsDevice, this);
            DebugConsole.DebugConsoleInit(this, graphics);
            GameSerializer.Init(this);
            GameScript.InitGameScript();
            Transform.UpdateGraphicsSize(graphics);
            InputManager.InitInputManager(this);
            Camera.InitCamera(graphics);
            GUILabel.Initialize(this);

            Exiting += new EventHandler <EventArgs>((object obj, EventArgs args) =>
            {
                Debug.CloseDebug();
            });

            DebugConsole.RegisterCommand("reset", (string[] args) =>
            {
                reset();
            });

            w = new World();

            this.IsMouseVisible = true;

            base.Initialize();
        }
    public void ComponentDeserialize(Component cmp, BinaryNode node)
    {
        Camera camera = (Camera)cmp;

        camera.clearFlags          = (CameraClearFlags)int.Parse(GameSerializer.GetNodeAttr(node, "clear_flags"));
        camera.cullingMask         = int.Parse(GameSerializer.GetNodeAttr(node, "cullingMask"));
        camera.fieldOfView         = float.Parse(GameSerializer.GetNodeAttr(node, "fieldOfView"));
        camera.nearClipPlane       = float.Parse(GameSerializer.GetNodeAttr(node, "nearClipPlane"));
        camera.farClipPlane        = float.Parse(GameSerializer.GetNodeAttr(node, "farClipPlane"));
        camera.pixelRect           = UnityBasetypeSerializer.StringToRect(GameSerializer.GetNodeAttr(node, "pixelRect"));
        camera.rect                = UnityBasetypeSerializer.StringToRect(GameSerializer.GetNodeAttr(node, "rect"));
        camera.depth               = float.Parse(GameSerializer.GetNodeAttr(node, "depth"));
        camera.renderingPath       = (RenderingPath)int.Parse(GameSerializer.GetNodeAttr(node, "renderingPath"));
        camera.useOcclusionCulling = bool.Parse(GameSerializer.GetNodeAttr(node, "useOcclusionCulling"));
        camera.hdr = bool.Parse(GameSerializer.GetNodeAttr(node, "hdr"));
    }
Example #31
0
        private void toPGNToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            // Prompt for where to save file
            if (saveDiag.ShowDialog() == DialogResult.OK)
            {
                // Open stream and serializer
                StreamWriter stream = new StreamWriter(new FileStream(saveDiag.FileName, FileMode.Append));
                GameSerializer s = new GameSerializer();

                try
                {
                    // Format, write and close
                    s.ToStream(new PGNSerializer(), this.game, stream);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }