Skip to content
Open
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
100 changes: 59 additions & 41 deletions fluXis/FluXisGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using fluXis.Database.Maps;
using fluXis.Graphics.Background;
using fluXis.Graphics.Sprites.Icons;
using fluXis.Graphics.UserInterface.Buttons;
using fluXis.Graphics.UserInterface.Buttons.Presets;
using fluXis.Graphics.UserInterface.Panel;
using fluXis.Graphics.UserInterface.Panel.Presets;
using fluXis.Graphics.UserInterface.Panel.Types;
Expand Down Expand Up @@ -82,6 +84,7 @@ public partial class FluXisGame : FluXisGameBase, IKeyBindingHandler<FluXisGloba
private FluXisScreenStack screenStack;
private Container<VisibilityContainer> overlayContainer;
private Dashboard dashboard;
private LoginOverlay loginOverlay;
private UserProfileOverlay userProfileOverlay;
private MapSetOverlay mapSetOverlay;
private Toolbar toolbar;
Expand Down Expand Up @@ -145,8 +148,7 @@ private void load()
loadComponent(new MusicPlayer(), overlayContainer.Add, true);
loadComponent(new SettingsMenu(), overlayContainer.Add, true);

var login = new LoginOverlay();
loadComponent(login, buffer.Add, true);
loadComponent(loginOverlay = new LoginOverlay(), buffer.Add, true);

loadComponent(new RegisterOverlay(), buffer.Add, true);
loadComponent(new MultifactorOverlay(), buffer.Add, true);
Expand All @@ -163,11 +165,7 @@ private void load()

loadComponent(MenuScreen = new MenuScreen());

LoadQueue.Push(new LoadTask("Downloading server config...", c => APIClient.PullServerConfig(c, _ =>
{
panelContainer.Content = new SingleButtonPanel(FontAwesome6.Solid.TriangleExclamation, "Failed to download server config!",
"Online functionality will be unavailable until you restart the game.", "Okay", () => c?.Invoke());
}), false));
LoadQueue.Push(new LoadTask("Downloading server config...", downloadServerConfig, false));

LoadQueue.Push(new LoadTask("Loading splashes...", c => Task.Run(() =>
{
Expand All @@ -176,40 +174,7 @@ private void load()
c();
}), false));

LoadQueue.Push(new LoadTask("Logging in...", c =>
{
if (!APIClient.CanUseOnline)
{
c();
return;
}

if (APIClient.HasCredentials)
_ = tryRelog();
else
showLogin();

return;

async Task tryRelog()
{
var error = await APIClient.ReLogin();
if (error != null) showLogin();
else cont();
}

void showLogin() => Schedule(() => login.Show(cont, () =>
{
APIClient.DisableOnline();
c();
}));

void cont()
{
APIClient.TryConnecting();
c();
}
}, false));
LoadQueue.Push(new LoadTask("Logging in...", tryLogin, false));

LoadQueue.Push(new LoadTask("Checking for bundled maps...", MapStore.DownloadBundledMaps, false));
LoadQueue.Push(new LoadTask("Loading collections...", Collections.Fetch, false));
Expand Down Expand Up @@ -251,6 +216,59 @@ private void loadNext()
LoadQueue.PerformNext(loadNext);
}

private void downloadServerConfig(Action c)
{
APIClient.PullServerConfig(c, _ =>
{
panelContainer.Content = new ButtonPanel
{
Icon = FontAwesome6.Solid.TriangleExclamation,
Text = "Failed to download server config!",
SubText = "Online functionality will be unavailable.",
Buttons = new[]
{
new PrimaryButtonData("Retry", () => downloadServerConfig(c)),
new ButtonData { Text = "Play offline", Action = () => c?.Invoke() }
}
};
});
}

private void tryLogin(Action c)
{
if (!APIClient.CanUseOnline)
{
c();
return;
}

if (APIClient.HasCredentials)
_ = tryRelog();
else
showLogin();

return;

async Task tryRelog()
{
var error = await APIClient.ReLogin();
if (error != null) showLogin();
else cont();
}

void showLogin() => Schedule(() => loginOverlay.Show(cont, () =>
{
APIClient.DisableOnline();
c();
}));

void cont()
{
APIClient.TryConnecting();
c();
}
}

public void WaitForReady(Action action)
{
if (screenStack?.CurrentScreen is null or LoadingScreen or IntroAnimation)
Expand Down