fix: Drizzle transaction execution, canvas re-init, crowd removal

- Add .run() to all Drizzle queries inside sqlite.transaction() in
  orchestrator.ts and mock.ts — queries were building but never executing,
  leaving fights stuck as 'live' forever
- Remove spectator crowd from drawArenaDecor()
- Rename duplicate spawnProp to spawnWeaponProp (was crashing module load)
- Replace canvas element on re-init to avoid "KAPLAY already initialized"
- Add safeText() to strip brackets from k.text() calls (Kaplay treats
  [ ] as style markup, crashes on unclosed tags)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-07 00:53:15 +00:00
co-authored by Claude Opus 4.6
parent 4d8b18a58a
commit e49735002c
4 changed files with 31 additions and 180 deletions
+7 -7
View File
@@ -360,7 +360,7 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
botAHp: hpA,
botBHp: hpB,
totalRounds: round,
}).where(eq(schema.fights.id, fightId))
}).where(eq(schema.fights.id, fightId)).run()
// Check for KO
if (hpA <= KO_THRESHOLD || hpB <= KO_THRESHOLD) {
@@ -390,7 +390,7 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
status: 'finished',
winnerId,
endedAt: new Date().toISOString(),
}).where(eq(schema.fights.id, fightId))
}).where(eq(schema.fights.id, fightId)).run()
// Update bot stats
if (winnerId) {
@@ -409,7 +409,7 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
bestStreak: newBestStreak,
tier: calculateTier(newWinnerElo, winner.wins + 1),
lastFightAt: new Date().toISOString(),
}).where(eq(schema.bots.id, winnerId))
}).where(eq(schema.bots.id, winnerId)).run()
db.update(schema.bots).set({
losses: sql`${schema.bots.losses} + 1`,
@@ -417,11 +417,11 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
winStreak: 0,
tier: calculateTier(newLoserElo, loser.wins),
lastFightAt: new Date().toISOString(),
}).where(eq(schema.bots.id, loserId))
}).where(eq(schema.bots.id, loserId)).run()
} else {
// Draw — update lastFightAt for both
db.update(schema.bots).set({ lastFightAt: new Date().toISOString() }).where(eq(schema.bots.id, botA.id))
db.update(schema.bots).set({ lastFightAt: new Date().toISOString() }).where(eq(schema.bots.id, botB.id))
db.update(schema.bots).set({ lastFightAt: new Date().toISOString() }).where(eq(schema.bots.id, botA.id)).run()
db.update(schema.bots).set({ lastFightAt: new Date().toISOString() }).where(eq(schema.bots.id, botB.id)).run()
}
})
@@ -479,7 +479,7 @@ export async function runFightAsync(botAId: string, botBId: string): Promise<str
db.update(schema.fights).set({
status: 'cancelled',
endedAt: new Date().toISOString(),
}).where(eq(schema.fights.id, fightId))
}).where(eq(schema.fights.id, fightId)).run()
fightEvents.cleanup(fightId)
})
.finally(() => {