Ejemplo n.º 1
0
        public static BitmapOrigin CreateFromNode(Wz_Node node, GlobalFindNodeFunction findNode)
        {
            BitmapOrigin bp = new BitmapOrigin();
            Wz_Uol       uol;

            while ((uol = node.GetValue <Wz_Uol>(null)) != null)
            {
                node = uol.HandleUol(node);
            }

            //获取linkNode
            var    linkNode = node.GetLinkedSourceNode(findNode);
            Wz_Png png      = linkNode?.GetValue <Wz_Png>() ?? (Wz_Png)node.Value;

            bp.Bitmap = png?.ExtractPng();
            Wz_Node   originNode = node.FindNodeByPath("origin");
            Wz_Vector vec        = (originNode == null) ? null : originNode.GetValue <Wz_Vector>();

            bp.Origin = (vec == null) ? new Point() : new Point(vec.X, vec.Y);

            return(bp);
        }
Ejemplo n.º 2
0
        public RenderFrame CreateFrame(Wz_Node frameNode)
        {
            string key = frameNode.FullPathToFile.Replace('\\', '/');
            Wz_Png png = null;

            string source = frameNode.FindNodeByPath("source").GetValueEx <string>(null);

            if (!string.IsNullOrEmpty(source))
            {
                Wz_Node sourceNode = PluginManager.FindWz(source);
                if (sourceNode != null)
                {
                    png = sourceNode.Value as Wz_Png;
                    key = sourceNode.FullPathToFile.Replace('\\', '/');
                }
            }
            else
            {
                png = frameNode.Value as Wz_Png;
            }

            if (png == null)
            {
                return(null);
            }

            RenderFrame frame = new RenderFrame();
            Wz_Vector   vec   = frameNode.FindNodeByPath("origin").GetValueEx <Wz_Vector>(null);

            frame.Texture = GetTexture(png, key);
            frame.Origin  = (vec == null ? new Vector2() : new Vector2(vec.X, vec.Y));
            frame.Delay   = frameNode.FindNodeByPath("delay").GetValueEx <int>(100);
            frame.Z       = frameNode.FindNodeByPath("z").GetValueEx <int>(0);
            frame.A0      = frameNode.FindNodeByPath("a0").GetValueEx <int>(255);
            frame.A1      = frameNode.FindNodeByPath("a1").GetValueEx <int>(frame.A0);
            return(frame);
        }
Ejemplo n.º 3
0
        private Frame LoadFrame(Wz_Node node)
        {
            //处理uol
            while (node?.Value is Wz_Uol uol)
            {
                node = uol.HandleUol(node);
            }
            if (node == null)
            {
                return(new Frame());
            }
            //寻找link
            var linkNode = node.GetLinkedSourceNode(PluginManager.FindWz);
            //加载资源
            var atlas = Load <TextureAtlas>(linkNode);
            //读取其他信息
            var frame = new Frame()
            {
                Texture   = atlas.Texture,
                AtlasRect = atlas.SrcRect,
                Z         = node.Nodes["z"].GetValueEx(0),
                Delay     = node.Nodes["delay"].GetValueEx(100),
                Blend     = node.Nodes["blend"].GetValueEx(0) != 0,
                Origin    = (node.Nodes["origin"]?.Value as Wz_Vector)?.ToPoint() ?? Point.Zero
            };
            Wz_Vector lt = node.Nodes["lt"]?.Value as Wz_Vector;
            Wz_Vector rb = node.Nodes["rb"]?.Value as Wz_Vector;

            if (lt != null && rb != null)
            {
                frame.BoundingBox = new Rectangle(lt.X, lt.Y, Math.Abs(lt.X - rb.X), Math.Abs(lt.Y - rb.Y));
            }
            frame.A0 = node.Nodes["a0"].GetValueEx(255);
            frame.A1 = node.Nodes["a1"].GetValueEx(frame.A0);
            return(frame);
        }
Ejemplo n.º 4
0
 public static Point ToPoint(this Wz_Vector vector)
 {
     return(new Point(vector.X, vector.Y));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 比较两个节点绑定的值是否相同。
        /// </summary>
        /// <param Name="dataNew">新的值。</param>
        /// <param Name="dataOld">旧的值。</param>
        /// <returns></returns>
        public virtual bool CompareData(object dataNew, object dataOld)
        {
            // skip virtual dir
            {
                if (dataNew is Wz_File fileNew && fileNew.IsSubDir)
                {
                    dataNew = null;
                }
                if (dataOld is Wz_File fileOld && fileOld.IsSubDir)
                {
                    dataNew = null;
                }
            }

            if (dataNew == null && dataOld == null)
            {
                return(true);
            }
            if (dataNew == null ^ dataOld == null)
            {
                return(false);
            }

            Type type = dataNew.GetType();

            if (type != dataOld.GetType())
            {
                return(false);
            }

            if (type.IsClass)
            {
                switch (dataNew)
                {
                case string str:
                    return(str == (string)dataOld);

                case Wz_Image img:
                    Wz_Image imgOld = (Wz_Image)dataOld;
                    return(img.Size == imgOld.Size && img.Checksum == imgOld.Checksum);

                case Wz_File file:
                    Wz_File fileOld = (Wz_File)dataOld;
                    return(file.Type == fileOld.Type);

                case Wz_Png png:
                    Wz_Png pngOld = (Wz_Png)dataOld;
                    switch (this.PngComparison)
                    {
                    case WzPngComparison.SizeOnly:
                        return(png.Width == pngOld.Width && png.Height == pngOld.Height);

                    case WzPngComparison.SizeAndDataLength:
                        return(png.Width == pngOld.Width &&
                               png.Height == pngOld.Height &&
                               png.DataLength == pngOld.DataLength);

                    case WzPngComparison.Pixel:
                        if (!(png.Width == pngOld.Width && png.Height == pngOld.Height && png.Form == pngOld.Form))
                        {
                            return(false);
                        }
                        byte[] pixelNew = png.GetRawData();
                        byte[] pixelOld = pngOld.GetRawData();
                        if (pixelNew == null || pixelOld == null || pixelNew.Length != pixelOld.Length)
                        {
                            return(false);
                        }
                        for (int i = 0, i1 = pixelNew.Length; i < i1; i++)
                        {
                            if (pixelNew[i] != pixelOld[i])
                            {
                                return(false);
                            }
                        }
                        return(true);

                    default:
                        goto case WzPngComparison.SizeAndDataLength;
                    }
                    break;

                case Wz_Vector vector:
                    Wz_Vector vectorOld = (Wz_Vector)dataOld;
                    return(vector.X == vectorOld.X && vector.Y == vectorOld.Y);

                case Wz_Uol uol:
                    return(uol.Uol == ((Wz_Uol)dataOld).Uol);

                case Wz_Sound sound:
                    Wz_Sound soundOld = (Wz_Sound)dataOld;
                    return(sound.Ms == soundOld.Ms && sound.DataLength == soundOld.DataLength);
                }
            }

            return(object.Equals(dataNew, dataOld));
        }