Skip to content

Commit

Permalink
Pass local variables from loops to components and slots
Browse files Browse the repository at this point in the history
  • Loading branch information
araszka committed Feb 8, 2024
1 parent 8a33ab2 commit 404c6b7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/ManiaTemplates/Lib/MtTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ MtComponent rootComponent
{
_renderMethods.Add(
renderMethodName,
CreateComponentRenderMethod(component, renderMethodName, componentBody)
CreateComponentRenderMethod(component, renderMethodName, componentBody, currentContext)
);
}
Expand All @@ -450,6 +450,12 @@ MtComponent rootComponent
//Create available arguments
var renderArguments = new List<string>();
//Add local variables to component render method call
foreach (var localVariableName in currentContext.Keys)
{
renderArguments.Add($"{localVariableName}: {localVariableName}");
}
//Attach attributes to render method call
foreach (var (attributeName, attributeValue) in attributeList)
Expand Down Expand Up @@ -489,7 +495,7 @@ MtComponent rootComponent
var slotArguments = new HashSet<string>();
//Add local variables
//Add local variables to slot render call
foreach (var localVariableName in currentContext.Keys)
{
slotArguments.Add($"{localVariableName}: {localVariableName}");
Expand Down Expand Up @@ -539,7 +545,7 @@ MtComponent rootComponent
/// <summary>
/// Creates the method which renders the contents of a component.
/// </summary>
private string CreateComponentRenderMethod(MtComponent component, string renderMethodName, string componentBody)
private string CreateComponentRenderMethod(MtComponent component, string renderMethodName, string componentBody, MtDataContext currentContext)
{
var renderMethod = new StringBuilder(_maniaTemplateLanguage.FeatureBlockStart())
.Append("private void ")
Expand All @@ -548,6 +554,12 @@ private string CreateComponentRenderMethod(MtComponent component, string renderM
//open method arguments
var arguments = new List<string>();
//Add local variables to component render method call
foreach (var (localVariableName, localVariableType) in currentContext)
{
arguments.Add($"{localVariableType} {localVariableName}");
}
//add slot render methods
AppendSlotRenderArgumentsToList(arguments, component);
Expand Down

0 comments on commit 404c6b7

Please sign in to comment.