Skip to content

Commit e867de9

Browse files
committed
Added support for generating custom variables in Gum component states
Added auto test for ^^
1 parent fe2a8b9 commit e867de9

File tree

9 files changed

+719
-537
lines changed

9 files changed

+719
-537
lines changed

FRBDK/Glue/GumPlugin/GumPlugin/CodeGeneration/StateCodeGenerator.cs

Lines changed: 500 additions & 492 deletions
Large diffs are not rendered by default.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ComponentSave xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3+
<Name>ComponentWithCustomVariables</Name>
4+
<BaseType>Container</BaseType>
5+
<State>
6+
<Name>Default</Name>
7+
<Variable>
8+
<Type>bool</Type>
9+
<Name>BoolDefaultTrue</Name>
10+
<Value xsi:type="xsd:boolean">true</Value>
11+
<SetsValue>true</SetsValue>
12+
<IsCustomVariable>true</IsCustomVariable>
13+
</Variable>
14+
<Variable>
15+
<Type>float</Type>
16+
<Name>FloatDefault1f</Name>
17+
<Value xsi:type="xsd:float">1</Value>
18+
<SetsValue>true</SetsValue>
19+
<IsCustomVariable>true</IsCustomVariable>
20+
</Variable>
21+
<Variable>
22+
<Type>int</Type>
23+
<Name>IntDefault25</Name>
24+
<Value xsi:type="xsd:int">25</Value>
25+
<SetsValue>true</SetsValue>
26+
<IsCustomVariable>true</IsCustomVariable>
27+
</Variable>
28+
<Variable>
29+
<Type>State</Type>
30+
<Name>State</Name>
31+
<Value xsi:type="xsd:string">Default</Value>
32+
<Category>States and Visibility</Category>
33+
<SetsValue>false</SetsValue>
34+
</Variable>
35+
<Variable>
36+
<Type>string</Type>
37+
<Name>StringDefaultabcd</Name>
38+
<Value xsi:type="xsd:string">abcd</Value>
39+
<SetsValue>true</SetsValue>
40+
<IsCustomVariable>true</IsCustomVariable>
41+
</Variable>
42+
</State>
43+
<Behaviors />
44+
</ComponentSave>

Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Content/GumProject/EventExport/gum_events.json

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,6 @@
33
"vchel": [],
44
"Owner": [],
55
"d1638316d18f4a1e23a287aaaa12b6c540f704e257a6549bc9a672497ccc934e": [
6-
{
7-
"NewName": "TestScreen.ColoredRectangleInstance1",
8-
"OldName": null,
9-
"ElementType": "Screens",
10-
"EventType": 5,
11-
"TimestampUtc": "2025-03-07T12:27:01.4154925Z"
12-
},
13-
{
14-
"NewName": "TestScreen.RectangleWithInvalidParent",
15-
"OldName": "TestScreen.ColoredRectangleInstance1",
16-
"ElementType": "Screens",
17-
"EventType": 7,
18-
"TimestampUtc": "2025-03-07T12:27:15.5787244Z"
19-
},
20-
{
21-
"NewName": "TestScreen.RectangleWithInvalidParent",
22-
"OldName": "TestScreen.ColoredRectangleInstance1",
23-
"ElementType": "Screens",
24-
"EventType": 7,
25-
"TimestampUtc": "2025-03-07T12:27:15.5797247Z"
26-
},
27-
{
28-
"NewName": "TestScreen.RectangleWithInvalidParent",
29-
"OldName": "TestScreen.ColoredRectangleInstance1",
30-
"ElementType": "Screens",
31-
"EventType": 7,
32-
"TimestampUtc": "2025-03-07T12:27:15.5797247Z"
33-
},
34-
{
35-
"NewName": "TestScreen.RectangleWithInvalidParent",
36-
"OldName": "TestScreen.ColoredRectangleInstance1",
37-
"ElementType": "Screens",
38-
"EventType": 7,
39-
"TimestampUtc": "2025-03-07T12:27:15.5807245Z"
40-
},
41-
{
42-
"NewName": "TestScreen.RectangleWithInvalidParent",
43-
"OldName": "TestScreen.ColoredRectangleInstance1",
44-
"ElementType": "Screens",
45-
"EventType": 7,
46-
"TimestampUtc": "2025-03-07T12:27:15.5817245Z"
47-
},
486
{
497
"NewName": "TestScreen.SpriteInstance",
508
"OldName": null,
@@ -100,6 +58,62 @@
10058
"ElementType": "Screens",
10159
"EventType": 5,
10260
"TimestampUtc": "2025-03-17T12:43:57.5372718Z"
61+
},
62+
{
63+
"NewName": "ComponentWithCustomVariables",
64+
"OldName": null,
65+
"ElementType": "Components",
66+
"EventType": 0,
67+
"TimestampUtc": "2025-03-24T23:45:15.5153562Z"
68+
},
69+
{
70+
"NewName": "TestScreen.ComponentWithCustomVariablesInstance",
71+
"OldName": null,
72+
"ElementType": "Screens",
73+
"EventType": 5,
74+
"TimestampUtc": "2025-03-24T23:46:20.9059763Z"
75+
},
76+
{
77+
"NewName": "TestScreen.ComponentWithCustomVariablesInstance1",
78+
"OldName": null,
79+
"ElementType": "Screens",
80+
"EventType": 5,
81+
"TimestampUtc": "2025-03-25T00:15:48.7117315Z"
82+
},
83+
{
84+
"NewName": "TestScreen.CustomVariablesOnInstance",
85+
"OldName": "TestScreen.ComponentWithCustomVariablesInstance1",
86+
"ElementType": "Screens",
87+
"EventType": 7,
88+
"TimestampUtc": "2025-03-25T00:16:00.3648276Z"
89+
},
90+
{
91+
"NewName": "TestScreen.CustomVariablesOnInstance",
92+
"OldName": "TestScreen.ComponentWithCustomVariablesInstance1",
93+
"ElementType": "Screens",
94+
"EventType": 7,
95+
"TimestampUtc": "2025-03-25T00:16:00.3668298Z"
96+
},
97+
{
98+
"NewName": "TestScreen.CustomVariablesOnInstance",
99+
"OldName": "TestScreen.ComponentWithCustomVariablesInstance1",
100+
"ElementType": "Screens",
101+
"EventType": 7,
102+
"TimestampUtc": "2025-03-25T00:16:00.36783Z"
103+
},
104+
{
105+
"NewName": "TestScreen.CustomVariablesOnInstance",
106+
"OldName": "TestScreen.ComponentWithCustomVariablesInstance1",
107+
"ElementType": "Screens",
108+
"EventType": 7,
109+
"TimestampUtc": "2025-03-25T00:16:00.3688317Z"
110+
},
111+
{
112+
"NewName": "TestScreen.CustomVariablesOnInstance",
113+
"OldName": "TestScreen.ComponentWithCustomVariablesInstance1",
114+
"ElementType": "Screens",
115+
"EventType": 7,
116+
"TimestampUtc": "2025-03-25T00:16:00.3688317Z"
103117
}
104118
]
105119
}

Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Content/GumProject/GumProject.gumx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@
149149
<ElementType>Component</ElementType>
150150
<LinkType>ReferenceOriginal</LinkType>
151151
</ComponentReference>
152+
<ComponentReference>
153+
<Name>ComponentWithCustomVariables</Name>
154+
<ElementType>Component</ElementType>
155+
<LinkType>ReferenceOriginal</LinkType>
156+
</ComponentReference>
152157
<ComponentReference>
153158
<Name>ContainerOfInFolder</Name>
154159
<ElementType>Component</ElementType>

Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Content/GumProject/Screens/TestScreen.gusx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@
428428
<Value xsi:type="xsd:float">-24</Value>
429429
<SetsValue>true</SetsValue>
430430
</Variable>
431+
<Variable>
432+
<Type>float</Type>
433+
<Name>ComponentWithCustomVariablesInstance.X</Name>
434+
<Value xsi:type="xsd:float">153</Value>
435+
<SetsValue>true</SetsValue>
436+
</Variable>
437+
<Variable>
438+
<Type>float</Type>
439+
<Name>ComponentWithCustomVariablesInstance.Y</Name>
440+
<Value xsi:type="xsd:float">-173</Value>
441+
<SetsValue>true</SetsValue>
442+
</Variable>
431443
<Variable>
432444
<Type>float</Type>
433445
<Name>ContainerInstance.X</Name>
@@ -440,6 +452,42 @@
440452
<Value xsi:type="xsd:float">415</Value>
441453
<SetsValue>true</SetsValue>
442454
</Variable>
455+
<Variable>
456+
<Type>bool</Type>
457+
<Name>CustomVariablesOnInstance.BoolDefaultTrue</Name>
458+
<Value xsi:type="xsd:boolean">false</Value>
459+
<SetsValue>true</SetsValue>
460+
</Variable>
461+
<Variable>
462+
<Type>float</Type>
463+
<Name>CustomVariablesOnInstance.FloatDefault1f</Name>
464+
<Value xsi:type="xsd:float">2</Value>
465+
<SetsValue>true</SetsValue>
466+
</Variable>
467+
<Variable>
468+
<Type>int</Type>
469+
<Name>CustomVariablesOnInstance.IntDefault25</Name>
470+
<Value xsi:type="xsd:int">50</Value>
471+
<SetsValue>true</SetsValue>
472+
</Variable>
473+
<Variable>
474+
<Type>string</Type>
475+
<Name>CustomVariablesOnInstance.StringDefaultabcd</Name>
476+
<Value xsi:type="xsd:string">efgh</Value>
477+
<SetsValue>true</SetsValue>
478+
</Variable>
479+
<Variable>
480+
<Type>float</Type>
481+
<Name>CustomVariablesOnInstance.X</Name>
482+
<Value xsi:type="xsd:float">329</Value>
483+
<SetsValue>true</SetsValue>
484+
</Variable>
485+
<Variable>
486+
<Type>float</Type>
487+
<Name>CustomVariablesOnInstance.Y</Name>
488+
<Value xsi:type="xsd:float">-176</Value>
489+
<SetsValue>true</SetsValue>
490+
</Variable>
443491
<Variable>
444492
<IsFile>true</IsFile>
445493
<Type>string</Type>
@@ -1904,5 +1952,15 @@ wrap the text.</Value>
19041952
<BaseType>ColoredRectangle</BaseType>
19051953
<DefinedByBase>false</DefinedByBase>
19061954
</Instance>
1955+
<Instance>
1956+
<Name>ComponentWithCustomVariablesInstance</Name>
1957+
<BaseType>ComponentWithCustomVariables</BaseType>
1958+
<DefinedByBase>false</DefinedByBase>
1959+
</Instance>
1960+
<Instance>
1961+
<Name>CustomVariablesOnInstance</Name>
1962+
<BaseType>ComponentWithCustomVariables</BaseType>
1963+
<DefinedByBase>false</DefinedByBase>
1964+
</Instance>
19071965
<Behaviors />
19081966
</ScreenSave>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace GlueTestProject.GumRuntimes
6+
{
7+
public partial class ComponentWithCustomVariablesRuntime
8+
{
9+
partial void CustomInitialize ()
10+
{
11+
}
12+
}
13+
}

Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/GumScreen.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,29 @@ void CustomInitialize()
8989
TextGue_ShouldTruncate_WhenSetToTruncate();
9090

