rimworld-animation-studio/Assets/Scripts/AnimationComponents/AnimationDef.cs

90 lines
3.3 KiB
C#
Raw Normal View History

2022-09-13 05:36:34 +00:00
using System.Collections.Generic;
2022-09-19 00:07:44 +00:00
using System.Linq;
2022-09-13 05:36:34 +00:00
using System.Xml;
using System.Xml.Serialization;
2022-09-19 00:07:44 +00:00
using UnityEngine;
2022-09-13 05:36:34 +00:00
namespace RimWorldAnimationStudio
{
public class AnimationDef
{
public string defName = "Undefined";
public string label = "Undefined";
public bool sounds = false;
2022-09-14 05:25:58 +00:00
[XmlArray("sexTypes"), XmlArrayItem("li")] public List<string> sexTypes = new List<string>();
[XmlArray("interactionDefTypes"), XmlArrayItem("li")] public List<string> interactionDefTypes = new List<string>();
[XmlArray("actors"), XmlArrayItem("li")] public List<Actor> actors = new List<Actor>();
[XmlArray("animationStages"), XmlArrayItem("li")] public List<AnimationStage> animationStages = new List<AnimationStage>();
2022-09-13 05:36:34 +00:00
[XmlIgnore] public int animationTimeTicks = 0;
2022-09-13 05:36:34 +00:00
public void Initialize()
{
animationTimeTicks = 0;
foreach (AnimationStage stage in animationStages)
{
stage.Initialize();
animationTimeTicks += stage.playTimeTicks;
}
}
2022-09-19 00:07:44 +00:00
// move to app manager
2022-09-19 00:07:44 +00:00
public void RunPreSaveOperations()
{
// Stage edits
for (int i = 0; i < animationStages.Count; i++)
{
AnimationStage stage = animationStages[i];
// Sort keyframes by atTick
foreach (PawnAnimationClip clip in stage.animationClips)
{ clip.keyframes = clip.keyframes.OrderBy(x => x.atTick).ToList(); }
// Check if looping
int stageWindowSize = animationStages[i].stageWindowSize > 0 ? animationStages[i].stageWindowSize : animationStages[i].animationClips.Select(x => x.duration).Max();
int cycles = Mathf.CeilToInt(animationStages[i].playTimeTicks / stageWindowSize);
stage.isLooping = cycles > 1;
}
// Actor edits
for (int i = 0; i < actors.Count; i++)
2022-09-19 00:07:44 +00:00
{
Actor actor = actors[i];
actor.isFucking = actor.requiredGenitals.Contains("Any appendage") ? (bool?)true : null;
2022-09-19 00:07:44 +00:00
if (actor.isFucking == true)
{ actor.requiredGenitals.Remove("Any appendage"); }
actor.isFucked = actor.requiredGenitals.Contains("Any orifice") ? (bool?)true : null;
2022-09-19 00:07:44 +00:00
if (actor.isFucked == true)
{ actor.requiredGenitals.Remove("Any orifice"); }
actor.controlGenitalAngle = animationStages.Any(x => x.animationClips[i].keyframes.Any(y => y.genitalAngle != 0)) ? (bool?)true : null;
//if (actor.requiredGender.Contains("Female")) actor.gender = ActorGender.Female;
//else if (actor.requiredGender.Contains("Male")) actor.gender = ActorGender.Male;
//else actor.gender = ActorGender.None;
2022-09-19 00:07:44 +00:00
}
//actors.OrderBy(x => (int)x.gender);
2022-09-19 00:07:44 +00:00
}
public void RunPostLoadOperations()
{
foreach (Actor actor in actors)
{
if (actor.isFucking == true)
{ actor.requiredGenitals.Add("Any appendage"); }
if (actor.isFucked == true)
{ actor.requiredGenitals.Add("Any orifice"); }
}
}
2022-09-13 05:36:34 +00:00
}
}