Skip to content

Commit

Permalink
ImportPose now aways runs StopSpeedAndResetTimeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Minmoose committed Jan 3, 2025
1 parent 1195759 commit 1591e3d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 45 deletions.
32 changes: 24 additions & 8 deletions Brio/Capabilities/Posing/PosingCapability.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Brio.Capabilities.Actor;
using Brio.Capabilities.Core;
using Brio.Config;
using Brio.Core;
using Brio.Entities.Actor;
Expand All @@ -12,6 +13,7 @@
using Dalamud.Plugin.Services;
using OneOf;
using OneOf.Types;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -113,26 +115,39 @@ public void ImportPose(string path, PoseImporterOptions? options = null)
{
if(path.EndsWith(".cmp"))
{
ImportPose(ResourceProvider.Instance.GetFileDocument<CMToolPoseFile>(path), options, reset: false, reconcile: false);
ImportPose(ResourceProvider.Instance.GetFileDocument<CMToolPoseFile>(path), options);
return;
}

ImportPose(ResourceProvider.Instance.GetFileDocument<PoseFile>(path), options, reset: false, reconcile: false);
ImportPose(ResourceProvider.Instance.GetFileDocument<PoseFile>(path), options);
}
catch
{
Brio.NotifyError("Invalid pose file.");
}
}

public void ImportPose(OneOf<PoseFile, CMToolPoseFile> rawPoseFile, PoseImporterOptions? options = null, bool asExpression = false, bool asScene = false, bool asIPCpose = false, bool asBody = false)
public void ImportPose(OneOf<PoseFile, CMToolPoseFile> 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<ActionTimelineCapability>(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<PoseFile, CMToolPoseFile> rawPoseFile, PoseImporterOptions? options = null, bool generateSnapshot = true, bool reset = true, bool reconcile = true,
internal void ImportPose_internal(OneOf<PoseFile, CMToolPoseFile> 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(
Expand All @@ -143,6 +158,7 @@ private void ImportPose(OneOf<PoseFile, CMToolPoseFile> 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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
32 changes: 13 additions & 19 deletions Brio/IPC/BrioIPCService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@ private unsafe bool LoadFromFile_Impl(IGameObject gameObject, string fileURI)
{
if(entity.TryGetCapability<PosingCapability>(out var posingCapability))
{
var actionTimeline = entity.GetCapability<ActionTimelineCapability>();
actionTimeline.StopSpeedAndResetTimeline(() => {
posingCapability.ImportPose(fileURI);
}, false);
posingCapability.ImportPose(fileURI);

return true;
}
Expand All @@ -385,26 +382,23 @@ private unsafe bool LoadFromJson_Impl(IGameObject gameObject, string json, bool
{
if(entity.TryGetCapability<PosingCapability>(out var posingCapability))
{
var actionTimeline = entity.GetCapability<ActionTimelineCapability>();
actionTimeline.StopSpeedAndResetTimeline(() => {
try
try
{
if(isLegacyCMToolPose)
{
if(isLegacyCMToolPose)
{
posingCapability.ImportPose(JsonSerializer.Deserialize<CMToolPoseFile>(json), null, asIPCpose: true);
}
else
{
posingCapability.ImportPose(JsonSerializer.Deserialize<PoseFile>(json), null, asIPCpose: false);
}
posingCapability.ImportPose(JsonSerializer.Deserialize<CMToolPoseFile>(json), null, asIPCpose: true);
}
catch
else
{
Brio.NotifyError("Invalid pose file loaded from IPC.");
posingCapability.ImportPose(JsonSerializer.Deserialize<PoseFile>(json), null, asIPCpose: false);
}
}, false);

return true;
return true;
}
catch
{
Brio.NotifyError("Invalid pose file loaded from IPC.");
}
}
}

Expand Down
23 changes: 5 additions & 18 deletions Brio/UI/Controls/Stateless/FileUIHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
});
}
Expand All @@ -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<PoseFile, CMToolPoseFile> rawPoseFile, PoseImporterOptions? options, bool asExpression, bool asBody, bool freezeOnLoad)
{
if(capability.Actor.TryGetCapability<ActionTimelineCapability>(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)
Expand Down

0 comments on commit 1591e3d

Please sign in to comment.