Replicated the weapon flying tick setup using resources
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 26s
Create tag and build when new code gets to main / Export (push) Successful in 5m42s

This commit is contained in:
2026-04-07 16:32:26 +02:00
parent cc7cb90041
commit 1d856fd937
145 changed files with 12943 additions and 109 deletions

View File

@@ -0,0 +1,105 @@
// Copyright © Gamesmiths Guild.
using System;
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;
/// <summary>
/// Resolver resource that binds a node property to a field declared by an <see cref="IActivationDataProvider"/>.
/// </summary>
/// <remarks>
/// At build time the resolver defines a graph variable for the field so that the data binder can write to it, and binds
/// the node input to that variable. At runtime the value is read from the graph's variables after the data binder has
/// populated them.
/// </remarks>
[Tool]
[GlobalClass]
public partial class ActivationDataResolverResource : StatescriptResolverResource
{
/// <inheritdoc/>
public override string ResolverTypeId => "ActivationData";
/// <summary>
/// Gets or sets the class name of the <see cref="IActivationDataProvider"/> implementation that declares the field.
/// </summary>
[Export]
public string ProviderClassName { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the name of the activation data field to bind to.
/// </summary>
[Export]
public string FieldName { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the expected type of the activation data field.
/// </summary>
[Export]
public StatescriptVariableType FieldType { get; set; } = StatescriptVariableType.Int;
/// <inheritdoc/>
public override void BindInput(Graph graph, ForgeNode runtimeNode, string nodeId, byte index)
{
if (string.IsNullOrEmpty(ProviderClassName))
{
GD.PushError(
$"Statescript: Activation Data resolver on node '{nodeId}' (input {index}) " +
"has no provider selected. Select a provider and field in the graph editor.");
return;
}
if (string.IsNullOrEmpty(FieldName))
{
GD.PushError(
$"Statescript: Activation Data resolver on node '{nodeId}' (input {index}) " +
$"has provider '{ProviderClassName}' but no field selected. " +
"Select a field in the graph editor.");
return;
}
Type clrType = StatescriptVariableTypeConverter.ToSystemType(FieldType);
var variableName = new StringKey(FieldName);
// Define the variable so the data binder's SetVar call succeeds at runtime.
// Check if the variable is already defined to avoid duplicates when multiple nodes bind the same field.
var alreadyDefined = false;
foreach (VariableDefinition existing in graph.VariableDefinitions.VariableDefinitions)
{
if (existing.Name == variableName)
{
alreadyDefined = true;
break;
}
}
if (!alreadyDefined)
{
graph.VariableDefinitions.VariableDefinitions.Add(
new VariableDefinition(variableName, default, clrType));
}
runtimeNode.BindInput(index, variableName);
}
/// <inheritdoc/>
public override IPropertyResolver BuildResolver(Graph graph)
{
if (string.IsNullOrEmpty(ProviderClassName) || string.IsNullOrEmpty(FieldName))
{
GD.PushError(
"Statescript: Activation Data resolver has incomplete configuration " +
$"(provider: '{ProviderClassName}', field: '{FieldName}'). " +
"The resolver will return a default value.");
return new VariantResolver(default, typeof(int));
}
Type clrType = StatescriptVariableTypeConverter.ToSystemType(FieldType);
return new VariableResolver(new StringKey(FieldName), clrType);
}
}

View File

@@ -0,0 +1 @@
uid://dcshceitj3lc

View File

@@ -0,0 +1,56 @@
// 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;
/// <summary>
/// Resolver resource that reads a value from a Forge entity attribute at runtime.
/// </summary>
[Tool]
[GlobalClass]
public partial class AttributeResolverResource : StatescriptResolverResource
{
/// <inheritdoc/>
public override string ResolverTypeId => "Attribute";
/// <summary>
/// Gets or sets the attribute set class name.
/// </summary>
[Export]
public string AttributeSetClass { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the attribute name within the attribute set.
/// </summary>
[Export]
public string AttributeName { get; set; } = string.Empty;
/// <inheritdoc/>
public override void BindInput(Graph graph, ForgeNode runtimeNode, string nodeId, byte index)
{
if (string.IsNullOrEmpty(AttributeSetClass) || string.IsNullOrEmpty(AttributeName))
{
return;
}
var attributeKey = new StringKey($"{AttributeSetClass}.{AttributeName}");
var propertyName = new StringKey($"__attr_{nodeId}_{index}");
graph.VariableDefinitions.DefineProperty(propertyName, new AttributeResolver(attributeKey));
runtimeNode.BindInput(index, propertyName);
}
/// <inheritdoc/>
public override IPropertyResolver BuildResolver(Graph graph)
{
var attributeKey = new StringKey($"{AttributeSetClass}.{AttributeName}");
return new AttributeResolver(attributeKey);
}
}

View File

@@ -0,0 +1 @@
uid://cyiritjnyt65r

View File

@@ -0,0 +1,64 @@
// 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;
/// <summary>
/// Resolver resource that compares two nested numeric resolvers and produces a boolean result.
/// </summary>
[Tool]
[GlobalClass]
public partial class ComparisonResolverResource : StatescriptResolverResource
{
/// <inheritdoc/>
public override string ResolverTypeId => "Comparison";
/// <summary>
/// Gets or sets the left-hand operand resolver.
/// </summary>
[Export]
public StatescriptResolverResource? Left { get; set; }
/// <summary>
/// Gets or sets the comparison operation.
/// </summary>
[Export]
public ComparisonOperation Operation { get; set; }
/// <summary>
/// Gets or sets the right-hand operand resolver.
/// </summary>
[Export]
public StatescriptResolverResource? Right { get; set; }
/// <inheritdoc/>
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);
}
/// <inheritdoc/>
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);
}
}

