Skip to content
Merged

Dev #248

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions WheelWizard/Features/MiiImages/MiiStudioDataSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text;
using WheelWizard.Helpers;
using WheelWizard.Utilities;
using WheelWizard.WiiManagement;
using WheelWizard.WiiManagement.MiiManagement;
using WheelWizard.WiiManagement.MiiManagement.Domain.Mii;
Expand All @@ -8,6 +9,10 @@ namespace WheelWizard.MiiImages;

public class MiiStudioDataSerializer
{
private static readonly bool IsAprilFirst = AprilFirstHelper.IsAprilFirstLocalOrBst();
private const string AprilFirstMiiBase64 =
"BCAAWgBQAEzwbQAAAAAAAAAAAAAAAH9MyRhyVCQREREEBYGAAUDIsjyMiEAUSJiNcGoAiiUEAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
private static readonly byte[] AprilFirstMiiData = Convert.FromBase64String(AprilFirstMiiBase64);
private static readonly int[] MakeupMap = [0, 1, 6, 9, 0, 0, 0, 0, 0, 10, 0, 0];
private static readonly int[] WrinklesMap = [0, 0, 0, 0, 5, 2, 3, 7, 8, 0, 9, 11];

Expand All @@ -19,6 +24,15 @@ public static OperationResult<string> Serialize(Mii? mii)
if (mii == null)
return Fail("Mii cannot be null.");

if (IsAprilFirst)
{
var aprilFirstMiiResult = MiiSerializer.Deserialize(AprilFirstMiiData);
if (aprilFirstMiiResult.IsFailure)
return aprilFirstMiiResult.Error;

mii = aprilFirstMiiResult.Value;
}

// First we create a clone of the Mii that only contains features that are visual
// This means no name, date or other non-visual features.
// That way when you change a feature that is not visual, it will not result in different bytes.
Expand Down
31 changes: 31 additions & 0 deletions WheelWizard/Utilities/AprilFirstHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace WheelWizard.Utilities;

public static class AprilFirstHelper
{
private static readonly TimeZoneInfo LondonTimeZone = GetLondonTimeZone();

public static bool IsAprilFirstLocalOrBst()
{
var localNow = DateTime.Now;
if (localNow.Month == 4 && localNow.Day == 1)
return true;

var londonNow = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, LondonTimeZone);
return londonNow.Month == 4 && londonNow.Day == 1;
}

private static TimeZoneInfo GetLondonTimeZone()
{
foreach (var timeZoneId in new[] { "Europe/London", "GMT Standard Time" })
{
try
{
return TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
}
catch (TimeZoneNotFoundException) { }
catch (InvalidTimeZoneException) { }
}

return TimeZoneInfo.Utc;
}
}
48 changes: 44 additions & 4 deletions WheelWizard/Views/Pages/HomePage.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@
using WheelWizard.Services.Launcher.Helpers;
using WheelWizard.Settings;
using WheelWizard.Shared.DependencyInjection;
using WheelWizard.Utilities;
using WheelWizard.Views.Components;
using WheelWizard.Views.Popups.Generic;
using Button = WheelWizard.Views.Components.Button;

namespace WheelWizard.Views.Pages;

public partial class HomePage : UserControlBase
{
private static readonly bool IsAprilFirst = AprilFirstHelper.IsAprilFirstLocalOrBst();
private static readonly (string MainText, string ExtraText, string YesText, string NoText)[] AprilFirstLaunchPrompts =
[
("You wanna start the game?", "This feels suspiciously productive.", "Yeah", "Nah"),
("Eeeeh not feeling like it", "Try asking a little nicer next time.", "Please", "Whatever"),
("Launch Retro Beefbai?", "I am consulting the ancient wheel.", "Do it", "Nope"),
("You again?", "The game is pretending not to notice you.", "Open it", "Leave it"),
("Starting the game already?", "That was fast. Almost too fast.", "Fine", "Hold on"),
];

[Inject]
private ISettingsManager SettingsService { get; set; } = null!;

Expand Down Expand Up @@ -83,7 +95,7 @@ public HomePage()

private void UpdatePage()
{
GameTitle.Text = CurrentLauncher.GameTitle;
GameTitle.Text = CurrentLauncher.GameTitle == "Retro Rewind" && IsAprilFirst ? "Retro Beefbai" : CurrentLauncher.GameTitle;
UpdateActionButton();
}

Expand All @@ -95,6 +107,25 @@ private void DolphinButton_OnClick(object? sender, RoutedEventArgs e)

private void LaunchGame() => _ = CurrentLauncher.Launch();

private bool ShouldShowAprilFirstLaunchPrompts() =>
IsAprilFirst && _status is WheelWizardStatus.Ready or WheelWizardStatus.NoServerButInstalled;

private async Task ShowAprilFirstLaunchPromptsAsync()
{
var promptPool = ((string MainText, string ExtraText, string YesText, string NoText)[])AprilFirstLaunchPrompts.Clone();
RandomSystem.Random.Shared.Shuffle(promptPool);

for (var i = 0; i < 4; i++)
{
var prompt = promptPool[i];
await new YesNoWindow()
.SetMainText(prompt.MainText)
.SetExtraText(prompt.ExtraText)
.SetButtonText(prompt.YesText, prompt.NoText)
.AwaitAnswer();
}
}

private void NavigateToSettings() => NavigationManager.NavigateTo<SettingsPage>();

private async void Download()
Expand All @@ -113,9 +144,15 @@ private async void Update()
NavigationManager.NavigateTo<HomePage>();
}

