41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
|
using YamlDotNet.Core;
|
||
|
using YamlDotNet.Core.Events;
|
||
|
using YamlDotNet.Serialization;
|
||
|
|
||
|
namespace TimePasses.Model;
|
||
|
|
||
|
public interface IWhen {
|
||
|
string Text { get; }
|
||
|
bool Slowly { get; }
|
||
|
|
||
|
bool IsValid(Plugin plugin);
|
||
|
}
|
||
|
|
||
|
public class WhenConverter : IYamlTypeConverter {
|
||
|
public bool Accepts(Type type) {
|
||
|
// FIXME? typeof(IWhen).IsAssignableFrom(type)
|
||
|
return typeof(IWhen) == type;
|
||
|
}
|
||
|
|
||
|
public object? ReadYaml(IParser parser, Type type) {
|
||
|
parser.Consume<MappingStart>();
|
||
|
var name = parser.Consume<Scalar>();
|
||
|
if (!name.IsKey) {
|
||
|
throw new YamlException("invalid when: missing key");
|
||
|
}
|
||
|
|
||
|
switch (name.Value) {
|
||
|
case "quest": {
|
||
|
return Plugin.Deserializer.Deserialize<WhenQuest>(parser);
|
||
|
}
|
||
|
default: {
|
||
|
throw new YamlException($"invalid when: unknown type {name.Value}");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void WriteYaml(IEmitter emitter, object? value, Type type) {
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
}
|