Esempio n. 1
0
        public TMXTile(XMLElement element)
        {
            name = element.GetAttribute("name", "");
            type = element.GetAttribute("type", "");
            x    = element.GetIntAttribute("x", 0);
            y    = element.GetIntAttribute("y", 0);
            string w = element.GetAttribute("width", null);
            string h = element.GetAttribute("height", null);

            width  = System.Int32.Parse((w == null || "".Equals(w)) ? "0" : w);
            height = System.Int32.Parse((h == null || "".Equals(h)) ? "0" : h);
            XMLElement imageElement = element
                                      .GetChildrenByName("image");

            if (imageElement != null)
            {
                image = imageElement.GetAttribute("source", null);
            }
            XMLElement propsElement = element
                                      .GetChildrenByName("properties");

            if (propsElement != null)
            {
                props = new TMXProperty();
                List <XMLElement> property = propsElement.List("property");
                for (int i = 0; i < property.Count; i++)
                {
                    XMLElement propElement = property[i];
                    string     name_0      = propElement.GetAttribute("name", null);
                    string     value_ren   = propElement.GetAttribute("value", null);
                    props.SetProperty(name_0, value_ren);
                }
            }
        }
Esempio n. 2
0
        public TMXTileGroup(XMLElement element)
        {
            name    = element.GetAttribute("name", null);
            width   = element.GetIntAttribute("width", 0);
            height  = element.GetIntAttribute("height", 0);
            objects = new List <TMXTile>();

            XMLElement propsElement = element.GetChildrenByName("properties");

            if (propsElement != null)
            {
                List <XMLElement> properties = propsElement.List("property");
                if (properties != null)
                {
                    props = new TMXProperty();
                    for (int p = 0; p < properties.Count; p++)
                    {
                        XMLElement propElement = properties[p];
                        string     name_0      = propElement.GetAttribute("name", null);
                        string     value_ren   = propElement.GetAttribute("value", null);
                        props.SetProperty(name_0, value_ren);
                    }
                }
            }
            List <XMLElement> objectNodes = element.List("object");

            for (int i = 0; i < objectNodes.Count; i++)
            {
                XMLElement objElement = objectNodes[i];
                TMXTile    obj0       = new TMXTile(objElement);
                obj0.index = i;
                CollectionUtils.Add(objects, obj0);
            }
        }
Esempio n. 3
0
        public static ParticleSystem LoadConfiguredSystem(InputStream refs,
                                                          ConfigEmitterFactory factory, ParticleSystem system,
                                                          LColor mask)
        {
            if (factory == null)
            {
                factory = new NewConfigEmitterFactory();
            }
            try {
                XMLDocument document = XMLParser.Parse(refs);

                XMLElement element = document.GetRoot();
                if (!element.GetName().Equals("system", System.StringComparison.InvariantCultureIgnoreCase))
                {
                    Log.DebugWrite("Not a particle system file");
                }

                if (system == null)
                {
                    system = new ParticleSystem("assets/particle.tga", 2000, mask);
                }
                bool additive = "true".Equals(element.GetAttribute("additive"));
                if (additive)
                {
                    system.SetBlendingMode(ParticleSystem.BLEND_ADDITIVE);
                }
                else
                {
                    system.SetBlendingMode(ParticleSystem.BLEND_COMBINE);
                }
                bool points = "true".Equals(element.GetAttribute("points"));
                system.SetUsePoints(points);

                List <XMLElement> List = element.List("emitter");
                for (int i = 0; i < List.Count; i++)
                {
                    XMLElement    em      = (XMLElement)List[i];
                    ConfigEmitter emitter = factory.CreateEmitter("new");

                    ElementToEmitter(em, emitter);

                    system.AddEmitter(emitter);
                }

                system.SetRemoveCompletedEmitters(false);
                return(system);
            } catch (IOException e) {
                Log.Exception(e);
            } catch (Exception e) {
                Log.Exception(e);
                throw new IOException("Unable to load particle system config");
            }
            return(system);
        }
