-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame_Wuthering_Waves.py
More file actions
352 lines (306 loc) · 13.9 KB
/
Game_Wuthering_Waves.py
File metadata and controls
352 lines (306 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any
from uuid import uuid4
@dataclass
class WutheringWavesGame:
"""
Wuthering Waves specific state + helpers.
This module exists to keep `ComboTrackerEngine` focused on core combo parsing/tracking,
while game-specific metadata (target game, WW teams/presets, WW combo->team mappings)
lives in one place.
"""
# Per-combo target game ("generic" | "wuthering_waves")
combo_target_game: dict[str, str] = field(default_factory=dict)
# Team presets
# ww_teams: team_id -> {
# "name": str,
# "dash_image": str, # RMB / dash (shared)
# "swap_images": {"1":..,"2":..,"3":..},
# "lmb_images": {"1":..,"2":..,"3":..},
# "ability_images": {"1":{"e":..,"q":..,"r":..}, ...}
# }
ww_teams: dict[str, dict[str, Any]] = field(default_factory=dict)
ww_active_team_id: str | None = None
# Per-combo assigned team (when target_game = wuthering_waves)
combo_ww_team: dict[str, str] = field(default_factory=dict)
# Active character slot during an attempt ("1", "2", or "3").
# In WW, pressing the current slot (e.g. 3 when on character 3) should not end the combo
# until you switch off that character. Reset on new attempt / fail.
ww_active_character: str | None = None
# Character slot keys (for WW and future games with swap slots)
WW_CHARACTER_SLOTS = ("1", "2", "3")
# -------------------------
# Ender / combo-end policy (engine delegates here to avoid game-specific branches)
# -------------------------
def can_ender_drop_combo(self, engine: Any, input_name: str) -> bool:
"""
True iff this key is allowed to end the combo.
Only combo enders can end combos, and only when off cooldown.
WW: pressing the current character slot (1/2/3) does not end the combo until you switch off.
"""
if not (input_name or "").strip():
return False
if not engine._is_combo_ender(input_name):
return False
if engine._ender_on_cooldown(input_name):
return False
if not getattr(engine, "last_input_time", None) and getattr(engine, "current_index", 0) == 0:
return False
if self.get_target_game(getattr(engine, "active_combo_name", None) or "") == "wuthering_waves":
key = (input_name or "").strip().lower()
if key in self.WW_CHARACTER_SLOTS and self.ww_active_character and key == self.ww_active_character:
return False
return True
def on_accepted_key(self, engine: Any, input_name: str) -> None:
"""When the correct key is 1/2/3 and game is WW, track active character for ender logic."""
if self.get_target_game(getattr(engine, "active_combo_name", None) or "") != "wuthering_waves":
return
key = (input_name or "").strip().lower()
if key in self.WW_CHARACTER_SLOTS:
self.ww_active_character = key
def get_target_game(self, combo_name: str) -> str:
name = (combo_name or "").strip()
g = str(self.combo_target_game.get(name, "generic") or "generic").strip().lower()
return g if g in ("generic", "wuthering_waves") else "generic"
def set_target_game(self, combo_name: str, target_game: str | None):
name = (combo_name or "").strip()
g = str(target_game or "").strip().lower()
if not name:
return
if g in ("generic", "wuthering_waves"):
self.combo_target_game[name] = g
else:
self.combo_target_game.pop(name, None)
def apply_combo_team_assignment(self, combo_name: str, *, target_game: str, ww_team_id: str | None):
"""
Apply per-combo WW team assignment.
Expected to be called after `set_target_game()`.
"""
name = (combo_name or "").strip()
if not name:
return
g = str(target_game or "generic").strip().lower()
if g == "wuthering_waves":
tid = str(ww_team_id or "").strip()
if tid and tid in self.ww_teams:
self.combo_ww_team[name] = tid
self.ww_active_team_id = tid
else:
self.combo_ww_team.pop(name, None)
else:
self.combo_ww_team.pop(name, None)
def rename_combo(self, old_name: str, new_name: str):
old = (old_name or "").strip()
new = (new_name or "").strip()
if not old or not new or old == new:
return
if old in self.combo_target_game and new not in self.combo_target_game:
self.combo_target_game[new] = self.combo_target_game.pop(old)
if old in self.combo_ww_team and new not in self.combo_ww_team:
self.combo_ww_team[new] = self.combo_ww_team.pop(old)
def delete_combo(self, name: str):
cname = (name or "").strip()
if not cname:
return
self.combo_target_game.pop(cname, None)
self.combo_ww_team.pop(cname, None)
# -------------------------
# Editor payload helpers
# -------------------------
def editor_payload(self, combo_name: str, target_game_override: str | None = None) -> dict[str, Any]:
"""
Build the WW-related section of the editor payload for the frontend.
Returns keys:
- target_game
- ww_teams
- ww_team_id
- ww_team_name
- ww_team_dash_image
- ww_team_swap_images
- ww_team_lmb_images
- ww_team_ability_images
"""
name = (combo_name or "").strip()
target_game = str(target_game_override).strip().lower() if target_game_override else self.get_target_game(name)
ww_teams = []
for tid, tv in self.ww_teams.items():
if not isinstance(tv, dict):
continue
ww_teams.append({"id": str(tid), "name": str(tv.get("name", "") or "Team")})
ww_teams.sort(key=lambda x: (x.get("name") or "").lower())
# Selected team: active team > combo assignment > none
# We prioritize the active ephemeral team to support stateless editing/switching.
sel_team_id = ""
if target_game == "wuthering_waves":
if self.ww_active_team_id and self.ww_active_team_id in self.ww_teams:
sel_team_id = self.ww_active_team_id
elif name and name in self.combo_ww_team and self.combo_ww_team[name] in self.ww_teams:
sel_team_id = self.combo_ww_team[name]
team_name = ""
team_swap_images: dict[str, str] = {}
team_lmb_images: dict[str, str] = {}
team_dash_image = ""
team_ability_images: dict[str, dict[str, str]] = {}
if sel_team_id and sel_team_id in self.ww_teams:
tv = self.ww_teams.get(sel_team_id) or {}
team_name = str(tv.get("name", "") or "")
team_dash_image = str(tv.get("dash_image", "") or "")
si = tv.get("swap_images", {})
if isinstance(si, dict):
team_swap_images = {k: str(v) for k, v in si.items() if k in ("1", "2", "3") and str(v).strip()}
li = tv.get("lmb_images", {})
if isinstance(li, dict):
team_lmb_images = {k: str(v) for k, v in li.items() if k in ("1", "2", "3") and str(v).strip()}
ai = tv.get("ability_images", {})
if isinstance(ai, dict):
for ck, vv in ai.items():
if ck in ("1", "2", "3") and isinstance(vv, dict):
team_ability_images[ck] = {a: str(u) for a, u in vv.items() if a in ("e", "q", "r") and str(u).strip()}
return {
"target_game": target_game,
"ww_teams": ww_teams,
"ww_team_id": sel_team_id,
"ww_team_name": team_name,
"ww_team_dash_image": team_dash_image,
"ww_team_swap_images": team_swap_images,
"ww_team_lmb_images": team_lmb_images,
"ww_team_ability_images": team_ability_images,
}
# -------------------------
# Team operations (called by engine)
# -------------------------
def set_active_ww_team(self, team_id: str):
tid = str(team_id or "").strip()
if tid and tid in self.ww_teams:
self.ww_active_team_id = tid
def save_or_update_ww_team(
self,
*,
team_id: str,
team_name: str,
dash_image: str | None,
swap_images: Any | None,
lmb_images: Any | None,
ability_images: Any | None,
) -> tuple[bool, str | None, str]:
"""
Returns (ok, err, resolved_team_id).
"""
tid = str(team_id or "").strip() or uuid4().hex[:10]
name = str(team_name or "").strip() or "Team"
dash = str(dash_image or "").strip()
# Sanitize swap/lmb maps
swap: dict[str, str] = {}
if isinstance(swap_images, dict):
for k, v in swap_images.items():
kk = str(k or "").strip()
if kk not in ("1", "2", "3"):
continue
url = str(v or "").strip()
if url:
swap[kk] = url
lmb: dict[str, str] = {}
if isinstance(lmb_images, dict):
for k, v in lmb_images.items():
kk = str(k or "").strip()
if kk not in ("1", "2", "3"):
continue
url = str(v or "").strip()
if url:
lmb[kk] = url
abil: dict[str, dict[str, str]] = {}
if isinstance(ability_images, dict):
for ck, mapping in ability_images.items():
c = str(ck or "").strip()
if c not in ("1", "2", "3") or not isinstance(mapping, dict):
continue
m: dict[str, str] = {}
for akey, av in mapping.items():
a = str(akey or "").strip().lower()
if a not in ("e", "q", "r"):
continue
url = str(av or "").strip()
if url:
m[a] = url
if m:
abil[c] = m
self.ww_teams[tid] = {"name": name, "dash_image": dash, "swap_images": swap, "lmb_images": lmb, "ability_images": abil}
self.ww_active_team_id = tid
return True, None, tid
def delete_ww_team(self, team_id: str) -> tuple[bool, str | None]:
tid = str(team_id or "").strip()
if not tid or tid not in self.ww_teams:
return False, "Select a team to delete."
del self.ww_teams[tid]
# Remove any combo mappings pointing at this team
for cname, ct in list(self.combo_ww_team.items()):
if ct == tid:
del self.combo_ww_team[cname]
if self.ww_active_team_id == tid:
self.ww_active_team_id = None
return True, None
# -------------------------
# UI command glue (engine-coupled; caller holds engine._lock)
# -------------------------
def set_active_ww_team(engine, team_id: str) -> None:
tid = str(team_id or "").strip()
if tid and tid in engine.ww_teams:
engine.ww.set_active_ww_team(tid)
engine.save_combos()
engine._send({"type": "combo_data", **engine.get_editor_payload()})
engine._send({"type": "timeline_update", "steps": engine.timeline_steps()})
def save_or_update_ww_team(
engine,
*,
team_id: str | None,
team_name: str | None,
dash_image: str | None,
swap_images: Any | None,
lmb_images: Any | None,
ability_images: Any | None,
) -> tuple[bool, str | None]:
name = str(team_name or "").strip()
if not name:
return False, "Please provide a Team name."
ok, err, _tid = engine.ww.save_or_update_ww_team(
team_id=str(team_id or "").strip(),
team_name=name,
dash_image=dash_image,
swap_images=swap_images,
lmb_images=lmb_images,
ability_images=ability_images,
)
if not ok:
return False, err
engine.save_combos()
engine._send({"type": "init", **engine.init_payload()})
return True, None
def delete_ww_team(engine, team_id: str) -> tuple[bool, str | None]:
ok, err = engine.ww.delete_ww_team(team_id)
if not ok:
return False, err
engine.save_combos()
engine._send({"type": "init", **engine.init_payload()})
return True, None
def select_team_stateless(engine, team_id: str, target_game: str) -> None:
"""Stateless team selection - doesn't persist, just updates UI."""
tid = str(team_id or "").strip()
game = str(target_game or "generic").strip().lower()
if game == "wuthering_waves" and tid and tid in engine.ww.ww_teams:
engine.ww.set_active_ww_team(tid)
engine._send({"type": "combo_data", **engine.get_editor_payload(target_game_override=game)})
engine._send({"type": "timeline_update", "steps": engine.timeline_steps()})
elif game == "wuthering_waves" and not tid:
engine.ww.set_active_ww_team("")
engine._send({"type": "combo_data", **engine.get_editor_payload(target_game_override=game)})
engine._send({"type": "timeline_update", "steps": engine.timeline_steps()})
def update_target_game_stateless(engine, target_game: str) -> None:
"""Stateless target game update - doesn't persist, just updates UI."""
game = str(target_game or "generic").strip().lower()
if game not in ("generic", "wuthering_waves"):
game = "generic"
payload = engine.get_editor_payload(target_game_override=game)
payload["target_game"] = game
engine._send({"type": "combo_data", **payload})
engine._send({"type": "timeline_update", "steps": engine.timeline_steps()})