Skip to content

Commit

Permalink
Merge pull request #1282 from AsgardXIV/brio3
Browse files Browse the repository at this point in the history
Brio Despawn
  • Loading branch information
Luminiari authored Jan 20, 2023
2 parents e47e039 + 31ecb47 commit 43f8afe
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Anamnesis/Actor/Refresh/BrioActorRefresher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public async Task RefreshActor(ActorMemory actor)
await Dispatch.MainThread();
bool isPosing = PoseService.Instance.IsEnabled;

RedrawType redrawType = RedrawType.AllowFull | RedrawType.PreservePosition | RedrawType.AllowOptimized;
RedrawType redrawType = RedrawType.AllowFull | RedrawType.PreservePosition | RedrawType.AllowOptimized | RedrawType.ForceAllowNPCAppearance;

if(actor.IsWeaponDirty && !isPosing)
if(actor.IsWeaponDirty)
{
redrawType |= RedrawType.RedrawWeaponsOnOptimized;
redrawType |= RedrawType.ForceRedrawWeaponsOnOptimized;
}

if (actor.IsWeaponDirty && isPosing)
Expand Down
40 changes: 35 additions & 5 deletions Anamnesis/Brio/Brio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Anamnesis.Brio;

using System;
using System.Threading.Tasks;
using static Anamnesis.Penumbra.Penumbra.RedrawData;

public static class Brio
{
Expand All @@ -21,13 +22,24 @@ public static async Task<string> Redraw(int targetIndex, RedrawType redrawType)
return result;
}

public static async Task<int> Spawn()
public static async Task<int> Spawn(SpawnOptions options)
{
var resultRaw = await BrioApi.Post("/spawn", 0);
SpawnRequest data = new();
data.SpawnOptions = options;
var resultRaw = await BrioApi.Post("/spawn", data);
var resultId = int.Parse(resultRaw);
await Task.Delay(500);
return resultId;
}

public static async Task<bool> Despawn(int actorIndex)
{
DespawnData data = new();
data.ObjectIndex = actorIndex;
var resultRaw = await BrioApi.Post("/despawn", data);
var result = bool.Parse(resultRaw);
return result;
}
}

[Flags]
Expand All @@ -36,14 +48,32 @@ public enum RedrawType
None = 0,
AllowOptimized = 1,
AllowFull = 2,
RedrawWeaponsOnOptimized = 4,
ForceRedrawWeaponsOnOptimized = 4,
PreservePosition = 8,
ForceAllowNPCAppearance = 16,

All = AllowOptimized | AllowFull | RedrawWeaponsOnOptimized | PreservePosition,
All = AllowOptimized | AllowFull | ForceRedrawWeaponsOnOptimized | PreservePosition | ForceAllowNPCAppearance,
}

[Flags]
public enum SpawnOptions
{
None = 0,
ApplyModelPosition = 1,
}

public class RedrawData
{
public int ObjectIndex { get; set; } = -1;
public RedrawType? RedrawType { get; set; } = Anamnesis.Brio.RedrawType.All;
}
}

public class DespawnData
{
public int ObjectIndex { get; set; } = -1;
}

public class SpawnRequest
{
public SpawnOptions SpawnOptions { get; set; }
}
1 change: 1 addition & 0 deletions Anamnesis/Files/CharacterFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public async Task Apply(ActorMemory actor, SaveModes mode, bool allowRefresh = t
{
this.MainHand?.Write(actor.MainHand, true);
this.OffHand?.Write(actor.OffHand, false);
actor.IsWeaponDirty = true;
}

if (this.IncludeSection(SaveModes.EquipmentGear, mode))
Expand Down
7 changes: 6 additions & 1 deletion Anamnesis/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
<MenuItem Visibility="{Binding IsValid, Converter={StaticResource B2V}}"
Click="OnTargetActorClicked"
Header="Target" />
</ContextMenu>

<MenuItem Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=SettingsService.Settings.UseExternalRefreshBrio, Converter={StaticResource B2V}}"
IsEnabled="{Binding IsGPoseActor}"
Click="OnDespawnActorClicked"
Header="Despawn" />
</ContextMenu>
</ToggleButton.ContextMenu>

<Grid Margin="6,0">
Expand Down
14 changes: 14 additions & 0 deletions Anamnesis/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,20 @@ private void OnTargetActorClicked(object sender, RoutedEventArgs e)
}
}

private async void OnDespawnActorClicked(object sender, RoutedEventArgs e)
{
if (sender is FrameworkElement el && el.DataContext is PinnedActor actor)
{
if (!actor.IsValid || actor.Memory == null)
return;

if(await Brio.Brio.Despawn(actor.Memory.ObjectIndex))
{
TargetService.UnpinActor(actor);
}
}
}

private void OnActorPinPreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Middle)
Expand Down
6 changes: 5 additions & 1 deletion Anamnesis/Views/TargetSelectorView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ private void OnAddPlayerTargetActorClicked(object sender, RoutedEventArgs e)

private async void OnCreateActorClicked(object sender, RoutedEventArgs e)
{
var nextActorId = await Brio.Spawn();
SpawnOptions options = SpawnOptions.None;
if (PoseService.Instance.IsEnabled || PoseService.Instance.FreezeWorldPosition)
options |= SpawnOptions.ApplyModelPosition;

var nextActorId = await Brio.Spawn(options);
if(nextActorId != -1)
{
var actors = ActorService.Instance.GetAllActors(true);
Expand Down

0 comments on commit 43f8afe

Please sign in to comment.