Esempio n. 4
0
        public static NeuralNetwork FromXML(string xml)
        {
            XMLElement root = XMLReader.Parse(xml);

            int layerCount = int.Parse(root.GetAttribute("Layers").Value);

            XMLElement[] layerXEs = new XMLElement[layerCount];

            Layer[] layers = new Layer[layerCount];
            foreach (XMLElement layerXE in root.Children)
            {
                int layerIndex = int.Parse(layerXE.GetAttribute("Index").Value);

                layerXEs[layerIndex] = layerXE;
            }

            for (int i = 0; i < layerXEs.Length; i++)
            {
                Layer previousLayer = i == 0 ? null : layers[i - 1];

                Layer layer = Layer.FromXML(layerXEs[i], previousLayer);
                layers[i] = layer;
            }

            return(new NeuralNetwork(layers));
        }
Esempio n. 5
0
        internal static ActivationFunction FromXML(XMLElement root)
        {
            if (root.GetAttribute("Name").Value == "None")
            {
                return(None());
            }

            if (root.GetAttribute("Name").Value == "Sigmoid")
            {
                XMLElement customDataXE = root.ChildWithTag("CustomData");
                float      steepness    = int.Parse(customDataXE.ChildWithTag("steepness").GetAttribute("Value").Value);

                return(Sigmoid(steepness));
            }

            if (root.GetAttribute("Name").Value == "ReLU")
            {
                XMLElement customDataXE   = root.ChildWithTag("CustomData");
                bool       zeroIsPositive = bool.Parse(customDataXE.ChildWithTag("zeroIsPositive").GetAttribute("Value").Value);

                return(ReLU(zeroIsPositive));
            }

            if (root.GetAttribute("Name").Value == "TanH")
            {
                XMLElement customDataXE = root.ChildWithTag("CustomData");
                float      steepness    = int.Parse(customDataXE.ChildWithTag("steepness").GetAttribute("Value").Value);

                return(TanH(steepness));
            }

            if (root.GetAttribute("Name").Value == "LeakyReLU")
            {
                XMLElement customDataXE    = root.ChildWithTag("CustomData");
                float      leakynessFactor = int.Parse(customDataXE.ChildWithTag("leakynessFactor").GetAttribute("Value").Value);
                bool       zeroIsPositive  = bool.Parse(customDataXE.ChildWithTag("zeroIsPositive").GetAttribute("Value").Value);

                return(LeakyReLU(leakynessFactor, zeroIsPositive));
            }

            if (root.GetAttribute("Name").Value == "SoftPlus")
            {
                XMLElement customDataXE = root.ChildWithTag("CustomData");
                float      steepness    = int.Parse(customDataXE.ChildWithTag("steepness").GetAttribute("Value").Value);

                return(SoftPlus(steepness));
            }

            if (root.GetAttribute("Name").Value == "SoftMax")
            {
                XMLElement customDataXE = root.ChildWithTag("CustomData");
                float      steepness    = int.Parse(customDataXE.ChildWithTag("steepness").GetAttribute("Value").Value);

                return(SoftMax(steepness));
            }

            throw new NotImplementedException();    // Never reached
        }
Esempio n. 6
0
 private static void ParseRangeElement(XMLElement element,
                                       Range range)
 {
     if (element == null)
     {
         return;
     }
     range.SetMin(element.GetFloatAttribute("min", 0));
     range.SetMax(element.GetFloatAttribute("max", 0));
     range.SetEnabled("true".Equals(element.GetAttribute("enabled", "")));
 }
Esempio n. 7
0
        private void Set(XMLElement Pack)
        {
            this.fileName = Pack.GetAttribute("file", null);
            this.name     = Pack.GetAttribute("name", fileName);
            int r = Pack.GetIntAttribute("r", -1);
            int g = Pack.GetIntAttribute("g", -1);
            int b = Pack.GetIntAttribute("b", -1);
            int a = Pack.GetIntAttribute("a", -1);

            if (r != -1 && g != -1 && b != -1 && a != -1)
            {
                colorMask = new LColor(r, g, b, a);
            }
            if (fileName != null)
            {
                List <XMLElement> blocks = Pack.List("block");
                foreach (XMLElement e  in  blocks)
                {
                    PackEntry entry = new PackEntry(null);
                    int       id    = e.GetIntAttribute("id", count);
                    entry.id            = id;
                    entry.fileName      = e.GetAttribute("name", null);
                    entry.bounds.left   = e.GetIntAttribute("left", 0);
                    entry.bounds.top    = e.GetIntAttribute("top", 0);
                    entry.bounds.right  = e.GetIntAttribute("right", 0);
                    entry.bounds.bottom = e.GetIntAttribute("bottom", 0);
                    if (entry.fileName != null)
                    {
                        temps.Put(entry.fileName, entry);
                    }
                    else
                    {
                        temps.Put(Convert.ToString(id), entry);
                    }
                    count++;
                }
                this.packing = false;
                this.packed  = true;
            }
            this.useAlpha = true;
        }
