Skip to content

Commit

Permalink
Added startup project
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkenJaden committed Jan 24, 2023
1 parent 5ec1aef commit b9f533e
Show file tree
Hide file tree
Showing 27 changed files with 332 additions and 210 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PackageVersion Include="coverlet.collector" Version="1.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.13" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.4.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
Expand Down
26 changes: 20 additions & 6 deletions LandOfSignals-Signalbox.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Signalbox.Instrumentation",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Signalbox.SourceGenerator", "Signalbox.SourceGenerator\Signalbox.SourceGenerator.csproj", "{34B02356-3EF1-496B-AE87-C6A261AF64BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LandOfSignals-Signalbox", "LandOfSignals-Signalbox\LandOfSignals-Signalbox.csproj", "{0FEBA410-1006-4B11-9A33-F1CC3E5715FA}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LandOfSignals-Signalbox.Server", "LandOfSignals-Signalbox\Server\LandOfSignals-Signalbox.Server.csproj", "{C676ADA9-0738-4166-9E49-1041B733B1E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LandOfSignals-Signalbox.Client", "LandOfSignals-Signalbox\Client\LandOfSignals-Signalbox.Client.csproj", "{D6C51AB8-8E2A-4F62-9FEF-FA435E4FDA2A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LandOfSignals-Signalbox.Shared", "LandOfSignals-Signalbox\Shared\LandOfSignals-Signalbox.Shared.csproj", "{F4AC1B1D-431C-47CA-9BC8-F8D19B5AE5BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -52,10 +56,18 @@ Global
{34B02356-3EF1-496B-AE87-C6A261AF64BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34B02356-3EF1-496B-AE87-C6A261AF64BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34B02356-3EF1-496B-AE87-C6A261AF64BF}.Release|Any CPU.Build.0 = Release|Any CPU
{0FEBA410-1006-4B11-9A33-F1CC3E5715FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FEBA410-1006-4B11-9A33-F1CC3E5715FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FEBA410-1006-4B11-9A33-F1CC3E5715FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FEBA410-1006-4B11-9A33-F1CC3E5715FA}.Release|Any CPU.Build.0 = Release|Any CPU
{C676ADA9-0738-4166-9E49-1041B733B1E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C676ADA9-0738-4166-9E49-1041B733B1E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C676ADA9-0738-4166-9E49-1041B733B1E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C676ADA9-0738-4166-9E49-1041B733B1E8}.Release|Any CPU.Build.0 = Release|Any CPU
{D6C51AB8-8E2A-4F62-9FEF-FA435E4FDA2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6C51AB8-8E2A-4F62-9FEF-FA435E4FDA2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6C51AB8-8E2A-4F62-9FEF-FA435E4FDA2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6C51AB8-8E2A-4F62-9FEF-FA435E4FDA2A}.Release|Any CPU.Build.0 = Release|Any CPU
{F4AC1B1D-431C-47CA-9BC8-F8D19B5AE5BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4AC1B1D-431C-47CA-9BC8-F8D19B5AE5BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4AC1B1D-431C-47CA-9BC8-F8D19B5AE5BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4AC1B1D-431C-47CA-9BC8-F8D19B5AE5BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -66,7 +78,9 @@ Global
{14E3D0CE-8319-4B63-8223-E2F6C422F076} = {5B68BEBD-7E5A-4DF5-B585-924D8644BD86}
{FD09BCF2-27BD-422D-B5F1-DF986B2FFB7E} = {5B68BEBD-7E5A-4DF5-B585-924D8644BD86}
{34B02356-3EF1-496B-AE87-C6A261AF64BF} = {3D340E00-DCF1-4AF3-A109-1645E6211945}
{0FEBA410-1006-4B11-9A33-F1CC3E5715FA} = {024D51A0-4E30-498D-B6C9-195AEE178C0E}
{C676ADA9-0738-4166-9E49-1041B733B1E8} = {024D51A0-4E30-498D-B6C9-195AEE178C0E}
{D6C51AB8-8E2A-4F62-9FEF-FA435E4FDA2A} = {024D51A0-4E30-498D-B6C9-195AEE178C0E}
{F4AC1B1D-431C-47CA-9BC8-F8D19B5AE5BE} = {024D51A0-4E30-498D-B6C9-195AEE178C0E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {735FB670-E73E-429B-8232-FF5952B85CB7}
Expand Down
12 changes: 12 additions & 0 deletions LandOfSignals-Signalbox/Client/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
@@ -1,12 +1,12 @@
using Blazored.LocalStorage;
using Signalbox.Engine.Storage;

namespace LandOfSignals_Signalbox;
namespace LandOfSignals_Signalbox.Client;

public class BlazorSignalboxStorage : ISignalboxStorage
public class BlazorGameStorage : ISignalboxStorage
{
private ISyncLocalStorageService? _syncLocalStorageService;
private readonly Dictionary<string, string> _lastSavedValue = new();
private readonly Dictionary<string, string> _lastSavedValue = new Dictionary<string, string>();

public IServiceProvider? AspNetCoreServices { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics;
using Signalbox.Engine.Utilities;

namespace LandOfSignals_Signalbox;
namespace LandOfSignals_Signalbox.Client;

public class BlazorTimer : ITimer
{
Expand All @@ -23,7 +23,7 @@ public void Dispose()
public void Start()
{
Stop();
_cts = new();
_cts = new CancellationTokenSource();
_ = StartTimer();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@page "/"
@using Microsoft.AspNetCore.Components.Web
@using SkiaSharp.Views.Blazor

<PageTitle>Index</PageTitle>
<PageTitle>LandOfSignals - Signalbox</PageTitle>

<SKGLView IgnorePixelScaling="true"
EnableRenderLoop="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,66 @@
using SkiaSharp;
using SkiaSharp.Views.Blazor;

namespace LandOfSignals_Signalbox;
namespace LandOfSignals_Signalbox.Client;

public partial class Game
{
private ISignalbox _signalbox = null!;
private ISignalbox _game = null!;
private IInteractionManager _interactionManager = null!;

private readonly PerSecondTimedStat _fps = InstrumentationBag.Add<PerSecondTimedStat>("SkiaSharp-OnPaintSurfaceFPS");
private readonly ElapsedMillisecondsTimedStat _renderTime = InstrumentationBag.Add<ElapsedMillisecondsTimedStat>("GameElement-GameRender");

protected override async Task OnInitializedAsync()
{
_signalbox = DI.ServiceLocator.GetService<ISignalbox>();
_game = DI.ServiceLocator.GetService<ISignalbox>();
_interactionManager = DI.ServiceLocator.GetService<IInteractionManager>();

await _signalbox.InitializeAsync(200, 200);
await _game.InitializeAsync(200, 200);
}

private void OnPaintSurface(SKPaintGLSurfaceEventArgs e)
{
using (_renderTime.Measure())
{
_signalbox.SetSize(e.Info.Width, e.Info.Height);
_game.SetSize(e.Info.Width, e.Info.Height);
if (e.Surface.Context is GRContext context && context != null)
{
// Set the context so all rendering happens in the same place
_signalbox.SetContext(new SKContextWrapper(context));
_game.SetContext(new SKContextWrapper(context));
}
_signalbox.Render(new SKCanvasWrapper(e.Surface.Canvas));
_game.Render(new SKCanvasWrapper(e.Surface.Canvas));
}

_fps.Update();
}

private void OnPointerDown(PointerEventArgs e)
{
if (e.Buttons == 1)
switch (e.Buttons)
{
_interactionManager.PointerClick((int)e.OffsetX, (int)e.OffsetY);
}
else if (e.Buttons == 2)
{
_interactionManager.PointerAlternateClick((int)e.OffsetX, (int)e.OffsetY);
case 1:
_interactionManager.PointerClick((int)e.OffsetX, (int)e.OffsetY);
break;
case 2:
_interactionManager.PointerAlternateClick((int)e.OffsetX, (int)e.OffsetY);
break;
}
}

private void OnPointerMove(PointerEventArgs e)
{
if (e.Buttons == 1)
switch (e.Buttons)
{
_interactionManager.PointerDrag((int)e.OffsetX, (int)e.OffsetY);
}
else if (e.Buttons == 2)
{
_interactionManager.PointerAlternateDrag((int)e.OffsetX, (int)e.OffsetY);
}
else
{
_interactionManager.PointerMove((int)e.OffsetX, (int)e.OffsetY);
case 1:
_interactionManager.PointerDrag((int)e.OffsetX, (int)e.OffsetY);
break;
case 2:
_interactionManager.PointerAlternateDrag((int)e.OffsetX, (int)e.OffsetY);
break;
default:
_interactionManager.PointerMove((int)e.OffsetX, (int)e.OffsetY);
break;
}
}

Expand All @@ -92,13 +93,14 @@ private void OnTouchMove(TouchEventArgs e)
if (touch is null)
return;

if (e.Touches.Length == 1)
{
_interactionManager.PointerDrag((int)touch.ClientX, (int)touch.ClientY);
}
else if (e.Touches.Length == 2)
switch (e.Touches.Length)
{
_interactionManager.PointerAlternateDrag((int)touch.ClientX, (int)touch.ClientY);
case 1:
_interactionManager.PointerDrag((int)touch.ClientX, (int)touch.ClientY);
break;
case 2:
_interactionManager.PointerAlternateDrag((int)touch.ClientX, (int)touch.ClientY);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<PublishIISAssets>true</PublishIISAssets>
<AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName>

<BlazorEnableTimeZoneSupport>false</BlazorEnableTimeZoneSupport>
<BlazorWebAssemblyPreserveCollationData>false</BlazorWebAssemblyPreserveCollationData>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishTrimmed>true</PublishTrimmed>
<RunAOTCompilation>true</RunAOTCompilation>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" PrivateAssets="all" />

<PackageReference Include="Blazored.LocalStorage" />

<PackageReference Include="SkiaSharp" />
<PackageReference Include="SkiaSharp.Views.Blazor" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Signalbox.Engine\Signalbox.Engine.csproj" />
<ProjectReference Include="..\..\Signalbox.Instrumentation\Signalbox.Instrumentation.csproj" />
<ProjectReference Include="..\..\Signalbox.Rendering.Skia\Signalbox.Rendering.Skia.csproj" />
<ProjectReference Include="..\..\Signalbox.Rendering\Signalbox.Rendering.csproj" />
<ProjectReference Include="..\..\Signalbox.SourceGenerator\Signalbox.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\Shared\LandOfSignals-Signalbox.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using Blazored.LocalStorage;
using LandOfSignals_Signalbox;
using Blazored.LocalStorage;
using LandOfSignals_Signalbox.Client;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Signalbox.Engine.Storage;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<Game>("#app");
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddBlazoredLocalStorage();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped(_ => new HttpClient { BaseAddress = new(builder.HostEnvironment.BaseAddress) });

var host = builder.Build();

// Dodgy!!
if (DI.ServiceLocator.GetService<ISignalboxStorage>() is BlazorSignalboxStorage storage)
if (DI.ServiceLocator.GetService<ISignalboxStorage>() is BlazorGameStorage storage)
{
storage.AspNetCoreServices = host.Services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:10393",
"sslPort": 44314
"applicationUrl": "http://localhost:56441",
"sslPort": 44352
}
},
"profiles": {
"Signalbox": {
"LandOfSignals-Signalbox": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7043;http://localhost:5043",
"applicationUrl": "https://localhost:7136;http://localhost:5028",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
4 changes: 4 additions & 0 deletions LandOfSignals-Signalbox/Client/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@inherits LayoutComponentBase

<NavMenu />
@Body
1 change: 1 addition & 0 deletions LandOfSignals-Signalbox/Client/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 11 additions & 0 deletions LandOfSignals-Signalbox/Client/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using LandOfSignals_Signalbox.Client
@using LandOfSignals_Signalbox.Client.Shared
@using SkiaSharp.Views.Blazor
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
overflow: hidden;
height: -webkit-fill-available;
min-height: -webkit-fill-available;
background-color: #58c467;
background-color: #a5a5a5;
user-select: none;
}

#banner {
position: absolute;
top: 30vh;
width: 100%;
text-align: center;
background-size: 420px;
padding: 50px 0px 50px 0px;
}

a {
color: #0077cc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<head>
<meta charset="utf-8" />

<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
Expand All @@ -13,7 +12,14 @@

<body>
<div id="app">
<p>Please wait...</p>
<div id="banner">
<h1>LandOfSignals - Signalbox</h1>
<p>Please wait...</p>
<p>
<a href="https://markenjaden.de/">@MarkenJaden</a> <br />
<a href="https://github.com/LandOfRails/LandOfSignals-Signalbox">https://github.com/LandOfRails/LandOfSignals-Signalbox</a>
</p>
</div>
</div>

<div id="blazor-error-ui">
Expand Down
Loading

0 comments on commit b9f533e

Please sign in to comment.