Skip to content

Commit 387f3a9

Browse files
cornerloanLifeHckr
authored andcommitted
async? more like not async
if we have any events that have multiple different text outputs based on RNG we should set their initial output to ""
1 parent d4b994f commit 387f3a9

3 files changed

Lines changed: 69 additions & 72 deletions

File tree

Classes/Events/EventDatabase.cs

Lines changed: 58 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Threading.Tasks;
32
using Godot;
43

54
/// <summary>
@@ -15,23 +14,23 @@ public partial class EventDatabase
1514
["EVENT_EVENT1_OPTION1", "EVENT_EVENT1_OPTION2", "EVENT_EVENT1_OPTION3"],
1615
["EVENT_EVENT1_OUTCOME1", "EVENT_EVENT1_OUTCOME2", "EVENT_EVENT1_OUTCOME3"],
1716
[
18-
async (self, node) =>
17+
(self, node) =>
1918
{
2019
int randIndex = StageProducer.GlobalRng.RandiRange(
2120
0,
2221
StageProducer.PlayerStats.CurNotes.Length
2322
);
2423
StageProducer.PlayerStats.RemoveNote(randIndex);
2524
},
26-
async (self, node) =>
25+
(self, node) =>
2726
{
2827
int randIndex = StageProducer.GlobalRng.RandiRange(
2928
0,
3029
StageProducer.PlayerStats.CurRelics.Length
3130
);
3231
StageProducer.PlayerStats.RemoveRelic(randIndex);
3332
},
34-
async (self, node) =>
33+
(self, node) =>
3534
{
3635
StageProducer.PlayerStats.Money /= 2;
3736
},
@@ -49,10 +48,10 @@ public partial class EventDatabase
4948
["EVENT_EVENT2_OPTION1", "EVENT_EVENT2_OPTION2"],
5049
["", "EVENT_EVENT2_OUTCOME1"],
5150
[
52-
async (self, node) =>
51+
(self, node) =>
5352
{
5453
var spinner = node.GetNodeOrNull<Sprite2D>("EventSprite");
55-
int spinOutcome = (int)StageProducer.GlobalRng.RandWeighted([1, 1, 1, 1, 1, 1]);
54+
int spinOutcome = (int)StageProducer.GlobalRng.RandiRange(0, 5);
5655

5756
int outcomeCount = 6;
5857
float sectorAngle = 360f / outcomeCount;
@@ -66,61 +65,57 @@ public partial class EventDatabase
6665
.SetTrans(Tween.TransitionType.Cubic)
6766
.SetEase(Tween.EaseType.Out);
6867

69-
var tcs = new TaskCompletionSource<bool>();
70-
tween.TweenCallback(Callable.From(() => tcs.SetResult(true)));
71-
await tcs.Task;
72-
73-
switch (spinOutcome)
74-
{
75-
case 0:
76-
GD.Print("lost half money");
77-
StageProducer.PlayerStats.Money /= 2;
78-
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME2";
79-
break;
80-
case 1:
81-
GD.Print("took damage");
82-
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME3";
83-
StageProducer.PlayerStats.CurrentHealth = Math.Max(
84-
1,
85-
StageProducer.PlayerStats.CurrentHealth - 10
86-
);
87-
break;
88-
case 2:
89-
GD.Print("gain money");
90-
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME4";
91-
StageProducer.PlayerStats.Money += 50;
92-
break;
93-
case 3:
94-
GD.Print("random note");
95-
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME5";
96-
StageProducer.PlayerStats.AddNote(
97-
Scribe.GetRandomRewardNotes(1, StageProducer.CurRoom + 10)[0]
98-
);
99-
break;
100-
case 4:
101-
GD.Print("random relic");
102-
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME6";
103-
StageProducer.PlayerStats.AddRelic(
104-
Scribe.GetRandomRelics(
105-
1,
106-
StageProducer.CurRoom + 10,
107-
StageProducer.PlayerStats.RarityOdds
108-
)[0]
109-
);
110-
break;
111-
case 5:
112-
GD.Print("heal");
113-
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME7";
114-
StageProducer.PlayerStats.CurrentHealth = Math.Min(
115-
StageProducer.PlayerStats.CurrentHealth + 20,
116-
StageProducer.PlayerStats.MaxHealth
117-
);
118-
break;
119-
}
120-
121-
GD.Print($"new description {self.OutcomeDescriptions[0]}");
68+
// Defer execution of the outcome until the tween finishes
69+
tween.TweenCallback(
70+
Callable.From(() =>
71+
{
72+
switch (spinOutcome)
73+
{
74+
case 0:
75+
StageProducer.PlayerStats.Money /= 2;
76+
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME2";
77+
break;
78+
case 1:
79+
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME3";
80+
StageProducer.PlayerStats.CurrentHealth = Math.Max(
81+
1,
82+
StageProducer.PlayerStats.CurrentHealth - 10
83+
);
84+
break;
85+
case 2:
86+
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME4";
87+
StageProducer.PlayerStats.Money += 50;
88+
break;
89+
case 3:
90+
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME5";
91+
StageProducer.PlayerStats.AddNote(
92+
Scribe.GetRandomRewardNotes(1, StageProducer.CurRoom + 10)[
93+
0
94+
]
95+
);
96+
break;
97+
case 4:
98+
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME6";
99+
StageProducer.PlayerStats.AddRelic(
100+
Scribe.GetRandomRelics(
101+
1,
102+
StageProducer.CurRoom + 10,
103+
StageProducer.PlayerStats.RarityOdds
104+
)[0]
105+
);
106+
break;
107+
case 5:
108+
self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME7";
109+
StageProducer.PlayerStats.CurrentHealth = Math.Min(
110+
StageProducer.PlayerStats.CurrentHealth + 20,
111+
StageProducer.PlayerStats.MaxHealth
112+
);
113+
break;
114+
}
115+
})
116+
);
122117
},
123-
async (self, node) => {
118+
(self, node) => {
124119
// does nothing
125120
},
126121
],
@@ -133,18 +128,18 @@ public partial class EventDatabase
133128
["EVENT_EVENT3_OPTION1", "EVENT_EVENT3_OPTION2", "EVENT_EVENT3_OPTION3"],
134129
["EVENT_EVENT3_OUTCOME1", "EVENT_EVENT3_OUTCOME2", "EVENT_EVENT3_OUTCOME3"],
135130
[
136-
async (self, node) =>
131+
(self, node) =>
137132
{
138133
StageProducer.PlayerStats.CurrentHealth = Math.Min(
139134
StageProducer.PlayerStats.CurrentHealth + 10,
140135
StageProducer.PlayerStats.MaxHealth
141136
);
142137
},
143-
async (self, node) =>
138+
(self, node) =>
144139
{
145140
StageProducer.PlayerStats.MaxComboBar -= 5;
146141
},
147-
async (self, node) =>
142+
(self, node) =>
148143
{
149144
StageProducer.PlayerStats.Money -= 30;
150145
StageProducer.PlayerStats.AddNote(Scribe.NoteDictionary[3]);

Classes/Events/EventTemplate.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System;
2-
using System.Threading.Tasks;
32
using Godot;
43

5-
public delegate Task EventAction(EventTemplate self, Node contextNode);
4+
public delegate void EventAction(EventTemplate self, Node contextNode);
65
public delegate bool EventCondition();
76

87
public partial class EventTemplate

Scenes/EventScene/EventScene.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public partial class EventScene : Node
2222
private static Theme _buttonTheme = GD.Load<Theme>("res://Scenes/UI/Assets/GeneralTheme.tres"); // Store the theme
2323

2424
private EventTemplate _eventReference;
25+
private int updateOutputIndex;
2526

2627
public static EventScene NewEventScene()
2728
{
@@ -53,6 +54,11 @@ public override void _Process(double delta)
5354
{
5455
_buttonContainer.GetChild<Control>(0).GrabFocus();
5556
}
57+
58+
if (_eventDescription.Text == "")
59+
{
60+
_eventDescription.Text = _eventReference.OutcomeDescriptions[updateOutputIndex];
61+
}
5662
}
5763

5864
/// <summary>
@@ -82,15 +88,10 @@ public void DisplayEvent()
8288
button.Disabled = !isEnabled;
8389

8490
int capturedIndex = i;
85-
button.Pressed += async () =>
91+
button.Pressed += () =>
8692
{
8793
GD.Print($"Selected option: {_eventReference.ButtonDescriptions[capturedIndex]}");
88-
89-
var action = _eventReference.OptionActions[capturedIndex];
90-
if (action != null)
91-
{
92-
await action(_eventReference, this);
93-
}
94+
_eventReference.OptionActions[capturedIndex]?.Invoke(_eventReference, this);
9495
AnyButtonPressed(capturedIndex);
9596
};
9697

@@ -106,6 +107,8 @@ public void DisplayEvent()
106107

107108
private void AnyButtonPressed(int capturedIndex)
108109
{
110+
updateOutputIndex = capturedIndex;
111+
109112
foreach (var choices in _buttonContainer.GetChildren())
110113
{
111114
if (choices is not Button)

0 commit comments

Comments
 (0)