From 23e52788a01258875d23477647a000b47f1bd49f Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Wed, 19 Mar 2025 23:47:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D0=BD=D0=B0=D1=8F=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=20?= =?UTF-8?q?=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mROA.CodegenTools/InsertTemplatePart.cs | 2 +- mROA.CodegenTools/ProgrammableTextPart.cs | 24 +++++++++++++++++++++++ mROA.CodegenTools/TemplateDocument.cs | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 mROA.CodegenTools/ProgrammableTextPart.cs diff --git a/mROA.CodegenTools/InsertTemplatePart.cs b/mROA.CodegenTools/InsertTemplatePart.cs index fd9ac4d..26ead20 100644 --- a/mROA.CodegenTools/InsertTemplatePart.cs +++ b/mROA.CodegenTools/InsertTemplatePart.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace mROA.CodegenTools { - public class InsertTemplatePart : ITemplatePart, ITagged + public class InsertTemplatePart : ITagged { private object _insertedValue; private string _tag; diff --git a/mROA.CodegenTools/ProgrammableTextPart.cs b/mROA.CodegenTools/ProgrammableTextPart.cs new file mode 100644 index 0000000..132bbcf --- /dev/null +++ b/mROA.CodegenTools/ProgrammableTextPart.cs @@ -0,0 +1,24 @@ +using System; + +namespace mROA.CodegenTools +{ + public class ProgrammableTextPart : ITemplatePart + { + public TemplateDocument Context { get; set; } + public int TargetLength => 0; + + private Func _bakeFunc; + + public ProgrammableTextPart(Func bakeFunc, TemplateDocument context) + { + _bakeFunc = bakeFunc; + Context = context; + } + + + public string Bake() + { + return _bakeFunc(Context.AdditionalContext); + } + } +} \ No newline at end of file diff --git a/mROA.CodegenTools/TemplateDocument.cs b/mROA.CodegenTools/TemplateDocument.cs index 85b006f..0f73749 100644 --- a/mROA.CodegenTools/TemplateDocument.cs +++ b/mROA.CodegenTools/TemplateDocument.cs @@ -7,6 +7,7 @@ namespace mROA.CodegenTools public class TemplateDocument { public List Parts { get; } + public object AdditionalContext { get; set; } public ITagged this[string tag] => Parts.OfType().FirstOrDefault(i => i.Tag == tag); public void Insert(string tag, object value) {