feat: the rebuild gamemode of "Gauntlet"

This commit is contained in:
2026-06-10 02:12:25 +08:00
parent 2d857a490b
commit 5653473c12
28 changed files with 1313 additions and 254 deletions
+73
View File
@@ -0,0 +1,73 @@
extends Node
# EventBus - Centralized Observer Pattern for inter-manager communication
# Replaces direct cross-references between managers
# =============================================================================
# Events Registry
# =============================================================================
# Player Events
const EVENT_PLAYER_JOINED = "player_joined"
const EVENT_PLAYER_LEFT = "player_left"
const EVENT_PLAYER_READY = "player_ready"
# Match Events
const EVENT_MATCH_STARTED = "match_started"
const EVENT_MATCH_ENDED = "match_ended"
const EVENT_GAME_MODE_CHANGED = "game_mode_changed"
# Economy Events
const EVENT_CURRENCY_CHANGED = "currency_changed"
const EVENT_ITEM_PURCHASED = "item_purchased"
const EVENT_GACHA_PULL = "gacha_pull"
# Profile Events
const EVENT_PROFILE_LOADED = "profile_loaded"
const EVENT_PROFILE_UPDATED = "profile_updated"
const EVENT_AVATAR_CHANGED = "avatar_changed"
# Session Events
const EVENT_SESSION_REFRESHED = "session_refreshed"
const EVENT_SESSION_EXPIRED = "session_expired"
# =============================================================================
# Signal Bus
# =============================================================================
signal event_emitted(event_name: String, data: Variant)
# =============================================================================
# Internal Registry
# =============================================================================
var _listeners: Dictionary = {} # event_name -> Array[Callable]
# =============================================================================
# Public API
# =============================================================================
func emit(event_name: String, data: Variant = null) -> void:
"""Emit an event to all registered listeners."""
if _listeners.has(event_name):
for callback in _listeners[event_name]:
if data != null:
callback.call(data)
else:
callback.call()
event_emitted.emit(event_name, data)
func on(event_name: String, callback: Callable) -> void:
"""Subscribe to an event."""
if not _listeners.has(event_name):
_listeners[event_name] = []
_listeners[event_name].append(callback)
func off(event_name: String, callback: Callable) -> void:
"""Unsubscribe from an event."""
if _listeners.has(event_name):
_listeners[event_name].erase(callback)
func clear() -> void:
"""Remove all listeners. Useful for cleanup between scenes."""
_listeners.clear()