Esempio n. 1
0
        private static List <FrameInfo> TryRenderNode(ScriptNode node, out string filename)
        {
            filename = "??";

resolveAgain:
            {
                // Try to resolve UOL
                while (node.Get() is WzUOL)
                {
                    var uol     = node.Get() as WzUOL;
                    var path    = uol.ActualPath();
                    var newNode = node.GetNode(path);
                    if (newNode == null)
                    {
                        return(null);
                    }
                    node = newNode;
                }
            }

            {
                // If its a single canvas, render that
                var canvas = node.GetCanvas();
                if (canvas != null)
                {
                    filename = GetFilenameForNode(node);
                    return(new List <FrameInfo>(RenderFrame(canvas)));
                }
            }

            {
                // If its a prop, figure out if we can render it
                var animateableProp = FindAnimateableProp(node);
                if (animateableProp == null)
                {
                    var info = node.GetNode("info");
                    if (info == null)
                    {
                        return(null);
                    }

                    // Maybe we can find a link node
                    var link = node.GetString("info/link");
                    if (link != null)
                    {
                        var path = "../" + link + ".img";
                        Console.WriteLine("Trying to get node @ {0}", path);
                        var tmp = node.GetNode(path);
                        if (tmp != null)
                        {
                            node = tmp;
                            goto resolveAgain;
                        }
                    }

                    // Figure out if the info node is any good
                    animateableProp = FindAnimateableProp(info);
                    if (animateableProp != null && animateableProp is ScriptNode)
                    {
                        node = animateableProp;
                        goto resolveAgain;
                    }
                }
                else
                {
                    node = animateableProp;
                }
            }

            {
                // Try to render elements
                var frames = new List <FrameInfo>();

                bool indexesAreImageOrUOL = true;
                bool foundAny             = false;
                for (var i = 0; ; i++)
                {
                    var p = node.Get(i.ToString());
                    if (p == null)
                    {
                        break;
                    }
                    foundAny = true;
                    if (!(p is WzCanvas || p is WzUOL))
                    {
                        if (i == 0)
                        {
                            continue;
                        }
                        indexesAreImageOrUOL = false;
                        break;
                    }

                    frames.AddRange(RenderFrame(p));
                }

                if (foundAny && indexesAreImageOrUOL)
                {
                    if (node.GetInt32("zigzag", 0) == 1)
                    {
                        // Apply a zigzag
                        if (frames.Count > 2)
                        {
                            // Zigzag
                            var tmp = new List <FrameInfo>(frames);
                            tmp.RemoveAt(0);
                            tmp.RemoveAt(tmp.Count - 1);
                            tmp.Reverse();
                            frames.AddRange(tmp);
                        }
                    }
                }

                filename = GetFilenameForNode(node);
                return(frames);
            }
        }
        private void RenderCurrentlySelectedItems(object sender, EventArgs e)
        {
            if (blockRendering)
            {
                return;
            }

            var    skinId           = 0;
            var    stance           = "stand1"; // TODO: Fix for 2h
            var    luminousLarkness = 3;        // Different weapon
            var    stanceFrame      = 0;
            var    stanceUol        = stance + "/" + stanceFrame + "/";
            var    itemNodes        = new List <ScriptNode>();
            string earType          = "normal";

            foreach (var lbi in selectedItems.Items)
            {
                var ci = (ChosenItem)lbi;
                if (ci.NodePath.Contains("Character/00"))
                {
                    skinId = ci.ID;
                }
                else
                {
                    var node = ci.GetNode(_mainNode);

                    if (node != null)
                    {
                        itemNodes.Add(node);
                    }
                    else
                    {
                        Console.WriteLine("Unable to find {0} for {1}", ci.NodePath, ci.ID);
                    }
                }
            }

            var actionFrame = new ActionFrame();

            itemNodes.Insert(0, _mainNode.GetNode(string.Format("Character/{0:D8}.img", 2000 + skinId)));
            itemNodes.Insert(1, _mainNode.GetNode(string.Format("Character/{0:D8}.img", 12000 + skinId)));

            // Load all items and their positions
            foreach (var item in itemNodes)
            {
                // TODO: For Cash Weapon covers items, get the weapon category id thingy
                // its basically the two digits after 1, eg 01[70]2557

                var nodeToRenderUOL = stanceUol;
                if (item.GetFullPath().Contains("Face/"))
                {
                    nodeToRenderUOL = "default";
                }

                ScriptNode nodeToRender = item.GetNode(nodeToRenderUOL);

                if (nodeToRender == null)
                {
                    Console.WriteLine("Unable to find {0} in {1}", nodeToRenderUOL, item.GetFullPath());
                    continue;
                }

                var infoNode = item.GetNode("info");
                if (infoNode == null)
                {
                    continue;
                }

                var larkenessColors = nodeToRender.Get("weapon2") != null;

                foreach (var _imageNode in nodeToRender)
                {
                    var imageNode = _imageNode;
                    var category  = imageNode.Name;

                    if (category == "ear" || category == "lefEar" || category == "highlefEar")
                    {
                        if (category != earType)
                        {
                            continue;
                        }
                    }

                    if (larkenessColors && category != "weapon" + luminousLarkness)
                    {
                        // Skip Luminous coloars
                        continue;
                    }

                    if (category == "hairShade")
                    {
                        // Take subnode, based on the skin color. Go figure
                        // We'll fall back to 0 if not found
                        var skinAsString = skinId.ToString();
                        var tmp          = imageNode.GetNode(skinAsString);
                        if (tmp == null)
                        {
                            tmp = imageNode.GetNode("0");
                        }
                        if (tmp == null)
                        {
                            Console.WriteLine("Unable to find skin entry for hairShade node.");
                            continue;
                        }

                        imageNode = tmp;
                    }

                    var canvas = imageNode.GetCanvas();
                    if (canvas == null)
                    {
                        continue;
                    }

                    var mapNodes = imageNode.GetNode("map");
                    if (mapNodes == null)
                    {
                        continue;
                    }

                    var vslot = infoNode.GetString("vslot");
                    var islot = infoNode.GetString("islot");

                    // TODO: Set defaults
                    if (vslot == null || islot == null)
                    {
                        continue;
                    }

                    actionFrame.Merge(islot, vslot, imageNode);
                }
            }

            actionFrame.UpdateVisibility();


            var bm = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            using (var g = Graphics.FromImage(bm))
            {
                var centerX = bm.Width / 2;
                var centerY = (int)(bm.Height - (bm.Height * 0.20));

                foreach (var si in actionFrame.Sprites.Where(x => x.Visible))
                {
                    var x = si.Position.X;
                    var y = si.Position.Y;
                    Console.WriteLine("Rendering {0} {1} {2}", si.Source.Canvas.GetFullPath(), x, y);

                    x += centerX;
                    y += centerY;

                    g.DrawImage(si.Source.Canvas.Tile, x, y);
                }

                pictureBox1.Image = bm;
            }
        }
Esempio n. 3
0
 public static IEnumerable <FrameInfo> RenderFrame(ScriptNode p)
 {
     return(RenderFrame(p.Get()));
 }