add assets and frontend to backend package
This commit is contained in:
parent
e4d2ad4a14
commit
a5a3f2cc81
8 changed files with 56 additions and 21 deletions
|
@ -4,7 +4,7 @@ namespace TanksServer.GameLogic;
|
|||
|
||||
internal sealed class CollideBullets : ITickStep
|
||||
{
|
||||
private readonly Sprite _explosiveSprite = Sprite.FromImageFile("assets/explosion.png");
|
||||
private readonly Sprite _explosiveSprite = Sprite.FromImageFile(Path.Combine(Program.AssetsDir, "explosion.png"));
|
||||
private readonly Predicate<Bullet> _removeBulletsPredicate;
|
||||
private readonly MapEntityManager _entityManager;
|
||||
private readonly MapService _map;
|
||||
|
|
|
@ -22,9 +22,10 @@ internal sealed class MapService
|
|||
|
||||
public MapService()
|
||||
{
|
||||
foreach (var file in Directory.EnumerateFiles("./assets/maps/", "*.txt"))
|
||||
var dir = Path.Combine(Program.AssetsDir, "maps");
|
||||
foreach (var file in Directory.EnumerateFiles(dir, "*.txt"))
|
||||
LoadMapString(file);
|
||||
foreach (var file in Directory.EnumerateFiles("./assets/maps/", "*.png"))
|
||||
foreach (var file in Directory.EnumerateFiles(dir, "*.png"))
|
||||
LoadMapPng(file);
|
||||
Current = GetRandomMap();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
global using System;
|
||||
global using System.Collections.Concurrent;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IO;
|
||||
global using System.Linq;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
|
|
|
@ -4,11 +4,11 @@ namespace TanksServer.Graphics;
|
|||
|
||||
internal sealed class DrawPowerUpsStep(MapEntityManager entityManager) : IDrawStep
|
||||
{
|
||||
private readonly Sprite _genericSprite = Sprite.FromImageFile("assets/powerup_generic.png");
|
||||
private readonly Sprite _smartSprite = Sprite.FromImageFile("assets/powerup_smart.png");
|
||||
private readonly Sprite _magazineSprite = Sprite.FromImageFile("assets/powerup_magazine.png");
|
||||
private readonly Sprite _explosiveSprite = Sprite.FromImageFile("assets/powerup_explosive.png");
|
||||
private readonly Sprite _fastSprite = Sprite.FromImageFile("assets/powerup_fastbullet.png");
|
||||
private readonly Sprite _genericSprite = Sprite.FromImageFile(Path.Combine(Program.AssetsDir, "powerup_generic.png"));
|
||||
private readonly Sprite _smartSprite = Sprite.FromImageFile(Path.Combine(Program.AssetsDir, "powerup_smart.png"));
|
||||
private readonly Sprite _magazineSprite = Sprite.FromImageFile(Path.Combine(Program.AssetsDir, "powerup_magazine.png"));
|
||||
private readonly Sprite _explosiveSprite = Sprite.FromImageFile(Path.Combine(Program.AssetsDir, "powerup_explosive.png"));
|
||||
private readonly Sprite _fastSprite = Sprite.FromImageFile(Path.Combine(Program.AssetsDir, "powerup_fastbullet.png"));
|
||||
|
||||
public void Draw(GamePixelGrid pixels)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace TanksServer.Graphics;
|
|||
internal sealed class DrawTanksStep(MapEntityManager entityManager) : IDrawStep
|
||||
{
|
||||
private readonly SpriteSheet _tankSprites =
|
||||
SpriteSheet.FromImageFile("assets/tank.png", (int)MapService.TileSize, (int)MapService.TileSize);
|
||||
SpriteSheet.FromImageFile(Path.Combine(Program.AssetsDir, "tank.png"), (int)MapService.TileSize, (int)MapService.TileSize);
|
||||
|
||||
public void Draw(GamePixelGrid pixels)
|
||||
{
|
||||
|
|
|
@ -11,22 +11,44 @@ namespace TanksServer;
|
|||
|
||||
public static class Program
|
||||
{
|
||||
internal static string AssetsDir = (Environment.GetEnvironmentVariable("TANKSSERVER_ASSETS") ?? "./assets") + "/";
|
||||
|
||||
[RequiresUnreferencedCode("Calls Endpoints.Map")]
|
||||
[RequiresDynamicCode("Calls Endpoints.Map")]
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var app = Configure(args);
|
||||
|
||||
var clientFileProvider = new PhysicalFileProvider(Path.Combine(app.Environment.ContentRootPath, "client"));
|
||||
app.Logger.LogInformation("Running in {}", app.Environment.ContentRootPath);
|
||||
|
||||
app.UseDefaultFiles(new DefaultFilesOptions { FileProvider = clientFileProvider });
|
||||
app.UseStaticFiles(new StaticFileOptions { FileProvider = clientFileProvider });
|
||||
AddStaticClientHost(app);
|
||||
|
||||
app.Services.GetRequiredService<Endpoints>().Map(app);
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
|
||||
private static void AddStaticClientHost(WebApplication app)
|
||||
{
|
||||
var clientDir = Environment.GetEnvironmentVariable("TANKSSERVER_CLIENT");
|
||||
bool required = clientDir != null;
|
||||
|
||||
clientDir ??= Path.Combine(app.Environment.ContentRootPath, "client");
|
||||
bool available = Directory.Exists(clientDir);
|
||||
|
||||
if (!available)
|
||||
{
|
||||
if (required)
|
||||
throw new InvalidOperationException($"The environment variable TANKSSERVER_CLIENT is set, but the specified directory {clientDir} does not exist.");
|
||||
app.Logger.LogError("Not providing static file host for client because {} does not exist", clientDir);
|
||||
return;
|
||||
}
|
||||
|
||||
var clientFileProvider = new PhysicalFileProvider(clientDir);
|
||||
app.UseDefaultFiles(new DefaultFilesOptions { FileProvider = clientFileProvider });
|
||||
app.UseStaticFiles(new StaticFileOptions { FileProvider = clientFileProvider });
|
||||
}
|
||||
|
||||
[RequiresUnreferencedCode("Calls Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<TOptions>(IConfiguration)")]
|
||||
[RequiresDynamicCode("Calls Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<TOptions>(IConfiguration)")]
|
||||
private static WebApplication Configure(string[] args)
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="./assets/**" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Always"/>
|
||||
<None Include="./assets/**" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Always" Condition="'$(ContinuousIntegrationBuild)'!='true'" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue