1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00
MLEM/Demos.Web/Pages/Index.razor.cs

38 lines
1.2 KiB
C#
Raw Normal View History

2024-09-02 20:33:04 +02:00
using System.Threading.Tasks;
using Microsoft.JSInterop;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
2024-09-15 23:01:37 +02:00
using MLEM.Formatting;
2024-09-02 20:33:04 +02:00
using MLEM.Misc;
2024-09-15 23:01:37 +02:00
using MLEM.Ui;
using MLEM.Ui.Elements;
2024-09-02 20:33:04 +02:00
namespace Demos.Web.Pages;
public partial class Index {
2024-09-15 23:01:37 +02:00
private GameImpl game;
2024-09-02 20:33:04 +02:00
protected override async Task OnAfterRenderAsync(bool firstRender) {
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
await this.JsRuntime.InvokeAsync<object>("initRenderJS", DotNetObjectReference.Create(this));
}
[JSInvokable]
public void TickDotNet() {
if (this.game == null) {
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
this.game = new GameImpl();
2024-09-15 23:01:37 +02:00
this.game.OnLoadContent += g => g.UiSystem.Add("WebDisclaimer", new Paragraph(Anchor.BottomCenter, 1, "The Web version of MLEM's demos is still in development.\nFor the best experience, please try their Desktop and Android versions instead.") {
PositionOffset = new Vector2(0, 1),
Alignment = TextAlignment.Center,
TextScale = 0.075F
});
2024-09-02 20:33:04 +02:00
this.game.Run();
}
this.game.Tick();
}
}