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")
))