Skip to content

Commit c3421cd

Browse files
authored
Merge pull request #139 from Project-Funk-Engine/HarbingerSystem
More robust note system Note placement bar adds color based on inputs Reward selection implements a button group and doesn't set _selection from focus change, only sets from actual button selection
2 parents 0449a62 + 8d35c30 commit c3421cd

13 files changed

Lines changed: 200 additions & 84 deletions

File tree

Classes/Relics/RelicEffect.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ public partial class RelicEffect : IBattleEvent
1010
private BattleEffectTrigger Trigger { get; set; }
1111
private int _baseValue;
1212
public int Value;
13-
private Action<BattleDirector, RelicEffect, int> _onRelicEffect;
13+
private Action<BattleEventArgs, RelicEffect, int> _onRelicEffect;
1414
private bool _effectPersists = false;
1515

1616
public RelicEffect(
1717
BattleEffectTrigger trigger,
1818
int val,
19-
Action<BattleDirector, RelicEffect, int> onRelicEffect
19+
Action<BattleEventArgs, RelicEffect, int> onRelicEffect,
20+
bool persists = false
2021
)
2122
{
2223
_baseValue = val;
2324
Value = _baseValue;
2425
Trigger = trigger;
2526
_onRelicEffect = onRelicEffect;
27+
_effectPersists = persists;
2628
}
2729

2830
public void OnBattleEnd()
@@ -31,9 +33,9 @@ public void OnBattleEnd()
3133
Value = _baseValue;
3234
}
3335

34-
public void OnTrigger(BattleDirector battleDirector)
36+
public void OnTrigger(BattleEventArgs e)
3537
{
36-
_onRelicEffect(battleDirector, this, Value);
38+
_onRelicEffect(e, this, Value);
3739
}
3840

3941
public BattleEffectTrigger GetTrigger()

Globals/FunkEngineNameSpace.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,18 @@ private void AddBossRoom(int width, int height)
372372
}
373373

374374
#region Interfaces
375+
376+
public class BattleEventArgs(BattleDirector director) : EventArgs
377+
{
378+
public BattleDirector BD = director;
379+
}
380+
375381
/**
376382
* <summary>A BattleDirector driven battle event. Needs an enum defined trigger.</summary>
377383
*/
378384
public interface IBattleEvent
379385
{
380-
void OnTrigger(BattleDirector BD);
386+
void OnTrigger(BattleEventArgs e);
381387
BattleEffectTrigger GetTrigger();
382388
}
383389

