updating state chart addon
This commit is contained in:
@@ -11,7 +11,7 @@ namespace GodotStateCharts
|
||||
/// <summary>
|
||||
/// The wrapped node.
|
||||
/// </summary>
|
||||
protected readonly Node Wrapped;
|
||||
public readonly Node Wrapped;
|
||||
|
||||
protected NodeWrapper(Node wrapped)
|
||||
{
|
||||
|
||||
39
addons/godot_state_charts/csharp/ResourceWrapper.cs
Normal file
39
addons/godot_state_charts/csharp/ResourceWrapper.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace GodotStateCharts
|
||||
{
|
||||
using Godot;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all wrapper classes for Godot Resource types. Provides common functionality. Not to be used directly.
|
||||
/// </summary>
|
||||
public abstract class ResourceWrapper
|
||||
{
|
||||
/// <summary>
|
||||
/// The wrapped resource. Useful for you need to access the underlying resource directly,
|
||||
/// e.g. for serialization.
|
||||
/// </summary>
|
||||
public readonly Resource Wrapped;
|
||||
|
||||
protected ResourceWrapper(Resource wrapped)
|
||||
{
|
||||
Wrapped = wrapped;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows to call methods on the wrapped resource deferred.
|
||||
/// </summary>
|
||||
public Variant CallDeferred(string method, params Variant[] args)
|
||||
{
|
||||
return Wrapped.CallDeferred(method, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows to call methods on the wrapped resource.
|
||||
/// </summary>
|
||||
public Variant Call(string method, params Variant[] args)
|
||||
{
|
||||
return Wrapped.Call(method, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
addons/godot_state_charts/csharp/ResourceWrapper.cs.uid
Normal file
1
addons/godot_state_charts/csharp/ResourceWrapper.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://j8ro24kpswjd
|
||||
89
addons/godot_state_charts/csharp/SerializedStateChart.cs
Normal file
89
addons/godot_state_charts/csharp/SerializedStateChart.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace GodotStateCharts
|
||||
{
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
/// <summary>
|
||||
/// C# wrapper for the SerializedStateChart Godot resource.
|
||||
/// </summary>
|
||||
public class SerializedStateChart : ResourceWrapper
|
||||
{
|
||||
private SerializedStateChart(Resource wrapped) : base(wrapped) { }
|
||||
|
||||
public static SerializedStateChart Of(Resource resource)
|
||||
{
|
||||
if (resource.GetScript().As<Script>() is not GDScript gdScript
|
||||
|| !gdScript.ResourcePath.EndsWith("serialized_state_chart.gd"))
|
||||
{
|
||||
throw new ArgumentException("Given resource is not a SerializedStateChart.");
|
||||
}
|
||||
return new SerializedStateChart(resource);
|
||||
}
|
||||
|
||||
public int Version
|
||||
{
|
||||
get => Wrapped.Get("version").AsInt32();
|
||||
set => Wrapped.Set("version", value);
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => Wrapped.Get("name").AsString();
|
||||
set => Wrapped.Set("name", value);
|
||||
}
|
||||
|
||||
public Godot.Collections.Dictionary ExpressionProperties
|
||||
{
|
||||
get => Wrapped.Get("expression_properties").AsGodotDictionary();
|
||||
set => Wrapped.Set("expression_properties", value);
|
||||
}
|
||||
|
||||
public Godot.Collections.Array QueuedEvents
|
||||
{
|
||||
get => Wrapped.Get("queued_events").AsGodotArray();
|
||||
set => Wrapped.Set("queued_events", value);
|
||||
}
|
||||
|
||||
public bool PropertyChangePending
|
||||
{
|
||||
get => Wrapped.Get("property_change_pending").AsBool();
|
||||
set => Wrapped.Set("property_change_pending", value);
|
||||
}
|
||||
|
||||
public bool StateChangePending
|
||||
{
|
||||
get => Wrapped.Get("state_change_pending").AsBool();
|
||||
set => Wrapped.Set("state_change_pending", value);
|
||||
}
|
||||
|
||||
public bool LockedDown
|
||||
{
|
||||
get => Wrapped.Get("locked_down").AsBool();
|
||||
set => Wrapped.Set("locked_down", value);
|
||||
}
|
||||
|
||||
public Godot.Collections.Array QueuedTransitions
|
||||
{
|
||||
get => Wrapped.Get("queued_transitions").AsGodotArray();
|
||||
set => Wrapped.Set("queued_transitions", value);
|
||||
}
|
||||
|
||||
public bool TransitionsProcessingActive
|
||||
{
|
||||
get => Wrapped.Get("transitions_processing_active").AsBool();
|
||||
set => Wrapped.Set("transitions_processing_active", value);
|
||||
}
|
||||
|
||||
public SerializedStateChartState State
|
||||
{
|
||||
get
|
||||
{
|
||||
var stateRes = Wrapped.Get("state").As<Resource>();
|
||||
return stateRes != null ? SerializedStateChartState.Of(stateRes) : null;
|
||||
}
|
||||
set => Wrapped.Set("state", value?.Wrapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://vsn1msuytiho
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
|
||||
namespace GodotStateCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// C# wrapper for the SerializedStateChartState Godot resource.
|
||||
/// </summary>
|
||||
public class SerializedStateChartState : ResourceWrapper
|
||||
{
|
||||
private SerializedStateChartState(Resource wrapped) : base(wrapped)
|
||||
{
|
||||
}
|
||||
|
||||
public static SerializedStateChartState Of(Resource resource)
|
||||
{
|
||||
if (resource.GetScript().As<Script>() is not GDScript gdScript
|
||||
|| !gdScript.ResourcePath.EndsWith("serialized_state_chart_state.gd"))
|
||||
{
|
||||
throw new ArgumentException("Given resource is not a SerializedStateChartState.");
|
||||
}
|
||||
|
||||
return new SerializedStateChartState(resource);
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => Wrapped.Get("name").AsString();
|
||||
set => Wrapped.Set("name", value);
|
||||
}
|
||||
|
||||
public int StateType
|
||||
{
|
||||
get => Wrapped.Get("state_type").AsInt32();
|
||||
set => Wrapped.Set("state_type", value);
|
||||
}
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => Wrapped.Get("active").AsBool();
|
||||
set => Wrapped.Set("active", value);
|
||||
}
|
||||
|
||||
public string PendingTransitionName
|
||||
{
|
||||
get => Wrapped.Get("pending_transition_name").AsString();
|
||||
set => Wrapped.Set("pending_transition_name", value);
|
||||
}
|
||||
|
||||
public float PendingTransitionRemainingDelay
|
||||
{
|
||||
get => Wrapped.Get("pending_transition_remaining_delay").AsSingle();
|
||||
set => Wrapped.Set("pending_transition_remaining_delay", value);
|
||||
}
|
||||
|
||||
public float PendingTransitionInitialDelay
|
||||
{
|
||||
get => Wrapped.Get("pending_transition_initial_delay").AsSingle();
|
||||
set => Wrapped.Set("pending_transition_initial_delay", value);
|
||||
}
|
||||
|
||||
public List<SerializedStateChartState> Children
|
||||
{
|
||||
get
|
||||
{
|
||||
var wrappedChildren = Wrapped.Get("children").AsGodotArray();
|
||||
var result = new List<SerializedStateChartState>();
|
||||
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||
foreach (var item in wrappedChildren)
|
||||
{
|
||||
result.Add(Of(item.As<Resource>()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
set
|
||||
{
|
||||
var wrappedChildren = new Godot.Collections.Array();
|
||||
foreach (var child in value)
|
||||
{
|
||||
wrappedChildren.Add(child.Wrapped);
|
||||
}
|
||||
|
||||
Wrapped.Set("children", wrappedChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bxbsjxky868w0
|
||||
32
addons/godot_state_charts/csharp/StateChartSerializer.cs
Normal file
32
addons/godot_state_charts/csharp/StateChartSerializer.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace GodotStateCharts;
|
||||
using Godot;
|
||||
|
||||
public class StateChartSerializer
|
||||
{
|
||||
private static readonly GodotObject Wrapped = GD.Load("res://addons/godot_state_charts/state_chart_serializer.gd");
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the given state chart and returns a serialized object that
|
||||
/// can be stored as part of a saved game.
|
||||
/// </summary>
|
||||
/// <param name="stateChart">the state chart to serialize</param>
|
||||
/// <returns>a resource containing the serialized state</returns>
|
||||
public static SerializedStateChart Serialize(StateChart stateChart)
|
||||
{
|
||||
return SerializedStateChart.Of(Wrapped.Call("serialize", stateChart.Wrapped).As<Resource>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the given serialized state chart into the given state chart. Returns a set of
|
||||
/// error messages. If the serialized state chart was no longer compatible with the current state
|
||||
/// chart, nothing will happen. The operation is successful when the returned array is empty.
|
||||
/// </summary>
|
||||
public static string[] Deserialize(SerializedStateChart serializedStateChart, StateChart stateChart)
|
||||
{
|
||||
var variant = Wrapped.Call("deserialize", serializedStateChart.Wrapped, stateChart.Wrapped);
|
||||
return variant.AsStringArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://cfttxxidmbax6
|
||||
Reference in New Issue
Block a user