feat(blocks): add text2speech/translate/videoSensing block factories - #153
feat(blocks): add text2speech/translate/videoSensing block factories#153nakasyou wants to merge 1 commit into
Conversation
…locks Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #153 +/- ##
==========================================
+ Coverage 80.72% 80.80% +0.08%
==========================================
Files 50 53 +3
Lines 4083 4101 +18
Branches 590 590
==========================================
+ Hits 3296 3314 +18
Misses 549 549
Partials 238 238
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@Kicky1618 review |
There was a problem hiding this comment.
Pull request overview
Adds first-class block factory helpers for several Scratch “default extension” opcodes (Text to Speech, Translate, Video Sensing) so hikkaku/blocks can emit those blocks directly and so they’re covered by unit tests and docs generation.
Changes:
- Added new block factory modules:
text2speech,translate,videosensing - Added unit tests asserting the expected extension opcodes are emitted
- Re-exported the new modules from the public
blocksentrypoint
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/hikkaku/src/blocks/videosensing.ts | Implements Video Sensing block factories (including a hat-like block). |
| packages/hikkaku/src/blocks/videosensing.test.ts | Verifies Video Sensing opcodes appear in composed block output. |
| packages/hikkaku/src/blocks/translate.ts | Implements Translate reporter block factories. |
| packages/hikkaku/src/blocks/translate.test.ts | Verifies Translate opcodes appear in composed block output. |
| packages/hikkaku/src/blocks/text2speech.ts | Implements Text to Speech statement block factories. |
| packages/hikkaku/src/blocks/text2speech.test.ts | Verifies Text to Speech opcodes appear in composed block output. |
| packages/hikkaku/src/blocks/index.ts | Exposes the new modules via the public hikkaku/blocks entrypoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export const translate = ( | ||
| words: PrimitiveSource<HikkakuString>, | ||
| language: PrimitiveSource<HikkakuString>, | ||
| ) => { | ||
| return valueBlock<HikkakuString>('translate_getTranslate', { | ||
| inputs: { | ||
| WORDS: fromPrimitiveSource(InputType.String, words, 'hello'), | ||
| LANGUAGE: fromPrimitiveSource(InputType.String, language, 'ja'), | ||
| }, | ||
| }) |
There was a problem hiding this comment.
translate_getTranslate’s LANGUAGE argument is typically a dropdown/menu in Scratch, but here it’s represented as a plain string input. Elsewhere, dropdowns are modeled as fields or menuInput with a shadow menu block (e.g. sensing_keypressed). Consider aligning with that approach so generated SB3 retains expected menu/shadow structure and callers get clearer intent.
| export const translate = ( | ||
| words: PrimitiveSource<HikkakuString>, | ||
| language: PrimitiveSource<HikkakuString>, | ||
| ) => { | ||
| return valueBlock<HikkakuString>('translate_getTranslate', { | ||
| inputs: { | ||
| WORDS: fromPrimitiveSource(InputType.String, words, 'hello'), | ||
| LANGUAGE: fromPrimitiveSource(InputType.String, language, 'ja'), | ||
| }, | ||
| }) | ||
| } |
There was a problem hiding this comment.
This new module’s public exports are missing JSDoc comments, while most existing block factories in this directory include structured JSDoc used for reference docs/examples (see blocks/looks.ts, blocks/music.ts, etc.). Adding doc comments here would keep the generated docs consistent with the rest of the blocks API.
| export const whenMotionGreaterThan = ( | ||
| reference: PrimitiveSource<HikkakuNumber>, | ||
| ) => { | ||
| return block('videoSensing_whenMotionGreaterThan', { | ||
| inputs: { | ||
| REFERENCE: fromPrimitiveSource(InputType.Number, reference, 10), | ||
| }, | ||
| }) | ||
| } |
There was a problem hiding this comment.
This new module adds public block factories but does not include the JSDoc-style documentation used throughout packages/hikkaku/src/blocks (inputs/outputs + @example). Since the PR mentions documentation generation, consider adding JSDoc for these exports to match the rest of the blocks API.
| export const whenMotionGreaterThan = ( | ||
| reference: PrimitiveSource<HikkakuNumber>, | ||
| ) => { | ||
| return block('videoSensing_whenMotionGreaterThan', { | ||
| inputs: { | ||
| REFERENCE: fromPrimitiveSource(InputType.Number, reference, 10), | ||
| }, | ||
| }) |
There was a problem hiding this comment.
videoSensing_whenMotionGreaterThan is a hat block in Scratch, but this factory creates it as a normal statement (no topLevel: true and no stack attachment). This can lead to invalid scripts (hat blocks chained under another block) and prevents the block from being used like other hat helpers (e.g. whenFlagClicked). Consider adding topLevel: true and an optional stack?: () => void parameter using attachStack (as done in blocks/events.ts).
| attribute: PrimitiveSource<HikkakuString>, | ||
| subject: PrimitiveSource<HikkakuString>, | ||
| ) => { | ||
| return valueBlock<HikkakuNumber>('videoSensing_videoOn', { | ||
| inputs: { | ||
| ATTRIBUTE: fromPrimitiveSource(InputType.String, attribute, 'motion'), | ||
| SUBJECT: fromPrimitiveSource(InputType.String, subject, 'this sprite'), |
There was a problem hiding this comment.
These dropdown-like parameters (ATTRIBUTE, SUBJECT) are currently encoded as plain string inputs via fromPrimitiveSource. Elsewhere in this codebase, menu/dropdown inputs are typically modeled with menuInput(...) + a shadow menu reporter block (see sensing.getKeyPressed / menuOfKeyOptions) or as fields when the value is a true field. Encoding this as a primitive string input may lose the expected menu shadow block / UI semantics in generated SB3. Consider switching to a menu helper (or fields) consistent with other dropdowns.
| attribute: PrimitiveSource<HikkakuString>, | |
| subject: PrimitiveSource<HikkakuString>, | |
| ) => { | |
| return valueBlock<HikkakuNumber>('videoSensing_videoOn', { | |
| inputs: { | |
| ATTRIBUTE: fromPrimitiveSource(InputType.String, attribute, 'motion'), | |
| SUBJECT: fromPrimitiveSource(InputType.String, subject, 'this sprite'), | |
| attribute: VideoSensingAttribute, | |
| subject: VideoSensingSubject, | |
| ) => { | |
| return valueBlock<HikkakuNumber>('videoSensing_videoOn', { | |
| fields: { | |
| ATTRIBUTE: [attribute, null], | |
| SUBJECT: [subject, null], |
| export const videoToggle = (state: PrimitiveSource<HikkakuString>) => { | ||
| return block('videoSensing_videoToggle', { | ||
| inputs: { | ||
| VIDEO_STATE: fromPrimitiveSource(InputType.String, state, 'on'), |
There was a problem hiding this comment.
VIDEO_STATE is a dropdown in Scratch, but it is currently represented as a generic string input. To match other dropdown/menu patterns in this repo (and Scratch’s SB3 structure), consider modeling this as fields: { VIDEO_STATE: [...] } or via menuInput + a shadow menu reporter block, rather than fromPrimitiveSource(InputType.String, ...).
| export const videoToggle = (state: PrimitiveSource<HikkakuString>) => { | |
| return block('videoSensing_videoToggle', { | |
| inputs: { | |
| VIDEO_STATE: fromPrimitiveSource(InputType.String, state, 'on'), | |
| export const videoToggle = (state: VideoState) => { | |
| return block('videoSensing_videoToggle', { | |
| fields: { | |
| VIDEO_STATE: [state, null], |
| export const speakAndWait = (words: PrimitiveSource<HikkakuString>) => { | ||
| return block('text2speech_speakAndWait', { | ||
| inputs: { | ||
| WORDS: fromPrimitiveSource(InputType.String, words, 'hello'), | ||
| }, | ||
| }) |
There was a problem hiding this comment.
The exported block factories in this new module are missing the JSDoc pattern used across packages/hikkaku/src/blocks (description, inputs/outputs, @example, etc.), which is likely important for the reference doc generation mentioned in the PR description. Consider adding doc comments for the public exports (similar to music.ts / looks.ts) so generated docs remain consistent.
| export const setVoice = (voice: PrimitiveSource<HikkakuString>) => { | ||
| return block('text2speech_setVoice', { | ||
| inputs: { | ||
| VOICE: fromPrimitiveSource(InputType.String, voice, 'ALTO'), | ||
| }, | ||
| }) |
There was a problem hiding this comment.
TextToSpeechVoice is declared, but setVoice accepts PrimitiveSource<HikkakuString> and encodes VOICE as a generic string input. If this block is meant to reflect Scratch’s voice dropdown, consider using the TextToSpeechVoice type in the API (and encoding as a dropdown via fields or menuInput + a shadow menu block) so callers get type safety and the generated SB3 better matches Scratch semantics.
Motivation
Description
packages/hikkaku/src/blocks/text2speech.ts,translate.ts, andvideosensing.tsproviding block factories fortext2speech_*,translate_*, andvideoSensing_*opcodes respectively.text2speech.test.ts,translate.test.ts, andvideosensing.test.tsthat assert the expected opcodes are emitted when blocks are composed.packages/hikkaku/src/blocks/index.tsso they are available from the publicblocksentrypoint.PrimitiveSource<HikkakuString>/PrimitiveSource<HikkakuNumber>) to satisfy existingHikkakuTypeconstraints and avoid unconnected value-block test errors.Testing
bun fmtto apply formatting and fixes (successful).bun run typecheck && bun run testinpackages/hikkaku, and all tests passed (50tests across27files).bun ref:buildto update reference docs (successful); note that a full repo-levelbun typecheckpreviously failed in this environment becausemoonis not installed when buildingpackages/moonscratch, which is environment-specific and unrelated to these package changes.Codex Task