9191
ItemInScreen_ShouldHaveScreenParent_WhenInvalidParentIsAssignedInGum();
92+
93+
CustomVariables_ShouldBeSetToDefaults();
94+
95+
CustomVariables_ShouldMatchInstanceValues();
96+
}
97+
98+
private void CustomVariables_ShouldMatchInstanceValues()
99+
{
100+
var instance = EntireGumScreen.CustomVariablesOnInstance;
101+
102+
instance.IntDefault25.ShouldBe(50);
103+
instance.FloatDefault1f.ShouldBe(2.0f);
104+
instance.StringDefaultabcd.ShouldBe("efgh");
105+
instance.BoolDefaultTrue.ShouldBe(false);
106+
}
107+
108+
private void CustomVariables_ShouldBeSetToDefaults()
109+
{
110+
var instance = EntireGumScreen.ComponentWithCustomVariablesInstance;
111+
instance.IntDefault25.ShouldBe(25);
112+
instance.FloatDefault1f.ShouldBe(1f);
113+
instance.StringDefaultabcd.ShouldBe("abcd");
114+
instance.BoolDefaultTrue.ShouldBe(true);
92115
}
93116

94117
private void ItemInScreen_ShouldHaveScreenParent_WhenInvalidParentIsAssignedInGum()

Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/ManuallyUpdatedScreen.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ void CustomActivity(bool firstTimeCalled)
204204

