Beispiel #1
0
        public void LoadLayer(MapLayer mapLayer, XElement layerData)
        {
            if (mapLayer == null)
            {
                throw new ArgumentNullException("mapLayer");
            }

            if (layerData == null)
            {
                throw new InvalidDataException("Layer does not have a data element");
            }

            string encoding = (string)layerData.Attribute("encoding");

            switch (encoding)
            {
                case "base64":
                    ApplyIds(GetMapIdsFromBase64(layerData.Value, (string)layerData.Attribute("compression")), mapLayer);
                    break;

                case "csv":
                    ApplyIds(ParseCsvData(layerData), mapLayer);
                    break;

                default:
                    if (string.IsNullOrEmpty(encoding))
                    {
                        ApplyIds(GetMapIdsFromXml(layerData.Elements("tile")), mapLayer);
                    }
                    else
                    {
                        throw new InvalidDataException("Unsupported layer data encoding (expected base64 or csv)");
                    }
                    break;
            }
        }
Beispiel #2
0
        private void ApplyIds(IEnumerable<int> ids, MapLayer layer)
        {
            IEnumerator<int> enumerator = ids.GetEnumerator();

            for (int y = 0; y < _size.Height; y++)
            {
                for (int x = 0; x < _size.Width; x++)
                {
                    enumerator.MoveNext();

                    layer.TileIds[y, x] = enumerator.Current;
                }
            }
        }