fix: make vhsTracking accept ChoreoContext directly, remove as any cast

Effect functions now accept FightContext | ChoreoContext union type,
eliminating the unsafe cast in rounds.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 06:21:06 +00:00
co-authored by Claude Opus 4.6
parent 86bf534f50
commit 81048ff22f
2 changed files with 8 additions and 7 deletions
+7 -5
View File
@@ -1,7 +1,9 @@
import type { GameObj } from 'kaplay'
import type { FightContext } from './types'
import type { FightContext, ChoreoContext } from './types'
export function glitchRGB(ctx: FightContext, duration: number = 0.2): void {
type EffectContext = FightContext | ChoreoContext
export function glitchRGB(ctx: EffectContext, duration: number = 0.2): void {
const { k, W, H, safeColor, trackedTimeout } = ctx
const layers = [
{ color: '#ff0000', dx: 4 + Math.random() * 6, dy: -2 },
@@ -20,7 +22,7 @@ export function glitchRGB(ctx: FightContext, duration: number = 0.2): void {
}
}
export function scanlineGlitch(ctx: FightContext, duration: number = 0.3): void {
export function scanlineGlitch(ctx: EffectContext, duration: number = 0.3): void {
const { k, W, H, safeColor } = ctx
const lines: GameObj[] = []
const count = 6 + Math.floor(Math.random() * 8)
@@ -41,7 +43,7 @@ export function scanlineGlitch(ctx: FightContext, duration: number = 0.3): void
ctx.trackedTimeout(() => { lines.forEach(l => { if (l.exists()) l.destroy() }) }, duration * 1000)
}
export function vhsTracking(ctx: FightContext, duration: number = 0.4): void {
export function vhsTracking(ctx: EffectContext, duration: number = 0.4): void {
const { k, W, H, safeColor, theme } = ctx
const bands: GameObj[] = []
const bandCount = 3
@@ -61,7 +63,7 @@ export function vhsTracking(ctx: FightContext, duration: number = 0.4): void {
ctx.trackedTimeout(() => { bands.forEach(b => { if (b.exists()) b.destroy() }) }, duration * 1000)
}
export function dimensionalShift(ctx: FightContext, duration: number = 0.6): void {
export function dimensionalShift(ctx: EffectContext, duration: number = 0.6): void {
const { k, W, H, safeColor, trackedInterval, trackedTimeout, clearTracked } = ctx
const colors = ['#ff00ff', '#00ffff', '#ff0000', '#0000ff', '#ffff00']
let idx = 0
+1 -2
View File
@@ -64,9 +64,8 @@ export function createRoundSystem(ctx: ChoreoContext, deps: RoundDeps) {
showSpeechBubble,
} = deps
// Local vhsTracking wrapper — effects.ts expects FightContext, pass ctx as compatible
function vhsTracking(duration?: number) {
_vhsTracking(ctx as any, duration)
_vhsTracking(ctx, duration)
}
const heartfeltLines = [