mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
2989d9a72c
- Insert adds a new keyframe to the selected timeline - New stages have frames cloned from the last frame of current stage - Existing key are now replaced when another key is dropped on them - Fixed bug where starting a new animation could result in errors
132 lines
5.1 KiB
C#
132 lines
5.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Xml;
|
|
using System.Xml.Serialization;
|
|
using UnityEngine;
|
|
|
|
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>();
|
|
[XmlArray("tags"), XmlArrayItem("li")] public List<string> tags;
|
|
|
|
[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";
|
|
|
|
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 AlienRaceDef GetAlienRaceDef()
|
|
{
|
|
if (alienRaceDef == null)
|
|
{ alienRaceDef = AlienRaceDefs.GetNamed("Human"); }
|
|
|
|
return alienRaceDef;
|
|
}
|
|
|
|
public void SetAlienRaceDef(string alienRaceDefName)
|
|
{
|
|
AlienRaceDef alienRaceDef = AlienRaceDefs.GetNamed(alienRaceDefName);
|
|
|
|
if (alienRaceDef != null)
|
|
{ this.alienRaceDef = alienRaceDef; }
|
|
}
|
|
|
|
public Vector3 GetAlienRaceOffset()
|
|
{
|
|
if (alienRaceDef == null)
|
|
{ alienRaceDef = AlienRaceDefs.GetNamed("Human"); }
|
|
|
|
AlienRaceOffset raceOffset = raceOffsets.FirstOrDefault(x => x.defName == alienRaceDef.defName);
|
|
|
|
if (raceOffset == null)
|
|
{
|
|
raceOffset = new AlienRaceOffset(alienRaceDef.defName);
|
|
raceOffsets.Add(raceOffset);
|
|
}
|
|
|
|
return raceOffset.GetOffset();
|
|
}
|
|
|
|
public void SetAlienRaceOffset(Vector2 offset)
|
|
{
|
|
if (alienRaceDef == null)
|
|
{ return; }
|
|
|
|
AlienRaceOffset raceOffset = raceOffsets.FirstOrDefault(x => x.defName == alienRaceDef.defName);
|
|
|
|
if (raceOffset == null)
|
|
{
|
|
raceOffset = new AlienRaceOffset(alienRaceDef.defName);
|
|
raceOffsets.Add(raceOffset);
|
|
}
|
|
|
|
raceOffset.SetOffset(offset);
|
|
}
|
|
|
|
public Vector3 GetFinalTransformOffset()
|
|
{
|
|
Vector3 offset = GetAlienRaceOffset() + (GetAlienRaceDef().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);
|
|
|
|
foreach (AnimationStage stage in Workspace.animationDef.animationStages)
|
|
{
|
|
PawnAnimationClip clip = new PawnAnimationClip();
|
|
|
|
if (clip.MakeNew())
|
|
{
|
|
stage.animationClips.Add(clip);
|
|
stage.Initialize();
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public int GetActorID()
|
|
{
|
|
if (Workspace.animationDef == null) return -1;
|
|
|
|
return Workspace.animationDef.actors.IndexOf(this);
|
|
}
|
|
}
|
|
}
|