Last active
May 29, 2024 13:12
-
-
Save eka/e572c28df0ed1ce3943fee1e454e1de5 to your computer and use it in GitHub Desktop.
EventBus for Godot Use in Autoload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Godot; | |
using System; | |
public partial class GameEventsManager : Node | |
{ | |
private static GameEventsManager _instance; | |
public static GameEventsManager Instance => _instance; | |
[Signal] | |
public delegate void UpdateWorldSpeedEventHandler(float speed); | |
[Signal] | |
public delegate void PlayerDiedEventHandler(); | |
[Signal] | |
public delegate void BackToMainEventHandler(); | |
[Signal] | |
public delegate void StartGameEventHandler(); | |
[Signal] | |
public delegate void PauseGameEventHandler(); | |
[Signal] | |
public delegate void ResumeGameEventHandler(); | |
[Signal] | |
public delegate void EnemyKilledEventHandler(); | |
[Signal] | |
public delegate void UpdateScoreEventHandler(int score, int bestScore); | |
[Signal] | |
public delegate void PlayerDamageEventHandler(int livesLeft); | |
[Signal] | |
public delegate void PlayerFuelIsEmptyEventHandler(); | |
[Signal] | |
public delegate void UpdatePlayerFuelEventHandler(float fuel, float maxFuel, bool isInDanger); | |
[Signal] | |
public delegate void PlayerFuelCollectedEventHandler(); | |
[Signal] | |
public delegate void ShowCreditsEventHandler(); | |
[Signal] | |
public delegate void GameStartedEventHandler(); | |
[Signal] | |
public delegate void ShowSettingsEventHandler(); | |
[Signal] | |
public delegate void SettingsClosedEventHandler(); | |
[Signal] | |
public delegate void InitialSoundSettingsEventHandler(float masterVolume, float musicVolume, float sfxVolume); | |
[Signal] | |
public delegate void UpdateSoundSettingsEventHandler(float masterVolume, float musicVolume, float sfxVolume); | |
[Signal] | |
public delegate void PlaySfxEventHandler(SoundResource sfxSoundResource); | |
[Signal] | |
public delegate void StopSfxEventHandler(SoundResource sfxSoundResource); | |
public Action<Action<int>> GetBestScoreAction; | |
public Action<Action<SaveData>> GetSaveDataAction; | |
public void EmitEnemyKilled() | |
{ | |
EmitSignal(SignalName.EnemyKilled); | |
} | |
public void EmitUpdateWorldSpeed(float speed) | |
{ | |
EmitSignal(SignalName.UpdateWorldSpeed, speed); | |
} | |
public void EmitPlayerDied() | |
{ | |
EmitSignal(SignalName.PlayerDied); | |
} | |
public void EmitStartGame() | |
{ | |
EmitSignal(SignalName.StartGame); | |
} | |
public void EmitPauseGame() | |
{ | |
EmitSignal(SignalName.PauseGame); | |
} | |
public void EmitResumeGame() | |
{ | |
EmitSignal(SignalName.ResumeGame); | |
} | |
public void EmitUpdateScore(int score, int bestScore) | |
{ | |
EmitSignal(SignalName.UpdateScore, score, bestScore); | |
} | |
public void EmitBackToMain() | |
{ | |
EmitSignal(SignalName.BackToMain); | |
} | |
public void EmitPlayerDamage(int livesLeft) | |
{ | |
EmitSignal(SignalName.PlayerDamage, livesLeft); | |
} | |
public void EmitPlayerFuelIsEmpty() | |
{ | |
EmitSignal(SignalName.PlayerFuelIsEmpty); | |
} | |
public void EmitUpdatePlayerFuel(float fuel, float maxFuel, bool isInDanger) | |
{ | |
EmitSignal(SignalName.UpdatePlayerFuel, fuel, maxFuel, isInDanger); | |
} | |
public void EmitPlayerFuelCollected() | |
{ | |
EmitSignal(SignalName.PlayerFuelCollected); | |
} | |
public override void _Ready() | |
{ | |
_instance = this; | |
} | |
public void EmitShowCredits() | |
{ | |
EmitSignal(SignalName.ShowCredits); | |
} | |
public void EmitGetBestScore(Action<int> returnCallback) | |
{ | |
GetBestScoreAction?.Invoke(returnCallback); | |
} | |
public void EmitGetSaveData(Action<SaveData> returnCallback) | |
{ | |
GetSaveDataAction?.Invoke(returnCallback); | |
} | |
public void EmitGameStarted() | |
{ | |
EmitSignal(SignalName.GameStarted); | |
} | |
public void EmitShowSettings() | |
{ | |
EmitSignal(SignalName.ShowSettings); | |
} | |
public void EmitSettingsClosed() | |
{ | |
EmitSignal(SignalName.SettingsClosed); | |
} | |
public void EmitInitialSoundSettings(float masterVolume, float musicVolume, float sfxVolume) | |
{ | |
EmitSignal(SignalName.InitialSoundSettings, masterVolume, musicVolume, sfxVolume); | |
} | |
public void EmitUpdateSoundSettings(float masterVolume, float musicVolume, float sfxVolume) | |
{ | |
EmitSignal(SignalName.UpdateSoundSettings, masterVolume, musicVolume, sfxVolume); | |
} | |
public void EmitPlaySfx(SoundResource sfxSoundResource) | |
{ | |
EmitSignal(SignalName.PlaySfx, sfxSoundResource); | |
} | |
public void EmitStopSfx(SoundResource sfxSoundResource) | |
{ | |
EmitSignal(SignalName.StopSfx, sfxSoundResource); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment