mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Code refactor
This commit is contained in:
parent
cd4711a8e5
commit
757badf4f6
517 changed files with 2534 additions and 2221 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
@ -8,33 +9,163 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
public class AnimationDef
|
||||
{
|
||||
public string defName = "Undefined";
|
||||
public string label = "Undefined";
|
||||
// Data to/from animationDef
|
||||
public string defName;
|
||||
public string label;
|
||||
public bool sounds = true;
|
||||
[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;
|
||||
|
||||
[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>();
|
||||
|
||||
[XmlIgnore] public int animationTimeTicks { get { return animationStages.Sum(x => x.playTimeTicks); } }
|
||||
[XmlIgnore] public int animationTimeTicksQuick { get { return animationStages.Sum(x => x.playTimeTicksQuick); } }
|
||||
|
||||
// Data serialization control
|
||||
public bool ShouldSerializesexTypes() { return sexTypes.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializeinteractionDefTypes() { return interactionDefTypes.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializeactors() { return actors.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializeanimationStages() { return animationStages.NotNullOrEmpty(); }
|
||||
|
||||
// Data helper functions
|
||||
[XmlIgnore] public string DefName
|
||||
{
|
||||
get { return defName != null && defName != "" ? defName : "newAnimation"; }
|
||||
set { defName = value; EventsManager.OnAnimationDefChanged(); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public string Label
|
||||
{
|
||||
get { return label != null && label != "" ? label : "newAnimation"; }
|
||||
set { label = value; EventsManager.OnAnimationDefChanged(); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public List<string> SexTypes
|
||||
{
|
||||
get { return sexTypes.NullOrEmpty() ? sexTypes = new List<string>() : sexTypes; }
|
||||
set { sexTypes = value.NotNullOrEmpty() ? value : null; EventsManager.OnAnimationDefChanged(); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public List<string> InteractionDefTypes
|
||||
{
|
||||
get { return interactionDefTypes.NullOrEmpty() ? interactionDefTypes = new List<string>() : interactionDefTypes; }
|
||||
set { interactionDefTypes = value.NotNullOrEmpty() ? value : null; EventsManager.OnAnimationDefChanged(); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public List<Actor> Actors
|
||||
{
|
||||
get { return actors.NullOrEmpty() ? actors = new List<Actor>() : actors; }
|
||||
set { actors = value.NotNullOrEmpty() ? value : null; EventsManager.OnAnimationDefChanged(); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public List<AnimationStage> AnimationStages
|
||||
{
|
||||
get { if (animationStages.NullOrEmpty()){ animationStages = new List<AnimationStage>(); } return animationStages; }
|
||||
set { animationStages = value.NotNullOrEmpty() ? value : null; EventsManager.OnAnimationDefChanged(); }
|
||||
}
|
||||
|
||||
// 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
|
||||
public void Initialize()
|
||||
{
|
||||
foreach (AnimationStage stage in animationStages)
|
||||
foreach (AnimationStage stage in AnimationStages)
|
||||
{ stage.Initialize(); }
|
||||
}
|
||||
|
||||
public void ValidateData()
|
||||
public void AddActor()
|
||||
{
|
||||
sexTypes = sexTypes.Intersect(Tags.sexTypes.Concat(CustomTags.sexTypes))?.ToList();
|
||||
interactionDefTypes = interactionDefTypes.Intersect(Tags.interactionDefTypes.Concat(CustomTags.interactionDefTypes))?.ToList();
|
||||
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);
|
||||
|
||||
Workspace.ActorID = Workspace.animationDef.Actors.Count - 1;
|
||||
|
||||
foreach (AnimationStage stage in Workspace.animationDef.AnimationStages)
|
||||
{ stage.AddAnimationClip(Workspace.ActorID); }
|
||||
|
||||
EventsManager.OnActorCountChanged();
|
||||
Workspace.RecordEvent("Actor addition");
|
||||
}
|
||||
|
||||
public void RemoveActor()
|
||||
{
|
||||
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();
|
||||
|
||||
Workspace.RecordEvent("Stage addition");
|
||||
}
|
||||
|
||||
public void CloneAnimationStage()
|
||||
{
|
||||
AnimationStage stage = Workspace.GetCurrentAnimationStage().Copy();
|
||||
stage.StageName += " (Clone)";
|
||||
stage.Initialize();
|
||||
|
||||
Workspace.animationDef.AnimationStages.Insert(Workspace.StageID + 1, stage);
|
||||
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--;
|
||||
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() { }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue