forked from liza/Questionable
master #3
29
QuestPathGenerator/RoslynElements/CombatItemUseExtensions.cs
Normal file
29
QuestPathGenerator/RoslynElements/CombatItemUseExtensions.cs
Normal 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()))));
|
||||
}
|
||||
}
|
@ -107,6 +107,9 @@ internal static class QuestStepExtensions
|
||||
.AsSyntaxNodeOrToken(),
|
||||
AssignmentList(nameof(QuestStep.ComplexCombatData), step.ComplexCombatData)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.CombatItemUse), step.CombatItemUse,
|
||||
emptyStep.CombatItemUse)
|
||||
.AsSyntaxNodeOrToken(),
|
||||
Assignment(nameof(QuestStep.CombatDelaySecondsAtStart),
|
||||
step.CombatDelaySecondsAtStart,
|
||||
emptyStep.CombatDelaySecondsAtStart)
|
||||
|
@ -71,6 +71,7 @@ public static class RoslynShortcuts
|
||||
GatheringNodeGroup nodeGroup => nodeGroup.ToExpressionSyntax(),
|
||||
GatheringNode nodeLocation => nodeLocation.ToExpressionSyntax(),
|
||||
GatheringLocation location => location.ToExpressionSyntax(),
|
||||
CombatItemUse combatItemUse => combatItemUse.ToExpressionSyntax(),
|
||||
not null when value.GetType().IsEnum => MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(value.GetType().Name), IdentifierName(value.GetType().GetEnumName(value)!)),
|
||||
_ => throw new Exception($"Unsupported data type {value.GetType()} = {value}")
|
||||
|
Loading…
Reference in New Issue
Block a user