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
|
@ -8,80 +8,143 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
public class Actor
|
||||
{
|
||||
[XmlArray("defNames"), XmlArrayItem("li")] public List<string> defNames = new List<string>();
|
||||
[XmlArray("bodyDefTypes"), XmlArrayItem("li")] public List<string> bodyDefTypes = new List<string>();
|
||||
[XmlArray("requiredGender"), XmlArrayItem("li")] public List<string> requiredGender = new List<string>();
|
||||
[XmlArray("requiredGenitals"), XmlArrayItem("li")] public List<string> requiredGenitals = new List<string>();
|
||||
[XmlArray("raceOffsets"), XmlArrayItem("li")] public List<AlienRaceOffset> raceOffsets = new List<AlienRaceOffset>();
|
||||
[XmlArray("blacklistedRaces"), XmlArrayItem("li")] public List<string> blacklistedRaces = new List<string>();
|
||||
// Data to/from animationDef
|
||||
[XmlArray("defNames"), XmlArrayItem("li")] public List<string> defNames;
|
||||
[XmlArray("bodyDefTypes"), XmlArrayItem("li")] public List<string> bodyDefTypes;
|
||||
[XmlArray("requiredGenitals"), XmlArrayItem("li")] public List<string> requiredGenitals;
|
||||
[XmlArray("raceOffsets"), XmlArrayItem("li")] public List<PawnRaceOffset> raceOffsets;
|
||||
[XmlArray("tags"), XmlArrayItem("li")] public List<string> tags;
|
||||
public BodyTypeOffset bodyTypeOffset;
|
||||
public bool? initiator = false;
|
||||
public bool? controlGenitalAngle;
|
||||
public bool? isFucking;
|
||||
public bool? isFucked;
|
||||
|
||||
[XmlIgnore] public ActorGender gender;
|
||||
[XmlIgnore] private AlienRaceDef alienRaceDef;
|
||||
|
||||
public BodyTypeOffset bodyTypeOffset = new BodyTypeOffset();
|
||||
public bool initiator = false;
|
||||
public bool controlGenitalAngle;
|
||||
public bool isFucking;
|
||||
public bool isFucked;
|
||||
|
||||
[XmlIgnore] public string bodyType = "Male";
|
||||
|
||||
// Data serialization control
|
||||
public bool ShouldSerializedefNames() { return defNames.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializebodyDefTypes() { return bodyDefTypes.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializerequiredGender() { return requiredGender.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializerequiredGenitals() { return requiredGenitals.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializeraceOffsets() { return raceOffsets.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializeblacklistedRaces() { return blacklistedRaces.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializetags() { return tags.NotNullOrEmpty(); }
|
||||
public bool ShouldSerializeinitiator() { return initiator; }
|
||||
public bool ShouldSerializecontrolGenitalAngle() { return controlGenitalAngle; }
|
||||
public bool ShouldSerializeisFucking() { return isFucking; }
|
||||
public bool ShouldSerializeisFucked() { return isFucked; }
|
||||
public bool ShouldSerializebodyTypeOffset() { return bodyTypeOffset?.AllOffsetsEmpty() == false; }
|
||||
public bool ShouldSerializeinitiator() { return initiator == true; }
|
||||
public bool ShouldSerializecontrolGenitalAngle() { return controlGenitalAngle == true; }
|
||||
public bool ShouldSerializeisFucking() { return isFucking == true; }
|
||||
public bool ShouldSerializeisFucked() { return isFucked == true; }
|
||||
|
||||
public AlienRaceDef GetAlienRaceDef()
|
||||
{
|
||||
if (alienRaceDef == null)
|
||||
{ alienRaceDef = AlienRaceDefs.GetNamed("Human"); }
|
||||
|
||||
return alienRaceDef;
|
||||
// Data helper functions
|
||||
[XmlIgnore] public List<string> DefNames
|
||||
{
|
||||
get { return defNames.NullOrEmpty() ? defNames = new List<string>() : defNames; }
|
||||
set { defNames = value.NotNullOrEmpty() ? value : null; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
public void SetAlienRaceDef(string alienRaceDefName)
|
||||
{
|
||||
AlienRaceDef alienRaceDef = AlienRaceDefs.GetNamed(alienRaceDefName);
|
||||
|
||||
if (alienRaceDef != null)
|
||||
{ this.alienRaceDef = alienRaceDef; }
|
||||
[XmlIgnore] public List<string> BodyDefTypes
|
||||
{
|
||||
get { return bodyDefTypes.NullOrEmpty() ? bodyDefTypes = new List<string>() : bodyDefTypes; }
|
||||
set { bodyDefTypes = value.NotNullOrEmpty() ? value : null; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
public Vector3 GetAlienRaceOffset()
|
||||
{
|
||||
if (alienRaceDef == null)
|
||||
{ alienRaceDef = AlienRaceDefs.GetNamed("Human"); }
|
||||
[XmlIgnore] public List<string> RequiredGenitals
|
||||
{
|
||||
get { return requiredGenitals.NullOrEmpty() ? requiredGenitals = new List<string>() : requiredGenitals; }
|
||||
set { requiredGenitals = value.NotNullOrEmpty() ? value : null; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
AlienRaceOffset raceOffset = raceOffsets.FirstOrDefault(x => x.defName == alienRaceDef.defName);
|
||||
[XmlIgnore] public List<PawnRaceOffset> RaceOffsets {
|
||||
get { return raceOffsets.NullOrEmpty() ? raceOffsets = new List<PawnRaceOffset>() : raceOffsets; }
|
||||
set { raceOffsets = value.NotNullOrEmpty() ? value : null; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public List<string> Tags
|
||||
{
|
||||
get { return tags.NullOrEmpty() ? tags = new List<string>() : tags; }
|
||||
set { tags = value.NotNullOrEmpty() ? value : null; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public BodyTypeOffset BodyTypeOffset
|
||||
{
|
||||
get { return bodyTypeOffset == null ? bodyTypeOffset = new BodyTypeOffset() : bodyTypeOffset; }
|
||||
set { bodyTypeOffset = value; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public bool Initiator
|
||||
{
|
||||
get { return initiator == true; }
|
||||
set { if (value) { initiator = true; } else initiator = null; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public bool ControlGenitalAngle
|
||||
{
|
||||
get { return controlGenitalAngle == true; }
|
||||
set { if (value) { controlGenitalAngle = true; } else controlGenitalAngle = null; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public bool IsFucking
|
||||
{
|
||||
get { return isFucking == true; }
|
||||
set { if (value) { isFucking = true; } else isFucking = null; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
[XmlIgnore] public bool IsFucked
|
||||
{
|
||||
get { return isFucked == true; }
|
||||
set { if (value) { isFucked = true; } else isFucked = null; EventsManager.OnActorChanged(this); }
|
||||
}
|
||||
|
||||
// Local data
|
||||
[XmlIgnore] public string bodyType = "Male";
|
||||
[XmlIgnore] private PawnRaceDef pawnRaceDef;
|
||||
|
||||
// Methods
|
||||
public PawnRaceDef GetPawnRaceDef()
|
||||
{
|
||||
if (pawnRaceDef == null)
|
||||
{ pawnRaceDef = PawnRaceDefs.GetNamed("Human"); }
|
||||
|
||||
return pawnRaceDef;
|
||||
}
|
||||
|
||||
public void SetPawnRaceDef(string pawnRaceDefName)
|
||||
{
|
||||
PawnRaceDef pawnRaceDef = PawnRaceDefs.GetNamed(pawnRaceDefName);
|
||||
|
||||
if (pawnRaceDef != null)
|
||||
{
|
||||
this.pawnRaceDef = pawnRaceDef;
|
||||
EventsManager.OnActorChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 GetPawnRaceOffset()
|
||||
{
|
||||
if (pawnRaceDef == null)
|
||||
{ pawnRaceDef = PawnRaceDefs.GetNamed("Human"); }
|
||||
|
||||
PawnRaceOffset raceOffset = RaceOffsets.FirstOrDefault(x => x.defName == pawnRaceDef.defName);
|
||||
|
||||
if (raceOffset == null)
|
||||
{
|
||||
raceOffset = new AlienRaceOffset(alienRaceDef.defName);
|
||||
raceOffsets.Add(raceOffset);
|
||||
raceOffset = new PawnRaceOffset(pawnRaceDef.defName);
|
||||
RaceOffsets.Add(raceOffset);
|
||||
}
|
||||
|
||||
return raceOffset.GetOffset();
|
||||
}
|
||||
|
||||
public void SetAlienRaceOffset(Vector2 offset)
|
||||
public void SetPawnRaceOffset(Vector2 offset)
|
||||
{
|
||||
if (alienRaceDef == null)
|
||||
if (pawnRaceDef == null)
|
||||
{ return; }
|
||||
|
||||
AlienRaceOffset raceOffset = raceOffsets.FirstOrDefault(x => x.defName == alienRaceDef.defName);
|
||||
PawnRaceOffset raceOffset = RaceOffsets.FirstOrDefault(x => x.defName == pawnRaceDef.defName);
|
||||
|
||||
if (raceOffset == null)
|
||||
{
|
||||
raceOffset = new AlienRaceOffset(alienRaceDef.defName);
|
||||
raceOffsets.Add(raceOffset);
|
||||
raceOffset = new PawnRaceOffset(pawnRaceDef.defName);
|
||||
RaceOffsets.Add(raceOffset);
|
||||
|
||||
EventsManager.OnActorChanged(this);
|
||||
}
|
||||
|
||||
raceOffset.SetOffset(offset);
|
||||
|
@ -89,46 +152,25 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public Vector3 GetFinalTransformOffset()
|
||||
{
|
||||
Vector3 offset = GetAlienRaceOffset() + (GetAlienRaceDef().isHumanoid ? bodyTypeOffset.GetOffset(bodyType) : new Vector3());
|
||||
Vector3 offset = GetPawnRaceOffset() + (GetPawnRaceDef().isHumanoid ? BodyTypeOffset.GetOffset(bodyType) : new Vector3());
|
||||
|
||||
return new Vector3(offset.x, offset.z, offset.y);
|
||||
}
|
||||
|
||||
public void ValidateData()
|
||||
{
|
||||
bodyDefTypes = bodyDefTypes.Intersect(Tags.bodyDefTypes.Concat(CustomTags.bodyDefTypes))?.ToList();
|
||||
requiredGenitals = requiredGenitals.Intersect(Tags.bodyParts.Concat(CustomTags.bodyParts))?.ToList();
|
||||
raceOffsets = raceOffsets.Except(raceOffsets.Where(x => x.OffsetIsZero()))?.ToList();
|
||||
}
|
||||
|
||||
public bool MakeNew()
|
||||
{
|
||||
if (Workspace.animationDef == null)
|
||||
{ Debug.LogWarning("Cannot make new actor - there is no AnimationDef"); return false; }
|
||||
|
||||
Workspace.animationDef.actors.Add(this);
|
||||
Workspace.actorID = Workspace.animationDef.actors.Count - 1;
|
||||
|
||||
foreach (AnimationStage stage in Workspace.animationDef.animationStages)
|
||||
{
|
||||
PawnAnimationClip clip = new PawnAnimationClip();
|
||||
|
||||
if (clip.MakeNew())
|
||||
{
|
||||
stage.animationClips.Add(clip);
|
||||
stage.Initialize();
|
||||
stage.OnPostLoad();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetActorID()
|
||||
{
|
||||
if (Workspace.animationDef == null) return -1;
|
||||
|
||||
return Workspace.animationDef.actors.IndexOf(this);
|
||||
return Workspace.animationDef.Actors.IndexOf(this);
|
||||
}
|
||||
|
||||
// Pre-save / post-load
|
||||
public void OnPreSave()
|
||||
{
|
||||
BodyDefTypes = BodyDefTypes.Intersect(DefaultTags.bodyDefTypes.Concat(CustomTags.bodyDefTypes))?.ToList();
|
||||
RequiredGenitals = RequiredGenitals.Intersect(DefaultTags.bodyParts.Concat(CustomTags.bodyParts))?.ToList();
|
||||
RaceOffsets = RaceOffsets.Except(RaceOffsets.Where(x => x.OffsetIsZero()))?.ToList();
|
||||
}
|
||||
|
||||
public void OnPostLoad() { }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue