From e02c56e77e73c25d0786ed1cf487a68619c3e375 Mon Sep 17 00:00:00 2001 From: "D. Moonfire" Date: Mon, 16 Jan 2023 12:38:29 -0600 Subject: [PATCH] feat: implemented SingletonComponent to wrap most of the Is* components --- flake.lock | 12 +-- src/MfGames.Nitride.Calendar/IsCalendar.cs | 6 +- src/MfGames.Nitride.Feeds/IsFeed.cs | 10 +-- src/MfGames.Nitride.Gemtext/IsGemtext.cs | 6 +- ...rtyClass.cs => ClassAttributeReference.cs} | 4 +- .../ClassAttributeSourceGeneratorBase.cs | 66 ++++++++++++++ ...cs => ClassAttributeSyntaxReceiverBase.cs} | 45 +++++++--- .../CodeAnalysisExtensions.cs | 14 +-- .../MfGames.Nitride.Generators.csproj | 8 +- .../SingletonComponentSourceGenerator.cs | 90 +++++++++++++++++++ .../SingletonComponentSyntaxReceiver.cs | 13 +++ ...or.cs => WithPropertiesSourceGenerator.cs} | 63 +++---------- .../WithPropertiesSyntaxReceiver.cs | 12 +++ src/MfGames.Nitride.Html/IsHtml.cs | 6 +- src/MfGames.Nitride.IO/Paths/AddPathPrefix.cs | 3 +- src/MfGames.Nitride.Json/IsJson.cs | 6 +- src/MfGames.Nitride.Json/IsJsonExtensions.cs | 16 ---- src/MfGames.Nitride.Markdown/IsMarkdown.cs | 6 +- src/MfGames.Nitride.Yaml/IsYaml.cs | 6 +- src/MfGames.Nitride.Yaml/IsYamlExtensions.cs | 16 ---- .../MfGames.Nitride.Yaml.csproj | 6 +- 21 files changed, 276 insertions(+), 138 deletions(-) rename src/MfGames.Nitride.Generators/{WithPropertyClass.cs => ClassAttributeReference.cs} (90%) create mode 100644 src/MfGames.Nitride.Generators/ClassAttributeSourceGeneratorBase.cs rename src/MfGames.Nitride.Generators/{WithPropertySyntaxReceiver.cs => ClassAttributeSyntaxReceiverBase.cs} (62%) create mode 100644 src/MfGames.Nitride.Generators/SingletonComponentSourceGenerator.cs create mode 100644 src/MfGames.Nitride.Generators/SingletonComponentSyntaxReceiver.cs rename src/MfGames.Nitride.Generators/{WithPropertySourceGenerator.cs => WithPropertiesSourceGenerator.cs} (62%) create mode 100644 src/MfGames.Nitride.Generators/WithPropertiesSyntaxReceiver.cs delete mode 100644 src/MfGames.Nitride.Json/IsJsonExtensions.cs delete mode 100644 src/MfGames.Nitride.Yaml/IsYamlExtensions.cs diff --git a/flake.lock b/flake.lock index b67b61d..cb83bee 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "owner": "numtide", "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "type": "github" }, "original": { @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1662019588, - "narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=", + "lastModified": 1673631141, + "narHash": "sha256-AprpYQ5JvLS4wQG/ghm2UriZ9QZXvAwh1HlgA/6ZEVQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2da64a81275b68fdad38af669afeda43d401e94b", + "rev": "befc83905c965adfd33e5cae49acb0351f6e0404", "type": "github" }, "original": { diff --git a/src/MfGames.Nitride.Calendar/IsCalendar.cs b/src/MfGames.Nitride.Calendar/IsCalendar.cs index cd716d6..d9c190b 100644 --- a/src/MfGames.Nitride.Calendar/IsCalendar.cs +++ b/src/MfGames.Nitride.Calendar/IsCalendar.cs @@ -1,9 +1,11 @@ +using MfGames.Nitride.Generators; + namespace MfGames.Nitride.Calendar; /// /// A marker component for identifying an entity that represents a calendar. /// -public record IsCalendar +[SingletonComponent] +public partial class IsCalendar { - public static IsCalendar Instance { get; } = new(); } diff --git a/src/MfGames.Nitride.Feeds/IsFeed.cs b/src/MfGames.Nitride.Feeds/IsFeed.cs index d5282d8..95056c9 100644 --- a/src/MfGames.Nitride.Feeds/IsFeed.cs +++ b/src/MfGames.Nitride.Feeds/IsFeed.cs @@ -1,13 +1,11 @@ +using MfGames.Nitride.Generators; + namespace MfGames.Nitride.Feeds; /// /// A marker component that indicates this page is a feed. /// -public class IsFeed +[SingletonComponent] +public partial class IsFeed { - public IsFeed() - { - } - - public static IsFeed Instance { get; } = new(); } diff --git a/src/MfGames.Nitride.Gemtext/IsGemtext.cs b/src/MfGames.Nitride.Gemtext/IsGemtext.cs index 33fe6e3..972a291 100644 --- a/src/MfGames.Nitride.Gemtext/IsGemtext.cs +++ b/src/MfGames.Nitride.Gemtext/IsGemtext.cs @@ -1,10 +1,12 @@ +using MfGames.Nitride.Generators; + namespace MfGames.Nitride.Gemtext; /// /// A marker component for indicating that an entity is Gemtext, the format /// for text files using the Gemini protocol. /// -public record IsGemtext +[SingletonComponent] +public partial class IsGemtext { - public static IsGemtext Instance { get; } = new(); } diff --git a/src/MfGames.Nitride.Generators/WithPropertyClass.cs b/src/MfGames.Nitride.Generators/ClassAttributeReference.cs similarity index 90% rename from src/MfGames.Nitride.Generators/WithPropertyClass.cs rename to src/MfGames.Nitride.Generators/ClassAttributeReference.cs index a79b91a..0c68776 100644 --- a/src/MfGames.Nitride.Generators/WithPropertyClass.cs +++ b/src/MfGames.Nitride.Generators/ClassAttributeReference.cs @@ -6,9 +6,9 @@ namespace MfGames.Nitride.Generators; /// /// Internal class that consolidates all of the information needed to generate a -/// file. +/// class for adding With* properties. /// -internal class WithPropertyClass +public class ClassAttributeReference { /// /// Gets the syntax for the class declaration. diff --git a/src/MfGames.Nitride.Generators/ClassAttributeSourceGeneratorBase.cs b/src/MfGames.Nitride.Generators/ClassAttributeSourceGeneratorBase.cs new file mode 100644 index 0000000..e7a0350 --- /dev/null +++ b/src/MfGames.Nitride.Generators/ClassAttributeSourceGeneratorBase.cs @@ -0,0 +1,66 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Text; + +namespace MfGames.Nitride.Generators; + +/// +/// Base class for classes marked with an attribute. +/// +public abstract class ClassAttributeSourceGeneratorBase + : ISourceGenerator + where TSyntaxReceiver : ClassAttributeSyntaxReceiverBase +{ + public void Execute(GeneratorExecutionContext context) + { + // Get the generator infrastructure will create a receiver and + // populate it we can retrieve the populated instance via the + // context. + if (context.SyntaxReceiver is not TSyntaxReceiver syntaxReceiver) + { + return; + } + + // Report any messages. + foreach (string? message in syntaxReceiver.Messages) + { + context.Warning( + MessageCode.Debug, + Location.Create( + "Temporary.g.cs", + TextSpan.FromBounds(0, 0), + new LinePositionSpan( + new LinePosition(0, 0), + new LinePosition(0, 0))), + "{0}: Syntax Message: {1}", + this.GetType().Name, + message); + } + + // If we didn't find anything, then there is nothing to do. + if (syntaxReceiver.ReferenceList.Count == 0) + { + return; + } + + // Go through each one. + foreach (ClassAttributeReference reference in syntaxReceiver + .ReferenceList) + { + this.GenerateClassFile(context, reference); + } + } + + public void Initialize(GeneratorInitializationContext context) + { + // Register a factory that can create our custom syntax receiver + context.RegisterForSyntaxNotifications( + () => this.CreateSyntaxReceiver(context)); + } + + protected abstract TSyntaxReceiver CreateSyntaxReceiver( + GeneratorInitializationContext context); + + protected abstract void GenerateClassFile( + GeneratorExecutionContext context, + ClassAttributeReference reference); +} diff --git a/src/MfGames.Nitride.Generators/WithPropertySyntaxReceiver.cs b/src/MfGames.Nitride.Generators/ClassAttributeSyntaxReceiverBase.cs similarity index 62% rename from src/MfGames.Nitride.Generators/WithPropertySyntaxReceiver.cs rename to src/MfGames.Nitride.Generators/ClassAttributeSyntaxReceiverBase.cs index 833edd2..23aa60b 100644 --- a/src/MfGames.Nitride.Generators/WithPropertySyntaxReceiver.cs +++ b/src/MfGames.Nitride.Generators/ClassAttributeSyntaxReceiverBase.cs @@ -6,18 +6,26 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; namespace MfGames.Nitride.Generators; -internal class WithPropertySyntaxReceiver : ISyntaxReceiver +public abstract class ClassAttributeSyntaxReceiverBase : ISyntaxReceiver { + private readonly string attributeName; + private readonly GeneratorInitializationContext context; - public WithPropertySyntaxReceiver(GeneratorInitializationContext context) + public ClassAttributeSyntaxReceiverBase( + GeneratorInitializationContext context, + string attributeName) { this.context = context; - this.ClassList = new List(); + this.attributeName = attributeName; + this.ReferenceList = new List(); this.Messages = new List(); } - public List ClassList { get; } + /// + /// Gets or sets a value indicating whether we should debug parsing attributes. + /// + public bool DebugAttributes { get; set; } public List Messages { get; } @@ -26,6 +34,8 @@ internal class WithPropertySyntaxReceiver : ISyntaxReceiver /// public string? Namespace { get; private set; } + public List ReferenceList { get; } + public List UsingDirectiveList { get; set; } = new(); public void OnVisitSyntaxNode(SyntaxNode syntaxNode) @@ -64,21 +74,30 @@ internal class WithPropertySyntaxReceiver : ISyntaxReceiver } // See if the class has our set properties attribute. - bool found = cds.AttributeLists.AsEnumerable() + var attributes = cds.AttributeLists + .AsEnumerable() .SelectMany(x => x.Attributes) .Select(x => x.Name.ToString()) + .ToList(); + bool found = attributes .Any( - x => x switch - { - "WithProperties" => true, - "WithPropertiesAttribute" => true, - _ => false, - }); + x => x == this.attributeName + || x == $"{this.attributeName}Attribute"); + + if (this.DebugAttributes) + { + this.Messages.Add( + string.Format( + "Parsing {0} found? {1} from attributes [{2}]", + cds.Identifier, + found, + string.Join(", ", attributes))); + } if (found) { - this.ClassList.Add( - new WithPropertyClass + this.ReferenceList.Add( + new ClassAttributeReference { Namespace = this.Namespace!, UsingDirectiveList = this.UsingDirectiveList, diff --git a/src/MfGames.Nitride.Generators/CodeAnalysisExtensions.cs b/src/MfGames.Nitride.Generators/CodeAnalysisExtensions.cs index 3781d4f..cde11f3 100644 --- a/src/MfGames.Nitride.Generators/CodeAnalysisExtensions.cs +++ b/src/MfGames.Nitride.Generators/CodeAnalysisExtensions.cs @@ -18,7 +18,7 @@ public static class CodeAnalysisExtensions this GeneratorExecutionContext context, MessageCode messageCode, string format, - params object[] parameters) + params object?[] parameters) { Error(context, messageCode, null, format, parameters); } @@ -36,7 +36,7 @@ public static class CodeAnalysisExtensions MessageCode messageCode, Location? location, string format, - params object[] parameters) + params object?[] parameters) { context.Message( messageCode, @@ -57,7 +57,7 @@ public static class CodeAnalysisExtensions this GeneratorExecutionContext context, MessageCode messageCode, string format, - params object[] parameters) + params object?[] parameters) { Information(context, messageCode, null, format, parameters); } @@ -75,7 +75,7 @@ public static class CodeAnalysisExtensions MessageCode messageCode, Location? location, string format, - params object[] parameters) + params object?[] parameters) { context.Message( messageCode, @@ -96,7 +96,7 @@ public static class CodeAnalysisExtensions this GeneratorExecutionContext context, MessageCode messageCode, string format, - params object[] parameters) + params object?[] parameters) { Warning(context, messageCode, null, format, parameters); } @@ -114,7 +114,7 @@ public static class CodeAnalysisExtensions MessageCode messageCode, Location? location, string format, - params object[] parameters) + params object?[] parameters) { context.Message( messageCode, @@ -139,7 +139,7 @@ public static class CodeAnalysisExtensions Location? location, DiagnosticSeverity severity, string format, - params object[] parameters) + params object?[] parameters) { context.ReportDiagnostic( Diagnostic.Create( diff --git a/src/MfGames.Nitride.Generators/MfGames.Nitride.Generators.csproj b/src/MfGames.Nitride.Generators/MfGames.Nitride.Generators.csproj index bdbc10a..a5f7424 100644 --- a/src/MfGames.Nitride.Generators/MfGames.Nitride.Generators.csproj +++ b/src/MfGames.Nitride.Generators/MfGames.Nitride.Generators.csproj @@ -10,10 +10,10 @@ - - - - + + + + diff --git a/src/MfGames.Nitride.Generators/SingletonComponentSourceGenerator.cs b/src/MfGames.Nitride.Generators/SingletonComponentSourceGenerator.cs new file mode 100644 index 0000000..e634570 --- /dev/null +++ b/src/MfGames.Nitride.Generators/SingletonComponentSourceGenerator.cs @@ -0,0 +1,90 @@ +using System.Text; + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; + +namespace MfGames.Nitride.Generators; + +/// +/// Implements a source generator that creates the additional properties +/// and methods for a singleton component including the constructor and +/// instance methods, along with extension methods for adding them to entities. +/// +[Generator] +public class SingletonComponentSourceGenerator + : ClassAttributeSourceGeneratorBase +{ + protected override SingletonComponentSyntaxReceiver CreateSyntaxReceiver( + GeneratorInitializationContext context) + { + return new SingletonComponentSyntaxReceiver(context); + } + + protected override void GenerateClassFile( + GeneratorExecutionContext context, + ClassAttributeReference unit) + { + // Pull out some fields. + ClassDeclarationSyntax cds = unit.ClassDeclaration; + + // Create the partial class. + StringBuilder buffer = new(); + buffer.AppendLine("#nullable enable"); + + // Copy the using statements from the file. + foreach (UsingDirectiveSyntax? uds in unit.UsingDirectiveList) + { + buffer.AppendLine(uds.ToString()); + } + + buffer.AppendLine(); + + // Create the namespace. + SyntaxToken cls = cds.Identifier; + + buffer.AppendLine(string.Join( + "\n", + $"using MfGames.Gallium;", + $"", + $"namespace {unit.Namespace}", + $"{{", + $" public partial class {cls}", + $" {{", + $" static {cls}()", + $" {{", + $" Instance = new {cls}();", + $" }}", + $"", + $" private {cls}()", + $" {{", + $" }}", + $"", + $" public static {cls} Instance {{ get; }}", + $" }}", + $"", + $" public static class {cls}Extensions", + $" {{", + $" public static bool Has{cls}(this Entity entity)", + $" {{", + $" return entity.Has<{cls}>();", + $" }}", + $"", + $" public static Entity Remove{cls}(this Entity entity)", + $" {{", + $" return entity.Remove<{cls}>();", + $" }}", + $"", + $" public static Entity Set{cls}(this Entity entity)", + $" {{", + $" return entity.Set({cls}.Instance);", + $" }}", + $" }}", + $"}}", + "")); + + // Create the source text and write out the file. + var sourceText = SourceText.From(buffer.ToString(), Encoding.UTF8); + context.AddSource(cls + ".Generated.cs", sourceText); + } +} diff --git a/src/MfGames.Nitride.Generators/SingletonComponentSyntaxReceiver.cs b/src/MfGames.Nitride.Generators/SingletonComponentSyntaxReceiver.cs new file mode 100644 index 0000000..d63671d --- /dev/null +++ b/src/MfGames.Nitride.Generators/SingletonComponentSyntaxReceiver.cs @@ -0,0 +1,13 @@ +using Microsoft.CodeAnalysis; + +namespace MfGames.Nitride.Generators; + +public class SingletonComponentSyntaxReceiver : ClassAttributeSyntaxReceiverBase +{ + /// + public SingletonComponentSyntaxReceiver( + GeneratorInitializationContext context) + : base(context, "SingletonComponent") + { + } +} diff --git a/src/MfGames.Nitride.Generators/WithPropertySourceGenerator.cs b/src/MfGames.Nitride.Generators/WithPropertiesSourceGenerator.cs similarity index 62% rename from src/MfGames.Nitride.Generators/WithPropertySourceGenerator.cs rename to src/MfGames.Nitride.Generators/WithPropertiesSourceGenerator.cs index c9c7a48..3cb16d6 100644 --- a/src/MfGames.Nitride.Generators/WithPropertySourceGenerator.cs +++ b/src/MfGames.Nitride.Generators/WithPropertiesSourceGenerator.cs @@ -15,62 +15,22 @@ namespace MfGames.Nitride.Generators; /// together calls. /// [Generator] -public class WithPropertySourceGenerator : ISourceGenerator +public class WithPropertiesSourceGenerator + : ClassAttributeSourceGeneratorBase { - public void Execute(GeneratorExecutionContext context) + /// + protected override WithPropertiesSyntaxReceiver CreateSyntaxReceiver( + GeneratorInitializationContext context) { - // Get the generator infrastructure will create a receiver and - // populate it we can retrieve the populated instance via the - // context. - var syntaxReceiver = - (WithPropertySyntaxReceiver?)context.SyntaxReceiver; - - if (syntaxReceiver == null) - { - return; - } - - // Report any messages. - foreach (string? message in syntaxReceiver.Messages) - { - context.Information( - MessageCode.Debug, - Location.Create( - "Temporary.g.cs", - TextSpan.FromBounds(0, 0), - new LinePositionSpan( - new LinePosition(0, 0), - new LinePosition(0, 0))), - "Generating additional identifier code: {0}", - message); - } - - // If we didn't find anything, then there is nothing to do. - if (syntaxReceiver.ClassList.Count == 0) - { - return; - } - - // Go through each one. - foreach (WithPropertyClass classInfo in syntaxReceiver.ClassList) - { - this.GenerateClassFile(context, classInfo); - } + return new WithPropertiesSyntaxReceiver(context); } - public void Initialize(GeneratorInitializationContext context) - { - // Register a factory that can create our custom syntax receiver - context.RegisterForSyntaxNotifications( - () => new WithPropertySyntaxReceiver(context)); - } - - private void GenerateClassFile( + protected override void GenerateClassFile( GeneratorExecutionContext context, - WithPropertyClass unit) + ClassAttributeReference unit) { // Pull out some fields. - ClassDeclarationSyntax? cds = unit.ClassDeclaration; + ClassDeclarationSyntax cds = unit.ClassDeclaration; // Create the partial class. StringBuilder buffer = new(); @@ -100,9 +60,8 @@ public class WithPropertySourceGenerator : ISourceGenerator foreach (PropertyDeclarationSyntax pds in properties) { // See if we have a setter. - bool found = - pds.AccessorList?.Accessors.Any( - x => x.Keyword.ToString() == "set") + bool found = pds.AccessorList?.Accessors + .Any(x => x.Keyword.ToString() == "set") ?? false; if (!found) diff --git a/src/MfGames.Nitride.Generators/WithPropertiesSyntaxReceiver.cs b/src/MfGames.Nitride.Generators/WithPropertiesSyntaxReceiver.cs new file mode 100644 index 0000000..6cea03a --- /dev/null +++ b/src/MfGames.Nitride.Generators/WithPropertiesSyntaxReceiver.cs @@ -0,0 +1,12 @@ +using Microsoft.CodeAnalysis; + +namespace MfGames.Nitride.Generators; + +public class WithPropertiesSyntaxReceiver : ClassAttributeSyntaxReceiverBase +{ + /// + public WithPropertiesSyntaxReceiver(GeneratorInitializationContext context) + : base(context, "WithProperties") + { + } +} diff --git a/src/MfGames.Nitride.Html/IsHtml.cs b/src/MfGames.Nitride.Html/IsHtml.cs index 96833bc..8a2fbd3 100644 --- a/src/MfGames.Nitride.Html/IsHtml.cs +++ b/src/MfGames.Nitride.Html/IsHtml.cs @@ -1,9 +1,11 @@ +using MfGames.Nitride.Generators; + namespace MfGames.Nitride.Html; /// /// A marker component that indicates that the entity is an HTML file. /// -public record IsHtml +[SingletonComponent] +public partial class IsHtml { - public static IsHtml Instance { get; } = new(); } diff --git a/src/MfGames.Nitride.IO/Paths/AddPathPrefix.cs b/src/MfGames.Nitride.IO/Paths/AddPathPrefix.cs index dfa086b..142246f 100644 --- a/src/MfGames.Nitride.IO/Paths/AddPathPrefix.cs +++ b/src/MfGames.Nitride.IO/Paths/AddPathPrefix.cs @@ -33,7 +33,8 @@ public partial class AddPathPrefix : OperationBase { this.validator.ValidateAndThrow(this); - return this.replacePath.WithReplacement(this.RunReplacement) + return this.replacePath + .WithReplacement(this.RunReplacement) .Run(input); } diff --git a/src/MfGames.Nitride.Json/IsJson.cs b/src/MfGames.Nitride.Json/IsJson.cs index ec68980..7cb432e 100644 --- a/src/MfGames.Nitride.Json/IsJson.cs +++ b/src/MfGames.Nitride.Json/IsJson.cs @@ -1,9 +1,11 @@ +using MfGames.Nitride.Generators; + namespace MfGames.Nitride.Json; /// /// A marker class that indicates that the entity is JSON. /// -public record IsJson +[SingletonComponent] +public partial class IsJson { - public static IsJson Instance { get; } = new(); } diff --git a/src/MfGames.Nitride.Json/IsJsonExtensions.cs b/src/MfGames.Nitride.Json/IsJsonExtensions.cs deleted file mode 100644 index 37e3291..0000000 --- a/src/MfGames.Nitride.Json/IsJsonExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using MfGames.Gallium; - -namespace MfGames.Nitride.Json; - -public static class IsJsonExtensions -{ - public static Entity RemoveIsJson(this Entity entity) - { - return entity.Remove(); - } - - public static Entity SetIsJson(this Entity entity) - { - return entity.Set(IsJson.Instance); - } -} diff --git a/src/MfGames.Nitride.Markdown/IsMarkdown.cs b/src/MfGames.Nitride.Markdown/IsMarkdown.cs index 3a64e82..e190bba 100644 --- a/src/MfGames.Nitride.Markdown/IsMarkdown.cs +++ b/src/MfGames.Nitride.Markdown/IsMarkdown.cs @@ -1,9 +1,11 @@ +using MfGames.Nitride.Generators; + namespace MfGames.Nitride.Markdown; /// /// A marker class that indicates that the file is a Markdown file. /// -public record IsMarkdown +[SingletonComponent] +public partial class IsMarkdown { - public static IsMarkdown Instance { get; } = new(); } diff --git a/src/MfGames.Nitride.Yaml/IsYaml.cs b/src/MfGames.Nitride.Yaml/IsYaml.cs index d3046e2..23dadfd 100644 --- a/src/MfGames.Nitride.Yaml/IsYaml.cs +++ b/src/MfGames.Nitride.Yaml/IsYaml.cs @@ -1,9 +1,11 @@ +using MfGames.Nitride.Generators; + namespace MfGames.Nitride.Yaml; /// /// A marker class that indicates that the entity is YAML. /// -public record IsYaml +[SingletonComponent] +public partial class IsYaml { - public static IsYaml Instance { get; } = new(); } diff --git a/src/MfGames.Nitride.Yaml/IsYamlExtensions.cs b/src/MfGames.Nitride.Yaml/IsYamlExtensions.cs deleted file mode 100644 index 8cc6e76..0000000 --- a/src/MfGames.Nitride.Yaml/IsYamlExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using MfGames.Gallium; - -namespace MfGames.Nitride.Yaml; - -public static class IsYamlExtensions -{ - public static Entity RemoveIsYaml(this Entity entity) - { - return entity.Remove(); - } - - public static Entity SetIsYaml(this Entity entity) - { - return entity.Set(IsYaml.Instance); - } -} diff --git a/src/MfGames.Nitride.Yaml/MfGames.Nitride.Yaml.csproj b/src/MfGames.Nitride.Yaml/MfGames.Nitride.Yaml.csproj index 6efc5cd..1093a94 100644 --- a/src/MfGames.Nitride.Yaml/MfGames.Nitride.Yaml.csproj +++ b/src/MfGames.Nitride.Yaml/MfGames.Nitride.Yaml.csproj @@ -10,12 +10,12 @@ - + - - + +