205205
TestDetachedManualUpdateAccelerationVariables();
206206

207-
TestAttachedManualUpdateVariables();
208207

209208
TestManualUpdateRelativeVelocityVariables();
210209

@@ -219,7 +218,13 @@ void CustomActivity(bool firstTimeCalled)
219218

220219
}
221220

222-
if (this.PauseAdjustedCurrentTime > .6f && hasTestedAttachment)
221+
if(hasCalledCustomUpdateDependencies)
222+
{
223+
TestAttachedManualUpdateVariables();
224+
225+
}
226+
227+
if (this.PauseAdjustedCurrentTime > .6f && hasTestedAttachment && hasCalledCustomUpdateDependencies)
223228
{
224229
// UpdateDependencies is only called when there is a draw,
225230
// and multiple draws may be skipped if fps is low enough
@@ -346,7 +351,11 @@ private void TestEntityInListAttachedToObject()
346351

347352

348353
#endregion
349-
354+
bool hasCalledCustomUpdateDependencies = false;
355+
partial void CustomUpdateDependencies(double currentTime)
356+
{
357+
hasCalledCustomUpdateDependencies = true;
358+
}
350359
void CustomDestroy()
351360
{
352361
TextManager.RemoveText(manuallyUpdatedTextInCode);

Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/TestProjectDesktopNet6.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@
530530
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
531531
<Name>ComponentWithCustomInitialize</Name>
532532
</None>
533+
<None Include="Content\GumProject\Components\ComponentWithCustomVariables.gucx">
534+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
535+
<Name>ComponentWithCustomVariables</Name>
536+
</None>
533537
<None Include="Content\GumProject\Components\ContainerOfInFolder.gucx">
534538
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
535539
<Name>ContainerOfInFolder</Name>
@@ -2032,6 +2036,10 @@
20322036
<Compile Include="GumRuntimes\ComponentWithCustomInitializeRuntime.Generated.cs">
20332037
<DependentUpon>ComponentWithCustomInitializeRuntime.cs</DependentUpon>
20342038
</Compile>
2039+
<Compile Include="GumRuntimes\ComponentWithCustomVariablesRuntime.cs" />
2040+
<Compile Include="GumRuntimes\ComponentWithCustomVariablesRuntime.Generated.cs">
2041+
<DependentUpon>ComponentWithCustomVariablesRuntime.cs</DependentUpon>
2042+
</Compile>
20352043
<Compile Include="GumRuntimes\ContainerOfInFolderRuntime.cs" />
20362044
<Compile Include="GumRuntimes\ContainerOfInFolderRuntime.Generated.cs">
20372045
<DependentUpon>ContainerOfInFolderRuntime.cs</DependentUpon>

0 commit comments

Comments
 (0)