mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-02 13:53:40 +01:00
April Fools 2024
This commit is contained in:
parent
7d77f84fdb
commit
2ea89e216a
3 changed files with 111 additions and 0 deletions
96
Dalamud/Interface/Fools24.cs
Normal file
96
Dalamud/Interface/Fools24.cs
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Dalamud.Interface.Internal.Windows;
|
||||||
|
using Dalamud.Networking.Http;
|
||||||
|
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace Dalamud.Interface;
|
||||||
|
|
||||||
|
[ServiceManager.EarlyLoadedService]
|
||||||
|
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "One-off")]
|
||||||
|
internal class Fools24 : IServiceType
|
||||||
|
{
|
||||||
|
private readonly HappyHttpClient httpClient;
|
||||||
|
|
||||||
|
private CancellationTokenSource? cancellation;
|
||||||
|
private Task? horseIconTask = null;
|
||||||
|
|
||||||
|
private string[]? applicableIcons = null;
|
||||||
|
|
||||||
|
[ServiceManager.ServiceConstructor]
|
||||||
|
public Fools24(HappyHttpClient httpClient)
|
||||||
|
{
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsWaitingForIconList => this.horseIconTask?.IsCompleted == false;
|
||||||
|
|
||||||
|
public bool Failed { get; private set; }
|
||||||
|
|
||||||
|
public static bool IsDayApplicable()
|
||||||
|
{
|
||||||
|
var utcNow = DateTime.UtcNow;
|
||||||
|
|
||||||
|
var dateAhead = utcNow.AddHours(14);
|
||||||
|
var dateBehind = utcNow.AddHours(-12);
|
||||||
|
|
||||||
|
return dateAhead is { Day: 1, Month: 4 } || dateBehind is { Day: 1, Month: 4 } || DateTime.Now is { Day: 1, Month: 4 };
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? GetHorseIconLink(string internalName)
|
||||||
|
{
|
||||||
|
if (this.applicableIcons == null || this.applicableIcons.All(x => x != $"{internalName}.png"))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return $"https://raw.githubusercontent.com/goaaats/horse-icons/main/icons/{internalName}.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NotifyInstallerWindowOpened()
|
||||||
|
{
|
||||||
|
if (!IsDayApplicable())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Service<PluginImageCache>.Get().ClearIconCache();
|
||||||
|
|
||||||
|
if (this.horseIconTask?.IsCompleted == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.Failed = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.cancellation = new CancellationTokenSource();
|
||||||
|
this.horseIconTask = this.httpClient.SharedHttpClient.GetStringAsync("https://raw.githubusercontent.com/goaaats/horse-icons/main/iconlist.txt", this.cancellation.Token)
|
||||||
|
.ContinueWith(
|
||||||
|
f =>
|
||||||
|
{
|
||||||
|
if (!f.IsCompletedSuccessfully)
|
||||||
|
{
|
||||||
|
this.Failed = true;
|
||||||
|
this.applicableIcons = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f.Result is not { Length: > 0 })
|
||||||
|
{
|
||||||
|
this.Failed = true;
|
||||||
|
this.applicableIcons = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.applicableIcons = f.Result.Split(
|
||||||
|
'\n',
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
});
|
||||||
|
this.cancellation.CancelAfter(10000);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Failed to fetch horse icons");
|
||||||
|
this.Failed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -192,6 +192,11 @@ internal class PluginImageCache : IInternalDisposableService
|
||||||
iconTexture = null;
|
iconTexture = null;
|
||||||
loadedSince = null;
|
loadedSince = null;
|
||||||
|
|
||||||
|
// Wait for the horse icon list to be there, if applicable
|
||||||
|
var fools = Service<Fools24>.Get();
|
||||||
|
if (Fools24.IsDayApplicable() && fools.IsWaitingForIconList && !fools.Failed)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (manifest == null || manifest.InternalName == null)
|
if (manifest == null || manifest.InternalName == null)
|
||||||
{
|
{
|
||||||
Log.Error("THIS SHOULD NEVER HAPPEN! manifest == null || manifest.InternalName == null");
|
Log.Error("THIS SHOULD NEVER HAPPEN! manifest == null || manifest.InternalName == null");
|
||||||
|
|
@ -639,6 +644,14 @@ internal class PluginImageCache : IInternalDisposableService
|
||||||
if (isThirdParty)
|
if (isThirdParty)
|
||||||
return manifest.IconUrl;
|
return manifest.IconUrl;
|
||||||
|
|
||||||
|
var fools = Service<Fools24>.Get();
|
||||||
|
if (Fools24.IsDayApplicable())
|
||||||
|
{
|
||||||
|
var iconLink = fools.GetHorseIconLink(manifest.InternalName);
|
||||||
|
if (iconLink != null)
|
||||||
|
return iconLink;
|
||||||
|
}
|
||||||
|
|
||||||
return MainRepoDip17ImageUrl.Format(manifest.Dip17Channel!, manifest.InternalName, "icon.png");
|
return MainRepoDip17ImageUrl.Format(manifest.Dip17Channel!, manifest.InternalName, "icon.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -268,6 +268,8 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void OnOpen()
|
public override void OnOpen()
|
||||||
{
|
{
|
||||||
|
Service<Fools24>.Get().NotifyInstallerWindowOpened();
|
||||||
|
|
||||||
var pluginManager = Service<PluginManager>.Get();
|
var pluginManager = Service<PluginManager>.Get();
|
||||||
|
|
||||||
_ = pluginManager.ReloadPluginMastersAsync();
|
_ = pluginManager.ReloadPluginMastersAsync();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue