51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
namespace FoodFactory;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using FoodFactory.Conveyors;
|
|
using FoodFactory.Recipes;
|
|
using FoodFactory.Voxel;
|
|
|
|
public interface IFoodFactoryApi
|
|
{
|
|
T? GetApi<T>() where T : class;
|
|
IRecipes Recipes { get; }
|
|
IBlueprintManger BlueprintManger { get; }
|
|
ITickManger TickManger { get; }
|
|
IItemRenderer ItemRenderer { get; }
|
|
IVoxelGridRegistry GridRegistry { get; }
|
|
}
|
|
public interface ITickManger
|
|
{
|
|
delegate void Tick(TickArgs args);
|
|
event Tick GameTick;
|
|
}
|
|
public record struct TickArgs(int Tick, double Delta);
|
|
public class TickManger : ITickManger
|
|
{
|
|
public event ITickManger.Tick? GameTick;
|
|
public void BroadCast(TickArgs args) => GameTick?.Invoke(args);
|
|
}
|
|
public class FoodFactoryApi : IFoodFactoryApi
|
|
{
|
|
public required IRecipes Recipes { get; set; }
|
|
|
|
public required IBlueprintManger BlueprintManger { get; set; }
|
|
|
|
public required ITickManger TickManger { get; set; }
|
|
|
|
public required IItemRenderer ItemRenderer { get; set; }
|
|
|
|
public required IVoxelGridRegistry GridRegistry { get; set; }
|
|
|
|
private readonly Dictionary<Type, object> _otherApi = [];
|
|
public T? GetApi<T>() where T : class
|
|
{
|
|
if (_otherApi.TryGetValue(typeof(T), out var api))
|
|
{
|
|
return api as T;
|
|
}
|
|
return null;
|
|
}
|
|
}
|