Compare commits
2 Commits
7e8ccb061a
...
cdd944b9b5
Author | SHA1 | Date | |
---|---|---|---|
cdd944b9b5 | |||
c0d18507e3 |
23
Mods/Events/good_harvest.json
Normal file
23
Mods/Events/good_harvest.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"id": "event_good_harvest",
|
||||||
|
"title": "Bountiful Harvest",
|
||||||
|
"description": "A miraculous confluence of weather and soil fertility has led to an unexpectedly large harvest. Our granaries are overflowing!",
|
||||||
|
"meanTimeToHappen": 120,
|
||||||
|
"trigger": {
|
||||||
|
"minFollowers": 100,
|
||||||
|
"maxCorruption": 50
|
||||||
|
},
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"text": "A true blessing!",
|
||||||
|
"tooltip": "Gain a large amount (500) of Faith.",
|
||||||
|
"effects": [
|
||||||
|
{
|
||||||
|
"type": "AddResource",
|
||||||
|
"targetResource": "Faith",
|
||||||
|
"value": 500
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=22 format=3 uid="uid://bfil8sd154327"]
|
[gd_scene load_steps=26 format=3 uid="uid://bfil8sd154327"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://t71ewkpa5uqs" path="res://Scenes/Main/Main.cs" id="1_p8rbg"]
|
[ext_resource type="Script" uid="uid://t71ewkpa5uqs" path="res://Scenes/Main/Main.cs" id="1_p8rbg"]
|
||||||
[ext_resource type="Script" uid="uid://b77vh831r1e3c" path="res://Scenes/Main/MiraclePanel.cs" id="2_hcu3t"]
|
[ext_resource type="Script" uid="uid://b77vh831r1e3c" path="res://Scenes/Main/MiraclePanel.cs" id="2_hcu3t"]
|
||||||
@@ -16,10 +16,16 @@
|
|||||||
[ext_resource type="PackedScene" uid="uid://8w7tvsgkev1y" path="res://Scenes/tree.tscn" id="8_hcu3t"]
|
[ext_resource type="PackedScene" uid="uid://8w7tvsgkev1y" path="res://Scenes/tree.tscn" id="8_hcu3t"]
|
||||||
[ext_resource type="Shader" uid="uid://bf8nk145fjkgh" path="res://Shaders/corruption_shader.gdshader" id="9_wgovn"]
|
[ext_resource type="Shader" uid="uid://bf8nk145fjkgh" path="res://Shaders/corruption_shader.gdshader" id="9_wgovn"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cqkye7yykakns" path="res://Scenes/Followers/FollowerMarker.tscn" id="11_5ci8a"]
|
[ext_resource type="PackedScene" uid="uid://cqkye7yykakns" path="res://Scenes/Followers/FollowerMarker.tscn" id="11_5ci8a"]
|
||||||
|
[ext_resource type="Script" uid="uid://djmtle2h3yd2e" path="res://Scripts/Components/PauseManager.cs" id="11_xggvw"]
|
||||||
[ext_resource type="PackedScene" uid="uid://wysxqe44rxhf" path="res://Scenes/TempleMarker.tscn" id="14_udh0u"]
|
[ext_resource type="PackedScene" uid="uid://wysxqe44rxhf" path="res://Scenes/TempleMarker.tscn" id="14_udh0u"]
|
||||||
[ext_resource type="PackedScene" uid="uid://xk2xirjd1sma" path="res://Scenes/moddable_visual.tscn" id="17_qdkat"]
|
[ext_resource type="PackedScene" uid="uid://xk2xirjd1sma" path="res://Scenes/moddable_visual.tscn" id="17_qdkat"]
|
||||||
[ext_resource type="Script" uid="uid://furbvcmw31bx" path="res://Scripts/Components/ForestVisualizer.cs" id="18_qdkat"]
|
[ext_resource type="Script" uid="uid://furbvcmw31bx" path="res://Scripts/Components/ForestVisualizer.cs" id="18_qdkat"]
|
||||||
[ext_resource type="Script" uid="uid://cw8gpeaq3yfjn" path="res://Scripts/Components/RoadManager.cs" id="19_qdkat"]
|
[ext_resource type="Script" uid="uid://cw8gpeaq3yfjn" path="res://Scripts/Components/RoadManager.cs" id="19_qdkat"]
|
||||||
|
[ext_resource type="Script" uid="uid://2ipbgwlx1ld1" path="res://Scripts/Components/EventManager.cs" id="22_iwp64"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://gdejd44km3co" path="res://Scenes/UI/event_popup.tscn" id="23_4etfk"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xggvw"]
|
||||||
|
bg_color = Color(0, 0, 0, 0.733333)
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_cv8e0"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_cv8e0"]
|
||||||
shader = ExtResource("9_wgovn")
|
shader = ExtResource("9_wgovn")
|
||||||
@@ -37,7 +43,10 @@ _productionLabel = NodePath("UiLayer/Control/Main/Top/ProductionLabel")
|
|||||||
_miraclePanel = NodePath("UiLayer/Control/Main/ScrollContainer/Bottom")
|
_miraclePanel = NodePath("UiLayer/Control/Main/ScrollContainer/Bottom")
|
||||||
_worldSprite = NodePath("World Sprite")
|
_worldSprite = NodePath("World Sprite")
|
||||||
|
|
||||||
[node name="UiLayer" type="CanvasLayer" parent="."]
|
[node name="UiLayer" type="CanvasLayer" parent="." node_paths=PackedStringArray("_pauseButton", "_pauseMenu")]
|
||||||
|
script = ExtResource("11_xggvw")
|
||||||
|
_pauseButton = NodePath("MarginContainer/Button")
|
||||||
|
_pauseMenu = NodePath("PanelContainer")
|
||||||
|
|
||||||
[node name="Control" type="Control" parent="UiLayer"]
|
[node name="Control" type="Control" parent="UiLayer"]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
@@ -48,6 +57,7 @@ grow_horizontal = 2
|
|||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
|
mouse_filter = 2
|
||||||
|
|
||||||
[node name="Main" type="MarginContainer" parent="UiLayer/Control"]
|
[node name="Main" type="MarginContainer" parent="UiLayer/Control"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
@@ -58,6 +68,7 @@ grow_horizontal = 2
|
|||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 0
|
size_flags_vertical = 0
|
||||||
|
mouse_filter = 2
|
||||||
theme_override_constants/margin_left = 8
|
theme_override_constants/margin_left = 8
|
||||||
theme_override_constants/margin_top = 8
|
theme_override_constants/margin_top = 8
|
||||||
theme_override_constants/margin_right = 8
|
theme_override_constants/margin_right = 8
|
||||||
@@ -67,6 +78,7 @@ theme_override_constants/margin_bottom = 8
|
|||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 0
|
size_flags_vertical = 0
|
||||||
|
mouse_filter = 2
|
||||||
alignment = 1
|
alignment = 1
|
||||||
|
|
||||||
[node name="FaithLabel" type="Label" parent="UiLayer/Control/Main/Top"]
|
[node name="FaithLabel" type="Label" parent="UiLayer/Control/Main/Top"]
|
||||||
@@ -124,6 +136,44 @@ stream = ExtResource("6_32vk6")
|
|||||||
[node name="BuffAdded" type="AudioStreamPlayer" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"]
|
[node name="BuffAdded" type="AudioStreamPlayer" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"]
|
||||||
stream = ExtResource("7_crdpj")
|
stream = ExtResource("7_crdpj")
|
||||||
|
|
||||||
|
[node name="MarginContainer" type="MarginContainer" parent="UiLayer"]
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
mouse_filter = 2
|
||||||
|
theme_override_constants/margin_left = 4
|
||||||
|
theme_override_constants/margin_top = 4
|
||||||
|
theme_override_constants/margin_right = 4
|
||||||
|
theme_override_constants/margin_bottom = 4
|
||||||
|
|
||||||
|
[node name="Button" type="Button" parent="UiLayer/MarginContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 8
|
||||||
|
size_flags_vertical = 0
|
||||||
|
focus_mode = 0
|
||||||
|
text = "Pause"
|
||||||
|
|
||||||
|
[node name="PanelContainer" type="PanelContainer" parent="UiLayer"]
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
size_flags_horizontal = 4
|
||||||
|
size_flags_vertical = 4
|
||||||
|
mouse_filter = 2
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxFlat_xggvw")
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="UiLayer/PanelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 1
|
||||||
|
text = "Paused"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
|
uppercase = true
|
||||||
|
|
||||||
[node name="Notification Layer" type="CanvasLayer" parent="." node_paths=PackedStringArray("_sfx")]
|
[node name="Notification Layer" type="CanvasLayer" parent="." node_paths=PackedStringArray("_sfx")]
|
||||||
layer = 3
|
layer = 3
|
||||||
script = ExtResource("6_iwp64")
|
script = ExtResource("6_iwp64")
|
||||||
@@ -133,6 +183,13 @@ _sfx = NodePath("Advance Age")
|
|||||||
[node name="Advance Age" type="AudioStreamPlayer" parent="Notification Layer"]
|
[node name="Advance Age" type="AudioStreamPlayer" parent="Notification Layer"]
|
||||||
stream = ExtResource("8_4etfk")
|
stream = ExtResource("8_4etfk")
|
||||||
|
|
||||||
|
[node name="CenterContainer" type="CenterContainer" parent="Notification Layer"]
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
|
||||||
[node name="World Sprite" type="Sprite2D" parent="."]
|
[node name="World Sprite" type="Sprite2D" parent="."]
|
||||||
@@ -5627,3 +5684,9 @@ _unitsPerMarker = 1
|
|||||||
Category = 2
|
Category = 2
|
||||||
_moddableVisualScene = ExtResource("17_qdkat")
|
_moddableVisualScene = ExtResource("17_qdkat")
|
||||||
metadata/_custom_type_script = "uid://dj2wyrq07gfp2"
|
metadata/_custom_type_script = "uid://dj2wyrq07gfp2"
|
||||||
|
|
||||||
|
[node name="EventManager" type="Node" parent="." node_paths=PackedStringArray("_eventPopupContainer")]
|
||||||
|
script = ExtResource("22_iwp64")
|
||||||
|
_eventPopupScene = ExtResource("23_4etfk")
|
||||||
|
_eventPopupContainer = NodePath("../Notification Layer/CenterContainer")
|
||||||
|
metadata/_custom_type_script = "uid://2ipbgwlx1ld1"
|
||||||
|
8
Scenes/UI/event_option_button.tscn
Normal file
8
Scenes/UI/event_option_button.tscn
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[gd_scene format=3 uid="uid://b2o5rufqn8dpf"]
|
||||||
|
|
||||||
|
[node name="EventOptionButton" type="Button"]
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
26
Scenes/UI/event_popup.tscn
Normal file
26
Scenes/UI/event_popup.tscn
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
[gd_scene load_steps=3 format=3 uid="uid://gdejd44km3co"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://h1x5eqt0lc5m" path="res://Scripts/UI/EventPopup.cs" id="1_lkb7n"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://b2o5rufqn8dpf" path="res://Scenes/UI/event_option_button.tscn" id="2_gk0qx"]
|
||||||
|
|
||||||
|
[node name="EventPopup" type="PanelContainer" node_paths=PackedStringArray("_titleLabel", "_descriptionLabel", "_optionsContainer")]
|
||||||
|
offset_right = 40.0
|
||||||
|
offset_bottom = 40.0
|
||||||
|
script = ExtResource("1_lkb7n")
|
||||||
|
_titleLabel = NodePath("VBoxContainer/Title")
|
||||||
|
_descriptionLabel = NodePath("VBoxContainer/Description")
|
||||||
|
_optionsContainer = NodePath("VBoxContainer/OptionButtons")
|
||||||
|
_optionButtonScene = ExtResource("2_gk0qx")
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="Title" type="Label" parent="VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "TITLE"
|
||||||
|
|
||||||
|
[node name="Description" type="RichTextLabel" parent="VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="OptionButtons" type="VBoxContainer" parent="VBoxContainer"]
|
||||||
|
layout_mode = 2
|
74
Scripts/Components/EventManager.cs
Normal file
74
Scripts/Components/EventManager.cs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Godot;
|
||||||
|
using Limbo.Console.Sharp;
|
||||||
|
using ParasiticGod.Scripts.Core;
|
||||||
|
using ParasiticGod.Scripts.Singletons;
|
||||||
|
using ParasiticGod.Scripts.UI;
|
||||||
|
|
||||||
|
namespace ParasiticGod.Scripts.Components;
|
||||||
|
|
||||||
|
[GlobalClass]
|
||||||
|
public partial class EventManager : Node
|
||||||
|
{
|
||||||
|
[Export] private double _checkInterval = 5.0;
|
||||||
|
[Export] private PackedScene _eventPopupScene;
|
||||||
|
[Export] private Container _eventPopupContainer;
|
||||||
|
|
||||||
|
private List<EventDefinition> _allEvents;
|
||||||
|
private Timer _timer;
|
||||||
|
private RandomNumberGenerator _rng = new();
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
RegisterConsoleCommands();
|
||||||
|
_allEvents = GameBus.Instance.AllEvents;
|
||||||
|
|
||||||
|
_timer = new Timer { WaitTime = _checkInterval, Autostart = true };
|
||||||
|
AddChild(_timer);
|
||||||
|
_timer.Timeout += OnCheckEvents;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCheckEvents()
|
||||||
|
{
|
||||||
|
if (GetTree().Paused) return;
|
||||||
|
|
||||||
|
var state = GameBus.Instance.CurrentState;
|
||||||
|
|
||||||
|
foreach (var ev in _allEvents)
|
||||||
|
{
|
||||||
|
if (state.Get(Stat.Followers) < ev.Trigger.MinFollowers) continue;
|
||||||
|
if (state.Get(Stat.Corruption) > ev.Trigger.MaxCorruption) continue;
|
||||||
|
|
||||||
|
var probability = _checkInterval / ev.MeanTimeToHappen;
|
||||||
|
if (_rng.Randf() < probability)
|
||||||
|
{
|
||||||
|
FireEvent(ev);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FireEvent(EventDefinition eventDef)
|
||||||
|
{
|
||||||
|
GD.Print($"Firing event: {eventDef.Title}");
|
||||||
|
GetTree().Paused = true;
|
||||||
|
|
||||||
|
var popup = _eventPopupScene.Instantiate<EventPopup>();
|
||||||
|
_eventPopupContainer.AddChild(popup);
|
||||||
|
popup.DisplayEvent(eventDef);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ConsoleCommand("trigger_event", "Triggers an event by its ID for testing purposes.")]
|
||||||
|
private void TriggerEventCommand(string eventId)
|
||||||
|
{
|
||||||
|
var eventDef = _allEvents.Find(e => e.Id == eventId);
|
||||||
|
if (eventDef != null)
|
||||||
|
{
|
||||||
|
FireEvent(eventDef);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GD.PushError($"No event found with ID: {eventId}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
Scripts/Components/EventManager.cs.uid
Normal file
1
Scripts/Components/EventManager.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://2ipbgwlx1ld1
|
29
Scripts/Components/PauseManager.cs
Normal file
29
Scripts/Components/PauseManager.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace ParasiticGod.Scripts.Components;
|
||||||
|
|
||||||
|
[GlobalClass]
|
||||||
|
public partial class PauseManager : CanvasLayer
|
||||||
|
{
|
||||||
|
[Export] private Button _pauseButton;
|
||||||
|
[Export] private Control _pauseMenu;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
ProcessMode = ProcessModeEnum.Always;
|
||||||
|
_pauseMenu.Hide();
|
||||||
|
_pauseButton.Pressed += TogglePause;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Input(InputEvent @event)
|
||||||
|
{
|
||||||
|
if (@event.IsActionPressed("pause")) TogglePause();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TogglePause()
|
||||||
|
{
|
||||||
|
var isPaused = !GetTree().Paused;
|
||||||
|
GetTree().Paused = isPaused;
|
||||||
|
_pauseMenu.Visible = isPaused;
|
||||||
|
}
|
||||||
|
}
|
1
Scripts/Components/PauseManager.cs.uid
Normal file
1
Scripts/Components/PauseManager.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://djmtle2h3yd2e
|
22
Scripts/Core/EventDefinition.cs
Normal file
22
Scripts/Core/EventDefinition.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Godot.Collections;
|
||||||
|
using ParasiticGod.Scripts.Core.Effects;
|
||||||
|
|
||||||
|
namespace ParasiticGod.Scripts.Core;
|
||||||
|
|
||||||
|
public class EventDefinition
|
||||||
|
{
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public int MeanTimeToHappen { get; set; }
|
||||||
|
public EventTriggerDto Trigger { get; set; }
|
||||||
|
public List<EventOptionDefinition> Options { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EventOptionDefinition
|
||||||
|
{
|
||||||
|
public string Text { get; set; }
|
||||||
|
public string Tooltip { get; set; }
|
||||||
|
public Array<Effect> Effects { get; set; }
|
||||||
|
}
|
1
Scripts/Core/EventDefinition.cs.uid
Normal file
1
Scripts/Core/EventDefinition.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://ilyr01u70ciw
|
46
Scripts/Core/EventDto.cs
Normal file
46
Scripts/Core/EventDto.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace ParasiticGod.Scripts.Core;
|
||||||
|
|
||||||
|
public class EventTriggerDto
|
||||||
|
{
|
||||||
|
[JsonProperty("minFollowers")]
|
||||||
|
public long MinFollowers { get; set; } = 0;
|
||||||
|
|
||||||
|
[JsonProperty("maxCorruption")]
|
||||||
|
public double MaxCorruption { get; set; } = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EventOptionDto
|
||||||
|
{
|
||||||
|
[JsonProperty("text")]
|
||||||
|
public string Text { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("tooltip")]
|
||||||
|
public string Tooltip { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("effects")]
|
||||||
|
public List<EffectDto> Effects { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EventDto
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("title")]
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("description")]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("meanTimeToHappen")]
|
||||||
|
public int MeanTimeToHappen { get; set; } = 100; // in game days
|
||||||
|
|
||||||
|
[JsonProperty("trigger")]
|
||||||
|
public EventTriggerDto Trigger { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("options")]
|
||||||
|
public List<EventOptionDto> Options { get; set; }
|
||||||
|
}
|
1
Scripts/Core/EventDto.cs.uid
Normal file
1
Scripts/Core/EventDto.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://nwwqn028soa5
|
71
Scripts/Core/EventLoader.cs
Normal file
71
Scripts/Core/EventLoader.cs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Godot;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace ParasiticGod.Scripts.Core;
|
||||||
|
|
||||||
|
public static class EventLoader
|
||||||
|
{
|
||||||
|
public static List<EventDefinition> LoadAllEvents()
|
||||||
|
{
|
||||||
|
var loadedEvents = new Dictionary<string, EventDefinition>();
|
||||||
|
|
||||||
|
LoadEventsFromPath("res://Mods/Events", loadedEvents);
|
||||||
|
LoadEventsFromPath("user://Mods/Events", loadedEvents);
|
||||||
|
|
||||||
|
GD.Print($"Finished loading. Total unique events: {loadedEvents.Count}");
|
||||||
|
return new List<EventDefinition>(loadedEvents.Values);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LoadEventsFromPath(string path, Dictionary<string, EventDefinition> events)
|
||||||
|
{
|
||||||
|
if (!DirAccess.DirExistsAbsolute(path)) return;
|
||||||
|
|
||||||
|
using var dir = DirAccess.Open(path);
|
||||||
|
dir.ListDirBegin();
|
||||||
|
var fileName = dir.GetNext();
|
||||||
|
while (!string.IsNullOrEmpty(fileName))
|
||||||
|
{
|
||||||
|
if (!dir.CurrentIsDir() && fileName.EndsWith(".json"))
|
||||||
|
{
|
||||||
|
var filePath = path.PathJoin(fileName);
|
||||||
|
var ev = LoadEventFromFile(filePath);
|
||||||
|
if (ev != null)
|
||||||
|
{
|
||||||
|
events[ev.Id] = ev; // Add or overwrite
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fileName = dir.GetNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static EventDefinition LoadEventFromFile(string filePath)
|
||||||
|
{
|
||||||
|
var fileContent = FileAccess.GetFileAsString(filePath);
|
||||||
|
if (string.IsNullOrEmpty(fileContent)) return null;
|
||||||
|
|
||||||
|
var dto = JsonConvert.DeserializeObject<EventDto>(fileContent);
|
||||||
|
if (dto == null) return null;
|
||||||
|
|
||||||
|
var eventDef = new EventDefinition
|
||||||
|
{
|
||||||
|
Id = dto.Id,
|
||||||
|
Title = dto.Title,
|
||||||
|
Description = dto.Description,
|
||||||
|
MeanTimeToHappen = dto.MeanTimeToHappen,
|
||||||
|
Trigger = dto.Trigger
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var optionDto in dto.Options)
|
||||||
|
{
|
||||||
|
var optionDef = new EventOptionDefinition
|
||||||
|
{
|
||||||
|
Text = optionDto.Text,
|
||||||
|
Tooltip = optionDto.Tooltip,
|
||||||
|
Effects = MiracleLoader.ConvertEffectDtos(optionDto.Effects)
|
||||||
|
};
|
||||||
|
eventDef.Options.Add(optionDef);
|
||||||
|
}
|
||||||
|
return eventDef;
|
||||||
|
}
|
||||||
|
}
|
1
Scripts/Core/EventLoader.cs.uid
Normal file
1
Scripts/Core/EventLoader.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://ceimix3ejnadj
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -86,7 +87,17 @@ public static class MiracleLoader
|
|||||||
Effects = []
|
Effects = []
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var effectDto in miracleDto.Effects)
|
var effects = ConvertEffectDtos(miracleDto.Effects);
|
||||||
|
miracleDef.Effects = effects;
|
||||||
|
return miracleDef;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Array<Effect> ConvertEffectDtos(List<EffectDto> dtos)
|
||||||
|
{
|
||||||
|
var effects = new Array<Effect>();
|
||||||
|
if (dtos == null) return effects;
|
||||||
|
|
||||||
|
foreach (var effectDto in dtos)
|
||||||
{
|
{
|
||||||
if (EffectRegistry.TryGetValue(effectDto.Type, out var effectType))
|
if (EffectRegistry.TryGetValue(effectDto.Type, out var effectType))
|
||||||
{
|
{
|
||||||
@@ -118,11 +129,9 @@ public static class MiracleLoader
|
|||||||
unlockMiracleEffect.MiraclesToUnlock = new Array<string>(effectDto.MiraclesToUnlock);
|
unlockMiracleEffect.MiraclesToUnlock = new Array<string>(effectDto.MiraclesToUnlock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
effects.Add(effectInstance);
|
||||||
miracleDef.Effects.Add(effectInstance);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return effects;
|
||||||
return miracleDef;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
using Limbo.Console.Sharp;
|
using Limbo.Console.Sharp;
|
||||||
using ParasiticGod.Scripts.Core;
|
using ParasiticGod.Scripts.Core;
|
||||||
using ParasiticGod.Scripts.Core.Effects;
|
using ParasiticGod.Scripts.Core.Effects;
|
||||||
@@ -10,10 +11,11 @@ namespace ParasiticGod.Scripts.Singletons;
|
|||||||
public partial class GameBus : Node
|
public partial class GameBus : Node
|
||||||
{
|
{
|
||||||
public static GameBus Instance { get; private set; }
|
public static GameBus Instance { get; private set; }
|
||||||
public Dictionary<string, MiracleDefinition> AllMiracles { get; private set; }
|
public System.Collections.Generic.Dictionary<string, MiracleDefinition> AllMiracles { get; private set; }
|
||||||
public List<TierDefinition> FollowerTiers { get; private set; }
|
public List<TierDefinition> FollowerTiers { get; private set; }
|
||||||
public List<TierDefinition> HutTiers { get; private set; }
|
public List<TierDefinition> HutTiers { get; private set; }
|
||||||
public List<TierDefinition> TempleTiers { get; private set; }
|
public List<TierDefinition> TempleTiers { get; private set; }
|
||||||
|
public List<EventDefinition> AllEvents { get; private set; }
|
||||||
|
|
||||||
private PackedScene _gameOverScene = GD.Load<PackedScene>("res://Scenes/game_over.tscn");
|
private PackedScene _gameOverScene = GD.Load<PackedScene>("res://Scenes/game_over.tscn");
|
||||||
private PackedScene _winScene = GD.Load<PackedScene>("res://Scenes/win_screen.tscn");
|
private PackedScene _winScene = GD.Load<PackedScene>("res://Scenes/win_screen.tscn");
|
||||||
@@ -35,6 +37,7 @@ public partial class GameBus : Node
|
|||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
AllMiracles = MiracleLoader.LoadAllMiracles();
|
AllMiracles = MiracleLoader.LoadAllMiracles();
|
||||||
|
AllEvents = EventLoader.LoadAllEvents();
|
||||||
FollowerTiers = TierLoader.LoadTiers("res://Mods/Tiers/follower_tiers.json", "user://Mods/Tiers/follower_tiers.json");
|
FollowerTiers = TierLoader.LoadTiers("res://Mods/Tiers/follower_tiers.json", "user://Mods/Tiers/follower_tiers.json");
|
||||||
HutTiers = TierLoader.LoadTiers("res://Mods/Tiers/hut_tiers.json","user://Mods/Tiers/hut_tiers.json");
|
HutTiers = TierLoader.LoadTiers("res://Mods/Tiers/hut_tiers.json","user://Mods/Tiers/hut_tiers.json");
|
||||||
TempleTiers = TierLoader.LoadTiers("res://Mods/Tiers/temple_tiers.json","user://Mods/Tiers/temple_tiers.json");
|
TempleTiers = TierLoader.LoadTiers("res://Mods/Tiers/temple_tiers.json","user://Mods/Tiers/temple_tiers.json");
|
||||||
@@ -124,6 +127,15 @@ public partial class GameBus : Node
|
|||||||
GameWon?.Invoke();
|
GameWon?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ExecuteEffects(Array<Effect> effects)
|
||||||
|
{
|
||||||
|
foreach (var effect in effects)
|
||||||
|
{
|
||||||
|
effect.Execute(_gameState);
|
||||||
|
}
|
||||||
|
GetTree().Paused = false;
|
||||||
|
}
|
||||||
|
|
||||||
public void SubscribeToStat(Stat stat, Action<double> listener) => _gameState.Subscribe(stat, listener);
|
public void SubscribeToStat(Stat stat, Action<double> listener) => _gameState.Subscribe(stat, listener);
|
||||||
public void UnsubscribeFromStat(Stat stat, Action<double> listener) => _gameState.Unsubscribe(stat, listener);
|
public void UnsubscribeFromStat(Stat stat, Action<double> listener) => _gameState.Unsubscribe(stat, listener);
|
||||||
|
|
||||||
|
40
Scripts/UI/EventPopup.cs
Normal file
40
Scripts/UI/EventPopup.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using Godot;
|
||||||
|
using ParasiticGod.Scripts.Core;
|
||||||
|
using ParasiticGod.Scripts.Singletons;
|
||||||
|
|
||||||
|
namespace ParasiticGod.Scripts.UI;
|
||||||
|
|
||||||
|
[GlobalClass]
|
||||||
|
public partial class EventPopup : PanelContainer
|
||||||
|
{
|
||||||
|
[Export] private Label _titleLabel;
|
||||||
|
[Export] private RichTextLabel _descriptionLabel;
|
||||||
|
[Export] private VBoxContainer _optionsContainer;
|
||||||
|
[Export] private PackedScene _optionButtonScene; // A scene for a single button
|
||||||
|
|
||||||
|
public void DisplayEvent(EventDefinition eventDef)
|
||||||
|
{
|
||||||
|
_titleLabel.Text = eventDef.Title;
|
||||||
|
_descriptionLabel.Text = eventDef.Description;
|
||||||
|
|
||||||
|
foreach (var child in _optionsContainer.GetChildren())
|
||||||
|
{
|
||||||
|
child.QueueFree();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var option in eventDef.Options)
|
||||||
|
{
|
||||||
|
var button = _optionButtonScene.Instantiate<Button>();
|
||||||
|
button.Text = option.Text;
|
||||||
|
button.TooltipText = option.Tooltip;
|
||||||
|
|
||||||
|
button.Pressed += () =>
|
||||||
|
{
|
||||||
|
GameBus.Instance.ExecuteEffects(option.Effects);
|
||||||
|
QueueFree();
|
||||||
|
};
|
||||||
|
|
||||||
|
_optionsContainer.AddChild(button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
Scripts/UI/EventPopup.cs.uid
Normal file
1
Scripts/UI/EventPopup.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://h1x5eqt0lc5m
|
@@ -56,6 +56,11 @@ limbo_console_search_history={
|
|||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":82,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":82,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
pause={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user