2024-06-17 17:25:46 +00:00
|
|
|
using YamlDotNet.Core;
|
|
|
|
using YamlDotNet.Core.Events;
|
2024-06-17 18:20:33 +00:00
|
|
|
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
|
2024-06-17 17:25:46 +00:00
|
|
|
|
|
|
|
namespace TimePasses.Model;
|
|
|
|
|
|
|
|
public interface IWhen {
|
|
|
|
string Text { get; }
|
|
|
|
bool Slowly { get; }
|
|
|
|
|
|
|
|
bool IsValid(Plugin plugin);
|
|
|
|
}
|
|
|
|
|
2024-06-17 18:20:33 +00:00
|
|
|
public class WhenDiscriminator : ITypeDiscriminator {
|
|
|
|
public Type BaseType => typeof(IWhen);
|
2024-06-17 17:25:46 +00:00
|
|
|
|
2024-06-17 18:20:33 +00:00
|
|
|
public bool TryDiscriminate(IParser buffer, out Type? suggestedType) {
|
|
|
|
buffer.Consume<MappingStart>();
|
|
|
|
var name = buffer.Consume<Scalar>();
|
2024-06-17 17:25:46 +00:00
|
|
|
if (!name.IsKey) {
|
2024-06-17 18:20:33 +00:00
|
|
|
suggestedType = null;
|
|
|
|
return false;
|
2024-06-17 17:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (name.Value) {
|
|
|
|
case "quest": {
|
2024-06-17 18:20:33 +00:00
|
|
|
suggestedType = typeof(WhenQuest);
|
2024-06-17 17:41:16 +00:00
|
|
|
break;
|
2024-06-17 17:25:46 +00:00
|
|
|
}
|
|
|
|
default: {
|
2024-06-17 18:20:33 +00:00
|
|
|
suggestedType = null;
|
|
|
|
return false;
|
2024-06-17 17:25:46 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-17 17:41:16 +00:00
|
|
|
|
2024-06-17 18:20:33 +00:00
|
|
|
return true;
|
2024-06-17 17:25:46 +00:00
|
|
|
}
|
|
|
|
}
|