mirror of
https://github.com/xivdev/EXDSchema.git
synced 2025-06-06 16:17:46 +00:00
Refine Yaml output and reconsider life choices
This commit is contained in:
parent
2d96cd07b7
commit
b4e19ad8fb
6 changed files with 161 additions and 60 deletions
|
@ -1,41 +1,70 @@
|
||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
|
using SharpYaml;
|
||||||
|
using SharpYaml.Serialization;
|
||||||
|
|
||||||
namespace SchemaConverter.New;
|
namespace SchemaConverter.New;
|
||||||
|
|
||||||
public enum FieldType
|
public enum FieldType
|
||||||
{
|
{
|
||||||
scalar,
|
Scalar,
|
||||||
array,
|
Array,
|
||||||
icon,
|
Icon,
|
||||||
modelId,
|
ModelId,
|
||||||
color,
|
Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Sheet
|
public class Sheet
|
||||||
{
|
{
|
||||||
|
[YamlMember(0)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[YamlMember(1)]
|
||||||
public string? DisplayField { get; set; }
|
public string? DisplayField { get; set; }
|
||||||
|
|
||||||
|
[YamlMember(2)]
|
||||||
public List<Field> Fields { get; set; }
|
public List<Field> Fields { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Field
|
public class Field
|
||||||
{
|
{
|
||||||
|
[YamlMember(0)]
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
[YamlMember(1)]
|
||||||
public int? Count { get; set; }
|
public int? Count { get; set; }
|
||||||
public string? Comment { get; set; }
|
|
||||||
|
[YamlMember(2)]
|
||||||
|
[DefaultValue(FieldType.Scalar)]
|
||||||
public FieldType Type { get; set; }
|
public FieldType Type { get; set; }
|
||||||
|
|
||||||
|
[YamlMember(3)]
|
||||||
|
public string? Comment { get; set; }
|
||||||
|
|
||||||
|
[YamlMember(4)]
|
||||||
public List<Field>? Fields { get; set; }
|
public List<Field>? Fields { get; set; }
|
||||||
|
|
||||||
|
[YamlMember(5)]
|
||||||
public Link? Link { get; set; }
|
public Link? Link { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Link
|
public class Link
|
||||||
{
|
{
|
||||||
public List<string> Target { get; set; }
|
[YamlMember(0)]
|
||||||
public Condition? Condition { get; set; }
|
public Condition? Condition { get; set; }
|
||||||
|
|
||||||
|
[YamlMember(1)]
|
||||||
|
[YamlStyle(YamlStyle.Flow)]
|
||||||
|
public List<string> Target { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Condition
|
public class Condition
|
||||||
{
|
{
|
||||||
|
[YamlMember(0)]
|
||||||
public string Switch { get; set; }
|
public string Switch { get; set; }
|
||||||
|
|
||||||
|
[YamlMember(1)]
|
||||||
public Dictionary<int, List<string>> Cases { get; set; }
|
public Dictionary<int, List<string>> Cases { get; set; }
|
||||||
}
|
}
|
|
@ -123,17 +123,17 @@ public class SchemaConverter
|
||||||
Name = col.Name,
|
Name = col.Name,
|
||||||
Type = col.Type switch
|
Type = col.Type switch
|
||||||
{
|
{
|
||||||
"quad" => FieldType.modelId,
|
"quad" => FieldType.ModelId,
|
||||||
"icon" => FieldType.icon,
|
"icon" => FieldType.Icon,
|
||||||
"color" => FieldType.color,
|
"color" => FieldType.Color,
|
||||||
_ => FieldType.scalar,
|
_ => FieldType.Scalar,
|
||||||
},
|
},
|
||||||
Link = col.Link,
|
Link = col.Link,
|
||||||
};
|
};
|
||||||
newSchema.Fields.Add(field);
|
newSchema.Fields.Add(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
var newSchemaStr = SerializeUtil.Serialize(newSchema);
|
var newSchemaStr = SerializeUtil3.Serialize(newSchema);
|
||||||
File.WriteAllText(newSchemaPath, newSchemaStr);
|
File.WriteAllText(newSchemaPath, newSchemaStr);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Lumina" Version="3.11.0" />
|
<PackageReference Include="Lumina" Version="3.11.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="YamlDotNet" Version="13.3.1" />
|
<PackageReference Include="SharpYaml" Version="2.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,47 +1,48 @@
|
||||||
using YamlDotNet.Core;
|
// using YamlDotNet.Core;
|
||||||
using YamlDotNet.Core.Events;
|
// using YamlDotNet.Core.Events;
|
||||||
using YamlDotNet.Serialization;
|
// using YamlDotNet.Serialization;
|
||||||
using YamlDotNet.Serialization.EventEmitters;
|
// using YamlDotNet.Serialization.EventEmitters;
|
||||||
using YamlDotNet.Serialization.NamingConventions;
|
// using YamlDotNet.Serialization.NamingConventions;
|
||||||
|
//
|
||||||
namespace SchemaConverter;
|
// namespace SchemaConverter;
|
||||||
|
//
|
||||||
public static class SerializeUtil
|
// public static class SerializeUtil
|
||||||
{
|
// {
|
||||||
private static readonly ISerializer _serializer;
|
// private static readonly ISerializer _serializer;
|
||||||
|
//
|
||||||
static SerializeUtil()
|
// static SerializeUtil()
|
||||||
{
|
// {
|
||||||
_serializer = new SerializerBuilder()
|
// _serializer = new SerializerBuilder()
|
||||||
.WithIndentedSequences()
|
// .WithIndentedSequences()
|
||||||
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
// .WithNamingConvention(CamelCaseNamingConvention.Instance)
|
||||||
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults)
|
// .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults)
|
||||||
// .WithEventEmitter(nextEmitter => new FlowEverythingEmitter(nextEmitter))
|
// .DisableAliases()
|
||||||
.Build();
|
// // .WithEventEmitter(nextEmitter => new FlowEverythingEmitter(nextEmitter))
|
||||||
}
|
// .Build();
|
||||||
|
// }
|
||||||
public static string Serialize(object o)
|
//
|
||||||
{
|
// public static string Serialize(object o)
|
||||||
return _serializer.Serialize(o);
|
// {
|
||||||
}
|
// return _serializer.Serialize(o);
|
||||||
|
// }
|
||||||
public class FlowEverythingEmitter : ChainedEventEmitter
|
//
|
||||||
{
|
// public class FlowEverythingEmitter : ChainedEventEmitter
|
||||||
public FlowEverythingEmitter(IEventEmitter nextEmitter) : base(nextEmitter) { }
|
// {
|
||||||
|
// public FlowEverythingEmitter(IEventEmitter nextEmitter) : base(nextEmitter) { }
|
||||||
public override void Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
|
//
|
||||||
{
|
// public override void Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
|
||||||
Console.WriteLine($"Type: {eventInfo.Source.Type} Style: {eventInfo.Source.StaticType} Value: {eventInfo.Source.Value}");
|
// {
|
||||||
|
// Console.WriteLine($"Type: {eventInfo.Source.Type} Style: {eventInfo.Source.StaticType} Value: {eventInfo.Source.Value}");
|
||||||
eventInfo.Style = MappingStyle.Flow;
|
//
|
||||||
base.Emit(eventInfo, emitter);
|
// eventInfo.Style = MappingStyle.Flow;
|
||||||
}
|
// base.Emit(eventInfo, emitter);
|
||||||
|
// }
|
||||||
public override void Emit(SequenceStartEventInfo eventInfo, IEmitter emitter)
|
//
|
||||||
{
|
// public override void Emit(SequenceStartEventInfo eventInfo, IEmitter emitter)
|
||||||
Console.WriteLine($"Type: {eventInfo.Source.Type} StaticType: {eventInfo.Source.StaticType} Value: {eventInfo.Source.Value}");
|
// {
|
||||||
eventInfo.Style = SequenceStyle.Flow;
|
// Console.WriteLine($"Type: {eventInfo.Source.Type} StaticType: {eventInfo.Source.StaticType} Value: {eventInfo.Source.Value}");
|
||||||
nextEmitter.Emit(eventInfo, emitter);
|
// eventInfo.Style = SequenceStyle.Flow;
|
||||||
}
|
// nextEmitter.Emit(eventInfo, emitter);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
18
SchemaConverter/SerializeUtil2.cs
Normal file
18
SchemaConverter/SerializeUtil2.cs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// using YamlMap;
|
||||||
|
//
|
||||||
|
// namespace SchemaConverter;
|
||||||
|
//
|
||||||
|
// public static class SerializeUtil2
|
||||||
|
// {
|
||||||
|
// private static readonly YamlWriter _serializer;
|
||||||
|
//
|
||||||
|
// static SerializeUtil2()
|
||||||
|
// {
|
||||||
|
// _serializer = new YamlWriter();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static string Serialize(object o)
|
||||||
|
// {
|
||||||
|
// return _serializer.Write(o);
|
||||||
|
// }
|
||||||
|
// }
|
53
SchemaConverter/SerializeUtil3.cs
Normal file
53
SchemaConverter/SerializeUtil3.cs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
using SharpYaml;
|
||||||
|
using SharpYaml.Events;
|
||||||
|
using SharpYaml.Serialization;
|
||||||
|
using SharpYaml.Serialization.Serializers;
|
||||||
|
|
||||||
|
namespace SchemaConverter;
|
||||||
|
|
||||||
|
public static class SerializeUtil3
|
||||||
|
{
|
||||||
|
private static readonly Serializer _serializer;
|
||||||
|
|
||||||
|
static SerializeUtil3()
|
||||||
|
{
|
||||||
|
var settings = new SerializerSettings
|
||||||
|
{
|
||||||
|
EmitAlias = false,
|
||||||
|
EmitDefaultValues = false,
|
||||||
|
NamingConvention = new CamelCaseNamingConvention(),
|
||||||
|
IgnoreNulls = true,
|
||||||
|
};
|
||||||
|
settings.RegisterSerializer(typeof(Dictionary<int, List<string>>), new CustomDictionarySerializer());
|
||||||
|
settings.RegisterSerializer(typeof(New.FieldType), new CustomFieldTypeSerializer());
|
||||||
|
|
||||||
|
_serializer = new Serializer(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Serialize(object o)
|
||||||
|
{
|
||||||
|
return _serializer.Serialize(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class CustomDictionarySerializer : DictionarySerializer
|
||||||
|
{
|
||||||
|
protected override void WriteDictionaryItem(ref ObjectContext objectContext, KeyValuePair<object, object?> keyValue, KeyValuePair<Type, Type> types)
|
||||||
|
{
|
||||||
|
objectContext.SerializerContext.WriteYaml(keyValue.Key, types.Key);
|
||||||
|
objectContext.SerializerContext.WriteYaml(keyValue.Value, types.Value, YamlStyle.Flow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class CustomFieldTypeSerializer : ScalarSerializerBase
|
||||||
|
{
|
||||||
|
public override object? ConvertFrom(ref ObjectContext context, Scalar fromScalar)
|
||||||
|
{
|
||||||
|
return Enum.Parse<New.FieldType>(new PascalNamingConvention().Convert(fromScalar.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ConvertTo(ref ObjectContext objectContext)
|
||||||
|
{
|
||||||
|
return objectContext.Settings.NamingConvention.Convert(objectContext.Instance.ToString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue