Skip to content

Commit

Permalink
Add doc uuid support missing Ecs.Doc setter/getters
Browse files Browse the repository at this point in the history
  • Loading branch information
BeanCheeseBurrito committed Nov 13, 2024
1 parent dbac90e commit 7d4e7d5
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/Flecs.NET.Tests/Cpp/DocTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ private void SetColor()
Assert.Equal("A color", e.DocColor());
}

[Fact]
private void SetUuid()
{
using World world = World.Create();

Entity e = world.Entity("Foo");

e.SetDocUuid("81f50b40-09ff-4ce0-a388-4a52a14052c7");

Assert.True(e.Has<EcsDocDescription>(Ecs.Doc.Uuid));

Assert.Equal(e.DocUuid(), "81f50b40-09ff-4ce0-a388-4a52a14052c7");

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-13)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-13)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-13)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-13)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)

Check warning on line 76 in src/Flecs.NET.Tests/Cpp/DocTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The literal or constant value "81f50b40-09ff-4ce0-a388-4a52a14052c7" should be passed as the 'expected' argument in the call to 'Assert.Equal(expected, actual)' in method 'SetUuid' on type 'DocTests'. (https://xunit.github.io/xunit.analyzers/rules/xUnit2000)
}

[Fact]
private void GetNameNoDocName()
{
Expand Down
153 changes: 151 additions & 2 deletions src/Flecs.NET/Core/Ecs/Doc.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using static Flecs.NET.Bindings.flecs;

namespace Flecs.NET.Core;
Expand All @@ -7,8 +9,23 @@ public static partial class Ecs
/// <summary>
/// Utilities for documenting entities, components and systems.
/// </summary>
public static class Doc
[SuppressMessage("Naming", "CA1721:Property names should not match get methods")]
public class Doc : IFlecsModule
{
/// <summary>
/// Init doc module.
/// </summary>
/// <param name="world"></param>
public void InitModule(World world)
{

}

/// <summary>
/// Reference to <see cref="EcsDocUuid"/>.
/// </summary>
public static ref ulong Uuid => ref EcsDocUuid;

/// <summary>
/// Reference to <see cref="EcsDocBrief"/>.
/// </summary>
Expand All @@ -28,5 +45,137 @@ public static class Doc
/// Reference to <see cref="EcsDocColor"/>.
/// </summary>
public static ref ulong Color => ref EcsDocColor;

/// <summary>
/// Get doc uuid for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>The uuid string.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetUuid(Entity entity)
{
return entity.DocUuid();
}

/// <summary>
/// Get human-readable name for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>The uuid string.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetName(Entity entity)
{
return entity.DocName();
}

/// <summary>
/// Get brief description for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>The brief string.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetBrief(Entity entity)
{
return entity.DocBrief();
}

/// <summary>
/// Get detailed description for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>The detail string.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetDetail(Entity entity)
{
return entity.DocDetail();
}

/// <summary>
/// Get link to external documentation for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>The link string.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetLink(Entity entity)
{
return entity.DocLink();
}

/// <summary>
/// Get color for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>The color string.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetColor(Entity entity)
{
return entity.DocColor();
}

/// <summary>
/// Set uuid for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <param name="uuid">The uuid string.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetUuid(Entity entity, string uuid)
{
entity.SetDocUuid(uuid);
}

/// <summary>
/// Set human-readable name for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <param name="name">The name string.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetName(Entity entity, string name)
{
entity.SetDocName(name);
}

/// <summary>
/// Set brief description for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <param name="brief">The brief string</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetBrief(Entity entity, string brief)
{
entity.SetDocBrief(brief);
}

/// <summary>
/// Set detailed description for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <param name="detail">The detail string.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetDetail(Entity entity, string detail)
{
entity.SetDocDetail(detail);
}

/// <summary>
/// Set link to external documentation for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <param name="link">The link string.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetLink(Entity entity, string link)
{
entity.SetDocLink(link);
}

/// <summary>
/// Set color for an entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <param name="color">The color string.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetColor(Entity entity, string color)
{
entity.SetDocColor(color);
}
}
}
}
21 changes: 21 additions & 0 deletions src/Flecs.NET/Core/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,15 @@ public string DocColor()
return NativeString.GetString(ecs_doc_get_color(World, Id));
}

/// <summary>
/// Returns the entity's doc uuid.
/// </summary>
/// <returns></returns>
public string DocUuid()
{
return NativeString.GetString(ecs_doc_get_uuid(World, Id));
}

/// <summary>
/// Return number of alerts for entity.
/// </summary>
Expand Down Expand Up @@ -3040,6 +3049,18 @@ public ref Entity SetDocColor(string color)
return ref this;
}

/// <summary>
/// Set doc uuid.
/// </summary>
/// <param name="uuid">The uuid string.</param>
/// <returns></returns>
public ref Entity SetDocUuid(string uuid)
{
using NativeString nativeUuid = (NativeString)uuid;
ecs_doc_set_uuid(World, Id, nativeUuid);
return ref this;
}

/// <summary>
/// Make entity a unit.
/// </summary>
Expand Down

0 comments on commit 7d4e7d5

Please sign in to comment.