Traveller/scripts/map/roomInjectionProcessor/RoomInjectionProcessorTemplate.cs
Cold-Mint a957c91ffe
Add probability-based and time-interval based room injection processors.
加入基于概率的和基于时间间隔的房间注入处理器。
2024-05-30 22:49:54 +08:00

41 lines
1.3 KiB
C#

using System.Threading.Tasks;
using ColdMint.scripts.map.interfaces;
using ColdMint.scripts.serialization;
using Godot;
namespace ColdMint.scripts.map.roomInjectionProcessor;
/// <summary>
/// <para>Room injection processor template</para>
/// <para>房间注入处理器模板</para>
/// </summary>
/// <typeparam name="TConfig"></typeparam>
public abstract class RoomInjectionProcessorTemplate<TConfig> : IRoomInjectionProcessor
{
public abstract string GetId();
public Task<bool> CanBePlaced(RandomNumberGenerator randomNumberGenerator, string? jsonConfigData)
{
if (jsonConfigData == null)
{
return Task.FromResult(false);
}
var configData = JsonSerialization.Deserialize<TConfig>(jsonConfigData);
if (configData == null)
{
return Task.FromResult(false);
}
return OnCreateConfigData(randomNumberGenerator, configData);
}
/// <summary>
/// <para>When creating a configuration class</para>
/// <para>当创建配置类时</para>
/// </summary>
/// <param name="randomNumberGenerator"></param>
/// <param name="configData"></param>
/// <returns></returns>
protected abstract Task<bool> OnCreateConfigData(RandomNumberGenerator randomNumberGenerator, TConfig configData);
}