parent
902ff21e48
commit
47530de27e
10 changed files with 187 additions and 143 deletions
@ -0,0 +1,66 @@ |
|||||||
|
using System; |
||||||
|
|
||||||
|
namespace gaemstone; |
||||||
|
|
||||||
|
public partial class Doc |
||||||
|
{ |
||||||
|
/// <summary> |
||||||
|
/// A display name for this entity. |
||||||
|
/// Names in the entity hierarchy must be unique within the parent entity, |
||||||
|
/// This doesn't apply to display names - they are mostly informational. |
||||||
|
/// Displayed in the Entity Inspector. |
||||||
|
/// </summary> |
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] |
||||||
|
public class NameAttribute : Attribute |
||||||
|
{ |
||||||
|
public string Value { get; } |
||||||
|
public NameAttribute(string value) => Value = value; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// A brief description of this entity. |
||||||
|
/// Displayed in the Entity Inspector. |
||||||
|
/// </summary> |
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] |
||||||
|
public class BriefAttribute : Attribute |
||||||
|
{ |
||||||
|
public string Value { get; } |
||||||
|
public BriefAttribute(string value) => Value = value; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// A detailed description, or full documentation, of this entity's purpose and behaviors. |
||||||
|
/// It's encouraged to use multiple paragraphs and markdown formatting if necessary. |
||||||
|
/// Displayed in the Entity Inspector. |
||||||
|
/// </summary> |
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] |
||||||
|
public class DetailAttribute : Attribute |
||||||
|
{ |
||||||
|
public string Value { get; } |
||||||
|
public DetailAttribute(string value) => Value = value; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// A link to a website relating to this entity, such as |
||||||
|
/// a module's repository, or further documentation. |
||||||
|
/// Displayed in the Entity Inspector. |
||||||
|
/// </summary> |
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] |
||||||
|
public class LinkAttribute : Attribute |
||||||
|
{ |
||||||
|
public string Value { get; } |
||||||
|
public LinkAttribute(string value) => Value = value; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// A custom color to represent this entity. |
||||||
|
/// Displayed in the Entity Inspector. |
||||||
|
/// </summary> |
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] |
||||||
|
public class ColorAttribute : Attribute |
||||||
|
{ |
||||||
|
// TODO: Should we be passing a string? |
||||||
|
public string Value { get; } |
||||||
|
public ColorAttribute(string value) => Value = value; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
using gaemstone.ECS; |
||||||
|
using gaemstone.ECS.Utility; |
||||||
|
using gaemstone.Flecs; |
||||||
|
using static flecs_hub.flecs; |
||||||
|
|
||||||
|
namespace gaemstone; |
||||||
|
|
||||||
|
public static unsafe class DocExtensions |
||||||
|
{ |
||||||
|
private static Entity<TContext> Set<TContext, T>(Entity<TContext> entity, string? value) |
||||||
|
{ |
||||||
|
var id = entity.World.Pair<Flecs.Doc.Description, T>(); |
||||||
|
|
||||||
|
if (value != null) { |
||||||
|
var str = GlobalHeapAllocator.Instance.AllocateCString(value); |
||||||
|
var desc = new Flecs.Doc.Description { Value = (void*)(nint)str }; |
||||||
|
entity.Set(id, desc); |
||||||
|
} else { |
||||||
|
entity.Remove(id); |
||||||
|
} |
||||||
|
|
||||||
|
return entity; |
||||||
|
} |
||||||
|
|
||||||
|
public static string? GetDocName<TContext>(this Entity<TContext> entity, bool fallbackToEntityName = true) |
||||||
|
=> fallbackToEntityName || entity.Has<Flecs.Doc.Description, Core.Name>() |
||||||
|
? ecs_doc_get_name(entity.World, entity).FlecsToString() : null; |
||||||
|
public static Entity<TContext> SetDocName<TContext>(this Entity<TContext> entity, string? value) |
||||||
|
=> Set<TContext, Core.Name>(entity, value); |
||||||
|
|
||||||
|
public static string? GetDocBrief<TContext>(this Entity<TContext> entity) |
||||||
|
=> ecs_doc_get_brief(entity.World, entity).FlecsToString()!; |
||||||
|
public static Entity<TContext> SetDocBrief<TContext>(this Entity<TContext> entity, string? value) |
||||||
|
=> Set<TContext, Flecs.Doc.Brief>(entity, value); |
||||||
|
|
||||||
|
public static string? GetDocDetail<TContext>(this Entity<TContext> entity) |
||||||
|
=> ecs_doc_get_detail(entity.World, entity).FlecsToString()!; |
||||||
|
public static Entity<TContext> SetDocDetail<TContext>(this Entity<TContext> entity, string? value) |
||||||
|
=> Set<TContext, Flecs.Doc.Detail>(entity, value); |
||||||
|
|
||||||
|
public static string? GetDocLink<TContext>(this Entity<TContext> entity) |
||||||
|
=> ecs_doc_get_link(entity.World, entity).FlecsToString()!; |
||||||
|
public static Entity<TContext> SetDocLink<TContext>(this Entity<TContext> entity, string? value) |
||||||
|
=> Set<TContext, Flecs.Doc.Link>(entity, value); |
||||||
|
|
||||||
|
public static string? GetDocColor<TContext>(this Entity<TContext> entity) |
||||||
|
=> ecs_doc_get_color(entity.World, entity).FlecsToString()!; |
||||||
|
public static Entity<TContext> SetDocColor<TContext>(this Entity<TContext> entity, string? value) |
||||||
|
=> Set<TContext, Flecs.Doc.Color>(entity, value); |
||||||
|
} |
Loading…
Reference in new issue