Remove and save custom tags

This commit is contained in:
AbstractConcept 2022-09-21 16:15:25 -05:00
parent e36ef6a368
commit 2f3f807911
264 changed files with 1118 additions and 498 deletions

View file

@ -155,6 +155,7 @@ namespace RimWorldAnimationStudio
Vector3 headPos = new Vector3(headBob.x, headBob.z, 0);
Vector3 appendagePos = PawnUtility.AppendageOffsetAt(bodyType, bodyFacing);
float appendageRotation = clip.GenitalAngle.Evaluate(clipPercent);
actorBody.transform.position = bodyPos;
actorBody.transform.eulerAngles = new Vector3(0, 0, bodyAngle);
@ -163,7 +164,7 @@ namespace RimWorldAnimationStudio
actorBody.headRenderer.transform.eulerAngles = new Vector3(0, 0, headAngle);
actorBody.appendageRenderer.transform.localPosition = new Vector3(appendagePos.x, appendagePos.z, 0f);
actorBody.appendageRenderer.transform.eulerAngles = new Vector3(0,0,clip.GenitalAngle.Evaluate(clipPercent));
actorBody.appendageRenderer.transform.eulerAngles = new Vector3(0, 0, appendageRotation);
actorBody.bodyRenderer.sprite = Resources.Load<Sprite>("Textures/Humanlike/Bodies/" + bodyType + bodyFacing);
actorBody.headRenderer.sprite = Resources.Load<Sprite>("Textures/Humanlike/Heads/Head" + headFacing);
@ -172,6 +173,15 @@ namespace RimWorldAnimationStudio
actorBody.bodyRenderer.sortingLayerName = clip.layer;
actorBody.headRenderer.sortingLayerName = clip.layer;
actorBody.headRenderer.sortingOrder = bodyFacing == 0 ? -1 : 1;
actorBody.appendageRenderer.sortingLayerName = clip.layer;
// ActorKeyframeCard update
if (ActorKeyframeCard.Instance.positionXField.isFocused == false) { ActorKeyframeCard.Instance.positionXField.text = bodyPos.x.ToString("0.000"); }
if (ActorKeyframeCard.Instance.positionZField.isFocused == false) { ActorKeyframeCard.Instance.positionZField.text = bodyPos.y.ToString("0.000"); }
if (ActorKeyframeCard.Instance.rotationField.isFocused == false) { ActorKeyframeCard.Instance.rotationField.text = bodyAngle.ToString("0.000"); }
if (ActorKeyframeCard.Instance.headBobField.isFocused == false) { ActorKeyframeCard.Instance.headBobField.text = headBob.ToString("0.000"); }
if (ActorKeyframeCard.Instance.headRotationField.isFocused == false) { ActorKeyframeCard.Instance.headRotationField.text = headAngle.ToString("0.000"); }
if (ActorKeyframeCard.Instance.appendageRotationField.isFocused == false) { ActorKeyframeCard.Instance.appendageRotationField.text = appendageRotation.ToString("0.000"); }
}
}

View file

@ -15,6 +15,11 @@ namespace RimWorldAnimationStudio
public DialogBox exitDialog;
public SelectAnimationDialog selectAnimationDialog;
public void Start()
{
LoadCustomArrays();
}
public void TryToCloseApplication()
{
exitDialog.Pop();
@ -47,7 +52,9 @@ namespace RimWorldAnimationStudio
public void LoadAnimation(AnimationDef animationDef)
{
animationDef.RunPostLoadOperations();
UpdateCustomArrays(animationDef);
RunPostLoadOperations(animationDef);
Debug.Log("Loaded AnimationDef: " + animationDef.defName);
Workspace.animationDef = animationDef;
@ -67,6 +74,11 @@ namespace RimWorldAnimationStudio
}
}
public void RunPostLoadOperations(AnimationDef animationDef)
{
}
public void TrySaveAnimation()
{
if (Workspace.animationDef == null)
@ -82,10 +94,10 @@ namespace RimWorldAnimationStudio
public void SaveAnimation(string path)
{
Debug.Log("Saving AnimationDef: " + Workspace.animationDef.defName);
AnimationDef animationDef = Workspace.animationDef.Copy();
animationDef.RunPreSaveOperations();
RunPreSaveOperations(animationDef);
Debug.Log("Saving AnimationDef: " + Workspace.animationDef.defName);
Defs defs = new Defs();
defs.animationDefs.Add(animationDef);
@ -93,6 +105,22 @@ namespace RimWorldAnimationStudio
XmlUtility.WriteXML(defs, path);
}
public void RunPreSaveOperations(AnimationDef animationDef)
{
foreach (AnimationStage stage in animationDef.animationStages)
{
stage.ValidateData();
foreach (PawnAnimationClip clip in stage.animationClips)
{
clip.ValidateData();
foreach (PawnKeyframe keyframe in clip.keyframes)
{ keyframe.ValidateData(); }
}
}
}
public void NewAnimation()
{
var path = Path.Combine(Application.streamingAssetsPath, "AnimationDefs/newAnimationDef.xml");
@ -104,5 +132,50 @@ namespace RimWorldAnimationStudio
LoadAnimation(defs.animationDefs[0]);
}
public void SaveCustomArrays()
{
var path = Path.Combine(Application.streamingAssetsPath, "customTags.xml");
CustomTagsHelper helper = new CustomTagsHelper();
helper.defNames = CustomTags.defNames;
helper.bodyParts = CustomTags.bodyParts;
helper.bodyDefTypes = CustomTags.bodyDefTypes;
helper.sexTypes = CustomTags.sexTypes;
helper.interactionDefTypes = CustomTags.interactionDefTypes;
helper.soundDefs = CustomTags.soundDefs;
XmlUtility.WriteXML(helper, path);
}
public void LoadCustomArrays()
{
var path = Path.Combine(Application.streamingAssetsPath, "customTags.xml");
if (File.Exists(path) == false)
{ SaveCustomArrays(); return; }
CustomTagsHelper helper = XmlUtility.ReadXML<CustomTagsHelper>(path);
CustomTags.defNames = helper.defNames;
CustomTags.bodyParts = helper.bodyParts;
CustomTags.bodyDefTypes = helper.bodyDefTypes;
CustomTags.sexTypes = helper.sexTypes;
CustomTags.interactionDefTypes = helper.interactionDefTypes;
CustomTags.soundDefs = helper.soundDefs;
}
public void UpdateCustomArrays(AnimationDef animationDef)
{
CustomTags.defNames.AddRangeDistinct(animationDef.actors.SelectMany(x => x.defNames).Except(Tags.defNames));
CustomTags.bodyParts.AddRangeDistinct(animationDef.actors.SelectMany(x => x.requiredGenitals).Except(Tags.bodyParts));
CustomTags.bodyDefTypes.AddRangeDistinct(animationDef.actors.SelectMany(x => x.bodyDefTypes).Except(Tags.bodyDefTypes));
CustomTags.sexTypes.AddRangeDistinct(animationDef.sexTypes.Except(Tags.sexTypes));
CustomTags.interactionDefTypes.AddRangeDistinct(animationDef.interactionDefTypes.Except(Tags.interactionDefTypes));
CustomTags.soundDefs.AddRangeDistinct(animationDef.animationStages.SelectMany(x => x.animationClips.SelectMany(y => y.keyframes.Select(z => z.soundEffect))).Except(Tags.soundDefs));
SaveCustomArrays();
}
}
}