Esempio n. 8
0
        /// <summary>
        /// 根据TMX地图描述创建一个新层
        /// </summary>
        ///
        /// <param name="map"></param>
        /// <param name="element"></param>
        /// <exception cref="System.Exception"></exception>
        public TMXLayer(TMXTiledMap map, XMLElement element)
        {
            this.tmx    = map;
            this.name   = element.GetAttribute("name", "");
            this.width  = element.GetIntAttribute("width", 0);
            this.height = element.GetIntAttribute("height", 0);
            this.data   = new int[width, height, 3];
            this.MaxLightSize(width, height);

            // 获得当前图层属性
            XMLElement propsElement = element.GetChildrenByName("properties");

            if (propsElement != null)
            {
                props = new TMXProperty();
                List <XMLElement> properties = propsElement.List("property");
                for (int i = 0; i < properties.Count; i++)
                {
                    XMLElement propElement = properties[i];
                    string     name_0      = propElement.GetAttribute("name", null);
                    string     value_ren   = propElement.GetAttribute("value", null);
                    props.SetProperty(name_0, value_ren);
                }
            }

            XMLElement dataNode    = element.GetChildrenByName("data");
            string     encoding    = dataNode.GetAttribute("encoding", null);
            string     compression = dataNode.GetAttribute("compression", null);

            // 进行base64的压缩解码
            if ("base64".Equals(encoding) && "gzip".Equals(compression))
            {
                try
                {
                    byte[] sdec = Base64Coder.DecodeBase64(dataNode.GetContents().Trim().ToCharArray());

                    ByteArrayInputStream mask0 = new ByteArrayInputStream(sdec);

                    GZipInputStream dis = new GZipInputStream(mask0);

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            int tileId = 0;

                            tileId |= dis.ReadByte();
                            tileId |= dis.ReadByte() << 8;
                            tileId |= dis.ReadByte() << 16;
                            tileId |= dis.ReadByte() << 24;

                            if (tileId == 0)
                            {
                                data[x, y, 0] = -1;
                                data[x, y, 1] = 0;
                                data[x, y, 2] = 0;
                            }
                            else
                            {
                                TMXTileSet set = map.FindTileSet(tileId);

                                if (set != null)
                                {
                                    data[x, y, 0] = set.index;
                                    data[x, y, 1] = tileId - set.firstGID;
                                }
                                data[x, y, 2] = tileId;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Loon.Utils.Debug.Log.Exception(e);
                    throw new Exception("Unable to decode base64 !");
                }
            }
            else
            {
                throw new Exception("Unsupport tiled map type " + encoding
                                    + "," + compression + " only gzip base64 Support !");
            }
        }
Esempio n. 9
0
        internal static Layer FromXML(XMLElement root, Layer previousLayer) {

            float[] StringToArray(string s) {
                string[] valStrs = s.Split(',');
                float[] array = new float[valStrs.Length];
                for (int i = 0; i < valStrs.Length; i++) {
                    array[i] = float.Parse(valStrs[i]);
                }
                return array;
            }

            string type = root.Tag;
            if (type == typeof(InputLayer).Name) {
                int width = int.Parse(root.GetAttribute("Width").Value);
                int height = int.Parse(root.GetAttribute("Height").Value);
                int depth = int.Parse(root.GetAttribute("Depth").Value);

                return new InputLayer(width, height, depth);
            }

            if (type == typeof(MaxPoolingLayer).Name) {
                int filterSize = int.Parse(root.GetAttribute("FilterSize").Value);
                int stride = int.Parse(root.GetAttribute("Stride").Value);

                return new MaxPoolingLayer(filterSize, stride, previousLayer);
            }

            if (type == typeof(FullyConnectedLayer).Name) {
                int neurons = int.Parse(root.GetAttribute("Neurons").Value);
                ActivationFunctions.ActivationFunction activation = ActivationFunctions.FromXML(root.ChildWithTag("ActivationFunction"));

                FullyConnectedLayer layer = new FullyConnectedLayer(neurons, previousLayer, activation);

                float[] weights = StringToArray(root.ChildWithTag("Weights").Value);
                for (int i = 0; i < layer.Weights; i++) {
                    layer.SetWeight(i, weights[i]);
                }

                float[] biases = StringToArray(root.ChildWithTag("Biases").Value);
                for (int i = 0; i < layer.Biases; i++) {
                    layer.SetBias(i, biases[i]);
                }

                return layer;
            }

            if (type == typeof(ConvolutionalLayer).Name) {
                int filterCount = int.Parse(root.GetAttribute("FilterCount").Value);
                int filterSize = int.Parse(root.GetAttribute("FilterSize").Value);
                int stride = int.Parse(root.GetAttribute("Stride").Value);
                int zeroPadding = int.Parse(root.GetAttribute("ZeroPadding").Value);
                ActivationFunctions.ActivationFunction activation = ActivationFunctions.FromXML(root.ChildWithTag("ActivationFunction"));

                ConvolutionalLayer layer = new ConvolutionalLayer(filterCount, filterSize, stride, zeroPadding, previousLayer, activation);

                float[] weights = StringToArray(root.ChildWithTag("Weights").Value);
                for (int i = 0; i < layer.Weights; i++) {
                    layer.SetWeight(i, weights[i]);
                }

                float[] biases = StringToArray(root.ChildWithTag("Biases").Value);
                for (int i = 0; i < layer.Biases; i++) {
                    layer.SetBias(i, biases[i]);
                }

                return layer;
            }

            throw new NotImplementedException();    // Never reached
        }
Esempio n. 10
0
        public TMXTileSet(TMXTiledMap map, XMLElement element, bool loadImage)
        {
            this.map      = map;
            this.name     = element.GetAttribute("name", null);
            this.firstGID = element.GetIntAttribute("firstgid", 0);
            string source = element.GetAttribute("source", "");

            if (!"".Equals(source))
            {
                try
                {
                    Stream ins0 = Resources.OpenStream(map.GetTilesLocation()
                                                       + "/" + source);
                    XMLDocument doc        = XMLParser.Parse(ins0);
                    XMLElement  docElement = doc.GetRoot();
                    element = docElement;
                }
                catch (Exception e)
                {
                    Loon.Utils.Debug.Log.Exception(e);
                    throw new Exception(this.map.tilesLocation + "/"
                                        + source);
                }
            }
            string tileWidthString  = element.GetAttribute("tilewidth", "");
            string tileHeightString = element.GetAttribute("tileheight", "");

            if (tileWidthString.Length == 0 || tileHeightString.Length == 0)
            {
                throw new Exception(
                          "tileWidthString.length == 0 || tileHeightString.length == 0");
            }
            tileWidth  = Int32.Parse(tileWidthString);
            tileHeight = Int32.Parse(tileHeightString);

            string sv = element.GetAttribute("spacing", "");

            if ((sv != null) && (!"".Equals(sv)))
            {
                tileSpacing = Int32.Parse(sv);
            }

            string mv = element.GetAttribute("margin", "");

            if ((mv != null) && (!"".Equals(mv)))
            {
                tileMargin = Int32.Parse(mv);
            }

            List <XMLElement> list      = element.List("image");
            XMLElement        imageNode = list[0];
            string            fileName  = imageNode.GetAttribute("source", null);

            LColor trans = null;
            string t     = imageNode.GetAttribute("trans", null);

            if ((t != null) && (t.Length > 0))
            {
                trans = new LColor(((uint)Convert.ToInt32(t, 16)));
            }

            if (loadImage)
            {
                string   path = map.GetTilesLocation() + "/" + fileName;
                LTexture image;
                if (trans != null)
                {
                    image = TextureUtils.FilterColor(path, trans);
                }
                else
                {
                    image = LTextures.LoadTexture(path);
                }
                SetTileSetImage(image);
            }

            List <XMLElement> elements = element.List("tile");

            for (int i = 0; i < elements.Count; i++)
            {
                XMLElement tileElement = elements[i];

                int id = tileElement.GetIntAttribute("id", 0);
                id += firstGID;
                TMXProperty tileProps = new TMXProperty();

                XMLElement propsElement = tileElement
                                          .GetChildrenByName("properties");
                List <XMLElement> properties = propsElement.List("property");
                for (int p = 0; p < properties.Count; p++)
                {
                    XMLElement propElement = properties[p];
                    string     name_1      = propElement.GetAttribute("name", null);
                    string     value_ren   = propElement.GetAttribute("value", null);
                    tileProps.SetProperty(name_1, value_ren);
                }
                CollectionUtils.Put(props, id, tileProps);
            }
        }
Esempio n. 11
0
        private static void parseValueElement(XMLElement element,
                                              Value value)
        {
            if (element == null)
            {
                return;
            }

            string type = element.GetAttribute("type", "");
            string v    = element.GetAttribute("value", "");

            if (type == null || type.Length == 0)
            {
                if (value is SimpleValue)
                {
                    ((SimpleValue)value).SetValue(Convert.ToSingle(v));
                }
                else if (value is RandomValue)
                {
                    ((RandomValue)value).SetValue(Convert.ToSingle(v));
                }
                else
                {
                    Log.DebugWrite("problems reading element, skipping: "
                                   + element);
                }
            }
            else
            {
                if (type.Equals("simple"))
                {
                    ((SimpleValue)value).SetValue(Convert.ToSingle(v));
                }
                else if (type.Equals("random"))
                {
                    ((RandomValue)value).SetValue(Convert.ToSingle(v));
                }
                else if (type.Equals("linear"))
                {
                    int min = element.GetIntAttribute("min", 0);
                    int max = element.GetIntAttribute("max", 0);

                    bool active = element.GetBoolAttribute("active", false);

                    List <XMLElement> points = element.List("point");

                    List <Vector2f> curve = new List <Vector2f>();
                    for (int i = 0; i < points.Count; i++)
                    {
                        XMLElement point = (XMLElement)points[i];

                        float x = point.GetFloatAttribute("x", 0);
                        float y = point.GetFloatAttribute("y", 0);

                        curve.Add(new Vector2f(x, y));
                    }

                    ((LinearInterpolator)value).SetCurve(curve);
                    ((LinearInterpolator)value).SetMin(min);
                    ((LinearInterpolator)value).SetMax(max);
                    ((LinearInterpolator)value).SetActive(active);
                }
                else
                {
                    Log.DebugWrite("unkown type detected: " + type);
                }
            }
        }
Esempio n. 12
0
        private static void ElementToEmitter(XMLElement element,
                                             ConfigEmitter emitter)
        {
            emitter.SetImageName(element.GetAttribute("img", ""));
            emitter.name = element.GetAttribute("name", "");
            string renderType = element.GetAttribute("renderType", "");

            emitter.usePoints = Particle.INHERIT_POINTS;
            if (renderType.Equals("quads"))
            {
                emitter.usePoints = Particle.USE_QUADS;
            }
            if (renderType.Equals("points"))
            {
                emitter.usePoints = Particle.USE_POINTS;
            }

            string useOriented = element.GetAttribute("useOriented", "");

            if (useOriented != null)
            {
                emitter.useOriented = "true".Equals(useOriented);
            }

            string useAdditive = element.GetAttribute("useAdditive", "");

            if (useAdditive != null)
            {
                emitter.useAdditive = "true".Equals(useAdditive);
            }

            ParseRangeElement(GetFirstNamedElement(element, "spawnInterval"),
                              emitter.spawnInterval);
            ParseRangeElement(GetFirstNamedElement(element, "spawnCount"),
                              emitter.spawnCount);
            ParseRangeElement(GetFirstNamedElement(element, "initialLife"),
                              emitter.initialLife);
            ParseRangeElement(GetFirstNamedElement(element, "initialSize"),
                              emitter.initialSize);
            ParseRangeElement(GetFirstNamedElement(element, "xOffset"),
                              emitter.xOffset);
            ParseRangeElement(GetFirstNamedElement(element, "yOffset"),
                              emitter.yOffset);
            ParseRangeElement(GetFirstNamedElement(element, "initialDistance"),
                              emitter.initialDistance);
            ParseRangeElement(GetFirstNamedElement(element, "speed"), emitter.speed);
            ParseRangeElement(GetFirstNamedElement(element, "length"),
                              emitter.length);
            ParseRangeElement(GetFirstNamedElement(element, "emitCount"),
                              emitter.emitCount);

            parseValueElement(GetFirstNamedElement(element, "spread"),
                              emitter.spread);
            parseValueElement(GetFirstNamedElement(element, "angularOffset"),
                              emitter.angularOffset);
            parseValueElement(GetFirstNamedElement(element, "growthFactor"),
                              emitter.growthFactor);
            parseValueElement(GetFirstNamedElement(element, "gravityFactor"),
                              emitter.gravityFactor);
            parseValueElement(GetFirstNamedElement(element, "windFactor"),
                              emitter.windFactor);
            parseValueElement(GetFirstNamedElement(element, "startAlpha"),
                              emitter.startAlpha);
            parseValueElement(GetFirstNamedElement(element, "endAlpha"),
                              emitter.endAlpha);
            parseValueElement(GetFirstNamedElement(element, "alpha"), emitter.alpha);
            parseValueElement(GetFirstNamedElement(element, "size"), emitter.size);
            parseValueElement(GetFirstNamedElement(element, "velocity"),
                              emitter.velocity);
            parseValueElement(GetFirstNamedElement(element, "scaleY"),
                              emitter.scaleY);

            XMLElement        color = GetFirstNamedElement(element, "color");
            List <XMLElement> steps = color.List("step");

            emitter.colors.Clear();
            for (int i = 0; i < steps.Count; i++)
            {
                XMLElement step   = (XMLElement)steps[i];
                float      offset = step.GetFloatAttribute("offset", 0);
                float      r      = step.GetFloatAttribute("r", 0);
                float      g      = step.GetFloatAttribute("g", 0);
                float      b      = step.GetFloatAttribute("b", 0);

                emitter.AddColorPoint(offset, new LColor(r, g, b, 1));
            }

            emitter.Replay();
        }
Esempio n. 13
0
        private void Load(Stream ins, string tileSetsLocation)
        {
            screenRect = LSystem.screenRect;

            tilesLocation = tileSetsLocation;

            try
            {
                XMLDocument doc        = XMLParser.Parse(ins);
                XMLElement  docElement = doc.GetRoot();

                string orient = docElement.GetAttribute("orientation", "");
                if (!"orthogonal".Equals(orient))
                {
                    throw new Exception(
                              "Only orthogonal maps supported, found " + orient);
                }

                width      = docElement.GetIntAttribute("width", 0);
                height     = docElement.GetIntAttribute("height", 0);
                tileWidth  = docElement.GetIntAttribute("tilewidth", 0);
                tileHeight = docElement.GetIntAttribute("tileheight", 0);

                XMLElement propsElement = docElement
                                          .GetChildrenByName("properties");
                if (propsElement != null)
                {
                    props = new TMXProperty();
                    List <XMLElement> property = propsElement.List("property");
                    for (int i = 0; i < property.Count; i++)
                    {
                        XMLElement propElement = property[i];
                        string     name        = propElement.GetAttribute("name", null);
                        string     value_ren   = propElement.GetAttribute("value", null);
                        props.SetProperty(name, value_ren);
                    }
                }

                if (loadTileSets)
                {
                    TMXTileSet tileSet = null;
                    TMXTileSet lastSet = null;

                    List <XMLElement> setNodes = docElement.List("tileset");
                    for (int i_0 = 0; i_0 < setNodes.Count; i_0++)
                    {
                        XMLElement current = setNodes[i_0];

                        tileSet       = new TMXTileSet(this, current, true);
                        tileSet.index = i_0;

                        if (lastSet != null)
                        {
                            lastSet.SetLimit(tileSet.firstGID - 1);
                        }
                        lastSet = tileSet;

                        CollectionUtils.Add(tileSets, tileSet);
                    }
                }

                List <XMLElement> layerNodes = docElement.List("layer");
                for (int i_1 = 0; i_1 < layerNodes.Count; i_1++)
                {
                    XMLElement current_2 = layerNodes[i_1];
                    TMXLayer   layer     = new TMXLayer(this, current_2);
                    layer.index = i_1;

                    CollectionUtils.Add(layers, layer);
                }

                List <XMLElement> objectGroupNodes = docElement
                                                     .List("objectgroup");

                for (int i_3 = 0; i_3 < objectGroupNodes.Count; i_3++)
                {
                    XMLElement   current_4   = objectGroupNodes[i_3];
                    TMXTileGroup objectGroup = new TMXTileGroup(current_4);
                    objectGroup.index = i_3;

                    CollectionUtils.Add(objectGroups, objectGroup);
                }

                defWidth  = (int)(screenRect.GetWidth() / tileWidth);
                defHeight = (int)(screenRect.GetHeight() / tileHeight);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.StackTrace);
                throw new Exception("Failed to parse map", ex);
            }
        }
