fix(gameplay & db): fix casino spin freeze, bank deposit sync, and plant selection menu (fixes #8, #9, #10)

This commit is contained in:
Antigravity committed 2026-09-22 12:04:30 +00:00
1 parent 351d5f1cca
commit bd314730ff
7 files changed
+247 -33

No files matched your search

+82 -9
View File
@@ -498,6 +498,10 @@ def init_db():
zen_garden TEXT DEFAULT '{}',
tree_of_wisdom TEXT DEFAULT '{}',
achievements TEXT DEFAULT '{}',
stats TEXT DEFAULT '{}',
casino TEXT DEFAULT '{}',
zombie_lab TEXT DEFAULT '{}',
admin_updated_at TIMESTAMP DEFAULT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
)
@@ -608,6 +612,10 @@ def init_db():
cursor.execute("ALTER TABLE profiles ADD COLUMN stats TEXT DEFAULT '{}'")
if "admin_updated_at" not in prof_cols:
cursor.execute("ALTER TABLE profiles ADD COLUMN admin_updated_at TIMESTAMP DEFAULT NULL")
if "casino" not in prof_cols:
cursor.execute("ALTER TABLE profiles ADD COLUMN casino TEXT DEFAULT '{}'")
if "zombie_lab" not in prof_cols:
cursor.execute("ALTER TABLE profiles ADD COLUMN zombie_lab TEXT DEFAULT '{}'")
conn.commit()
conn.close()
@@ -1177,6 +1185,19 @@ def get_default_profile_dict():
"plantsPlanted": 0,
"levelsCompleted": 0,
"coinsEarned": 0
},
"casino": {
"deposit": 0,
"depositStartTime": 0,
"loan": 0,
"spinsTotal": 0,
"totalWon": 0,
"jackpotsWon": 0
},
"zombieLab": {
"unlockedStage": 1,
"mutations": {},
"levels": {"normal": 1, "conehead": 1, "buckethead": 1, "football": 1, "dancing": 1}
}
}
@@ -1212,8 +1233,8 @@ def register_user(username, password_hash, initial_data=None, ip_address="", use
cursor.execute("""
INSERT INTO profiles (
user_id, coins, level, max_unlocked_level, high_score, theme,
upgrades, materials, plant_levels, perks, zen_garden, tree_of_wisdom, achievements, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
upgrades, materials, plant_levels, perks, zen_garden, tree_of_wisdom, achievements, stats, casino, zombie_lab, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (
user_id,
profile_data.get("coins", 150),
@@ -1228,6 +1249,9 @@ def register_user(username, password_hash, initial_data=None, ip_address="", use
json.dumps(profile_data.get("zenGarden", {})),
json.dumps(profile_data.get("treeOfWisdom", {})),
json.dumps(profile_data.get("achievements", {})),
json.dumps(profile_data.get("stats", {})),
json.dumps(profile_data.get("casino", {})),
json.dumps(profile_data.get("zombieLab", {})),
now_str
))
conn.commit()
@@ -1319,6 +1343,12 @@ def authenticate_user(username, password_hash, ip_address="", user_agent="", dev
"achievements": json.loads(p["achievements"] or "{}"),
"stats": json.loads(p["stats"] or "{}") if "stats" in p.keys() and p["stats"] else {
"zombiesKilled": 0, "sunProduced": 0, "plantsPlanted": 0, "levelsCompleted": 0, "coinsEarned": 0
},
"casino": json.loads(p["casino"] or "{}") if "casino" in p.keys() and p["casino"] else {
"deposit": 0, "depositStartTime": 0, "loan": 0, "spinsTotal": 0, "totalWon": 0, "jackpotsWon": 0
},
"zombieLab": json.loads(p["zombie_lab"] or "{}") if "zombie_lab" in p.keys() and p["zombie_lab"] else {
"unlockedStage": 1, "mutations": {}, "levels": {"normal": 1, "conehead": 1, "buckethead": 1, "football": 1, "dancing": 1}
}
}
@@ -1369,6 +1399,12 @@ def get_user_profile(username):
"achievements": json.loads(p["achievements"] or "{}"),
"stats": json.loads(p["stats"] or "{}") if "stats" in p.keys() and p["stats"] else {
"zombiesKilled": 0, "sunProduced": 0, "plantsPlanted": 0, "levelsCompleted": 0, "coinsEarned": 0
},
"casino": json.loads(p["casino"] or "{}") if "casino" in p.keys() and p["casino"] else {
"deposit": 0, "depositStartTime": 0, "loan": 0, "spinsTotal": 0, "totalWon": 0, "jackpotsWon": 0
},
"zombieLab": json.loads(p["zombie_lab"] or "{}") if "zombie_lab" in p.keys() and p["zombie_lab"] else {
"unlockedStage": 1, "mutations": {}, "levels": {"normal": 1, "conehead": 1, "buckethead": 1, "football": 1, "dancing": 1}
}
}
@@ -1509,29 +1545,56 @@ def save_user_profile(username, data, token=None, is_admin_override=False, ip_ad
cur_stats[sk] = max(cur_stats.get(sk, 0), int(sv))
stats_json = json.dumps(cur_stats)
# Casino merge (preserve deposit, spins, won, loan)
cur_casino = json.loads(current["casino"] or "{}") if current and "casino" in current.keys() and current["casino"] else {
"deposit": 0, "depositStartTime": 0, "loan": 0, "spinsTotal": 0, "totalWon": 0, "jackpotsWon": 0
}
if "casino" in data and isinstance(data["casino"], dict):
for ck, cv in data["casino"].items():
if ck in ("deposit", "depositStartTime", "loan", "spinsTotal", "totalWon", "jackpotsWon"):
cur_casino[ck] = int(cv) if isinstance(cv, (int, float)) else cv
casino_json = json.dumps(cur_casino)
# Zombie Lab merge
cur_zombie_lab = json.loads(current["zombie_lab"] or "{}") if current and "zombie_lab" in current.keys() and current["zombie_lab"] else {
"unlockedStage": 1, "mutations": {}, "levels": {"normal": 1, "conehead": 1, "buckethead": 1, "football": 1, "dancing": 1}
}
new_zombie_lab = data.get("zombieLab") or data.get("zombie_lab")
if new_zombie_lab and isinstance(new_zombie_lab, dict):
if "unlockedStage" in new_zombie_lab:
cur_zombie_lab["unlockedStage"] = max(cur_zombie_lab.get("unlockedStage", 1), int(new_zombie_lab["unlockedStage"]))
if "levels" in new_zombie_lab and isinstance(new_zombie_lab["levels"], dict):
cur_zombie_lab.setdefault("levels", {}).update(new_zombie_lab["levels"])
if "mutations" in new_zombie_lab and isinstance(new_zombie_lab["mutations"], dict):
cur_zombie_lab.setdefault("mutations", {}).update(new_zombie_lab["mutations"])
zombie_lab_json = json.dumps(cur_zombie_lab)
if current:
cursor.execute("""
UPDATE profiles SET
coins = ?, level = ?, max_unlocked_level = ?, high_score = ?, theme = ?,
upgrades = ?, materials = ?, plant_levels = ?, perks = ?,
zen_garden = ?, tree_of_wisdom = ?, achievements = ?, stats = ?, admin_updated_at = ?, updated_at = ?
zen_garden = ?, tree_of_wisdom = ?, achievements = ?, stats = ?,
casino = ?, zombie_lab = ?, admin_updated_at = ?, updated_at = ?
WHERE user_id = ?
""", (
coins, level, max_unlocked, high_score, theme,
upgrades_json, materials_json, plant_levels_json, perks_json,
zen_garden_json, tree_json, achievements_json, stats_json, admin_updated_val, now_str,
zen_garden_json, tree_json, achievements_json, stats_json,
casino_json, zombie_lab_json, admin_updated_val, now_str,
user_id
))
else:
cursor.execute("""
INSERT INTO profiles (
user_id, coins, level, max_unlocked_level, high_score, theme,
upgrades, materials, plant_levels, perks, zen_garden, tree_of_wisdom, achievements, stats, admin_updated_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
upgrades, materials, plant_levels, perks, zen_garden, tree_of_wisdom, achievements, stats, casino, zombie_lab, admin_updated_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (
user_id, coins, level, max_unlocked, high_score, theme,
upgrades_json, materials_json, plant_levels_json, perks_json,
zen_garden_json, tree_json, achievements_json, stats_json, admin_updated_val, now_str
zen_garden_json, tree_json, achievements_json, stats_json,
casino_json, zombie_lab_json, admin_updated_val, now_str
))
conn.commit()
@@ -1765,6 +1828,12 @@ def admin_get_user_detail(user_id):
"stats": json.loads(p["stats"] or "{}") if "stats" in p.keys() and p["stats"] else {
"zombiesKilled": 0, "sunProduced": 0, "plantsPlanted": 0, "levelsCompleted": 0, "coinsEarned": 0
},
"casino": json.loads(p["casino"] or "{}") if "casino" in p.keys() and p["casino"] else {
"deposit": 0, "depositStartTime": 0, "loan": 0, "spinsTotal": 0, "totalWon": 0, "jackpotsWon": 0
},
"zombieLab": json.loads(p["zombie_lab"] or "{}") if "zombie_lab" in p.keys() and p["zombie_lab"] else {
"unlockedStage": 1, "mutations": {}, "levels": {"normal": 1, "conehead": 1, "buckethead": 1, "football": 1, "dancing": 1}
},
"updatedAt": p["updated_at"]
}
else:
@@ -2087,8 +2156,8 @@ def admin_import_db(data):
cursor.execute("""
INSERT INTO profiles (
user_id, coins, level, max_unlocked_level, high_score, theme,
upgrades, materials, plant_levels, perks, zen_garden, tree_of_wisdom, achievements, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
upgrades, materials, plant_levels, perks, zen_garden, tree_of_wisdom, achievements, stats, casino, zombie_lab, admin_updated_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (
p.get("user_id"),
p.get("coins", 150),
@@ -2103,6 +2172,10 @@ def admin_import_db(data):
p.get("zen_garden", "{}"),
p.get("tree_of_wisdom", "{}"),
p.get("achievements", "{}"),
p.get("stats", "{}"),
p.get("casino", "{}"),
p.get("zombie_lab", "{}"),
p.get("admin_updated_at"),
p.get("updated_at")
))
+54
View File
@@ -1320,6 +1320,59 @@ def test_v2_7_features():
record("POST /api/admin/system/cleanup authorized request", "FAIL", str(e))
def test_gitea_critical_bugfixes():
"""Verify bugfixes for Gitea issues #8, #9, and #10."""
print("\n--- 19. Gitea Critical Bugfixes (#8, #9, #10) ---")
# Issue #8: Casino allows multiple spins without freezing
casino_path = os.path.join(GAME_DIR, "js/systems/casino.js")
with open(casino_path, "r", encoding="utf-8") as f:
casino_code = f.read()
game_path = os.path.join(GAME_DIR, "js/game.js")
with open(game_path, "r", encoding="utf-8") as f:
game_code = f.read()
record("Issue #8: casino.js spin resets isSpinning to false", "PASS" if "this.isSpinning = false;" in casino_code else "FAIL")
record("Issue #8: game.js btnSpin handler releases isSpinning on completion", "PASS" if "this.casino.isSpinning = false" in game_code and "btnSpin.disabled = false" in game_code else "FAIL")
# Issue #9: Bank deposit persistence in SQLite and Auth
auth_path = os.path.join(GAME_DIR, "js/systems/auth.js")
with open(auth_path, "r", encoding="utf-8") as f:
auth_code = f.read()
record("Issue #9: auth.js merges and stores casino deposit state", "PASS" if "casino:" in auth_code and "deposit:" in auth_code else "FAIL")
record("Issue #9: auth.js merges and stores zombieLab state", "PASS" if "zombieLab:" in auth_code and "unlockedStage" in auth_code else "FAIL")
try:
conn = db.get_connection()
cursor = conn.cursor()
cursor.execute("PRAGMA table_info(profiles)")
cols = [r["name"] for r in cursor.fetchall()]
conn.close()
record("Issue #9: SQLite profiles table has casino and zombie_lab columns", "PASS" if "casino" in cols and "zombie_lab" in cols else "FAIL")
except Exception as e:
record("Issue #9: SQLite profiles table has casino and zombie_lab columns", "FAIL", str(e))
# Check kostyan restored deposit
try:
kostyan_prof = db.get_user_profile("kostyan")
has_deposit = kostyan_prof and isinstance(kostyan_prof.get("casino"), dict) and kostyan_prof["casino"].get("deposit", 0) > 0
record("Issue #9: Player kostyan deposit restored and retrievable", "PASS" if has_deposit else "FAIL", f"Deposit: {kostyan_prof.get('casino', {}).get('deposit')}")
except Exception as e:
record("Issue #9: Player kostyan deposit restored and retrievable", "FAIL", str(e))
# Issue #10: Seed selection top menu and sticky HUD
css_path = os.path.join(GAME_DIR, "css/style.css")
with open(css_path, "r", encoding="utf-8") as f:
css_code = f.read()
record("Issue #10: style.css has sticky seed deck selection bar", "PASS" if ".seed-deck-bar" in css_code and "position: sticky" in css_code else "FAIL")
economy_path = os.path.join(GAME_DIR, "js/systems/economy.js")
with open(economy_path, "r", encoding="utf-8") as f:
economy_code = f.read()
record("Issue #10: economy.js guaranteed fallback for cards array in draw()", "PASS" if "this.setDeckFromSelection()" in economy_code else "FAIL")
record("Issue #10: game.js hides pre-battle modals on startLevel", "PASS" if "seed-select-modal" in game_code and "dave-modal" in game_code else "FAIL")
def main():
print("==================================================")
print("🌱 PLANTS VS. ZOMBIES — AUTONOMOUS TEST SUITE 🌱")
@@ -1343,6 +1396,7 @@ def main():
test_admin_panel_and_configurator()
test_http_endpoint()
test_v2_7_features()
test_gitea_critical_bugfixes()
passed = sum(1 for r in TEST_RESULTS if r["status"] == "PASS")
total = len(TEST_RESULTS)