fifa17-recon: fix active squad resetting on reload
FIFA's updateActiveSquad PUT stores each slot as itemData={id:<clubItemId>}
(a reference), not the full player. We saved the bare references, so the
squad reloaded empty ("active squad resets"). Add Store.reconstruct_squad()
to re-embed the full club item by id on GET /squad/0, so the saved squad
reloads with its real players.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PN5bmpDVQR1aXgefyWAt7o
This commit is contained in:
@@ -149,6 +149,22 @@ class Store:
|
||||
sq = self.load()["squads"]
|
||||
return sq[0] if sq else None
|
||||
|
||||
def reconstruct_squad(self, squad):
|
||||
"""FIFA's updateActiveSquad PUT stores each slot as itemData={id:<clubItemId>}
|
||||
(a reference). Re-embed the FULL club item by id so the squad reloads with
|
||||
real players instead of empty slots ('active squad resets')."""
|
||||
by_id = {it["id"]: it for it in self.items()}
|
||||
out = dict(squad)
|
||||
players = []
|
||||
for pl in squad.get("players", []):
|
||||
iid = (pl.get("itemData") or {}).get("id", 0)
|
||||
if iid and iid in by_id:
|
||||
players.append({**pl, "itemData": by_id[iid]})
|
||||
else:
|
||||
players.append(pl)
|
||||
out["players"] = players
|
||||
return out
|
||||
|
||||
def new_item_id(self):
|
||||
with _LOCK:
|
||||
p = self.load(); i = p["nextItemId"]; p["nextItemId"] += 1; self._save()
|
||||
|
||||
@@ -204,7 +204,7 @@ def squad_route(h):
|
||||
STORE.save_squad(sq)
|
||||
return 200, sq
|
||||
saved = STORE.active_squad()
|
||||
return 200, (saved if saved else SQUAD)
|
||||
return 200, (STORE.reconstruct_squad(saved) if saved else SQUAD)
|
||||
|
||||
|
||||
# ---- STORE / PACKS (first-cut; iterate against the log) ---------------------
|
||||
|
||||
Reference in New Issue
Block a user