CodeGen update

This commit is contained in:
Liza 2025-01-22 18:37:15 +01:00
parent b3d9ce382d
commit 2cf059ec38
Signed by: liza
GPG Key ID: 2C41B84815CF6445
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,29 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Questionable.Model.Questing;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
using static Questionable.QuestPathGenerator.RoslynShortcuts;
namespace Questionable.QuestPathGenerator.RoslynElements;
internal static class CombatItemUseExtensions
{
public static ExpressionSyntax ToExpressionSyntax(this CombatItemUse combatItemuse)
{
var emptyItemuse = new CombatItemUse();
return ObjectCreationExpression(
IdentifierName(nameof(CombatItemUse)))
.WithInitializer(
InitializerExpression(
SyntaxKind.ObjectInitializerExpression,
SeparatedList<ExpressionSyntax>(
SyntaxNodeList(
Assignment(nameof(CombatItemUse.ItemId), combatItemuse.ItemId,
emptyItemuse.ItemId)
.AsSyntaxNodeOrToken(),
Assignment(nameof(CombatItemUse.Condition), combatItemuse.Condition, emptyItemuse.Condition)
.AsSyntaxNodeOrToken(),
Assignment(nameof(combatItemuse.Value), combatItemuse.Value, emptyItemuse.Value)
.AsSyntaxNodeOrToken()))));
}
}

View File

@ -107,6 +107,9 @@ internal static class QuestStepExtensions
.AsSyntaxNodeOrToken(), .AsSyntaxNodeOrToken(),
AssignmentList(nameof(QuestStep.ComplexCombatData), step.ComplexCombatData) AssignmentList(nameof(QuestStep.ComplexCombatData), step.ComplexCombatData)
.AsSyntaxNodeOrToken(), .AsSyntaxNodeOrToken(),
Assignment(nameof(QuestStep.CombatItemUse), step.CombatItemUse,
emptyStep.CombatItemUse)
.AsSyntaxNodeOrToken(),
Assignment(nameof(QuestStep.CombatDelaySecondsAtStart), Assignment(nameof(QuestStep.CombatDelaySecondsAtStart),
step.CombatDelaySecondsAtStart, step.CombatDelaySecondsAtStart,
emptyStep.CombatDelaySecondsAtStart) emptyStep.CombatDelaySecondsAtStart)

View File

@ -71,6 +71,7 @@ public static class RoslynShortcuts
GatheringNodeGroup nodeGroup => nodeGroup.ToExpressionSyntax(), GatheringNodeGroup nodeGroup => nodeGroup.ToExpressionSyntax(),
GatheringNode nodeLocation => nodeLocation.ToExpressionSyntax(), GatheringNode nodeLocation => nodeLocation.ToExpressionSyntax(),
GatheringLocation location => location.ToExpressionSyntax(), GatheringLocation location => location.ToExpressionSyntax(),
CombatItemUse combatItemUse => combatItemUse.ToExpressionSyntax(),
not null when value.GetType().IsEnum => MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, not null when value.GetType().IsEnum => MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
IdentifierName(value.GetType().Name), IdentifierName(value.GetType().GetEnumName(value)!)), IdentifierName(value.GetType().Name), IdentifierName(value.GetType().GetEnumName(value)!)),
_ => throw new Exception($"Unsupported data type {value.GetType()} = {value}") _ => throw new Exception($"Unsupported data type {value.GetType()} = {value}")