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

@ -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();
}
}
}