Globals/Scribe.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public partial class Scribe : Node
108108
new RelicEffect(
109109
BattleEffectTrigger.OnPickup,
110110
10,
111-
(director, self, val) =>
111+
(e, self, val) =>
112112
{
113113
StageProducer.PlayerStats.MaxHealth += val;
114114
StageProducer.PlayerStats.CurrentHealth += val;
@@ -126,9 +126,9 @@ public partial class Scribe : Node
126126
new RelicEffect(
127127
BattleEffectTrigger.NotePlaced,
128128
2,
129-
(director, self, val) =>
129+
(e, self, val) =>
130130
{
131-
director.Player.Heal(val);
131+
e.BD.Player.Heal(val);
132132
}
133133
),
134134
}
@@ -143,9 +143,9 @@ public partial class Scribe : Node
143143
new RelicEffect(
144144
BattleEffectTrigger.OnLoop,
145145
1,
146-
(director, self, val) =>
146+
(e, self, val) =>
147147
{
148-
director.NPB.IncreaseBonusMult(val);
148+
e.BD.NPB.IncreaseBonusMult(val);
149149
self.Value++;
150150
}
151151
),
@@ -161,9 +161,9 @@ public partial class Scribe : Node
161161
new RelicEffect(
162162
BattleEffectTrigger.OnLoop,
163163
10,
164-
(director, self, val) =>
164+
(e, self, val) =>
165165
{
166-
director.NPB.IncreaseCharge(val);
166+
e.BD.NPB.IncreaseCharge(val);
167167
self.Value += 5;
168168
}
169169
),

Globals/Translations/Translations.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CONTROLS_RETURN_BUTTON,Return,返回
1717
ESCAPE_MENU_RESUME,Resume,继续
1818
ESCAPE_MENU_QUIT,Quit,退出
1919
ESCAPE_MENU_TITLE,Quit to Title,返回标题
20-
CHEST_ROOM_REWARDS,Rewards!,奖励!
20+
CHEST_ROOM_REWARDS,Reward Selection!,奖励!
2121
CHEST_ROOM_SKIP,Skip,跳过
2222
CHEST_ROOM_ACCEPT,Accept,接受
2323
BATTLE_ROOM_BEGIN_BUTTON,"Begin Battle [Enter]","开始战斗 [Enter]"

Scenes/BattleDirector/NotePlacementBar.tscn

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[gd_scene load_steps=12 format=3 uid="uid://duhiilcv4tat3"]
22

3-
[ext_resource type="Script" path="res://Scenes/BattleDirector/Scripts/NotePlacementBar.cs" id="1_456es"]
3+
[ext_resource type="Script" uid="uid://gj666xe815py" path="res://Scenes/BattleDirector/Scripts/NotePlacementBar.cs" id="1_456es"]
44
[ext_resource type="Texture2D" uid="uid://cnyr5usjdv0ni" path="res://Scenes/BattleDirector/Assets/NoteQueue_Frame.png" id="2_3tw16"]
55
[ext_resource type="Texture2D" uid="uid://c3chrsxrulapd" path="res://Classes/Notes/Assets/Note_PlayerBasic.png" id="3_6ylx6"]
66
[ext_resource type="Texture2D" uid="uid://caw70lr5e1yiq" path="res://Classes/Notes/Assets/Note_PlayerDouble.png" id="4_6w8ha"]
@@ -14,14 +14,23 @@ width = 34
1414
height = 100
1515

1616
[sub_resource type="Gradient" id="Gradient_xvck1"]
17-
offsets = PackedFloat32Array(0, 0.373239, 0.690141, 1)
18-
colors = PackedColorArray(0, 1, 0, 1, 1, 0, 0.4, 1, 0, 1, 0.95, 1, 1, 0, 0, 1)
17+
offsets = PackedFloat32Array(0)
18+
colors = PackedColorArray(0, 0, 0, 1)
1919

2020
[sub_resource type="GradientTexture2D" id="GradientTexture2D_0bqho"]
2121
gradient = SubResource("Gradient_xvck1")
2222
width = 32
2323
height = 98
24-
fill_to = Vector2(0, 1)
24+
fill_from = Vector2(0, 1)
25+
fill_to = Vector2(0, 0)
26+
27+
[sub_resource type="Gradient" id="Gradient_2uknl"]
28+
offsets = PackedFloat32Array(0)
29+
colors = PackedColorArray(0.46, 0.2162, 0.39905, 1)
30+
31+
[sub_resource type="GradientTexture1D" id="GradientTexture1D_d62c7"]
32+
gradient = SubResource("Gradient_2uknl")
33+
width = 1
2534

2635
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_fy2uu"]
2736
lifetime_randomness = 0.32
@@ -41,14 +50,6 @@ turbulence_noise_scale = 5.0
4150
turbulence_influence_min = 0.0
4251
turbulence_influence_max = 0.018
4352

44-
[sub_resource type="Gradient" id="Gradient_2uknl"]
45-
offsets = PackedFloat32Array(0)
46-
colors = PackedColorArray(0.46, 0.2162, 0.39905, 1)
47-
48-
[sub_resource type="GradientTexture1D" id="GradientTexture1D_d62c7"]
49-
gradient = SubResource("Gradient_2uknl")
50-
width = 1
51-
5253
[node name="NotePlacementBar" type="Control" node_paths=PackedStringArray("_notePlacementBar", "_particles", "_fullBarParticles", "_currentComboMultText", "_currentNote", "_nextNote")]
5354
layout_mode = 3
5455
anchors_preset = 15
@@ -80,12 +81,12 @@ z_index = 1
8081
position = Vector2(-1, -32)
8182
emitting = false
8283
amount = 22
83-
process_material = SubResource("ParticleProcessMaterial_fy2uu")
8484
texture = SubResource("GradientTexture1D_d62c7")
8585
lifetime = 2.0
8686
preprocess = 0.1
8787
explosiveness = 0.3
8888
randomness = 0.05
89+
process_material = SubResource("ParticleProcessMaterial_fy2uu")
8990

9091
[node name="FullBarParticles" type="CPUParticles2D" parent="PlacementBar"]
9192
position = Vector2(14, 98)

Scenes/BattleDirector/Scripts/BattleDirector.cs

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using FunkEngine;
33
using Godot;
4+
using Melanchall.DryWetMidi.Interaction;
45

56
/**<summary>BattleDirector: Higher priority director to manage battle effects. Can directly access managers, which should signal up to Director WIP</summary>
67
*/
@@ -42,8 +43,9 @@ private bool PlayerAddNote(ArrowType type, Beat beat)
4243

4344
Note noteToPlace = NPB.NotePlaced();
4445
noteToPlace.OnHit(this, Timing.Okay);
46+
4547
CD.AddPlayerNote(noteToPlace, type, beat);
46-
NotePlaced?.Invoke(this);
48+
Harbinger.Instance.InvokeNotePlaced(new ArrowData(type, beat, noteToPlace));
4749
return true;
4850
}
4951

@@ -84,6 +86,7 @@ public override void _Ready()
8486
}
8587

