From 1591e3d698184ae470b5f59751fa9bfca0ec0b6b Mon Sep 17 00:00:00 2001 From: Kenneth M Date: Fri, 3 Jan 2025 03:49:55 -0600 Subject: [PATCH] ImportPose now aways runs `StopSpeedAndResetTimeline` --- Brio/Capabilities/Posing/PosingCapability.cs | 32 +++++++++++++++----- Brio/IPC/BrioIPCService.cs | 32 ++++++++------------ Brio/UI/Controls/Stateless/FileUIHelpers.cs | 23 +++----------- 3 files changed, 42 insertions(+), 45 deletions(-) diff --git a/Brio/Capabilities/Posing/PosingCapability.cs b/Brio/Capabilities/Posing/PosingCapability.cs index 43b2fe09..56434b8f 100644 --- a/Brio/Capabilities/Posing/PosingCapability.cs +++ b/Brio/Capabilities/Posing/PosingCapability.cs @@ -1,4 +1,5 @@ using Brio.Capabilities.Actor; +using Brio.Capabilities.Core; using Brio.Config; using Brio.Core; using Brio.Entities.Actor; @@ -12,6 +13,7 @@ using Dalamud.Plugin.Services; using OneOf; using OneOf.Types; +using System; using System.Collections.Generic; using System.Linq; @@ -113,11 +115,11 @@ public void ImportPose(string path, PoseImporterOptions? options = null) { if(path.EndsWith(".cmp")) { - ImportPose(ResourceProvider.Instance.GetFileDocument(path), options, reset: false, reconcile: false); + ImportPose(ResourceProvider.Instance.GetFileDocument(path), options); return; } - ImportPose(ResourceProvider.Instance.GetFileDocument(path), options, reset: false, reconcile: false); + ImportPose(ResourceProvider.Instance.GetFileDocument(path), options); } catch { @@ -125,14 +127,27 @@ public void ImportPose(string path, PoseImporterOptions? options = null) } } - public void ImportPose(OneOf rawPoseFile, PoseImporterOptions? options = null, bool asExpression = false, bool asScene = false, bool asIPCpose = false, bool asBody = false) + public void ImportPose(OneOf rawPoseFile, PoseImporterOptions? options = null, bool asExpression = false, bool asScene = false, bool asIPCpose = false, bool asBody = false, bool freezeOnLoad = false) { - ImportPose(rawPoseFile, options, reset: false, reconcile: false, asExpression: asExpression, asScene: asScene, asIPCpose: asIPCpose, asBody: asBody); + if(Actor.TryGetCapability(out var actionTimeline)) + { + Brio.Log.Verbose($"Importing Pose... {asExpression} {asScene} {asIPCpose} {asBody} {freezeOnLoad}"); + + actionTimeline.StopSpeedAndResetTimeline(() => + { + ImportPose_internal(rawPoseFile, options, reset: false, reconcile: false, asExpression: asExpression, asScene: asScene, asIPCpose: asIPCpose, asBody: asBody); + + }, !(ConfigurationService.Instance.Configuration.Posing.FreezeActorOnPoseImport || freezeOnLoad)); + } + else + { + Brio.Log.Warning($"Actor did not have ActionTimelineCapability while Importing a Pose... {asExpression} {asScene} {asIPCpose} {asBody} {freezeOnLoad}"); + } } - // TODO fix this bool hell after Scenes are added + // TODO change this boolean hell into flags after Scenes are added PoseFile? tempPose; - private void ImportPose(OneOf rawPoseFile, PoseImporterOptions? options = null, bool generateSnapshot = true, bool reset = true, bool reconcile = true, + internal void ImportPose_internal(OneOf rawPoseFile, PoseImporterOptions? options = null, bool generateSnapshot = true, bool reset = true, bool reconcile = true, bool asExpression = false, bool expressionPhase2 = false, bool asScene = false, bool asIPCpose = false, bool asBody = false) { var poseFile = rawPoseFile.Match( @@ -143,6 +158,7 @@ private void ImportPose(OneOf rawPoseFile, PoseImporte if(poseFile.Bones.Count == 0 && poseFile.MainHand.Count == 0 && poseFile.OffHand.Count == 0) { Brio.NotifyError("Invalid pose file."); + Brio.Log.Verbose($"Invalid pose file. {reconcile} {reset} {generateSnapshot} {asExpression} {expressionPhase2} {asScene} {asIPCpose} {asBody}"); return; } @@ -208,7 +224,7 @@ public void Snapshot(bool reset = true, bool reconcile = true, bool asExpression if(asExpression == true) { - ImportPose(tempPose!, new PoseImporterOptions(new BoneFilter(_posingService), TransformComponents.All, false), + ImportPose_internal(tempPose!, new PoseImporterOptions(new BoneFilter(_posingService), TransformComponents.All, false), generateSnapshot: true, expressionPhase2: true); return; @@ -273,7 +289,7 @@ private void Reconcile(bool reset = true, bool generateSnapshot = true) { Reset(generateSnapshot, false); } - ImportPose(poseFile, options: all, generateSnapshot: false); + ImportPose_internal(poseFile, options: all, generateSnapshot: false); }, delayTicks: 2); } diff --git a/Brio/IPC/BrioIPCService.cs b/Brio/IPC/BrioIPCService.cs index 7105abfc..cf971ae4 100644 --- a/Brio/IPC/BrioIPCService.cs +++ b/Brio/IPC/BrioIPCService.cs @@ -367,10 +367,7 @@ private unsafe bool LoadFromFile_Impl(IGameObject gameObject, string fileURI) { if(entity.TryGetCapability(out var posingCapability)) { - var actionTimeline = entity.GetCapability(); - actionTimeline.StopSpeedAndResetTimeline(() => { - posingCapability.ImportPose(fileURI); - }, false); + posingCapability.ImportPose(fileURI); return true; } @@ -385,26 +382,23 @@ private unsafe bool LoadFromJson_Impl(IGameObject gameObject, string json, bool { if(entity.TryGetCapability(out var posingCapability)) { - var actionTimeline = entity.GetCapability(); - actionTimeline.StopSpeedAndResetTimeline(() => { - try + try + { + if(isLegacyCMToolPose) { - if(isLegacyCMToolPose) - { - posingCapability.ImportPose(JsonSerializer.Deserialize(json), null, asIPCpose: true); - } - else - { - posingCapability.ImportPose(JsonSerializer.Deserialize(json), null, asIPCpose: false); - } + posingCapability.ImportPose(JsonSerializer.Deserialize(json), null, asIPCpose: true); } - catch + else { - Brio.NotifyError("Invalid pose file loaded from IPC."); + posingCapability.ImportPose(JsonSerializer.Deserialize(json), null, asIPCpose: false); } - }, false); - return true; + return true; + } + catch + { + Brio.NotifyError("Invalid pose file loaded from IPC."); + } } } diff --git a/Brio/UI/Controls/Stateless/FileUIHelpers.cs b/Brio/UI/Controls/Stateless/FileUIHelpers.cs index fa23dc2d..5fc37f6e 100644 --- a/Brio/UI/Controls/Stateless/FileUIHelpers.cs +++ b/Brio/UI/Controls/Stateless/FileUIHelpers.cs @@ -76,7 +76,7 @@ public static void DrawImportPoseMenuPopup(PosingCapability capability, bool sho public static void ShowImportPoseModal(PosingCapability capability, PoseImporterOptions? options = null, bool asExpression = false, bool asBody = false, bool freezeOnLoad = false) { - TypeFilter filter = new TypeFilter("Poses", typeof(CMToolPoseFile), typeof(PoseFile)); + TypeFilter filter = new("Poses", typeof(CMToolPoseFile), typeof(PoseFile)); if(ConfigurationService.Instance.Configuration.UseLibraryWhenImporting) @@ -85,11 +85,11 @@ public static void ShowImportPoseModal(PosingCapability capability, PoseImporter { if(r is CMToolPoseFile cmPose) { - ImportPose(cmPose, options, asExpression, asBody, freezeOnLoad); + capability.ImportPose(cmPose, options: options, asExpression: asExpression, asBody: asBody, freezeOnLoad: freezeOnLoad); } else if(r is PoseFile pose) { - ImportPose(pose, options, asExpression, asBody, freezeOnLoad); + capability.ImportPose(pose, options: options, asExpression: asExpression, asBody: asBody, freezeOnLoad: freezeOnLoad); } }); } @@ -99,27 +99,14 @@ public static void ShowImportPoseModal(PosingCapability capability, PoseImporter { if(r is CMToolPoseFile cmPose) { - ImportPose(cmPose, options, asExpression, asBody, freezeOnLoad); + capability.ImportPose(cmPose, options: options, asExpression: asExpression, asBody: asBody, freezeOnLoad: freezeOnLoad); } else if(r is PoseFile pose) { - ImportPose(pose, options, asExpression, asBody, freezeOnLoad); + capability.ImportPose(pose, options: options, asExpression: asExpression, asBody: asBody, freezeOnLoad: freezeOnLoad); } }); } - - void ImportPose(OneOf rawPoseFile, PoseImporterOptions? options, bool asExpression, bool asBody, bool freezeOnLoad) - { - if(capability.Actor.TryGetCapability(out var actionTimeline)) - { - Brio.Log.Verbose($"Importing Pose... {asExpression} {asBody} {freezeOnLoad}"); - - actionTimeline.StopSpeedAndResetTimeline(() => - { - capability.ImportPose(rawPoseFile, options, asExpression: asExpression, asBody: asBody); - }, !(ConfigurationService.Instance.Configuration.Posing.FreezeActorOnPoseImport || freezeOnLoad)); - } - } } public static void ShowExportPoseModal(PosingCapability capability)