You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

49 lines
2.1 KiB

using gaemstone.ECS;
using gaemstone.ECS.Utility;
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, flecs.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, flecs.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);
}