NetAF.Blazor 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NetAF.Blazor --version 1.0.0
                    
NuGet\Install-Package NetAF.Blazor -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetAF.Blazor" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetAF.Blazor" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NetAF.Blazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NetAF.Blazor --version 1.0.0
                    
#r "nuget: NetAF.Blazor, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NetAF.Blazor@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NetAF.Blazor&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NetAF.Blazor&version=1.0.0
                    
Install as a Cake Tool

NetAF.Blazor

A Blazor implementation of NetAF. This repo demonstrates how NetAF can be used in a Blazor app by making use of the various classes in NetAF.Targets.Html.

Getting Started

Running the Example

Getting started running NetAF in Blazor is easy!

  • Clone the repo.
  • Build and run NetAF.Blazor.
  • The app will be served at https://localhost:7295/. Navigate to https://localhost:7295/ in your broswer to start the game.

image

How it Works

The Blazor app provides a single page for rendering and interacting with the game. NetAF provides frame builders to generate the HTML for your game, which is then displayed directly in the page using:

<div>
    @((MarkupString)frameAsHtml)
</div>

The page itself is an implementation of IFramePresenter, when an update occurs in the game the Present method is called, which allows the page to receive the generated HTML content.

Besides the generated content the page displays a simple acknowledge button and a input box that allow the user to interact with the game. Based on the games current mode these elements are either visible or hidden.

The game itself is executed as a background task.

@page "/"
@using NetAF.Logic.Modes
@using NetAF.Rendering.FrameBuilders
@implements IFramePresenter
@rendermode @(new InteractiveServerRenderMode(prerender:false))

<PageTitle>NetAF</PageTitle>

<div>
    @((MarkupString)frameAsHtml)
</div>

<br />

@if (showInput)
{
    <input type="text" @ref="textInput" @bind="text" @onkeyup="HandleInput" />
}

@if (showAcknowledge)
{
    <button class="btn btn-primary" @ref="acknowledgeButton" @onclick="Acknowledge">OK</button>
}

@code {
    private HtmlAdapter? htmlAdapter;
    private string frameAsHtml = string.Empty;
    private string text = string.Empty;
    private bool showInput = false;
    private bool showAcknowledge = false;
    private ElementReference acknowledgeButton;
    private ElementReference textInput;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (!firstRender)
            return;

        if (GameExecutor.IsExecuting)
            GameExecutor.CancelExecution();

        htmlAdapter = new HtmlAdapter(this);
        GameConfiguration configuration = new(htmlAdapter, FrameBuilderCollections.Html, new(80, 50));
        GameExecutor.Execute(ExampleGame.Create(configuration));
        await InvokeAsync(StateHasChanged);
    }

    private void Acknowledge()
    {
        GameExecutor.Update();
    }

    private void HandleInput(KeyboardEventArgs e)
    {
        if (e.Key == "Enter" && !string.IsNullOrWhiteSpace(text))
        {
            GameExecutor.Update(text);
            text = string.Empty;
        }
    }

    public async void Present(string frame)
    {
        frameAsHtml = frame;
        showInput = htmlAdapter?.Game?.Mode?.Type == GameModeType.Interactive;
        showAcknowledge = htmlAdapter?.Game?.Mode?.Type == GameModeType.Information;

        await InvokeAsync(StateHasChanged);

        if (showInput && textInput.Context != null)
            await textInput.FocusAsync();

        if (showAcknowledge && acknowledgeButton.Context != null)
            await acknowledgeButton.FocusAsync();
    }
}

Example Game

The ExampleGame is included in the repo.

Documentation

Please visit https://benpollarduk.github.io/NetAF-docs/ to view the NetAF documentation.

For Open Questions

Visit https://github.com/benpollarduk/NetAF.Blazor/issues

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.8 105 1/8/2026
1.0.7 149 1/5/2026
1.0.6 206 12/23/2025
1.0.5 953 4/24/2025
1.0.4 460 4/3/2025
1.0.3 535 3/25/2025
1.0.2 445 3/24/2025
1.0.1 271 3/18/2025
1.0.0 191 3/18/2025

Initial version.