2022-10-27 05:56:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
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
|
|
|
|
|
{
|
2022-10-27 05:56:04 +00:00
|
|
|
|
// Data to/from animationDef
|
|
|
|
|
public string defName;
|
|
|
|
|
public string label;
|
2022-10-12 05:22:29 +00:00
|
|
|
|
public bool sounds = true;
|
2022-10-27 05:56:04 +00:00
|
|
|
|
[XmlArray("sexTypes"), XmlArrayItem("li")] public List<string> sexTypes;
|
|
|
|
|
[XmlArray("interactionDefTypes"), XmlArrayItem("li")] public List<string> interactionDefTypes;
|
|
|
|
|
[XmlArray("actors"), XmlArrayItem("li")] public List<Actor> actors;
|
|
|
|
|
[XmlArray("animationStages"), XmlArrayItem("li")] public List<AnimationStage> animationStages;
|
2022-09-15 05:17:44 +00:00
|
|
|
|
|
2022-10-27 05:56:04 +00:00
|
|
|
|
// Data serialization control
|
2022-09-26 04:10:41 +00:00
|
|
|
|
public bool ShouldSerializesexTypes() { return sexTypes.NotNullOrEmpty(); }
|
|
|
|
|
public bool ShouldSerializeinteractionDefTypes() { return interactionDefTypes.NotNullOrEmpty(); }
|
|
|
|
|
public bool ShouldSerializeactors() { return actors.NotNullOrEmpty(); }
|
|
|
|
|
public bool ShouldSerializeanimationStages() { return animationStages.NotNullOrEmpty(); }
|
|
|
|
|
|
2022-10-27 05:56:04 +00:00
|
|
|
|
// Data helper functions
|
|
|
|
|
[XmlIgnore] public string DefName
|
|
|
|
|
{
|
|
|
|
|
get { return defName != null && defName != "" ? defName : "newAnimation"; }
|
2022-10-28 05:28:51 +00:00
|
|
|
|
set { defName = value; }
|
2022-10-27 05:56:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[XmlIgnore] public string Label
|
|
|
|
|
{
|
|
|
|
|
get { return label != null && label != "" ? label : "newAnimation"; }
|
2022-10-28 05:28:51 +00:00
|
|
|
|
set { label = value; }
|
2022-10-27 05:56:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[XmlIgnore] public List<string> SexTypes
|
|
|
|
|
{
|
|
|
|
|
get { return sexTypes.NullOrEmpty() ? sexTypes = new List<string>() : sexTypes; }
|
2022-10-28 05:28:51 +00:00
|
|
|
|
set { sexTypes = value.NotNullOrEmpty() ? value : null; }
|
2022-10-27 05:56:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[XmlIgnore] public List<string> InteractionDefTypes
|
|
|
|
|
{
|
|
|
|
|
get { return interactionDefTypes.NullOrEmpty() ? interactionDefTypes = new List<string>() : interactionDefTypes; }
|
2022-10-28 05:28:51 +00:00
|
|
|
|
set { interactionDefTypes = value.NotNullOrEmpty() ? value : null; }
|
2022-10-27 05:56:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[XmlIgnore] public List<Actor> Actors
|
|
|
|
|
{
|
|
|
|
|
get { return actors.NullOrEmpty() ? actors = new List<Actor>() : actors; }
|
2022-10-28 05:28:51 +00:00
|
|
|
|
set { actors = value.NotNullOrEmpty() ? value : null; }
|
2022-10-27 05:56:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[XmlIgnore] public List<AnimationStage> AnimationStages
|
|
|
|
|
{
|
|
|
|
|
get { if (animationStages.NullOrEmpty()){ animationStages = new List<AnimationStage>(); } return animationStages; }
|
2022-10-28 05:28:51 +00:00
|
|
|
|
set { animationStages = value.NotNullOrEmpty() ? value : null; }
|
2022-10-27 05:56:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Local data
|
|
|
|
|
[XmlIgnore] public int animationTimeTicks { get { return AnimationStages.Sum(x => x.PlayTimeTicks); } }
|
|
|
|
|
[XmlIgnore] public int animationTimeTicksQuick { get { return AnimationStages.Sum(x => x.PlayTimeTicksQuick); } }
|
|
|
|
|
|
|
|
|
|
// Methods
|
2022-09-13 05:36:34 +00:00
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2022-10-27 05:56:04 +00:00
|
|
|
|
foreach (AnimationStage stage in AnimationStages)
|
2022-10-14 19:00:57 +00:00
|
|
|
|
{ stage.Initialize(); }
|
2022-09-13 05:36:34 +00:00
|
|
|
|
}
|
2022-09-19 00:07:44 +00:00
|
|
|
|
|
2022-10-27 05:56:04 +00:00
|
|
|
|
public void AddActor()
|
|
|
|
|
{
|
|
|
|
|
if (Workspace.animationDef.Actors.Count >= 8)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("Cannot add actor - the animation can only contain a maximum of eight actors.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Actor actor = new Actor();
|
|
|
|
|
Actors.Add(actor);
|
|
|
|
|
|
|
|
|
|
foreach (AnimationStage stage in Workspace.animationDef.AnimationStages)
|
2022-10-28 05:28:51 +00:00
|
|
|
|
{ stage.AddAnimationClip(Workspace.animationDef.Actors.Count - 1); }
|
2022-10-27 05:56:04 +00:00
|
|
|
|
|
2022-10-28 05:28:51 +00:00
|
|
|
|
Initialize();
|
|
|
|
|
Workspace.ActorID = Workspace.animationDef.Actors.Count - 1;
|
|
|
|
|
|
|
|
|
|
EventsManager.OnActorCountChanged();
|
2022-10-27 05:56:04 +00:00
|
|
|
|
Workspace.RecordEvent("Actor addition");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveActor()
|
2022-09-19 00:07:44 +00:00
|
|
|
|
{
|
2022-10-27 05:56:04 +00:00
|
|
|
|
if (Workspace.animationDef.Actors.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("Cannot delete actor - the animation must contain at least one actor.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (AnimationStage stage in Workspace.animationDef.AnimationStages)
|
|
|
|
|
{ stage.AnimationClips.RemoveAt(Workspace.ActorID); }
|
|
|
|
|
|
|
|
|
|
Workspace.animationDef.Actors.RemoveAt(Workspace.ActorID);
|
|
|
|
|
Workspace.ActorID--;
|
|
|
|
|
|
|
|
|
|
EventsManager.OnActorCountChanged();
|
|
|
|
|
Workspace.RecordEvent("Actor deletion");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddAnimationStage()
|
|
|
|
|
{
|
|
|
|
|
AnimationStage stage = new AnimationStage();
|
|
|
|
|
AnimationStages.Add(stage);
|
|
|
|
|
|
|
|
|
|
foreach (Actor actor in Workspace.animationDef.Actors)
|
|
|
|
|
{ stage.AddAnimationClip(actor.GetActorID()); }
|
|
|
|
|
|
|
|
|
|
Initialize();
|
2022-10-28 05:28:51 +00:00
|
|
|
|
Workspace.StageID = Workspace.animationDef.AnimationStages.Count - 1;
|
2022-10-27 05:56:04 +00:00
|
|
|
|
|
2022-10-28 05:28:51 +00:00
|
|
|
|
EventsManager.OnStageCountChanged();
|
2022-10-27 05:56:04 +00:00
|
|
|
|
Workspace.RecordEvent("Stage addition");
|
2022-09-19 00:07:44 +00:00
|
|
|
|
}
|
2022-10-27 05:56:04 +00:00
|
|
|
|
|
|
|
|
|
public void CloneAnimationStage()
|
|
|
|
|
{
|
|
|
|
|
AnimationStage stage = Workspace.GetCurrentAnimationStage().Copy();
|
|
|
|
|
stage.StageName += " (Clone)";
|
|
|
|
|
|
|
|
|
|
Workspace.animationDef.AnimationStages.Insert(Workspace.StageID + 1, stage);
|
2022-10-28 05:28:51 +00:00
|
|
|
|
Initialize();
|
|
|
|
|
|
|
|
|
|
EventsManager.OnStageCountChanged();
|
2022-10-27 05:56:04 +00:00
|
|
|
|
Workspace.RecordEvent("Stage clone");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveAnimationStage(int startIndex, int delta)
|
|
|
|
|
{
|
|
|
|
|
if (startIndex + delta < 0 || startIndex + delta >= AnimationStages.Count) return;
|
|
|
|
|
|
|
|
|
|
AnimationStage stage = AnimationStages[startIndex];
|
|
|
|
|
AnimationStages[startIndex] = Workspace.animationDef.AnimationStages[startIndex + delta];
|
|
|
|
|
AnimationStages[startIndex + delta] = stage;
|
|
|
|
|
|
|
|
|
|
Workspace.StageID = startIndex + delta;
|
|
|
|
|
Workspace.RecordEvent("Stage move");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveAnimationStage()
|
|
|
|
|
{
|
|
|
|
|
if (Workspace.animationDef.AnimationStages.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("Cannot delete animation stage - the animation must contain at least one animation stage.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AnimationStages.RemoveAt(Workspace.StageID);
|
|
|
|
|
Workspace.StageID--;
|
2022-10-28 05:28:51 +00:00
|
|
|
|
|
|
|
|
|
EventsManager.OnStageCountChanged();
|
2022-10-27 05:56:04 +00:00
|
|
|
|
Workspace.RecordEvent("Stage deletion");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pre-save / post-load
|
|
|
|
|
public void OnPreSave()
|
|
|
|
|
{
|
|
|
|
|
SexTypes = SexTypes.Intersect(DefaultTags.sexTypes.Concat(CustomTags.sexTypes))?.ToList();
|
|
|
|
|
InteractionDefTypes = InteractionDefTypes.Intersect(DefaultTags.interactionDefTypes.Concat(CustomTags.interactionDefTypes))?.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnPostLoad() { }
|
2022-09-13 05:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|