Update source gen
This commit is contained in:
parent
26e881abc3
commit
527fa3440e
26
QuestPathGenerator.Tests/QuestGeneratorTest.cs
Normal file
26
QuestPathGenerator.Tests/QuestGeneratorTest.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Questionable.Model.V1;
|
||||
using Questionable.QuestPathGenerator;
|
||||
using Xunit;
|
||||
|
||||
namespace QuestPathGenerator.Tests;
|
||||
|
||||
public sealed class QuestGeneratorTest
|
||||
{
|
||||
[Fact]
|
||||
public void SyntaxNodeListWithNullValues()
|
||||
{
|
||||
var complexCombatData = new ComplexCombatData
|
||||
{
|
||||
DataId = 47,
|
||||
IgnoreQuestMarker = true,
|
||||
MinimumKillCount = 1,
|
||||
};
|
||||
|
||||
var list =
|
||||
RoslynShortcuts.SyntaxNodeList(
|
||||
RoslynShortcuts.AssignmentList(nameof(ComplexCombatData.CompletionQuestVariablesFlags),
|
||||
complexCombatData.CompletionQuestVariablesFlags)).ToList();
|
||||
|
||||
Assert.Empty(list);
|
||||
}
|
||||
}
|
22
QuestPathGenerator.Tests/QuestPathGenerator.Tests.csproj
Normal file
22
QuestPathGenerator.Tests/QuestPathGenerator.Tests.csproj
Normal file
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>12</LangVersion>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
|
||||
<PackageReference Include="xunit" Version="2.5.3"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\QuestPathGenerator\QuestPathGenerator.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -207,6 +207,8 @@ public class QuestSourceGenerator : ISourceGenerator
|
||||
}
|
||||
|
||||
private static IEnumerable<SyntaxNodeOrToken> CreateQuestInitializer(ushort questId, QuestRoot quest)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new SyntaxNodeOrToken[]
|
||||
{
|
||||
@ -241,6 +243,11 @@ public class QuestSourceGenerator : ISourceGenerator
|
||||
Token(SyntaxKind.CommaToken)
|
||||
};
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"QuestGen[{questId}]: {e.Message}", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static ExpressionSyntax CreateQuestSequence(List<QuestSequence> sequences)
|
||||
{
|
||||
@ -321,13 +328,15 @@ public class QuestSourceGenerator : ISourceGenerator
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.Sprint), step.Sprint, emptyStep.Sprint)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.IgnoreDistanceToObject), step.IgnoreDistanceToObject, emptyStep.IgnoreDistanceToObject)
|
||||
Assignment(nameof(QuestStep.IgnoreDistanceToObject),
|
||||
step.IgnoreDistanceToObject, emptyStep.IgnoreDistanceToObject)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.Comment), step.Comment, emptyStep.Comment)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.Aetheryte), step.Aetheryte, emptyStep.Aetheryte)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.AethernetShard), step.AethernetShard, emptyStep.AethernetShard)
|
||||
Assignment(nameof(QuestStep.AethernetShard), step.AethernetShard,
|
||||
emptyStep.AethernetShard)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.AetheryteShortcut), step.AetheryteShortcut,
|
||||
emptyStep.AetheryteShortcut)
|
||||
@ -357,7 +366,8 @@ public class QuestSourceGenerator : ISourceGenerator
|
||||
.AsSyntaxNodeOrToken(),
|
||||
AssignmentList(nameof(QuestStep.ComplexCombatData), step.ComplexCombatData)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.CombatDelaySecondsAtStart), step.CombatDelaySecondsAtStart,
|
||||
Assignment(nameof(QuestStep.CombatDelaySecondsAtStart),
|
||||
step.CombatDelaySecondsAtStart,
|
||||
emptyStep.CombatDelaySecondsAtStart)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.JumpDestination), step.JumpDestination,
|
||||
@ -378,11 +388,14 @@ public class QuestSourceGenerator : ISourceGenerator
|
||||
.AsSyntaxNodeOrToken(),
|
||||
AssignmentList(nameof(QuestStep.PointMenuChoices), step.PointMenuChoices)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.PickUpQuestId), step.PickUpQuestId, emptyStep.PickUpQuestId)
|
||||
Assignment(nameof(QuestStep.PickUpQuestId), step.PickUpQuestId,
|
||||
emptyStep.PickUpQuestId)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.TurnInQuestId), step.TurnInQuestId, emptyStep.TurnInQuestId)
|
||||
Assignment(nameof(QuestStep.TurnInQuestId), step.TurnInQuestId,
|
||||
emptyStep.TurnInQuestId)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.NextQuestId), step.NextQuestId, emptyStep.NextQuestId)
|
||||
Assignment(nameof(QuestStep.NextQuestId), step.NextQuestId,
|
||||
emptyStep.NextQuestId)
|
||||
.AsSyntaxNodeOrToken()))))),
|
||||
Token(SyntaxKind.CommaToken),
|
||||
}.ToArray())));
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Microsoft.CodeAnalysis;
|
||||
@ -14,7 +15,7 @@ public static class RoslynShortcuts
|
||||
{
|
||||
public static IEnumerable<SyntaxNodeOrToken> SyntaxNodeList(params SyntaxNodeOrToken?[] nodes)
|
||||
{
|
||||
nodes = nodes.Where(x => x != null).ToArray();
|
||||
nodes = nodes.Where(x => x != null && x.Value.RawKind != 0).ToArray();
|
||||
if (nodes.Length == 0)
|
||||
return [];
|
||||
|
||||
@ -30,6 +31,8 @@ public static class RoslynShortcuts
|
||||
}
|
||||
|
||||
public static ExpressionSyntax LiteralValue<T>(T? value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (value is string s)
|
||||
return LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(s));
|
||||
@ -77,7 +80,8 @@ public static class RoslynShortcuts
|
||||
SyntaxKind.ObjectInitializerExpression,
|
||||
SeparatedList<ExpressionSyntax>(
|
||||
SyntaxNodeList(
|
||||
Assignment<EAetheryteLocation?>(nameof(AethernetShortcut.From), aethernetShortcut.From,
|
||||
Assignment<EAetheryteLocation?>(nameof(AethernetShortcut.From),
|
||||
aethernetShortcut.From,
|
||||
null)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment<EAetheryteLocation?>(nameof(AethernetShortcut.To), aethernetShortcut.To,
|
||||
@ -111,7 +115,8 @@ public static class RoslynShortcuts
|
||||
SyntaxKind.ObjectInitializerExpression,
|
||||
SeparatedList<ExpressionSyntax>(
|
||||
SyntaxNodeList(
|
||||
Assignment<EDialogChoiceType?>(nameof(DialogueChoice.Type), dialogueChoice.Type, null)
|
||||
Assignment<EDialogChoiceType?>(nameof(DialogueChoice.Type), dialogueChoice.Type,
|
||||
null)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(DialogueChoice.ExcelSheet), dialogueChoice.ExcelSheet,
|
||||
emptyChoice.ExcelSheet)
|
||||
@ -134,7 +139,8 @@ public static class RoslynShortcuts
|
||||
SyntaxKind.ObjectInitializerExpression,
|
||||
SeparatedList<ExpressionSyntax>(
|
||||
SyntaxNodeList(
|
||||
Assignment<Vector3?>(nameof(JumpDestination.Position), jumpDestination.Position, null)
|
||||
Assignment<Vector3?>(nameof(JumpDestination.Position), jumpDestination.Position,
|
||||
null)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(JumpDestination.StopDistance), jumpDestination.StopDistance, null)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
@ -174,7 +180,8 @@ public static class RoslynShortcuts
|
||||
SyntaxKind.ObjectInitializerExpression,
|
||||
SeparatedList<ExpressionSyntax>(
|
||||
SyntaxNodeList(
|
||||
Assignment(nameof(ComplexCombatData.DataId), complexCombatData.DataId, emptyData.DataId)
|
||||
Assignment(nameof(ComplexCombatData.DataId), complexCombatData.DataId,
|
||||
emptyData.DataId)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(ComplexCombatData.MinimumKillCount),
|
||||
complexCombatData.MinimumKillCount, emptyData.MinimumKillCount)
|
||||
@ -182,7 +189,8 @@ public static class RoslynShortcuts
|
||||
Assignment(nameof(ComplexCombatData.RewardItemId), complexCombatData.RewardItemId,
|
||||
emptyData.RewardItemId)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(ComplexCombatData.RewardItemCount), complexCombatData.RewardItemCount,
|
||||
Assignment(nameof(ComplexCombatData.RewardItemCount),
|
||||
complexCombatData.RewardItemCount,
|
||||
emptyData.RewardItemCount)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
AssignmentList(nameof(ComplexCombatData.CompletionQuestVariablesFlags),
|
||||
@ -215,11 +223,18 @@ public static class RoslynShortcuts
|
||||
}
|
||||
else if (value is null)
|
||||
return LiteralExpression(SyntaxKind.NullLiteralExpression);
|
||||
else
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Unable to handle literal [{value}]: {e.StackTrace}", e);
|
||||
}
|
||||
|
||||
throw new Exception($"Unsupported data type {value.GetType()} = {value}");
|
||||
}
|
||||
|
||||
public static AssignmentExpressionSyntax? Assignment<T>(string name, T? value, T? defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (value == null && defaultValue == null)
|
||||
return null;
|
||||
@ -232,9 +247,19 @@ public static class RoslynShortcuts
|
||||
IdentifierName(name),
|
||||
LiteralValue(value));
|
||||
}
|
||||
|
||||
public static AssignmentExpressionSyntax? AssignmentList<T>(string name, IEnumerable<T> value)
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Unable to handle assignment [{name}]: {e.Message}", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static AssignmentExpressionSyntax? AssignmentList<T>(string name, IEnumerable<T>? value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
IEnumerable<T> list = value.ToList();
|
||||
if (!list.Any())
|
||||
return null;
|
||||
@ -248,6 +273,11 @@ public static class RoslynShortcuts
|
||||
LiteralValue(x)).AsSyntaxNodeOrToken()).ToArray())
|
||||
)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Unable to handle list [{name}]: {e.StackTrace}", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static SyntaxNodeOrToken? AsSyntaxNodeOrToken(this SyntaxNode? node)
|
||||
{
|
||||
|
@ -9,8 +9,8 @@
|
||||
},
|
||||
"System.Text.Json": {
|
||||
"type": "Transitive",
|
||||
"resolved": "8.0.3",
|
||||
"contentHash": "hpagS9joOwv6efWfrMmV9MjQXpiXZH72PgN067Ysfr6AWMSD1/1hEcvh/U5mUpPLezEWsOJSuVrmqDIVD958iA==",
|
||||
"resolved": "8.0.4",
|
||||
"contentHash": "bAkhgDJ88XTsqczoxEMliSrpijKZHhbJQldhAmObj/RbrN3sU5dcokuXmWJWsdQAhiMJ9bTayWsL1C9fbbCRhw==",
|
||||
"dependencies": {
|
||||
"System.Text.Encodings.Web": "8.0.0"
|
||||
}
|
||||
@ -18,7 +18,7 @@
|
||||
"questionable.model": {
|
||||
"type": "Project",
|
||||
"dependencies": {
|
||||
"System.Text.Json": "[8.0.3, )"
|
||||
"System.Text.Json": "[8.0.4, )"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,5 @@ public sealed class ComplexCombatData
|
||||
public uint? RewardItemId { get; set; }
|
||||
public int? RewardItemCount { get; set; }
|
||||
public IList<short?> CompletionQuestVariablesFlags { get; set; } = new List<short?>();
|
||||
public bool IgnoreQuestMarker { get; }
|
||||
public bool IgnoreQuestMarker { get; set; }
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuestPaths", "QuestPathGene
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Questionable.Model", "Questionable.Model\Questionable.Model.csproj", "{E15144A5-AFF5-4D86-9561-AFF7DF7F505D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuestPathGenerator.Tests", "QuestPathGenerator.Tests\QuestPathGenerator.Tests.csproj", "{4FD6F346-8961-4BD5-BDA2-E5F426DE4FC7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -36,5 +38,9 @@ Global
|
||||
{E15144A5-AFF5-4D86-9561-AFF7DF7F505D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E15144A5-AFF5-4D86-9561-AFF7DF7F505D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E15144A5-AFF5-4D86-9561-AFF7DF7F505D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4FD6F346-8961-4BD5-BDA2-E5F426DE4FC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4FD6F346-8961-4BD5-BDA2-E5F426DE4FC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4FD6F346-8961-4BD5-BDA2-E5F426DE4FC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4FD6F346-8961-4BD5-BDA2-E5F426DE4FC7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
Loading…
Reference in New Issue
Block a user