示例#1
0
        private void BuildLayers(XmlDocument document)
        {
            foreach (XmlNode layerNode in document.SelectNodes(AttributeNames.MapAttributes.MapTileLayer + "|" + AttributeNames.MapAttributes.MapObjectLayer))
            {
                LayerContent layer;
                if (layerNode.Name == AttributeNames.MapAttributes.TileLayer)
                {
                    layer = new TileLayerContent(layerNode);
                }
                else if (layerNode.Name == AttributeNames.MapAttributes.ObjectLayer)
                {
                    layer = new ObjectLayerContent(layerNode);
                }
                else
                {
                    throw new Exception(String.Format("Unknown layer: {0}. Must be tile or object layer.", layerNode.Name));
                }

                Utilities.ThrowExceptionIfIsNullOrEmpty(layer.Name, "layerName");

                string layerName      = layer.Name;
                int    duplicateCount = 2;

                // this handles renaming duplicates, how can we make this faster without O(n) searching through a list?
                // store these in hash tables and perform existence check prior to adding?
                while (layers.Any(l => l.Name == layerName))
                {
                    layerName = String.Format("{0}{1}", layer.Name, duplicateCount);
                    duplicateCount++;
                }

                layer.Name = layerName;

                layers.Add(layer);
            }
        }
        private void BuildLayers(XmlDocument document)
        {
            foreach (XmlNode layerNode in document.SelectNodes(AttributeNames.MapAttributes.MapTileLayer + "|" + AttributeNames.MapAttributes.MapObjectLayer))
            {
                LayerContent layer;
                if (layerNode.Name == AttributeNames.MapAttributes.TileLayer)
                    layer = new TileLayerContent(layerNode);
                else if (layerNode.Name == AttributeNames.MapAttributes.ObjectLayer)
                    layer = new ObjectLayerContent(layerNode);
                else
                    throw new Exception(String.Format("Unknown layer: {0}", layerNode.Name));

                string layerName = layer.Name;
                int duplicateCount = 2;

                while (layers.Any(l => l.Name == layerName))
                {
                    layerName = String.Format("{0}{1}", layer.Name, duplicateCount);
                    duplicateCount++;
                }

                layer.Name = layerName;

                layers.Add(layer);
            }
        }