View File

@@ -0,0 +1 @@
uid://c3hb4x0majsfa

View File

@@ -0,0 +1,38 @@
// 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;
/// <summary>
/// Resolver resource that reads the ability activation magnitude from the <see cref="GraphContext.ActivationContext"/>
/// at runtime. Produces a <see langword="float"/> value.
/// </summary>
[Tool]
[GlobalClass]
public partial class MagnitudeResolverResource : StatescriptResolverResource
{
/// <inheritdoc/>
public override string ResolverTypeId => "Magnitude";
/// <inheritdoc/>
public override void BindInput(Graph graph, ForgeNode runtimeNode, string nodeId, byte index)
{
var propertyName = new StringKey($"__mag_{nodeId}_{index}");
graph.VariableDefinitions.DefineProperty(propertyName, new MagnitudeResolver());
runtimeNode.BindInput(index, propertyName);
}
/// <inheritdoc/>
public override IPropertyResolver BuildResolver(Graph graph)
{
return new MagnitudeResolver();
}
}

View File

@@ -0,0 +1 @@
uid://88e4ahqgwac6

View File

@@ -0,0 +1,83 @@
// Copyright © Gamesmiths Guild.
using System;
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;
/// <summary>
/// Resolver resource that binds a node property to an entity's shared variable by name. At runtime the value is read
/// from the <see cref="GraphContext.SharedVariables"/> bag, which is populated from the entity's
/// <see cref="ForgeSharedVariableSet"/>.
/// </summary>
[Tool]
[GlobalClass]
public partial class SharedVariableResolverResource : StatescriptResolverResource
{
/// <inheritdoc/>
public override string ResolverTypeId => "SharedVariable";
/// <summary>
/// Gets or sets the resource path of the <see cref="ForgeSharedVariableSet"/> that defines the variable.
/// </summary>
[Export]
public string SharedVariableSetPath { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the name of the shared variable to bind to.
/// </summary>
[Export]
public string VariableName { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the expected type of the shared variable.
/// </summary>
[Export]
public StatescriptVariableType VariableType { get; set; } = StatescriptVariableType.Int;
/// <inheritdoc/>
public override void BindInput(Graph graph, ForgeNode runtimeNode, string nodeId, byte index)
{
if (string.IsNullOrEmpty(VariableName))
{
return;
}
Type clrType = StatescriptVariableTypeConverter.ToSystemType(VariableType);
var propertyName = new StringKey($"__shared_{nodeId}_{index}");
graph.VariableDefinitions.DefineProperty(
propertyName,
new SharedVariableResolver(new StringKey(VariableName), clrType));
runtimeNode.BindInput(index, propertyName);
}
/// <inheritdoc/>
public override void BindOutput(ForgeNode runtimeNode, byte index)
{
if (string.IsNullOrEmpty(VariableName))
{
return;
}
runtimeNode.BindOutput(index, new StringKey(VariableName), VariableScope.Shared);
}
/// <inheritdoc/>
public override IPropertyResolver BuildResolver(Graph graph)
{
if (string.IsNullOrEmpty(VariableName))
{
return new VariantResolver(default, typeof(int));
}
Type clrType = StatescriptVariableTypeConverter.ToSystemType(VariableType);
return new SharedVariableResolver(new StringKey(VariableName), clrType);
}
}

View File

@@ -0,0 +1 @@
uid://v0ukqap4vj40

View File

@@ -0,0 +1,56 @@
// Copyright © Gamesmiths Guild.
using Gamesmiths.Forge.Core;
using Gamesmiths.Forge.Godot.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;
/// <summary>
/// Resolver resource that checks whether the owner entity has a given tag, resolving to a boolean value at runtime.
/// </summary>
[Tool]
[GlobalClass]
public partial class TagResolverResource : StatescriptResolverResource
{
/// <inheritdoc/>
public override string ResolverTypeId => "Tag";
/// <summary>
/// Gets or sets the tag string to check for (e.g., "Status.Burning").
/// </summary>
[Export]
public string Tag { get; set; } = string.Empty;
/// <inheritdoc/>
public override void BindInput(Graph graph, ForgeNode runtimeNode, string nodeId, byte index)
{
if (string.IsNullOrEmpty(Tag))
{
return;
}
var tag = Tags.Tag.RequestTag(ForgeManagers.Instance.TagsManager, Tag);
var propertyName = new StringKey($"__tag_{nodeId}_{index}");
graph.VariableDefinitions.DefineProperty(propertyName, new TagResolver(tag));
runtimeNode.BindInput(index, propertyName);
}
/// <inheritdoc/>
public override IPropertyResolver BuildResolver(Graph graph)
{
if (string.IsNullOrEmpty(Tag))
{
return new VariantResolver(new Variant128(false), typeof(bool));
}
var tag = Tags.Tag.RequestTag(ForgeManagers.Instance.TagsManager, Tag);
return new TagResolver(tag);
}
}

View File

@@ -0,0 +1 @@
uid://bmkcmsbydtode

View File

@@ -0,0 +1,85 @@
// Copyright © Gamesmiths Guild.
using System;
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;
/// <summary>
/// Resolver resource that binds a node property to a graph variable by name.
/// </summary>
[Tool]
[GlobalClass]
public partial class VariableResolverResource : StatescriptResolverResource
{
/// <inheritdoc/>
public override string ResolverTypeId => "Variable";
/// <summary>
/// Gets or sets the name of the graph variable to bind to.
/// </summary>
[Export]
public string VariableName { get; set; } = string.Empty;
/// <inheritdoc/>
public override void BindInput(Graph graph, ForgeNode runtimeNode, string nodeId, byte index)
{
if (string.IsNullOrEmpty(VariableName))
{
return;
}
runtimeNode.BindInput(index, new StringKey(VariableName));
}
/// <inheritdoc/>
public override void BindOutput(ForgeNode runtimeNode, byte index)
{
if (string.IsNullOrEmpty(VariableName))
{
return;
}
runtimeNode.BindOutput(index, new StringKey(VariableName));
}
/// <inheritdoc/>
public override IPropertyResolver BuildResolver(Graph graph)
{
if (string.IsNullOrEmpty(VariableName))
{
return new VariantResolver(default, typeof(int));
}
Type? variableType = FindGraphVariableType(graph, VariableName);
return new VariableResolver(new StringKey(VariableName), variableType ?? typeof(int));
}
private static Type? FindGraphVariableType(Graph graph, string variableName)
{
var key = new StringKey(variableName);
foreach (VariableDefinition def in graph.VariableDefinitions.VariableDefinitions)
{
if (def.Name == key)
{
return def.ValueType;
}
}
foreach (ArrayVariableDefinition definition in graph.VariableDefinitions.ArrayVariableDefinitions)
{
if (definition.Name == key)
{
return definition.ElementType;
}
}
return null;
}
}

View File

@@ -0,0 +1 @@
uid://bso385kpryjl

View File

@@ -0,0 +1,91 @@
// Copyright © Gamesmiths Guild.
using System;
using Gamesmiths.Forge.Core;
using Gamesmiths.Forge.Statescript;
using Gamesmiths.Forge.Statescript.Properties;
using Godot;
using Godot.Collections;
using ForgeNode = Gamesmiths.Forge.Statescript.Node;
namespace Gamesmiths.Forge.Godot.Resources.Statescript.Resolvers;
/// <summary>
/// Resolver resource that holds a constant (inline) value for a node property.
/// </summary>
[Tool]
[GlobalClass]
public partial class VariantResolverResource : StatescriptResolverResource
{
/// <inheritdoc/>
public override string ResolverTypeId => "Variant";
/// <summary>
/// Gets or sets the constant value. Used when <see cref="IsArray"/> is <see langword="false"/>.
/// </summary>
[Export]
public Variant Value { get; set; }
/// <summary>
/// Gets or sets the type interpretation for the value.
/// </summary>
[Export]
public StatescriptVariableType ValueType { get; set; } = StatescriptVariableType.Int;
/// <summary>
/// Gets or sets a value indicating whether this resolver holds an array of values.
/// </summary>
[Export]
public bool IsArray { get; set; }
/// <summary>
/// Gets or sets the array values. Used when <see cref="IsArray"/> is <see langword="true"/>.
/// </summary>
[Export]
public Array<Variant> ArrayValues { get; set; } = [];
/// <summary>
/// Gets or sets a value indicating whether the array section is expanded in the editor.
/// </summary>
[Export]
public bool IsArrayExpanded { get; set; }
/// <inheritdoc/>
public override void BindInput(Graph graph, ForgeNode runtimeNode, string nodeId, byte index)
{
var propertyName = new StringKey($"__const_{nodeId}_{index}");
if (IsArray)
{
var values = new Variant128[ArrayValues.Count];
for (var i = 0; i < ArrayValues.Count; i++)
{
values[i] = StatescriptVariableTypeConverter.GodotVariantToForge(ArrayValues[i], ValueType);
}
Type clrType = StatescriptVariableTypeConverter.ToSystemType(ValueType);
graph.VariableDefinitions.ArrayVariableDefinitions.Add(
new ArrayVariableDefinition(propertyName, values, clrType));
}
else
{
Variant128 value = StatescriptVariableTypeConverter.GodotVariantToForge(Value, ValueType);
Type clrType = StatescriptVariableTypeConverter.ToSystemType(ValueType);
graph.VariableDefinitions.PropertyDefinitions.Add(
new PropertyDefinition(propertyName, new VariantResolver(value, clrType)));
}
runtimeNode.BindInput(index, propertyName);
}
/// <inheritdoc/>
public override IPropertyResolver BuildResolver(Graph graph)
{
Variant128 value = StatescriptVariableTypeConverter.GodotVariantToForge(Value, ValueType);
Type clrType = StatescriptVariableTypeConverter.ToSystemType(ValueType);
return new VariantResolver(value, clrType);
}
}

View File

@@ -0,0 +1 @@
uid://db2rt0n3jtytf