private void LoadFile()
        {
            ContainerNode rootNode = null;

            switch (Path.GetExtension(SaveLoc))
            {
            case @".nbtx":
            {
                try {
                    rootNode = ListNode.Deserialize(SaveLoc);
                } catch {
                    rootNode = ObjectNode.Deserialize(SaveLoc);
                }
            }
            break;

            case @".nbt":
            {
                using (var file = File.OpenRead(SaveLoc)) {
                    rootNode = Serializer.Deserialize <ContainerNode>(file);
                }
            }
            break;

            default:
                return;
            }

            if (rootNode == null)
            {
                return;
            }
            Root.Clear();
            Root.Add(rootNode);
        }
Exemple #2
0
        /// <summary>
        /// Loads a game state from file.
        /// </summary>
        /// <param name="location">The path to saved file.</param>
        public void LoadState(string location)
        {
            var root = ListNode.Deserialize(location);

            // Validation
            if (root.Name != "root")
            {
                throw new FormatException("ListNode was not of format 'root'");
            }

            #region Load Object Node "Player"

            var playerNode = (ObjectNode)root.Children.FirstOrDefault(o => o is ObjectNode && o.Name == "Player");

            // Validation
            if (playerNode == null)
            {
                throw new FormatException("ListNode of type 'root' did not contain expected ObjectNode 'Player'");
            }

            // Let's create a player object directly from the ObjectNode!
            Player = playerNode.Instantiate <Player.Player>();

            #endregion
        }