Ejemplo n.º 1
0
        public TmxLayer(XMLReader xLayer, int width, int height)
        {
            Name   = xLayer.Attribute("name") ?? "";
            Width  = width;
            Height = height;

            Opacity = xLayer.AttributeFloatN("opacity") ?? 1.0f;
            Visible = xLayer.AttributeBoolN("visible") ?? true;
            OffsetX = xLayer.AttributeFloat("offsetx");
            OffsetY = xLayer.AttributeFloat("offsety");

            Properties = TmxHelpers.GetPropertyDict(xLayer.Element("properties"));

            // Not a layer which contains tiles.
            if (width == 0)
            {
                return;
            }
            XMLReader xData    = xLayer.Element("data");
            string    encoding = xData.Attribute("encoding");

            Tiles = new Collection <TmxLayerTile>();
            switch (encoding)
            {
            case "csv":
            {
                string csvData = xData.CurrentContents();
                foreach (string s in csvData.Split(','))
                {
                    uint gid = uint.Parse(s.Trim());
                    Tiles.Add(new TmxLayerTile(gid));
                }

                break;
            }

            case null:
            {
                foreach (XMLReader e in xData.Elements("tile"))
                {
                    uint gid = e.AttributeUInt("gid");
                    Tiles.Add(new TmxLayerTile(gid));
                }

                break;
            }

            default:
                Engine.Log.Warning($"Unknown tmx layer encoding {encoding}", MessageSource.TMX);
                return;
            }
        }
Ejemplo n.º 2
0
        internal static TmxProperties ParseTmxProperties(JObject jObject)
        {
            var properties = new TmxProperties();

            foreach (KeyValuePair<string, JToken> keyval in jObject)
            {
                JToken jVal = keyval.Value;
                object value;

                switch (keyval.Value.Type)
                {
                    case JTokenType.Boolean:
                        value = jVal.Value<bool>();
                        break;
                    case JTokenType.Float:
                        value = jVal.Value<float>();
                        break;
                    case JTokenType.Integer:
                        value = jVal.Value<int>();
                        break;
                    default:
                        value = jVal.Value<string>();
                        break;
                }

                properties[keyval.Key] = value;
            }

            return properties;
        }