Esempio n. 1
0
        public static void ParseTileAreaNode(ParsingTree parsingTree, ParsingNode tileAreaNode)
        {
            if (parsingTree == null)
            {
                throw new ArgumentNullException(nameof(parsingTree));
            }
            if (tileAreaNode == null)
            {
                throw new ArgumentNullException(nameof(tileAreaNode));
            }

            var stream = new ParsingStream(
                tree: parsingTree,
                node: tileAreaNode);

            var areaStartingX = stream.ReadUInt16();
            var areaStartingY = stream.ReadUInt16();
            var areaZ         = stream.ReadByte();

            foreach (var tileNode in tileAreaNode.Children)
            {
                ParseTileNode(
                    parsingTree: parsingTree,
                    tileNode: tileNode,
                    areaStartingX: areaStartingX,
                    areaStartingY: areaStartingY,
                    areaZ: areaZ);
            }
        }
Esempio n. 2
0
        private static void ParseTileNode(
            ParsingTree parsingTree,
            ParsingNode tileNode,
            UInt16 areaStartingX,
            UInt16 areaStartingY,
            Byte areaZ
            )
        {
            if (tileNode.Type != NodeType.NormalTile && tileNode.Type != NodeType.HouseTile)
            {
                throw new MalformedTileAreaNodeException("Unknow tile area node type.");
            }

            var stream = new ParsingStream(parsingTree, tileNode);

            var tileX = areaStartingX + stream.ReadByte();
            var tileY = areaStartingY + stream.ReadByte();

            Tile tile = null;

            if (tileNode.Type == NodeType.HouseTile)
            {
                tile = ParseHouseTile(ref stream, (ushort)tileX, (ushort)tileY, areaZ);                 // Improve this, remove casts
            }
            var tileFlags = ParseTileAttributes(ref parsingTree, ref stream, ref tile, tileNode);

            if (tile != null)
            {
                tile.Flags.AddFlags(tileFlags);
            }
        }
Esempio n. 3
0
        public static void ParseItemNode(
            ParsingTree parsingTree,
            ParsingNode parsingNode
            )
        {
            if (parsingNode.Type != NodeType.Item)
            {
                throw new MalformedItemNodeException();
            }

            var stream = new ParsingStream(parsingTree, parsingNode);

            var itemId = stream.ReadUInt16();
            // var item = Item.CreateFromId(itemId);
        }
Esempio n. 4
0
        public static WorldHeader GetWorldHeader(ParsingTree tree)
        {
            if (tree == null)
            {
                throw new ArgumentNullException(nameof(tree));
            }

            var parsingStream = new ParsingStream(tree, tree.Root);

            var worldEncodingVersion     = parsingStream.ReadUInt32();
            var worldWidth               = parsingStream.ReadUInt16();
            var worldHeight              = parsingStream.ReadUInt16();
            var itemEncodingMajorVersion = parsingStream.ReadUInt32();
            var itemEncodingMinorVersion = parsingStream.ReadUInt32();

            return(new WorldHeader(
                       worldEncodingVersion: worldEncodingVersion,
                       worldWidth: worldWidth,
                       worldHeight: worldHeight,
                       itemEncodingMajorVersion: itemEncodingMajorVersion,
                       itemEncodingMinorVersion: itemEncodingMinorVersion));
        }
Esempio n. 5
0
        public static void LoadWorld(ref ParsingTree mapTree)
        {
            var rootNode = mapTree.Root;

            var mapNode = rootNode.Children[0];

            if (mapNode == null)
            {
                throw new MalformedWorldException();
            }

            foreach (var mapDataNode in mapNode.Children)
            {
                switch (mapDataNode.Type)
                {
                case NodeType.TileArea:
                    WorldLoader.ParseTileAreaNode(mapTree, mapDataNode);
                    break;

                    //default:
                    //throw new NotImplementedException();
                }
            }
        }
Esempio n. 6
0
        private static TileFlags ParseTileAttributes(ref ParsingTree parsingTree, ref ParsingStream stream, ref Tile tile, ParsingNode tileNode)
        {
            var           tileFlags = new TileFlags();
            NodeAttribute nodeAttribute;

            while (!stream.IsOver)
            {
                nodeAttribute = (NodeAttribute)stream.ReadByte();
                switch (nodeAttribute)
                {
                case NodeAttribute.TileFlags:
                    tileFlags = ParseTileFlags(ref stream);
                    break;

                case NodeAttribute.Item:
                    ParseTileItem(ref stream, ref tile, tileNode.Type == NodeType.HouseTile);
                    break;

                default:
                    throw new MalformedTileNodeException("Unknow node attribute " + nameof(nodeAttribute) + " of type " + nodeAttribute);
                }
            }

            foreach (var itemNode in tileNode.Children)
            {
                if (itemNode.Type != NodeType.Item)
                {
                    throw new MalformedItemNodeException();
                }

                var itemStream = new ParsingStream(parsingTree, itemNode);
                ParseTileItem(ref itemStream, ref tile, tileNode.Type == NodeType.HouseTile);
            }

            return(tileFlags);
        }
Esempio n. 7
0
        public static WorldAttributes GetWorldAttributes(ParsingTree tree)
        {
            if (tree == null)
            {
                throw new ArgumentNullException(nameof(tree));
            }

            if (tree.Root.Children.Count != 1)
            {
                throw new MalformedWorldException();
            }

            var worldDataNode = tree.Root.Children[0];

            if ((NodeType)worldDataNode.Type != NodeType.WorldData)
            {
                throw new MalformedWorldException();
            }

            var parsingStream = new ParsingStream(tree, worldDataNode);

            var    worldDescription = new List <string>();
            string spawnsFilename   = null;
            string housesFilename   = null;

            while (!parsingStream.IsOver)
            {
                var attribute = (NodeAttribute)parsingStream.ReadByte();
                switch (attribute)
                {
                case NodeAttribute.WorldDescription:
                    worldDescription.Add(parsingStream.ReadString());
                    break;

                case NodeAttribute.ExtensionFileForSpawns:
                    if (spawnsFilename != null)
                    {
                        throw new MalformedWorldAttributesNodeException("Multiple filenames for world spawns.");
                    }
                    else
                    {
                        spawnsFilename = parsingStream.ReadString();
                    }
                    break;

                case NodeAttribute.ExtensionFileForHouses:
                    if (housesFilename != null)
                    {
                        throw new MalformedWorldAttributesNodeException("Multiple filenames for world houses.");
                    }
                    else
                    {
                        housesFilename = parsingStream.ReadString();
                    }
                    break;

                default:
                    throw new MalformedWorldAttributesNodeException("Unknown attribute found in world attributes note.");
                }
            }

            var formattedWorldDescription = string.Join(
                separator: Environment.NewLine,
                values: worldDescription);

            return(new WorldAttributes(
                       worldDescription: formattedWorldDescription,
                       spawnsFilename: spawnsFilename,
                       housesFilename: housesFilename));
        }