Skip to content

Commit 0048ad1

Browse files
feat: Enhance action handling by integrating UIButton checks in Role class
1 parent 98b3f89 commit 0048ad1

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

roles/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ def _auto_discover_roles():
149149
# Führe Auto-Discovery beim Import aus
150150
_auto_discover_roles()
151151

152+
# Registriere automatisch alle Actions aus den Rollen-UI-Definitionen
153+
# Dies muss NACH _auto_discover_roles() passieren!
154+
try:
155+
from .actions import _auto_register_from_roles
156+
_auto_register_from_roles()
157+
print("[Rollen] Action-Registry automatisch gefüllt")
158+
except Exception as e:
159+
print(f"[Rollen] Warnung: Konnte Actions nicht automatisch registrieren: {e}")
160+
152161

153162
# ============================================================================
154163
# DYNAMISCHE ROLLEN-ZUGRIFFSFUNKTIONEN

roles/base.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,43 @@ def execute_action(
32413241
f"'{handler_name}' but method not found"
32423242
)
32433243

3244+
# NEW: Also check UIButtons (legacy system still used by most roles)
3245+
# UIButtons don't have explicit handlers, so route to on_nacht_aktion
3246+
for button in ui_def.buttons:
3247+
btn_action_type = button.action_type
3248+
if (btn_action_type == action_type or
3249+
btn_action_type == normalized_action or
3250+
btn_action_type == original_action):
3251+
# Found matching button - route to on_nacht_aktion with the action
3252+
ziel = targets[0] if len(targets) == 1 else None
3253+
try:
3254+
result = self.on_nacht_aktion(spieler, ziel, kontext, aktion=normalized_action)
3255+
if result is None:
3256+
# Role didn't handle it, but button exists - create success
3257+
return AktionsErgebnis(
3258+
erfolg=True,
3259+
nachricht="Aktion ausgeführt.",
3260+
effekte={"aktion_ausgefuehrt": True},
3261+
)
3262+
return result
3263+
except TypeError:
3264+
# Handler might not accept aktion kwarg
3265+
try:
3266+
result = self.on_nacht_aktion(spieler, ziel, kontext)
3267+
if result is None:
3268+
return AktionsErgebnis(
3269+
erfolg=True,
3270+
nachricht="Aktion ausgeführt.",
3271+
effekte={"aktion_ausgefuehrt": True},
3272+
)
3273+
return result
3274+
except Exception as e:
3275+
logger.error(f"on_nacht_aktion failed for button {btn_action_type}: {e}")
3276+
return AktionsErgebnis(
3277+
erfolg=False,
3278+
nachricht=f"Fehler bei Aktion: {str(e)}",
3279+
)
3280+
32443281
# LEGACY: route to on_nacht_aktion for backwards compatibility
32453282
import inspect
32463283

0 commit comments

Comments
 (0)