2023-02-17 18:12:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
using System.Numerics;
|
2023-02-17 18:12:44 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
using Pal.Client.Configuration;
|
2023-02-18 20:12:36 +00:00
|
|
|
|
using Pal.Client.Floors;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
|
|
|
|
namespace Pal.Client.Rendering
|
|
|
|
|
{
|
2023-02-17 18:12:44 +00:00
|
|
|
|
internal sealed class RenderAdapter : IRenderer, IDisposable
|
2023-02-15 22:17:19 +00:00
|
|
|
|
{
|
2023-02-17 18:12:44 +00:00
|
|
|
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
|
|
|
private readonly ILogger<RenderAdapter> _logger;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
private readonly IPalacePalConfiguration _configuration;
|
|
|
|
|
|
2023-02-17 18:12:44 +00:00
|
|
|
|
private IServiceScope? _renderScope;
|
2023-02-17 18:31:43 +00:00
|
|
|
|
private IRenderer _implementation;
|
2023-02-17 18:12:44 +00:00
|
|
|
|
|
|
|
|
|
public RenderAdapter(IServiceScopeFactory serviceScopeFactory, ILogger<RenderAdapter> logger,
|
|
|
|
|
IPalacePalConfiguration configuration)
|
2023-02-15 22:17:19 +00:00
|
|
|
|
{
|
2023-02-17 18:12:44 +00:00
|
|
|
|
_serviceScopeFactory = serviceScopeFactory;
|
|
|
|
|
_logger = logger;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_configuration = configuration;
|
2023-02-17 18:12:44 +00:00
|
|
|
|
|
2023-02-17 18:31:43 +00:00
|
|
|
|
_implementation = Recreate(null);
|
2023-02-17 18:12:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IRenderer Recreate(ERenderer? currentRenderer)
|
|
|
|
|
{
|
|
|
|
|
ERenderer targetRenderer = _configuration.Renderer.SelectedRenderer;
|
|
|
|
|
if (targetRenderer == currentRenderer)
|
2023-02-17 18:31:43 +00:00
|
|
|
|
return _implementation;
|
2023-02-17 18:12:44 +00:00
|
|
|
|
|
|
|
|
|
_renderScope?.Dispose();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("Selected new renderer: {Renderer}", _configuration.Renderer.SelectedRenderer);
|
|
|
|
|
_renderScope = _serviceScopeFactory.CreateScope();
|
|
|
|
|
if (targetRenderer == ERenderer.Splatoon)
|
|
|
|
|
return _renderScope.ServiceProvider.GetRequiredService<SplatoonRenderer>();
|
|
|
|
|
else
|
|
|
|
|
return _renderScope.ServiceProvider.GetRequiredService<SimpleRenderer>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ConfigUpdated()
|
|
|
|
|
{
|
2023-02-17 18:31:43 +00:00
|
|
|
|
_implementation = Recreate(_implementation.GetConfigValue());
|
2023-02-15 22:17:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-17 18:12:44 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
=> _renderScope?.Dispose();
|
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
public void SetLayer(ELayer layer, IReadOnlyList<IRenderElement> elements)
|
2023-02-17 18:31:43 +00:00
|
|
|
|
=> _implementation.SetLayer(layer, elements);
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
|
|
|
|
public void ResetLayer(ELayer layer)
|
2023-02-17 18:31:43 +00:00
|
|
|
|
=> _implementation.ResetLayer(layer);
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
2023-02-18 20:12:36 +00:00
|
|
|
|
public IRenderElement CreateElement(MemoryLocation.EType type, Vector3 pos, uint color, bool fill = false)
|
2023-02-17 18:31:43 +00:00
|
|
|
|
=> _implementation.CreateElement(type, pos, color, fill);
|
|
|
|
|
|
|
|
|
|
public ERenderer GetConfigValue()
|
|
|
|
|
=> throw new NotImplementedException();
|
|
|
|
|
|
|
|
|
|
public void DrawDebugItems(uint trapColor, uint hoardColor)
|
|
|
|
|
=> _implementation.DrawDebugItems(trapColor, hoardColor);
|
2023-02-16 12:17:55 +00:00
|
|
|
|
|
|
|
|
|
public void DrawLayers()
|
|
|
|
|
{
|
2023-02-17 18:31:43 +00:00
|
|
|
|
if (_implementation is SimpleRenderer sr)
|
2023-02-16 12:17:55 +00:00
|
|
|
|
sr.DrawLayers();
|
|
|
|
|
}
|
2023-02-15 22:17:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|