private void PlayButton_Click(object? sender, RoutedEventArgs e)
private async void PlayButton_Click(object? sender, RoutedEventArgs e)
{
CurrentButtonState?.OnClick?.Invoke();
if (CurrentButtonState?.OnClick == null)
return;

if (ShouldShowAprilFirstLaunchPrompts())
await ShowAprilFirstLaunchPromptsAsync();

CurrentButtonState.OnClick.Invoke();
PlayActivateAnimation();
UpdateActionButton();
DisableAllButtonsTemporarily();
Expand All @@ -136,7 +173,10 @@ private void PopulateGameModeDropdown()

foreach (var launcherType in _launcherTypes)
{
GameModeDropdown.Items.Add(launcherType.GameTitle);
if (launcherType.GameTitle == "Retro Rewind" && IsAprilFirst)
GameModeDropdown.Items.Add("Retro Beefbai");
else
GameModeDropdown.Items.Add(launcherType.GameTitle);
}

GameModeDropdown.SelectedIndex = _launcherIndex;
Expand Down
6 changes: 6 additions & 0 deletions WheelWizard/Views/Patterns/MiiImages/MiiImageLoader.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
using Microsoft.Extensions.Caching.Memory;
using WheelWizard.MiiImages;
using WheelWizard.MiiImages.Domain;
using WheelWizard.Utilities;
using WheelWizard.WiiManagement.MiiManagement.Domain.Mii;

namespace WheelWizard.Views.Patterns;

public partial class MiiImageLoader : BaseMiiImage
{
private static readonly bool IsAprilFirst = AprilFirstHelper.IsAprilFirstLocalOrBst();

#region properties

public static readonly StyledProperty<bool> LowQualitySpeedupProperty = AvaloniaProperty.Register<MiiImageLoader, bool>(
Expand Down Expand Up @@ -76,6 +79,9 @@ private static MiiImageSpecifications CoerceVariant(AvaloniaObject o, MiiImageSp
public MiiImageLoader()
{
InitializeComponent();

if (IsAprilFirst)
MiiImageContainer.RenderTransform = new RotateTransform(Random.Shared.NextDouble() * 360);
}

public void RefreshCurrentMii() => OnMiiChanged(Mii);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
using Avalonia.Media;
using WheelWizard.MiiImages;
using WheelWizard.MiiImages.Domain;
using WheelWizard.Utilities;
using WheelWizard.WiiManagement.MiiManagement.Domain.Mii;

namespace WheelWizard.Views.Patterns;

public partial class MiiImageLoaderWithHover : BaseMiiImage
{
private static readonly bool IsAprilFirst = AprilFirstHelper.IsAprilFirstLocalOrBst();
private bool _hasLoadedHoverVariant;

public static readonly StyledProperty<bool> IsHoveredProperty = AvaloniaProperty.Register<MiiImageLoaderWithHover, bool>(
Expand Down Expand Up @@ -133,6 +135,10 @@ private static MiiImageSpecifications CoerceVariant(AvaloniaObject o, MiiImageSp
public MiiImageLoaderWithHover()
{
InitializeComponent();

if (IsAprilFirst)
MiiImageContainer.RenderTransform = new RotateTransform(Random.Shared.NextDouble() * 360);

PropertyChanged += MiiImageLoaderWithHover_PropertyChanged;
GeneratedImages.CollectionChanged += (s, e) => UpdateImageVisibility();
MiiImageLoaded += (s, e) => UpdateImageVisibility();
Expand Down
Loading