|
1 | 1 | using System; |
2 | 2 | using FunkEngine; |
3 | 3 | using Godot; |
| 4 | +using Melanchall.DryWetMidi.Interaction; |
4 | 5 |
|
5 | 6 | /**<summary>BattleDirector: Higher priority director to manage battle effects. Can directly access managers, which should signal up to Director WIP</summary> |
6 | 7 | */ |
@@ -42,8 +43,9 @@ private bool PlayerAddNote(ArrowType type, Beat beat) |
42 | 43 |
|
43 | 44 | Note noteToPlace = NPB.NotePlaced(); |
44 | 45 | noteToPlace.OnHit(this, Timing.Okay); |
| 46 | + |
45 | 47 | CD.AddPlayerNote(noteToPlace, type, beat); |
46 | | - NotePlaced?.Invoke(this); |
| 48 | + Harbinger.Instance.InvokeNotePlaced(new ArrowData(type, beat, noteToPlace)); |
47 | 49 | return true; |
48 | 50 | } |
49 | 51 |
|
@@ -84,6 +86,7 @@ public override void _Ready() |
84 | 86 | } |
85 | 87 |
|
86 | 88 | TimeKeeper.InitVals(curSong.Bpm); |
| 89 | + Harbinger.Init(this); |
87 | 90 | InitPlayer(); |
88 | 91 | InitEnemies(); |
89 | 92 | CD.Initialize(curSong); |
@@ -128,7 +131,7 @@ private void UpdateBeat(Beat beat) |
128 | 131 | } |
129 | 132 | if (beat.Loop > TimeKeeper.LastBeat.Loop) |
130 | 133 | { |
131 | | - ChartLooped?.Invoke(this); |
| 134 | + Harbinger.Instance.InvokeChartLoop(beat.Loop); |
132 | 135 | } |
133 | 136 | TimeKeeper.LastBeat = beat; |
134 | 137 | } |
@@ -164,13 +167,13 @@ private void OnTimedInput(ArrowData data, double beatDif) |
164 | 167 | Timing timed = CheckTiming(beatDif); |
165 | 168 |
|
166 | 169 | data.NoteRef.OnHit(this, timed); |
167 | | - NPB.HandleTiming(timed); |
| 170 | + NPB.HandleTiming(timed, data.Type); |
168 | 171 | CM.ComboText(timed, data.Type, NPB.GetCurrentCombo()); |
169 | 172 | } |
170 | 173 |
|
171 | 174 | private void ForceMiss(ArrowType type) |
172 | 175 | { |
173 | | - NPB.HandleTiming(Timing.Miss); |
| 176 | + NPB.HandleTiming(Timing.Miss, type); |
174 | 177 | CM.ComboText(Timing.Miss, type, NPB.GetCurrentCombo()); |
175 | 178 | Player.TakeDamage(4); |
176 | 179 | } |
@@ -242,22 +245,15 @@ private void TransitionOutOfBattle() |
242 | 245 | #endregion |
243 | 246 |
|
244 | 247 | #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 | | - |
252 | 248 | private void AddEvent(IBattleEvent bEvent) |
253 | 249 | { |
254 | 250 | switch (bEvent.GetTrigger()) //TODO: Look into a way to get eventhandler from string |
255 | 251 | { |
256 | 252 | case BattleEffectTrigger.NotePlaced: |
257 | | - NotePlaced += bEvent.OnTrigger; |
| 253 | + Harbinger.Instance.NotePlaced += bEvent.OnTrigger; |
258 | 254 | break; |
259 | 255 | case BattleEffectTrigger.OnLoop: |
260 | | - ChartLooped += bEvent.OnTrigger; |
| 256 | + Harbinger.Instance.ChartLooped += bEvent.OnTrigger; |
261 | 257 | break; |
262 | 258 | } |
263 | 259 | } |
@@ -293,8 +289,64 @@ private void CleanUpRelics() |
293 | 289 | } |
294 | 290 | #endregion |
295 | 291 |
|
| 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 | + |
296 | 348 | private void DebugKillEnemy() |
297 | 349 | { |
298 | | - //Enemy.TakeDamage(1000); |
| 350 | + Enemy.TakeDamage(1000); |
299 | 351 | } |
300 | 352 | } |
0 commit comments