Skip to content

Commit

Permalink
BlazorGL template
Browse files Browse the repository at this point in the history
  • Loading branch information
nkast committed Feb 2, 2023
1 parent f284676 commit 5c71f36
Show file tree
Hide file tree
Showing 22 changed files with 2,930 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Templates/VisualStudio2022/ProjectTemplates/BlazorGL/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>KNI Web browser Platform Project (.NET6)</Name>
<Description>A KNI game project for Blazor webassembly using WebGL.</Description>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>KNI</ProjectSubType>
<LanguageTag>csharp</LanguageTag>
<PlatformTag>web</PlatformTag>
<ProjectTypeTag>games</ProjectTypeTag>
<ProjectTypeTag>KNI</ProjectTypeTag>
<ProjectTypeTag>web</ProjectTypeTag>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<SortOrder>43300</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>Game</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>TemplateIcon.png</Icon>
<PreviewImage>__PreviewImage.png</PreviewImage>
<CreateInPlace>true</CreateInPlace>
</TemplateData>
<TemplateContent>
<Project TargetFileName="$safeprojectname$Application.csproj" File="BlazorGLApplication.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true" TargetFileName="_Imports.razor">_Imports.razor</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="App.razor">App.razor</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Directory.Build.props">Directory.Build.props</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$Game.cs">Game1.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="MainLayout.razor">MainLayout.razor</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="MainLayout.razor.css">MainLayout.razor.css</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Program.cs">Program.cs</ProjectItem>
<Folder Name="Content" TargetFolderName="Content">
<ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$Content.mgcb">Content.mgcb</ProjectItem>
</Folder>
<Folder Name="Pages" TargetFolderName="Pages">
<ProjectItem ReplaceParameters="true" TargetFileName="Index.razor">Index.razor</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Index.razor.cs">Index.razor.cs</ProjectItem>
</Folder>
<Folder Name="Properties" TargetFolderName="Properties">
<ProjectItem ReplaceParameters="true" TargetFileName="launchSettings.json">launchSettings.json</ProjectItem>
</Folder>
<Folder Name="wwwroot" TargetFolderName="wwwroot">
<Folder Name="css" TargetFolderName="css">
<ProjectItem ReplaceParameters="false" TargetFileName="app.css">app.css</ProjectItem>
<Folder Name="bootstrap" TargetFolderName="bootstrap">
<ProjectItem ReplaceParameters="false" TargetFileName="bootstrap.min.css">bootstrap.min.css</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="bootstrap.min.css.map">bootstrap.min.css.map</ProjectItem>
</Folder>
</Folder>
<Folder Name="js" TargetFolderName="js">
<ProjectItem ReplaceParameters="false" TargetFileName="decode.min.js">decode.min.js</ProjectItem>
</Folder>
<ProjectItem ReplaceParameters="false" TargetFileName="favicon.ico">favicon.ico</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="index.html">index.html</ProjectItem>
</Folder>
</Project>
</TemplateContent>
</VSTemplate>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<MonoGamePlatform>BlazorGL</MonoGamePlatform>
</PropertyGroup>

<PropertyGroup>
<BlazorEnableTimeZoneSupport>false</BlazorEnableTimeZoneSupport>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>$(DefineConstants);TRACE;BLAZORGL</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>$(DefineConstants);TRACE;BLAZORGL</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="Pages\Index.razor.cs" />
<Compile Include="Program.cs" />
<Compile Include="$safeprojectname$Game.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="nkast.Xna.Framework" Version="3.8.9101" />
<PackageReference Include="nkast.Xna.Framework.Blazor" Version="3.8.9101" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.11" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<MonoGameContentReference Include="Content\$safeprojectname$Content.mgcb" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder17.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#----------------------------- Global Properties ----------------------------#

/outputDir:bin/$(Platform)
/intermediateDir:obj/$(Platform)
/platform:BlazorGL
/config:
/profile:Reach
/compress:True

#-------------------------------- References --------------------------------#


#---------------------------------- Content ---------------------------------#

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
</Project>

98 changes: 98 additions & 0 deletions Templates/VisualStudio2022/ProjectTemplates/BlazorGL/Game1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;


namespace $safeprojectname$
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class $safeprojectname$Game : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

public $safeprojectname$Game()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();

}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: Use this.Content to load your game content here
}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
KeyboardState keyboardState = Keyboard.GetState();

if (keyboardState.IsKeyDown(Keys.Escape) ||
keyboardState.IsKeyDown(Keys.Back))
{
#if ANDROID
// Exit() is obsolete on ANDROID
Microsoft.Xna.Framework.Game.Activity.MoveTaskToBack(true);
#elif __IOS__ || __TVOS__
// Exit() is obsolete on iOS
#else
Exit();
#endif
}

// TODO: Add your update logic here

base.Update(gameTime);
}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here

base.Draw(gameTime);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@inherits LayoutComponentBase

<div class="page">
<main>
@Body
</main>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
.page
{
position: relative;
display: flex;
flex-direction: column;
}

main
{
flex: 1;
}

.sidebar
{
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}

.top-row
{
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}

.top-row ::deep a, .top-row ::deep .btn-link
{
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}

.top-row ::deep a:hover, .top-row ::deep .btn-link:hover
{
text-decoration: underline;
}

.top-row ::deep a:first-child
{
overflow: hidden;
text-overflow: ellipsis;
}

@media (max-width: 640.98px)
{
.top-row:not(.auth)
{
display: none;
}

.top-row.auth
{
justify-content: space-between;
}

.top-row ::deep a, .top-row ::deep .btn-link
{
margin-left: 0;
}
}

@media (min-width: 641px)
{
.page
{
flex-direction: row;
}

.sidebar
{
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}

.top-row
{
position: sticky;
top: 0;
z-index: 1;
}

.top-row.auth ::deep a:first-child
{
flex: 1;
text-align: right;
width: 0;
}

.top-row, article
{
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@page "/"
@page "/index.html"
@inject IJSRuntime JsRuntime
@using nkast.Wasm.Canvas

<PageTitle>$projectname$</PageTitle>

<div id="canvasHolder" style="
margin:0%;
position: fixed;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
width:100vw;
height:100vh;
">
<canvas id="theCanvas" style="touch-action:none;"></canvas>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Microsoft.JSInterop;
using Microsoft.Xna.Framework;

namespace $safeprojectname$.Pages
{
public partial class Index
{
Game _game;

protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);

if (firstRender)
{
JsRuntime.InvokeAsync<object>("initRenderJS", DotNetObjectReference.Create(this));
}
}

[JSInvokable]
public void TickDotNet()
{
// init game
if (_game == null)
{
_game = new $safeprojectname$Game();
_game.Run();
}

// run gameloop
_game.Tick();
}

}
}
Loading

0 comments on commit 5c71f36

Please sign in to comment.