Example #1
0
 public AseFile(int width, int height)
 {
     this.Width  = width;
     this.Height = height;
     this.Layers = new LayerGroup(-1, "");
     this.frames = new List <Frame>();
     this.tags   = new List <FrameTag>();
 }
Example #2
0
        static Layer FindLayerGlobally(LayerGroup group, int index)
        {
            foreach (var g in group.Layers)
            {
                if (g.Index == index)
                {
                    return(g);
                }
            }

            foreach (var g in group.SubGroups)
            {
                var r = FindLayerGlobally(g, index);
                if (r != null)
                {
                    return(r);
                }
            }

            return(null);
        }
Example #3
0
        static IUserDataAcceptor ParseLayer(AseFile file,
                                            BinaryReader reader,
                                            Stack <LayerGroup> layerGroups,
                                            int readLayerIndex)
        {
            IUserDataAcceptor lastUserdataAcceptor;
            var flags = reader.ReadWord();

            var visible        = (flags & 0x1) != 0;
            var referenceLayer = (flags & 0x20) != 0;

            var layerType  = (AseLayerType)reader.ReadWord();
            var childLevel = reader.ReadWord(); // childLevel

            if ((layerGroups.Count - 1) != (childLevel))
            {
                layerGroups.Pop();
                if (layerGroups.Count == 0)
                {
                    // workaround broken files ..
                    Debug.LogWarning("Layer Structure Parsing Error.");
                    layerGroups.Push(file.Layers);
                }
            }

            reader.ReadWord();
            reader.ReadWord();

            var blendMode = (BlendMode)reader.ReadWord();
            var opacity   = reader.ReadByte() / 255.0f;

            reader.ReadBytes(3);

            var layerName = reader.ReadUTF8();
            var type      = layerName.StartsWith("@") ? LayerType.Meta : LayerType.Content;

            Debug.Log("Reading layer definition " + readLayerIndex + ", " + layerName);

            if (layerType == AseLayerType.Layer && !layerName.StartsWith("//") && !referenceLayer)
            {
                //layer.index = readLayerIndex;
                var layer = new Layer(readLayerIndex, type, layerName, visible, blendMode, opacity);
                if (layer.Type == LayerType.Meta || visible)
                {
                    MetaLayerParser.Parse(layer);
                    layerGroups.Peek().Layers.Add(layer);
                }

                lastUserdataAcceptor = layer;
            }
            else if (layerType == AseLayerType.LayerGroup)
            {
                // is a layer group.
                var layerGroup = new LayerGroup(readLayerIndex, layerName);
                MetaLayerParser.Parse(layerGroup);
                layerGroups.Peek().SubGroups.Add(layerGroup);
                layerGroups.Push(layerGroup);
                lastUserdataAcceptor = layerGroup;
            }
            else
            {
                lastUserdataAcceptor = new NoOpUserDataAcceptor();
            }

            return(lastUserdataAcceptor);
        }