diff --git a/QuestPathGenerator/GatheringSourceGenerator.cs b/QuestPathGenerator/GatheringSourceGenerator.cs index b2177b25f..589aabb24 100644 --- a/QuestPathGenerator/GatheringSourceGenerator.cs +++ b/QuestPathGenerator/GatheringSourceGenerator.cs @@ -44,7 +44,8 @@ public class GatheringSourceGenerator : ISourceGenerator var gatheringSchema = JsonSchema.FromText(jsonSchemaFile.GetText()!.ToString()); List<(ushort, GatheringRoot)> gatheringLocations = []; - foreach (var (id, node) in Utils.GetAdditionalFiles(context, jsonSchemaFile, gatheringSchema, InvalidJson)) + foreach (var (id, node) in Utils.GetAdditionalFiles(context, jsonSchemaFile, gatheringSchema, InvalidJson, + ushort.Parse)) { var gatheringLocation = node.Deserialize()!; gatheringLocations.Add((id, gatheringLocation)); diff --git a/QuestPathGenerator/QuestSourceGenerator.cs b/QuestPathGenerator/QuestSourceGenerator.cs index 8bff39152..3d3d1c054 100644 --- a/QuestPathGenerator/QuestSourceGenerator.cs +++ b/QuestPathGenerator/QuestSourceGenerator.cs @@ -47,8 +47,9 @@ public class QuestSourceGenerator : ISourceGenerator { var questSchema = JsonSchema.FromText(jsonSchemaFile.GetText()!.ToString()); - List<(ushort, QuestRoot)> quests = []; - foreach (var (id, node) in Utils.GetAdditionalFiles(context, jsonSchemaFile, questSchema, InvalidJson)) + List<(ElementId, QuestRoot)> quests = []; + foreach (var (id, node) in Utils.GetAdditionalFiles(context, jsonSchemaFile, questSchema, InvalidJson, + ElementId.FromString)) { var quest = node.Deserialize()!; if (quest.Disabled) @@ -65,8 +66,8 @@ public class QuestSourceGenerator : ISourceGenerator return; var partitionedQuests = quests - .OrderBy(x => x.Item1) - .GroupBy(x => $"LoadQuests{x.Item1 / 50}") + .OrderBy(x => x.Item1.Value) + .GroupBy(x => $"LoadQuests{x.Item1.Value / 50}") .ToList(); var methods = Utils.CreateMethods("LoadQuests", partitionedQuests, CreateInitializer); @@ -123,7 +124,7 @@ public class QuestSourceGenerator : ISourceGenerator context.AddSource("AssemblyQuestLoader.g.cs", code.ToFullString()); } - private static StatementSyntax[] CreateInitializer(List<(ushort QuestId, QuestRoot Root)> quests) + private static StatementSyntax[] CreateInitializer(List<(ElementId QuestId, QuestRoot Root)> quests) { List statements = []; @@ -138,9 +139,7 @@ public class QuestSourceGenerator : ISourceGenerator SeparatedList( new SyntaxNodeOrToken[] { - Argument( - LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal(quest.QuestId))), + Argument(LiteralValue(quest.QuestId)), Token(SyntaxKind.CommaToken), Argument(CreateQuestRootExpression(quest.QuestId, quest.Root)) }))))); @@ -149,7 +148,7 @@ public class QuestSourceGenerator : ISourceGenerator return statements.ToArray(); } - private static ObjectCreationExpressionSyntax CreateQuestRootExpression(ushort questId, QuestRoot quest) + private static ObjectCreationExpressionSyntax CreateQuestRootExpression(ElementId questId, QuestRoot quest) { try { diff --git a/QuestPathGenerator/RoslynShortcuts.cs b/QuestPathGenerator/RoslynShortcuts.cs index 0a8e19e23..027e597ae 100644 --- a/QuestPathGenerator/RoslynShortcuts.cs +++ b/QuestPathGenerator/RoslynShortcuts.cs @@ -74,6 +74,15 @@ public static class RoslynShortcuts SingletonSeparatedList( Argument(LiteralValue(leveId.Value))))); } + else if (value is SatisfactionSupplyNpcId satisfactionSupplyNpcId) + { + return ObjectCreationExpression( + IdentifierName(nameof(SatisfactionSupplyNpcId))) + .WithArgumentList( + ArgumentList( + SingletonSeparatedList( + Argument(LiteralValue(satisfactionSupplyNpcId.Value))))); + } else if (value is Vector3 vector) { return ObjectCreationExpression( diff --git a/QuestPathGenerator/Utils.cs b/QuestPathGenerator/Utils.cs index 5e1baac02..bbae8921e 100644 --- a/QuestPathGenerator/Utils.cs +++ b/QuestPathGenerator/Utils.cs @@ -14,8 +14,8 @@ namespace Questionable.QuestPathGenerator; public static class Utils { - public static IEnumerable<(ushort, JsonNode)> GetAdditionalFiles(GeneratorExecutionContext context, - AdditionalText jsonSchemaFile, JsonSchema jsonSchema, DiagnosticDescriptor invalidJson) + public static IEnumerable<(T, JsonNode)> GetAdditionalFiles(GeneratorExecutionContext context, + AdditionalText jsonSchemaFile, JsonSchema jsonSchema, DiagnosticDescriptor invalidJson, Func idParser) { var commonSchemaFile = context.AdditionalFiles.Single(x => Path.GetFileName(x.Path) == "common-schema.json"); List jsonSchemaFiles = [jsonSchemaFile, commonSchemaFile]; @@ -36,7 +36,7 @@ public static class Utils if (!name.Contains("_")) continue; - ushort id = ushort.Parse(name.Substring(0, name.IndexOf('_'))); + T id = idParser(name.Substring(0, name.IndexOf('_'))); var text = additionalFile.GetText(); if (text == null) @@ -68,9 +68,9 @@ public static class Utils } } - public static List CreateMethods(string prefix, - List> partitions, - Func, StatementSyntax[]> toInitializers) + public static List CreateMethods(string prefix, + List> partitions, + Func, StatementSyntax[]> toInitializers) { List methods = [ diff --git a/QuestPaths/AssemblyQuestLoader.cs b/QuestPaths/AssemblyQuestLoader.cs index 3ef7df15c..c5fbdfb77 100644 --- a/QuestPaths/AssemblyQuestLoader.cs +++ b/QuestPaths/AssemblyQuestLoader.cs @@ -9,9 +9,9 @@ namespace Questionable.QuestPaths; [SuppressMessage("ReSharper", "PartialTypeWithSinglePart", Justification = "Required for RELEASE")] public static partial class AssemblyQuestLoader { - private static Dictionary? _quests; + private static Dictionary? _quests; - public static IReadOnlyDictionary GetQuests() + public static IReadOnlyDictionary GetQuests() { if (_quests == null) { @@ -28,5 +28,5 @@ public static partial class AssemblyQuestLoader typeof(AssemblyQuestLoader).Assembly.GetManifestResourceStream("Questionable.QuestPaths.QuestSchema")!; [SuppressMessage("ReSharper", "UnusedMember.Local")] - private static void AddQuest(ushort questId, QuestRoot root) => _quests![questId] = root; + private static void AddQuest(ElementId questId, QuestRoot root) => _quests![questId] = root; } diff --git a/Questionable/Controller/QuestRegistry.cs b/Questionable/Controller/QuestRegistry.cs index 58b93f3ff..4457b3abf 100644 --- a/Questionable/Controller/QuestRegistry.cs +++ b/Questionable/Controller/QuestRegistry.cs @@ -87,13 +87,13 @@ internal sealed class QuestRegistry { _logger.LogInformation("Loading quests from assembly"); - foreach ((ushort questId, QuestRoot questRoot) in AssemblyQuestLoader.GetQuests()) + foreach ((ElementId questId, QuestRoot questRoot) in AssemblyQuestLoader.GetQuests()) { Quest quest = new() { - Id = new QuestId(questId), + Id = questId, Root = questRoot, - Info = _questData.GetQuestInfo(new QuestId(questId)), + Info = _questData.GetQuestInfo(questId), ReadOnly = true, }; _quests[quest.Id] = quest;