Skip to content

Commit

Permalink
Revert "Penumbra collections api"
Browse files Browse the repository at this point in the history
This reverts commit 2e6d5ae.
  • Loading branch information
Yuki-Codes committed Apr 21, 2022
1 parent 2e6d5ae commit 47a5bb3
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 178 deletions.
54 changes: 10 additions & 44 deletions Anamnesis/Character/Pages/AppearancePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,49 +119,6 @@

<StackPanel>

<GroupBox Style="{StaticResource PanelGroupBox}">

<GroupBox.Header>
<XivToolsWpf:Header Key="Character_Actor_Header"
Icon="Question" />
</GroupBox.Header>

<Grid Margin="0, 0, 0, 0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<XivToolsWpf:TextBlock Key="Character_Actor_Nickname"
Grid.Row="0"
Grid.Column="0"
Style="{StaticResource Label}" />

<TextBox Grid.Row="0"
Grid.Column="1"
Style="{StaticResource MaterialDesignTextBox}"
Text="{Binding Actor.Nickname, UpdateSourceTrigger=PropertyChanged}"/>

<XivToolsWpf:TextBlock Text="Penumbra Collection"
Grid.Row="1"
Grid.Column="0"
Style="{StaticResource Label}"
Visibility="{Binding Penumbra.IsEnabled, Converter={StaticResource B2V}}"/>

<ComboBox Grid.Row="1"
Grid.Column="1"
ItemsSource="{Binding Penumbra.Collections}"
SelectedValue="{Binding Actor.CharacterCollectionName}"
Visibility="{Binding Penumbra.IsEnabled, Converter={StaticResource B2V}}"/>
</Grid>

</GroupBox>

<GroupBox Style="{StaticResource PanelGroupBox}">
<GroupBox.Header>
<XivToolsWpf:Header Key="Character_Actor_Header"
Expand All @@ -183,7 +140,16 @@
<RowDefinition />
</Grid.RowDefinitions>

<XivToolsWpf:TextBlock Key="Character_Actor_Nickname"
Grid.Row="0"
Grid.Column="0"
Style="{StaticResource Label}" />

<TextBox Grid.Row="0"
Grid.Column="1"
Grid.ColumnSpan="2"
Style="{StaticResource MaterialDesignTextBox}"
Text="{Binding Actor.Nickname, UpdateSourceTrigger=PropertyChanged}"/>

<XivToolsWpf:TextBlock Key="Character_Actor_EntityType"
Grid.Row="2"
Expand Down Expand Up @@ -305,7 +271,7 @@
</XivToolsWpf:InfoControl.ToolTip>
</XivToolsWpf:InfoControl>

<StackPanel Orientation="Vertical" Grid.Row="3">
<StackPanel Orientation="Vertical" Grid.Row="2">
<Menu Grid.Row="1"
Margin="0,3, 3, 4"
Style="{StaticResource AnaMenu}">
Expand Down
2 changes: 0 additions & 2 deletions Anamnesis/Character/Pages/AppearancePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Anamnesis.Character.Pages
using Anamnesis.GameData;
using Anamnesis.Keyboard;
using Anamnesis.Memory;
using Anamnesis.Penumbra;
using Anamnesis.Services;
using Anamnesis.Styles;
using Anamnesis.Styles.Drawers;
Expand All @@ -40,7 +39,6 @@ public AppearancePage()
}

public ActorMemory? Actor { get; private set; }
public PenumbraService Penumbra => PenumbraService.Instance;

private void OnLoaded(object sender, RoutedEventArgs e)
{
Expand Down
5 changes: 1 addition & 4 deletions Anamnesis/Memory/ActorBasicMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public enum RenderModes : int
public double DistanceFromPlayer => Math.Sqrt(((int)this.DistanceFromPlayerX ^ 2) + ((int)this.DistanceFromPlayerY ^ 2));
public string NameHash => HashUtility.GetHashString(this.NameBytes.ToString(), true);

// For penumbra
public string? CharacterCollectionName { get; set; }

[AlsoNotifyFor(nameof(DisplayName))]
public string? Nickname { get; set; }

Expand All @@ -68,7 +65,7 @@ public bool CanRefresh

// If there is some sort of external refresh service
// assume we can always refresh.
if (SettingsService.Current.EnablePenumbraApi)
if (SettingsService.Current.UseExternalRefresh)
return true;

return this.IsOverworldActor;
Expand Down
5 changes: 2 additions & 3 deletions Anamnesis/Memory/ActorMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Anamnesis.Memory
{
using System;
using System.Threading.Tasks;
using Anamnesis.Penumbra;
using Anamnesis.Services;
using PropertyChanged;

Expand Down Expand Up @@ -189,9 +188,9 @@ public async Task RefreshAsync()

this.IsRefreshing = true;

if (SettingsService.Current.EnablePenumbraApi)
if (SettingsService.Current.UseExternalRefresh)
{
await PenumbraService.Redraw(this.Name, this.CharacterCollectionName);
await Penumbra.Penumbra.Redraw(this.Name);
return;
}
else
Expand Down
39 changes: 39 additions & 0 deletions Anamnesis/Penumbra/Penumbra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// © Anamnesis.
// Licensed under the MIT license.

namespace Anamnesis.Penumbra
{
using System.Threading.Tasks;

public static class Penumbra
{
public static async Task Redraw(string targetName)
{
RedrawData data = new();
data.Name = targetName;
data.Type = RedrawData.RedrawType.WithSettings;

await PenumbraApi.Post("/redraw", data);

await Task.Delay(500);
}

public class RedrawData
{
public enum RedrawType
{
WithoutSettings,
WithSettings,
OnlyWithSettings,
Unload,
RedrawWithoutSettings,
RedrawWithSettings,
AfterGPoseWithSettings,
AfterGPoseWithoutSettings,
}

public string Name { get; set; } = string.Empty;
public RedrawType Type { get; set; } = RedrawType.WithSettings;
}
}
}
33 changes: 12 additions & 21 deletions Anamnesis/Penumbra/PenumbraApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,37 @@ internal static class PenumbraApi

public static async Task Post(string route, object content)
{
await Request(route, "POST", content);
await PostRequest(route, content);
}

public static async Task<TResult> Get<TResult>(string route)
where TResult : notnull
{
return await Request<TResult>(route, "GET");
}

public static async Task<T> Request<T>(string route, string method, object? content = null)
public static async Task<T> Post<T>(string route, object content)
where T : notnull
{
WebResponse response = await Request(route, method, content);
WebResponse response = await PostRequest(route, content);

using StreamReader? sr = new StreamReader(response.GetResponseStream());
string json = sr.ReadToEnd();

return SerializerService.Deserialize<T>(json);
}

private static async Task<WebResponse> Request(string route, string method, object? content = null)
private static async Task<WebResponse> PostRequest(string route, object content)
{
if (!route.StartsWith('/'))
route = '/' + route;

string json = SerializerService.Serialize(content);

WebRequest request = WebRequest.Create(Url + route);
request.Timeout = TimeoutMs;
request.ContentType = "application/json; charset=utf-8";
request.Method = method;
request.Method = "POST";
UTF8Encoding encoding = new UTF8Encoding();

if (content != null)
{
string json = SerializerService.Serialize(content);
byte[] data = encoding.GetBytes(json);
request.ContentLength = data.Length;
Stream newStream = await request.GetRequestStreamAsync();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
byte[] data = encoding.GetBytes(json);
request.ContentLength = data.Length;
Stream newStream = await request.GetRequestStreamAsync();
newStream.Write(data, 0, data.Length);
newStream.Close();

try
{
Expand Down
101 changes: 0 additions & 101 deletions Anamnesis/Penumbra/PenumbraService.cs

This file was deleted.

1 change: 0 additions & 1 deletion Anamnesis/ServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public async Task InitializeServices()
await Add<AnimationService>();
await Add<Keyboard.HotkeyService>();
await Add<HistoryService>();
await Add<Penumbra.PenumbraService>();

IsInitialized = true;

Expand Down
2 changes: 1 addition & 1 deletion Anamnesis/Services/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum Fonts
public string? GalleryDirectory { get; set; }
public bool EnableTranslucency { get; set; } = true;
public bool ExtendIntoWindowChrome { get; set; } = true;
public bool EnablePenumbraApi { get; set; } = false;
public bool UseExternalRefresh { get; set; } = false;
public bool EnableGameHotkeyHooks { get; set; } = false;
public bool EnableHotkeys { get; set; } = true;

Expand Down
2 changes: 1 addition & 1 deletion Anamnesis/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
</Grid.RowDefinitions>

<XivToolsWPF:TextBlock Grid.Column="0" Grid.Row="0" Key="Settings_UseExternalRefresh" Style="{StaticResource Label}"/>
<CheckBox IsChecked="{Binding SettingsService.Settings.EnablePenumbraApi}" Grid.Column="1" Grid.Row="0" Margin="6"/>
<CheckBox IsChecked="{Binding SettingsService.Settings.UseExternalRefresh}" Grid.Column="1" Grid.Row="0" Margin="6"/>

<XivToolsWPF:InfoControl Grid.Row="1" Key="Settings_UseExternalRefreshWarning" Width="237" Grid.ColumnSpan="2"/>
</Grid>
Expand Down

0 comments on commit 47a5bb3

Please sign in to comment.