示例#1
0
 public void RecreateSprites()
 {
     if (Sprite != null)
     {
         Sprite.Remove();
         var source = Sprite.SourceElement;
         Sprite = new Sprite(source, file: GetSpritePath(source, Params.normalSpriteParams));
     }
     if (_deformSprite != null)
     {
         _deformSprite.Remove();
         var source = _deformSprite.Sprite.SourceElement;
         _deformSprite = new DeformableSprite(source, filePath: GetSpritePath(source, Params.deformSpriteParams));
     }
     if (DamagedSprite != null)
     {
         DamagedSprite.Remove();
         var source = DamagedSprite.SourceElement;
         DamagedSprite = new Sprite(source, file: GetSpritePath(source, Params.damagedSpriteParams));
     }
     for (int i = 0; i < ConditionalSprites.Count; i++)
     {
         var conditionalSprite = ConditionalSprites[i];
         var source            = conditionalSprite.ActiveSprite.SourceElement;
         conditionalSprite.Remove();
         ConditionalSprites[i] = new ConditionalSprite(source, character, file: GetSpritePath(source, null));
     }
     for (int i = 0; i < DecorativeSprites.Count; i++)
     {
         var decorativeSprite = DecorativeSprites[i];
         decorativeSprite.Remove();
         var source = decorativeSprite.Sprite.SourceElement;
         DecorativeSprites[i] = new DecorativeSprite(source, file: GetSpritePath(source, Params.decorativeSpriteParams[i]));
     }
 }
示例#2
0
        partial void InitProjSpecific(XElement element)
        {
            for (int i = 0; i < Params.decorativeSpriteParams.Count; i++)
            {
                var param            = Params.decorativeSpriteParams[i];
                var decorativeSprite = new DecorativeSprite(param.Element, file: GetSpritePath(param.Element, param));
                DecorativeSprites.Add(decorativeSprite);
                int groupID = decorativeSprite.RandomGroupID;
                if (!DecorativeSpriteGroups.ContainsKey(groupID))
                {
                    DecorativeSpriteGroups.Add(groupID, new List <DecorativeSprite>());
                }
                DecorativeSpriteGroups[groupID].Add(decorativeSprite);
                spriteAnimState.Add(decorativeSprite, new SpriteState());
            }
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    Sprite = new Sprite(subElement, file: GetSpritePath(subElement, Params.normalSpriteParams));
                    break;

                case "damagedsprite":
                    DamagedSprite = new Sprite(subElement, file: GetSpritePath(subElement, Params.damagedSpriteParams));
                    break;

                case "conditionalsprite":
                    var conditionalSprite = new ConditionalSprite(subElement, character, file: GetSpritePath(subElement, null));
                    ConditionalSprites.Add(conditionalSprite);
                    if (conditionalSprite.DeformableSprite != null)
                    {
                        CreateDeformations(subElement.GetChildElement("deformablesprite"));
                    }
                    break;

                case "deformablesprite":
                    _deformSprite = new DeformableSprite(subElement, filePath: GetSpritePath(subElement, Params.deformSpriteParams));
                    CreateDeformations(subElement);
                    break;

                case "lightsource":
                    LightSource             = new LightSource(subElement);
                    InitialLightSourceColor = LightSource.Color;
                    break;
                }

                void CreateDeformations(XElement e)
                {
                    foreach (XElement animationElement in e.GetChildElements("spritedeformation"))
                    {
                        int sync = animationElement.GetAttributeInt("sync", -1);
                        SpriteDeformation deformation = null;
                        if (sync > -1)
                        {
                            // if the element is marked with the sync attribute, use a deformation of the same type with the same sync value, if there is one already.
                            string typeName = animationElement.GetAttributeString("type", "").ToLowerInvariant();
                            deformation = ragdoll.Limbs
                                          .Where(l => l != null)
                                          .SelectMany(l => l.Deformations)
                                          .Where(d => d.TypeName == typeName && d.Sync == sync)
                                          .FirstOrDefault();
                        }
                        if (deformation == null)
                        {
                            deformation = SpriteDeformation.Load(animationElement, character.SpeciesName);
                            if (deformation != null)
                            {
                                ragdoll.SpriteDeformations.Add(deformation);
                            }
                        }
                        if (deformation != null)
                        {
                            Deformations.Add(deformation);
                        }
                    }
                }
            }
        }