Skip to content

refactor(sfx): extract shared scene SFX picker into sfx-selector#5

Open
nguyentran4896 wants to merge 1 commit into
hoquanghai:mainfrom
nguyentran4896:refactor/dedupe-sfx-picker
Open

refactor(sfx): extract shared scene SFX picker into sfx-selector#5
nguyentran4896 wants to merge 1 commit into
hoquanghai:mainfrom
nguyentran4896:refactor/dedupe-sfx-picker

Conversation

@nguyentran4896
Copy link
Copy Markdown

Summary

  • src/pipeline.ts (lines ~129–169) and rerender.ts (lines ~67–93) contained near-identical loops that iterate over scenes and call the 3-tier SFX selector to build a per-scene SfxMixSpec[] list.
  • This PR extracts that loop into a new exported function pickSfxForScenes() in src/assets/sfx-selector.ts and updates both call sites.
  • Behavior is fully preserved: same SFX files are picked in the same order. The only difference between the two original loops was logging style; the new function accepts an optional logger parameter so each call site retains its own log style (log.info/log.warn in pipeline, console.log/silent in rerender).

New function signature

pickSfxForScenes(args: {
  scenes: Script["scenes"];
  sceneStarts: Record<string, number>;
  sfxIndex: SfxIndex;
  sfxDir: string;
  logger?: { info(msg: string): void; warn(msg: string): void };
}): SfxMixSpec[]

New test cases (src/assets/sfx-scenes-picker.test.ts)

  • Returns empty list when scenes array is empty
  • Uses explicit sfx override when the file exists on disk
  • Skips scene when sfx.name === "none"
  • Picks semantically matched SFX when voiceText triggers a keyword rule
  • Falls back to template default when no semantic keyword matches
  • Passes log messages to the provided logger
  • Skips and warns when explicit SFX file does not exist on disk

Verification

npm run typecheck and npm test both pass (51 tests, 10 test files + new file).

🤖 Generated with Claude Code

Both pipeline.ts and rerender.ts contained near-identical loops that
built a per-scene SfxMixSpec[] list using the 3-tier selection logic.
Extract this into pickSfxForScenes() in sfx-selector.ts, accepting an
optional logger so each call site can retain its existing log style.
Both call sites are updated; behavior is identical.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant