public void AlignChildAnimation() { if (ChildAnimationPlaying == null) { return; } Sprite sprite = ChildAnimationPlaying.Owner; AnimationModule spriteModule = ChildAnimationPlaying.ModuleOwner; float X = Owner.X, Y = Owner.Y, Width = Owner.Width, Height = Owner.Height; //Default is center parent origin, center child origin float defaultx = X; float defaulty = Y; Placement porigin = ChildAnimationPlaying.ParentOriginType; if ((porigin & Placement.Left) != 0) { defaultx -= (Width / 2f); } if ((porigin & Placement.Right) != 0) { defaultx += Width / 2f; } if ((porigin & Placement.Top) != 0) { defaulty -= Height / 2f; } if ((porigin & Placement.Bottom) != 0) { defaulty += (Height / 2f); } float xadd = 0f, yadd = 0f; Placement origin = ChildAnimationPlaying.OriginType; if ((origin & Placement.Left) != 0) { xadd = -(ChildAnimationPlaying.Width / 2f); } if ((origin & Placement.Right) != 0) { xadd = ChildAnimationPlaying.Width / 2f; } if ((origin & Placement.Top) != 0) { yadd = ChildAnimationPlaying.Height / 2f; } if ((origin & Placement.Bottom) != 0) { yadd = -(ChildAnimationPlaying.Height / 2f); } //Move the "hat" sprite to the default origin of the sprite sprite.X = defaultx - xadd; sprite.Y = defaulty + yadd; //Offset the "hat" sprite sprite.X += ChildAnimationPlaying.XOffset; sprite.Y += ChildAnimationPlaying.YOffset; spriteModule.AlignChildAnimation(); }
private List <AnimationModule> Setup(ref Animation ani, List <Animation> inheritStack = null) { var temp = new List <AnimationModule>(); if (ani.setup_ran) { return(temp); } if (inheritStack == null) { inheritStack = new List <Animation>(); } Assembly assembly = Assembly.GetEntryAssembly(); ani.ModuleOwner = this; if (ani.Animations == null) { return(temp); } if (ani.InheritedAnimations != null) { if (inheritStack.Count > 0 && inheritStack.Contains(ani.InheritedAnimationOwner)) { throw new InvalidOperationException("Loop inheritance detected!"); } if (!ani.InheritedAnimationOwner.setup_ran) //If the inherited animation hasn't been setup yet { Animation inheritOwner = ani.InheritedAnimationOwner; inheritStack.Add(ani); //Add ourself to the stack Setup(ref inheritOwner, inheritStack); //Setup the inherited animation inheritStack.Remove(ani); //Remove ourself from the stack } AnimationHolder t = ani.Animations; AnimationHolder.Combind(ani.InheritedAnimations, ref t); } foreach (string ckey in ani.Animations.Animations.Keys) //To follow this, let's assume this is the "hat" animation for "walking left" animation { //ckey = "hat" Animation child_animation = ani.Animations[ckey]; //Same as ani.Animations.Animations[ckey]; //Get the animation object for "hat" child_animation.ParentAnimation = ani; //Set the parent of this child animation to this if (ani.InheritedAnimations == null) //Only inherit values if this animation didn't inherit animations from another animation { Animation.Combind(ani, ref child_animation, false); //Inherit values from parent animation to this animation (exclude animations) } if (!child_animation.IsEmpty) { ModuleSprite sprite; AnimationModule spriteModule; Type st = assembly.GetType(child_animation.SpriteFullName); //Get the type for the FullSpriteName if (st == null) { //Assume it's a file path if no type was found try { sprite = new BasicAnimatedSprite(child_animation.SpriteFullName); spriteModule = new AnimationModule("basic_sprite"); sprite.AttachModule(spriteModule); } catch { //If there was an error making this sprite //Just ignore it.. ani.setup_ran = true; return(temp); } } else { sprite = (ModuleSprite)Activator.CreateInstance(st); //Create a new instance of the child sprite if (sprite.ModuleExists <AnimationModule>()) { spriteModule = sprite.GetModules <AnimationModule>()[0]; //There can only ever bee one animation module } else { spriteModule = new AnimationModule(sprite.ToString()); sprite.AttachModule(spriteModule); } } child_animation.ModuleOwner = spriteModule; //Set the owner of the "hat" animation to the newly created sprite spriteModule.Animations = child_animation.Animations; //Set the animations for the hat sprite to the children animations of the "hat" animation. Owner.Attach(sprite); sprite.IsVisible = false; //Make sure this sprite isn't visible by default temp.Add(spriteModule); //Add the "hat" sprite as a children of this sprite spriteModule.SetupChildren(spriteModule.Animations); //Setup the children of "hat" animation, and put all of it's children in a list //Nevermind, don't do that //temp.AddRange(temp2); //Add all of children of the "hat" sprite as our children as well. } else { temp.Add(Empty); //This is an empty animation, fill it with a unused module } } ani.setup_ran = true; return(temp); }