Compare commits
2 Commits
902ff21e48
...
6b78cb2985
Author | SHA1 | Date |
---|---|---|
copygirl | 6b78cb2985 | 1 year ago |
copygirl | 47530de27e | 1 year ago |
39 changed files with 354 additions and 273 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,49 @@ |
||||
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); |
||||
} |
@ -1,94 +1,43 @@ |
||||
using System; |
||||
using gaemstone.ECS; |
||||
using static gaemstone.Flecs.Core; |
||||
|
||||
namespace gaemstone; |
||||
|
||||
[Module] |
||||
public partial class Doc |
||||
{ |
||||
[Tag] |
||||
public struct DisplayType { } |
||||
|
||||
[Tag] |
||||
public struct Relation { } |
||||
|
||||
/// <summary> |
||||
/// Tags are just <see cref="Flecs.Core.Component"/>s with 0 size. |
||||
/// This functions as a special entity that holds the appearance for tags. |
||||
/// This functions as a special entity that holds the appearance for tags |
||||
/// used by the entity inspector, and is not actually added to any entity. |
||||
/// Not related to <see cref="Flecs.Core.Tag"/> in any way. |
||||
/// </summary> |
||||
[Tag] |
||||
public struct Tag { } |
||||
|
||||
|
||||
// TODO: These need to actually be read at some point. |
||||
|
||||
/// <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. |
||||
/// Added to entities that represent a unique type of entity that should |
||||
/// be displayed uniquely in the entity inspector. If an entity is tagged |
||||
/// with such a display type entity, it too will be shown differently. |
||||
/// </summary> |
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] |
||||
public class Name : Attribute |
||||
{ |
||||
public string Value { get; } |
||||
public Name(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 Brief : Attribute |
||||
{ |
||||
public string Value { get; } |
||||
public Brief(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 Detail : Attribute |
||||
{ |
||||
public string Value { get; } |
||||
public Detail(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 Link : Attribute |
||||
{ |
||||
public string Value { get; } |
||||
public Link(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 Color : Attribute |
||||
{ |
||||
public float Red { get; } |
||||
public float Green { get; } |
||||
public float Blue { get; } |
||||
|
||||
public Color(float red, float green, float blue) |
||||
{ |
||||
if ((red < 0.0f) || (red > 1.0f)) throw new ArgumentOutOfRangeException(nameof(red )); |
||||
if ((green < 0.0f) || (green > 1.0f)) throw new ArgumentOutOfRangeException(nameof(green)); |
||||
if ((blue < 0.0f) || (blue > 1.0f)) throw new ArgumentOutOfRangeException(nameof(blue )); |
||||
Red = red; Green = green; Blue = blue; |
||||
} |
||||
} |
||||
/// <details> |
||||
/// <p> |
||||
/// Examples of such display types include: |
||||
/// <list> |
||||
/// <item> <see cref="Flecs.Core.Module"/> </item> |
||||
/// <item> <see cref="Flecs.Core.Component"/> </item> |
||||
/// <item> <see cref="Flecs.Core.Observer"/> </item> |
||||
/// <item> <see cref="Flecs.System.System"/> </item> |
||||
/// <item> <see cref="gaemstone.Doc.Relation"/> </item> |
||||
/// <item> <see cref="gaemstone.Doc.Tag"/> </item> |
||||
/// </list> |
||||
/// </p> |
||||
/// <p> |
||||
/// Used in conjuction with components and relations such as |
||||
/// (<see cref="Flecs.Doc.Description"/>, <see cref="Flecs.Doc.Color"/>) |
||||
/// to specify the appearance of this display type in the entity inspector. |
||||
/// </p> |
||||
/// </details> |
||||
[Tag] |
||||
public struct DisplayType { } |
||||
} |
||||
|
@ -1,6 +1,6 @@ |
||||
using System; |
||||
|
||||
namespace gaemstone.ECS; |
||||
namespace gaemstone; |
||||
|
||||
/// <summary> Use a custom name or path for this entity instead of the type's name. </summary> |
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
@ -1,7 +1,8 @@ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using gaemstone.ECS; |
||||
|
||||
namespace gaemstone.ECS; |
||||
namespace gaemstone; |
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] |
||||
public class ModuleAttribute : SingletonAttribute { } |
@ -1,7 +1,7 @@ |
||||
using System; |
||||
using gaemstone.Utility; |
||||
|
||||
namespace gaemstone.ECS; |
||||
namespace gaemstone; |
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] |
||||
public class SourceAttribute<T> : Attribute { } |
@ -1,6 +1,6 @@ |
||||
using System; |
||||
|
||||
namespace gaemstone.ECS; |
||||
namespace gaemstone; |
||||
|
||||
[AttributeUsage(AttributeTargets.Method)] |
||||
public class SystemAttribute : Attribute { } |
Loading…
Reference in new issue