Skip to content

Commit 67ebf13

Browse files
cornerloanLifeHckr
authored andcommitted
events now on the map, events now have prerequisites
Hope you like Italian, I'm making spaghetti
1 parent f93670a commit 67ebf13

4 files changed

Lines changed: 40 additions & 21 deletions

File tree

Classes/Events/EventDatabase.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,9 @@ public partial class EventDatabase
1212
new EventTemplate(
1313
1,
1414
"EVENT_EVENT1_DESC",
15-
new string[] { "EVENT_EVENT1_OPTION1", "EVENT_EVENT1_OPTION2", "EVENT_EVENT1_OPTION3" },
16-
new string[]
17-
{
18-
"EVENT_EVENT1_OUTCOME1",
19-
"EVENT_EVENT1_OUTCOME2",
20-
"EVENT_EVENT1_OUTCOME3",
21-
},
22-
new EventAction[]
23-
{
15+
["EVENT_EVENT1_OPTION1", "EVENT_EVENT1_OPTION2", "EVENT_EVENT1_OPTION3"],
16+
["EVENT_EVENT1_OUTCOME1", "EVENT_EVENT1_OUTCOME2", "EVENT_EVENT1_OUTCOME3"],
17+
[
2418
() =>
2519
{
2620
int randIndex = StageProducer.GlobalRng.RandiRange(
@@ -39,10 +33,15 @@ public partial class EventDatabase
3933
},
4034
() =>
4135
{
42-
StageProducer.PlayerStats.Money = (int)StageProducer.PlayerStats.Money / 2;
36+
StageProducer.PlayerStats.Money /= 2;
4337
},
44-
},
45-
GD.Load<Texture2D>("res://Classes/Events/Assets/TEMP.png")
38+
],
39+
GD.Load<Texture2D>("res://Classes/Events/Assets/TEMP.png"),
40+
[
41+
() => StageProducer.PlayerStats.CurNotes.Length > 0,
42+
() => StageProducer.PlayerStats.CurRelics.Length > 0,
43+
() => StageProducer.PlayerStats.Money > 0,
44+
]
4645
),
4746
};
4847
}

Classes/Events/EventTemplate.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Godot;
44

55
public delegate void EventAction();
6+
public delegate bool EventCondition();
67

78
public partial class EventTemplate
89
{
@@ -14,6 +15,7 @@ public partial class EventTemplate
1415

1516
// Note: Actions are NOT exported since delegates cannot be serialized
1617
public EventAction[] OptionActions;
18+
public EventCondition[] OptionEnabledConditions;
1719

1820
public EventTemplate() { }
1921

@@ -23,7 +25,8 @@ public EventTemplate(
2325
string[] buttonDescriptions,
2426
string[] outcomeDescriptions,
2527
EventAction[] optionActions,
26-
Texture2D texture
28+
Texture2D texture,
29+
EventCondition[] optionEnabledConditions = null
2730
)
2831
{
2932
Id = id;
@@ -32,5 +35,6 @@ Texture2D texture
3235
OutcomeDescriptions = outcomeDescriptions;
3336
OptionActions = optionActions;
3437
Texture = texture;
38+
OptionEnabledConditions = optionEnabledConditions;
3539
}
3640
}

Globals/StageProducer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ public void PreloadScene(int nextRoomIdx)
143143
break;
144144
case Stages.Shop:
145145
case Stages.Event:
146+
_loadTask = Task.Run(() =>
147+
{
148+
_preloadStage = GD.Load<PackedScene>(EventScene.LoadPath).Instantiate<Node>();
149+
});
150+
break;
146151
case Stages.Chest:
147152
_loadTask = Task.Run(() =>
148153
{

Scenes/EventScene/EventScene.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public partial class EventScene : Node
66
{
7-
public static readonly string LoadPath = "res://Scenes/ChestScene/ChestScene.tscn";
7+
public static readonly string LoadPath = "res://Scenes/EventScene/EventScene.tscn";
88
private PlayerPuppet _player;
99

1010
[Export]
@@ -23,23 +23,25 @@ public partial class EventScene : Node
2323

2424
private EventTemplate _eventReference;
2525

26-
public static EventScene NewEventScene(int eventId = 0)
26+
public static EventScene NewEventScene()
2727
{
2828
EventScene result = GD.Load<PackedScene>(LoadPath).Instantiate<EventScene>();
2929
result._player = GD.Load<PackedScene>(PlayerPuppet.LoadPath).Instantiate<PlayerPuppet>();
3030
result.PlayerMarker.AddChild(result._player);
31-
result.DisplayEvent(eventId);
31+
result.DisplayEvent();
3232
return result;
3333
}
3434

3535
//Eventually remove this, once integrated into game
3636
public override void _Ready()
3737
{
38+
GD.Print("loaded event");
3839
_player = GD.Load<PackedScene>(PlayerPuppet.LoadPath).Instantiate<PlayerPuppet>();
3940
PlayerMarker.AddChild(_player);
4041

42+
//int eventIndex = StageProducer.GlobalRng.RandiRange(0, EventDatabase.EventDictionary.Length);
4143
_eventReference = EventDatabase.EventDictionary[0];
42-
DisplayEvent(0);
44+
DisplayEvent();
4345
}
4446

4547
public override void _Process(double delta)
@@ -54,7 +56,7 @@ public override void _Process(double delta)
5456
/// Displays the event with the given index.
5557
/// </summary>
5658
/// <param name="eventIndex">Index of the event in EventDatabase.</param>
57-
public void DisplayEvent(int eventIndex)
59+
public void DisplayEvent()
5860
{
5961
_eventDescription.Text = _eventReference.EventDescription;
6062
EventSprite.Texture = _eventReference.Texture;
@@ -65,18 +67,27 @@ public void DisplayEvent(int eventIndex)
6567
{
6668
Text = _eventReference.ButtonDescriptions[i],
6769
Theme = _buttonTheme,
70+
SizeFlagsVertical = Control.SizeFlags.Expand | Control.SizeFlags.Fill,
6871
};
6972

70-
button.SizeFlagsVertical = Control.SizeFlags.Expand | Control.SizeFlags.Fill;
73+
// Check if the button should be enabled
74+
bool isEnabled =
75+
_eventReference.OptionEnabledConditions == null
76+
|| _eventReference.OptionEnabledConditions.Length <= i
77+
|| _eventReference.OptionEnabledConditions[i]?.Invoke() != false;
7178

72-
int capturedIndex = i; // was given a warning to capture the index
79+
button.Disabled = !isEnabled;
80+
81+
int capturedIndex = i;
7382
button.Pressed += () =>
7483
{
7584
GD.Print($"Selected option: {_eventReference.ButtonDescriptions[capturedIndex]}");
7685
_eventReference.OptionActions[capturedIndex]?.Invoke();
7786
AnyButtonPressed(capturedIndex);
7887
};
79-
if (capturedIndex == 0)
88+
89+
// Automatically focus the first *enabled* button
90+
if (capturedIndex == 0 && isEnabled)
8091
{
8192
button.CallDeferred("grab_focus");
8293
}

0 commit comments

Comments
 (0)