Esempio n. 14
0
        public LTextureList(Stream ins0)
        {
            this.imageList  = new Dictionary <string, ImageData>(10);
            this.autoExpand = false;
            this.visible    = true;

            int index = 0;

            string x = "x", y = "y", w = "w", h = "h";
            string scale = "scale", src = "src", maskName = "mask", empty = "empty";
            string name = "name", filterName = "filter", n = "nearest", l = "linear";

            XMLDocument       doc    = XMLParser.Parse(ins0);
            List <XMLElement> images = doc.GetRoot().Find("image");

            if (images.Count > 0)
            {
                IEnumerator <XMLElement> it = images.GetEnumerator();
                for (; it.MoveNext();)
                {
                    XMLElement ele = it.Current;
                    if (ele != null)
                    {
                        ImageData data = new ImageData();
                        data.x     = ele.GetIntAttribute(x, 0);
                        data.y     = ele.GetIntAttribute(y, 0);
                        data.w     = ele.GetIntAttribute(w, 0);
                        data.h     = ele.GetIntAttribute(h, 0);
                        data.scale = ele.GetFloatAttribute(scale, 0);
                        data.xref  = ele.GetAttribute(src, empty);
                        XMLElement mask = ele.GetChildrenByName(maskName);
                        if (mask != null)
                        {
                            int r = mask.GetIntAttribute("r", 0);
                            int g = mask.GetIntAttribute("g", 0);
                            int b = mask.GetIntAttribute("b", 0);
                            int a = mask.GetIntAttribute("a", 0);
                            data.mask = new LColor(r, g, b, a);
                        }
                        else
                        {
                            data.mask = null;
                        }
                        string filter = ele.GetAttribute(filterName, n);
                        if (filter.Equals(n))
                        {
                            data.scaleType = 0;
                        }
                        if (filter.Equals(l))
                        {
                            data.scaleType = 1;
                        }
                        data.index = index;
                        XMLElement parent = ele.GetParent();
                        if (parent != null)
                        {
                            CollectionUtils.Put(imageList, parent.GetAttribute(name, empty), data);
                            index++;
                        }
                    }
                }
            }
            this.count  = imageList.Count;
            this.values = new LTextureObject[count];
        }
Esempio n. 15
0
 internal int GetIntAttribute(XMLElement elem, string name)
 {
     string val = elem.GetAttribute(name);
     if (val == null)
     {
         ThrowException("Attribute " + name + " is not set");
     }
     try
     {
         return Int32.Parse(val);
     }
     catch (FormatException)
     {
         ThrowException("Attribute " + name + " should has integer value");
     }
     return -1;
 }
Esempio n. 16
0
 internal string GetAttribute(XMLElement elem, string name)
 {
     string val = elem.GetAttribute(name);
     if (val == null)
     {
         ThrowException("Attribute " + name + " is not set");
     }
     return val;
 }