partial void InitProjSpecific(XElement element) { foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "sprite": Sprite = new Sprite(subElement, "", GetSpritePath(subElement)); break; case "damagedsprite": DamagedSprite = new Sprite(subElement, "", GetSpritePath(subElement)); break; case "conditionalsprite": ConditionalSprites.Add(new ConditionalSprite(subElement, character, file: GetSpritePath(subElement))); break; case "deformablesprite": DeformSprite = new DeformableSprite(subElement, filePath: GetSpritePath(subElement)); foreach (XElement animationElement in subElement.Elements()) { 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); } } break; case "lightsource": LightSource = new LightSource(subElement); InitialLightSourceColor = LightSource.Color; break; case "sound": HitSoundTag = subElement.GetAttributeString("tag", ""); if (string.IsNullOrWhiteSpace(HitSoundTag)) { //legacy support HitSoundTag = subElement.GetAttributeString("file", ""); } break; } } }
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); } } } } }