Skip to content

Commit

Permalink
Finished documentation for GodotSharp public APIs
Browse files Browse the repository at this point in the history
• CS1591 now re-enabled
  • Loading branch information
Repiteo committed Jul 21, 2023
1 parent 851bc64 commit d6eacf5
Show file tree
Hide file tree
Showing 39 changed files with 4,321 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Compat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public double BlendNode(StringName name, AnimationNode node, double time, bool s

partial class CodeEdit
{
/// <inheritdoc cref="AddCodeCompletionOption(CodeCompletionKind, string, string, Nullable{Color}, Resource, Nullable{Variant})"/>
/// <inheritdoc cref="AddCodeCompletionOption(CodeCompletionKind, string, string, Nullable{Color}, Resource, Nullable{Variant}, int)"/>
[EditorBrowsable(EditorBrowsableState.Never)]
public void AddCodeCompletionOption(CodeCompletionKind type, string displayText, string insertText, Nullable<Color> textColor, Resource icon, Nullable<Variant> value)
{
Expand Down
36 changes: 36 additions & 0 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public Array(Variant[] array) : this()
this[i] = array[i];
}

/// <summary>
/// Constructs a new <see cref="Array"/> from the given <see cref="StringName"/> span.
/// </summary>
/// <param name="array">The StringNames to put in the new array.</param>
/// <returns>A new Godot Array.</returns>
public Array(Span<StringName> array) : this()
{
if (array == null)
Expand All @@ -84,6 +89,11 @@ public Array(Span<StringName> array) : this()
this[i] = array[i];
}

/// <summary>
/// Constructs a new <see cref="Array"/> from the given <see cref="NodePath"/> span.
/// </summary>
/// <param name="array">The NodePaths to put in the new array.</param>
/// <returns>A new Godot Array.</returns>
public Array(Span<NodePath> array) : this()
{
if (array == null)
Expand All @@ -100,6 +110,11 @@ public Array(Span<NodePath> array) : this()
this[i] = array[i];
}

/// <summary>
/// Constructs a new <see cref="Array"/> from the given <see cref="Rid"/> span.
/// </summary>
/// <param name="array">The Rids to put in the new array.</param>
/// <returns>A new Godot Array.</returns>
public Array(Span<Rid> array) : this()
{
if (array == null)
Expand All @@ -120,6 +135,11 @@ public Array(Span<Rid> array) : this()
// from derived types (e.g.: Node[]). Implicit conversion from Derived[] to Base[] are
// fine as long as the array is not mutated. However, Span does this type checking at
// instantiation, so it's not possible to use it even when not mutating anything.
/// <summary>
/// Constructs a new <see cref="Array"/> from the given <see cref="GodotObject"/> span.
/// </summary>
/// <param name="array">The GodotObjects to put in the new array.</param>
/// <returns>A new Godot Array.</returns>
// ReSharper disable once RedundantNameQualifier
public Array(ReadOnlySpan<GodotObject> array) : this()
{
Expand Down Expand Up @@ -149,6 +169,9 @@ private Array(godot_array nativeValueToOwn)
internal static Array CreateTakingOwnershipOfDisposableValue(godot_array nativeValueToOwn)
=> new Array(nativeValueToOwn);

/// <summary>
/// Deconstructs this <see cref="Array"/>.
/// </summary>
~Array()
{
Dispose(false);
Expand All @@ -163,6 +186,9 @@ public void Dispose()
GC.SuppressFinalize(this);
}

/// <summary>
/// Disposes implementation of this <see cref="Array"/>.
/// </summary>
public void Dispose(bool disposing)
{
// Always dispose `NativeValue` even if disposing is true
Expand Down Expand Up @@ -1773,9 +1799,19 @@ public IEnumerator<T> GetEnumerator()
/// <returns>A string representation of this array.</returns>
public override string ToString() => _underlyingArray.ToString();

/// <summary>
/// Converts this <see cref="Array{T}"/> to a <see cref="Variant"/>.
/// </summary>
/// <param name="from">The <see cref="Array{T}"/> to convert.</param>
/// <returns>A <see cref="Variant"/> representation of this <see cref="Array{T}"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Variant(Array<T> from) => Variant.CreateFrom(from);

/// <summary>
/// Converts this <see cref="Variant"/> to an <see cref="Array{T}"/>.
/// </summary>
/// <param name="from">The <see cref="Variant"/> to convert.</param>
/// <returns>An <see cref="Array{T}"/> representation of this <see cref="Variant"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Array<T>(Variant from) => from.AsGodotArray<T>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class GodotClassNameAttribute : Attribute
/// </summary>
public string Name { get; }

/// <summary>
/// Specify the original engine class name.
/// </summary>
/// <param name="name">Original engine class name.</param>
public GodotClassNameAttribute(string name)
{
Name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Godot
{
/// <summary>
/// Attribute that marks the current delegate as a signal, allowing it to
/// handle engine callbacks.
/// </summary>
[AttributeUsage(AttributeTargets.Delegate)]
public sealed class SignalAttribute : Attribute { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Godot
{
/// <summary>
/// Attribute that marks the current script as a tool script, allowing it
/// to be loaded and executed by the editor.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public sealed class ToolAttribute : Attribute { }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
namespace Godot.Bridge;

/// <summary>
/// A reload configuration for an assembly load context.
/// </summary>
public static class AlcReloadCfg
{
private static bool _configured = false;

/// <summary>
/// Configure this assembly load context.
/// </summary>
/// <param name="alcReloadEnabled">Specifies if a reload is enabled.</param>
public static void Configure(bool alcReloadEnabled)
{
if (_configured)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace Godot.Bridge;

/// <summary>
/// Serialized information container for handling <see cref="Godot.GodotObject"/> data.
/// </summary>
public sealed class GodotSerializationInfo : IDisposable
{
private readonly Collections.Dictionary _properties;
private readonly Collections.Dictionary _signalEvents;

/// <summary>
/// Disposes of this <see cref="GodotSerializationInfo"/>.
/// </summary>
public void Dispose()
{
_properties?.Dispose();
Expand All @@ -30,16 +36,33 @@ internal static GodotSerializationInfo CreateCopyingBorrowed(
NativeFuncs.godotsharp_dictionary_new_copy(signalEvents));
}

/// <summary>
/// Adds a property to this <see cref="GodotSerializationInfo"/>.
/// </summary>
/// <param name="name">The name of the property to add.</param>
/// <param name="value">The value to set for this property.</param>
public void AddProperty(StringName name, Variant value)
{
_properties[name] = value;
}

/// <summary>
/// Tries to get a property from this <see cref="GodotSerializationInfo"/>.
/// </summary>
/// <param name="name">The name of the property to parse.</param>
/// <param name="value">The value retrieved from this property.</param>
/// <returns><see langword="true"/> if a property was successfully retrieved;
/// otherwise, <see langword="false"/>.</returns>
public bool TryGetProperty(StringName name, out Variant value)
{
return _properties.TryGetValue(name, out value);
}

/// <summary>
/// Adds a signal event to this <see cref="GodotSerializationInfo"/>.
/// </summary>
/// <param name="name">The name of the signal to add.</param>
/// <param name="eventDelegate">The delegate to assign to this signal.</param>
public void AddSignalEventDelegate(StringName name, Delegate eventDelegate)
{
var serializedData = new Collections.Array();
Expand All @@ -54,6 +77,14 @@ public void AddSignalEventDelegate(StringName name, Delegate eventDelegate)
}
}

/// <summary>
/// Tries to get a signal from this <see cref="GodotSerializationInfo"/>.
/// </summary>
/// <typeparam name="T">The type of <see cref="Delegate"/> being retrieved.</typeparam>
/// <param name="name">The name of the signal to parse.</param>
/// <param name="value">The value retrieved from this signal.</param>
/// <returns><see langword="true"/> if a signal was successfully retrieved;
/// otherwise, <see langword="false"/>.</returns>
public bool TryGetSignalEventDelegate<T>(StringName name, [MaybeNullWhen(false)] out T value)
where T : Delegate
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,155 @@

namespace Godot.Bridge
{
/// <summary>
/// Collection of managed callbacks to handle a dotnet hot-reload environment.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe struct ManagedCallbacks
{
// @formatter:off
/// <summary>
/// Delegate for <see cref="SignalAwaiter.SignalCallback"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_variant**, int, godot_bool*, void> SignalAwaiter_SignalCallback;
/// <summary>
/// Delegate for <see cref="DelegateUtils.InvokeWithVariantArgs"/>
/// </summary>
public delegate* unmanaged<IntPtr, void*, godot_variant**, int, godot_variant*, void> DelegateUtils_InvokeWithVariantArgs;
/// <summary>
/// Delegate for <see cref="DelegateUtils.DelegateEquals"/>
/// </summary>
public delegate* unmanaged<IntPtr, IntPtr, godot_bool> DelegateUtils_DelegateEquals;
/// <summary>
/// Delegate for <see cref="DelegateUtils.DelegateHash"/>
/// </summary>
public delegate* unmanaged<IntPtr, int> DelegateUtils_DelegateHash;
/// <summary>
/// Delegate for <see cref="DelegateUtils.TrySerializeDelegateWithGCHandle"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_array*, godot_bool> DelegateUtils_TrySerializeDelegateWithGCHandle;
/// <summary>
/// Delegate for <see cref="DelegateUtils.TryDeserializeDelegateWithGCHandle"/>
/// </summary>
public delegate* unmanaged<godot_array*, IntPtr*, godot_bool> DelegateUtils_TryDeserializeDelegateWithGCHandle;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.FrameCallback"/>
/// </summary>
public delegate* unmanaged<void> ScriptManagerBridge_FrameCallback;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.CreateManagedForGodotObjectBinding"/>
/// </summary>
public delegate* unmanaged<godot_string_name*, IntPtr, IntPtr> ScriptManagerBridge_CreateManagedForGodotObjectBinding;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.CreateManagedForGodotObjectScriptInstance"/>
/// </summary>
public delegate* unmanaged<IntPtr, IntPtr, godot_variant**, int, godot_bool> ScriptManagerBridge_CreateManagedForGodotObjectScriptInstance;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.GetScriptNativeName"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_string_name*, void> ScriptManagerBridge_GetScriptNativeName;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.SetGodotObjectPtr"/>
/// </summary>
public delegate* unmanaged<IntPtr, IntPtr, void> ScriptManagerBridge_SetGodotObjectPtr;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.RaiseEventSignal"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_string_name*, godot_variant**, int, godot_bool*, void> ScriptManagerBridge_RaiseEventSignal;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.ScriptIsOrInherits"/>
/// </summary>
public delegate* unmanaged<IntPtr, IntPtr, godot_bool> ScriptManagerBridge_ScriptIsOrInherits;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.AddScriptBridge"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_string*, godot_bool> ScriptManagerBridge_AddScriptBridge;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.GetOrCreateScriptBridgeForPath"/>
/// </summary>
public delegate* unmanaged<godot_string*, godot_ref*, void> ScriptManagerBridge_GetOrCreateScriptBridgeForPath;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.RemoveScriptBridge"/>
/// </summary>
public delegate* unmanaged<IntPtr, void> ScriptManagerBridge_RemoveScriptBridge;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.TryReloadRegisteredScriptWithClass"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_bool> ScriptManagerBridge_TryReloadRegisteredScriptWithClass;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.UpdateScriptClassInfo"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_string*, godot_bool*, godot_bool*, godot_string*, godot_array*, godot_dictionary*, godot_dictionary*, godot_ref*, void> ScriptManagerBridge_UpdateScriptClassInfo;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.SwapGCHandleForType"/>
/// </summary>
public delegate* unmanaged<IntPtr, IntPtr*, godot_bool, godot_bool> ScriptManagerBridge_SwapGCHandleForType;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.GetPropertyInfoList"/>
/// </summary>
public delegate* unmanaged<IntPtr, delegate* unmanaged<IntPtr, godot_string*, void*, int, void>, void> ScriptManagerBridge_GetPropertyInfoList;
/// <summary>
/// Delegate for <see cref="ScriptManagerBridge.GetPropertyDefaultValues"/>
/// </summary>
public delegate* unmanaged<IntPtr, delegate* unmanaged<IntPtr, void*, int, void>, void> ScriptManagerBridge_GetPropertyDefaultValues;
/// <summary>
/// Delegate for <see cref="CSharpInstanceBridge.Call"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_string_name*, godot_variant**, int, godot_variant_call_error*, godot_variant*, godot_bool> CSharpInstanceBridge_Call;
/// <summary>
/// Delegate for <see cref="CSharpInstanceBridge.Set"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_string_name*, godot_variant*, godot_bool> CSharpInstanceBridge_Set;
/// <summary>
/// Delegate for <see cref="CSharpInstanceBridge.Get"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_string_name*, godot_variant*, godot_bool> CSharpInstanceBridge_Get;
/// <summary>
/// Delegate for <see cref="CSharpInstanceBridge.CallDispose"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_bool, void> CSharpInstanceBridge_CallDispose;
/// <summary>
/// Delegate for <see cref="CSharpInstanceBridge.CallToString"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_string*, godot_bool*, void> CSharpInstanceBridge_CallToString;
/// <summary>
/// Delegate for <see cref="CSharpInstanceBridge.HasMethodUnknownParams"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_string_name*, godot_bool> CSharpInstanceBridge_HasMethodUnknownParams;
/// <summary>
/// Delegate for <see cref="CSharpInstanceBridge.SerializeState"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_dictionary*, godot_dictionary*, void> CSharpInstanceBridge_SerializeState;
/// <summary>
/// Delegate for <see cref="CSharpInstanceBridge.DeserializeState"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_dictionary*, godot_dictionary*, void> CSharpInstanceBridge_DeserializeState;
/// <summary>
/// Delegate for <see cref="GCHandleBridge.FreeGCHandle"/>
/// </summary>
public delegate* unmanaged<IntPtr, void> GCHandleBridge_FreeGCHandle;
/// <summary>
/// Delegate for <see cref="GCHandleBridge.GCHandleIsTargetCollectible"/>
/// </summary>
public delegate* unmanaged<IntPtr, godot_bool> GCHandleBridge_GCHandleIsTargetCollectible;
/// <summary>
/// Delegate for <see cref="DebuggingUtils.GetCurrentStackInfo"/>
/// </summary>
public delegate* unmanaged<void*, void> DebuggingUtils_GetCurrentStackInfo;
/// <summary>
/// Delegate for <see cref="DisposablesTracker.OnGodotShuttingDown"/>
/// </summary>
public delegate* unmanaged<void> DisposablesTracker_OnGodotShuttingDown;
/// <summary>
/// Delegate for <see cref="GD.OnCoreApiAssemblyLoaded"/>
/// </summary>
public delegate* unmanaged<godot_bool, void> GD_OnCoreApiAssemblyLoaded;
// @formatter:on

/// <summary>
/// Initializes various delegates for managed callbacks.
/// </summary>
/// <returns>The initialized delegates.</returns>
public static ManagedCallbacks Create()
{
return new()
Expand Down Expand Up @@ -87,6 +196,10 @@ public static ManagedCallbacks Create()
};
}

/// <summary>
/// Initializes various delegates for managed callbacks.
/// </summary>
/// <param name="outManagedCallbacks">The initialized delegates.</param>
public static void Create(IntPtr outManagedCallbacks)
=> *(ManagedCallbacks*)outManagedCallbacks = Create();
}
Expand Down
Loading

0 comments on commit d6eacf5

Please sign in to comment.