Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6b2980285 |
4 changed files with 134 additions and 1 deletions
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Questionable.Model.Questing.Converter;
|
||||
|
||||
public sealed class ElementIdConverter : JsonConverter<ElementId>
|
||||
{
|
||||
public override ElementId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
return new QuestId(reader.GetUInt16());
|
||||
else
|
||||
return ElementId.FromString(reader.GetString() ?? throw new JsonException());
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, ElementId value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Questionable.Model.Questing.Converter;
|
||||
|
||||
public sealed class ElementIdListConverter : JsonConverter<List<ElementId>>
|
||||
{
|
||||
public override List<ElementId> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartArray)
|
||||
throw new JsonException();
|
||||
|
||||
reader.Read();
|
||||
|
||||
List<ElementId> values = [];
|
||||
while (reader.TokenType != JsonTokenType.EndArray)
|
||||
{
|
||||
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
values.Add(new QuestId(reader.GetUInt16()));
|
||||
else
|
||||
values.Add(ElementId.FromString(reader.GetString() ?? throw new JsonException()));
|
||||
|
||||
reader.Read();
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, List<ElementId> value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
foreach (ElementId elementId in value)
|
||||
{
|
||||
writer.WriteStringValue(elementId.ToString());
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Questionable.Model.Questing.Converter;
|
||||
|
||||
public sealed class QuestWorkConfigConverter : JsonConverter<QuestWorkValue>
|
||||
{
|
||||
public override QuestWorkValue Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
return new QuestWorkValue(reader.GetByte());
|
||||
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
throw new JsonException();
|
||||
|
||||
byte? high = null, low = null;
|
||||
EQuestWorkMode mode = EQuestWorkMode.Bitwise;
|
||||
while (reader.Read())
|
||||
{
|
||||
switch (reader.TokenType)
|
||||
{
|
||||
case JsonTokenType.PropertyName:
|
||||
string? propertyName = reader.GetString();
|
||||
if (propertyName == null || !reader.Read())
|
||||
throw new JsonException();
|
||||
|
||||
switch (propertyName)
|
||||
{
|
||||
case nameof(QuestWorkValue.High):
|
||||
high = reader.GetByte();
|
||||
break;
|
||||
|
||||
case nameof(QuestWorkValue.Low):
|
||||
low = reader.GetByte();
|
||||
break;
|
||||
|
||||
case nameof(QuestWorkValue.Mode):
|
||||
mode = new QuestWorkModeConverter().Read(ref reader, typeof(EQuestWorkMode), options);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new JsonException();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case JsonTokenType.EndObject:
|
||||
return new QuestWorkValue(high, low, mode);
|
||||
|
||||
default:
|
||||
throw new JsonException();
|
||||
}
|
||||
}
|
||||
|
||||
throw new JsonException();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, QuestWorkValue value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Dalamud.Extensions.MicrosoftLogging;
|
||||
using Dalamud.Game;
|
||||
using Dalamud.Game.ClientState.Objects;
|
||||
|
|
@ -23,6 +27,7 @@ using Questionable.Controller.Utils;
|
|||
using Questionable.Data;
|
||||
using Questionable.External;
|
||||
using Questionable.Functions;
|
||||
using Questionable.QuestPaths;
|
||||
using Questionable.Validation;
|
||||
using Questionable.Validation.Validators;
|
||||
using Questionable.Windows;
|
||||
|
|
@ -38,7 +43,10 @@ public sealed class QuestionablePlugin : IDalamudPlugin, IDisposable
|
|||
private readonly ServiceProvider? _serviceProvider;
|
||||
|
||||
public QuestionablePlugin(IDalamudPluginInterface pluginInterface, IClientState clientState, ITargetManager targetManager, IFramework framework, IGameGui gameGui, IDataManager dataManager, ISigScanner sigScanner, IObjectTable objectTable, IPluginLog pluginLog, ICondition condition, IChatGui chatGui, ICommandManager commandManager, IAddonLifecycle addonLifecycle, IKeyState keyState, IContextMenu contextMenu, IToastGui toastGui, IGameInteropProvider gameInteropProvider, IAetheryteList aetheryteList)
|
||||
{
|
||||
{
|
||||
File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Quests.json"), JsonSerializer.Serialize(AssemblyQuestLoader.GetQuests().Select(pair => (pair.Key.GetType().Name + ": " + pair.Key.ToString(), pair.Value)).ToList(), new JsonSerializerOptions()
|
||||
{ WriteIndented = true, IgnoreReadOnlyProperties = true, IncludeFields = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault, }));
|
||||
|
||||
ArgumentNullException.ThrowIfNull(pluginInterface, "pluginInterface");
|
||||
ArgumentNullException.ThrowIfNull(chatGui, "chatGui");
|
||||
try
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue