// Copyright © Gamesmiths Guild. using Gamesmiths.Forge.Core; using Gamesmiths.Forge.Statescript; using Gamesmiths.Forge.Statescript.Properties; using Godot; using ForgeNode = Gamesmiths.Forge.Statescript.Node; namespace Gamesmiths.Forge.Godot.Resources.Statescript.Resolvers; /// /// Resolver resource that compares two nested numeric resolvers and produces a boolean result. /// [Tool] [GlobalClass] public partial class ComparisonResolverResource : StatescriptResolverResource { /// public override string ResolverTypeId => "Comparison"; /// /// Gets or sets the left-hand operand resolver. /// [Export] public StatescriptResolverResource? Left { get; set; } /// /// Gets or sets the comparison operation. /// [Export] public ComparisonOperation Operation { get; set; } /// /// Gets or sets the right-hand operand resolver. /// [Export] public StatescriptResolverResource? Right { get; set; } /// public override void BindInput(Graph graph, ForgeNode runtimeNode, string nodeId, byte index) { IPropertyResolver comparisonResolver = BuildResolver(graph); var propertyName = new StringKey($"__cmp_{nodeId}_{index}"); graph.VariableDefinitions.DefineProperty(propertyName, comparisonResolver); runtimeNode.BindInput(index, propertyName); } /// public override IPropertyResolver BuildResolver(Graph graph) { IPropertyResolver leftResolver = Left?.BuildResolver(graph) ?? new VariantResolver(default, typeof(int)); IPropertyResolver rightResolver = Right?.BuildResolver(graph) ?? new VariantResolver(default, typeof(int)); var operation = (ComparisonOperation)(byte)Operation; return new ComparisonResolver(leftResolver, operation, rightResolver); } }