8688
TimeKeeper.InitVals(curSong.Bpm);
89+
Harbinger.Init(this);
8790
InitPlayer();
8891
InitEnemies();
8992
CD.Initialize(curSong);
@@ -128,7 +131,7 @@ private void UpdateBeat(Beat beat)
128131
}
129132
if (beat.Loop > TimeKeeper.LastBeat.Loop)
130133
{
131-
ChartLooped?.Invoke(this);
134+
Harbinger.Instance.InvokeChartLoop(beat.Loop);
132135
}
133136
TimeKeeper.LastBeat = beat;
134137
}
@@ -164,13 +167,13 @@ private void OnTimedInput(ArrowData data, double beatDif)
164167
Timing timed = CheckTiming(beatDif);
165168

166169
data.NoteRef.OnHit(this, timed);
167-
NPB.HandleTiming(timed);
170+
NPB.HandleTiming(timed, data.Type);
168171
CM.ComboText(timed, data.Type, NPB.GetCurrentCombo());
169172
}
170173

171174
private void ForceMiss(ArrowType type)
172175
{
173-
NPB.HandleTiming(Timing.Miss);
176+
NPB.HandleTiming(Timing.Miss, type);
174177
CM.ComboText(Timing.Miss, type, NPB.GetCurrentCombo());
175178
Player.TakeDamage(4);
176179
}
@@ -242,22 +245,15 @@ private void TransitionOutOfBattle()
242245
#endregion
243246

244247
#region BattleEffect Handling
245-
246-
private delegate void NotePlacedHandler(BattleDirector BD);
247-
private event NotePlacedHandler NotePlaced;
248-
249-
private delegate void ChartLoopHandler(BattleDirector BD);
250-
private event ChartLoopHandler ChartLooped;
251-
252248
private void AddEvent(IBattleEvent bEvent)
253249
{
254250
switch (bEvent.GetTrigger()) //TODO: Look into a way to get eventhandler from string
255251
{
256252
case BattleEffectTrigger.NotePlaced:
257-
NotePlaced += bEvent.OnTrigger;
253+
Harbinger.Instance.NotePlaced += bEvent.OnTrigger;
258254
break;
259255
case BattleEffectTrigger.OnLoop:
260-
ChartLooped += bEvent.OnTrigger;
256+
Harbinger.Instance.ChartLooped += bEvent.OnTrigger;
261257
break;
262258
}
263259
}
@@ -293,8 +289,64 @@ private void CleanUpRelics()
293289
}
294290
#endregion
295291

292+
public partial class Harbinger : Resource
293+
{
294+
private static Harbinger _instance;
295+
public static Harbinger Instance => _instance;
296+
297+
private BattleDirector _curDirector;
298+
299+
static Harbinger() { }
300+
301+
private Harbinger(BattleDirector BD)
302+
{
303+
_curDirector = BD;
304+
}
305+
306+
internal static void Init(BattleDirector BD)
307+
{
308+
_instance = new Harbinger(BD);
309+
}
310+
311+
/// <summary>
312+
/// Event Args to handle event types triggering from the action of a note, without timing.
313+
/// </summary>
314+
/// <param name="bd">The BattleDirector calling the event.</param>
315+
/// <param name="data">The note data of the passing note.</param>
316+
public class NoteEventArgs(BattleDirector bd, ArrowData data) : BattleEventArgs(bd)
317+
{
318+
public ArrowData Data = data;
319+
}
320+
321+
/// <summary>
322+
/// Event Args to handle event types triggering from the start of a new loop.
323+
/// </summary>
324+
/// <param name="bd">The BattleDirector calling the event.</param>
325+
/// <param name="incomingLoop">The loop starting.</param>
326+
public class LoopEventArgs(BattleDirector bd, int incomingLoop) : BattleEventArgs(bd)
327+
{
328+
public int Loop = incomingLoop;
329+
}
330+
331+
internal delegate void NotePlacedHandler(BattleEventArgs e);
332+
internal event NotePlacedHandler NotePlaced;
333+
334+
public void InvokeNotePlaced(ArrowData data)
335+
{
336+
NotePlaced?.Invoke(new NoteEventArgs(_curDirector, data));
337+
}
338+
339+
internal delegate void ChartLoopHandler(BattleEventArgs e);
340+
internal event ChartLoopHandler ChartLooped;
341+
342+
public void InvokeChartLoop(int incLoop)
343+
{
344+
ChartLooped?.Invoke(new LoopEventArgs(_curDirector, incLoop));
345+
}
346+
}
347+
296348
private void DebugKillEnemy()
297349
{
298-
//Enemy.TakeDamage(1000);
350+
Enemy.TakeDamage(1000);
299351
}
300352
}

0 commit comments

Comments
 (0)