-
Notifications
You must be signed in to change notification settings - Fork 3
feat(blocks): add text2speech/translate/videoSensing block factories #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { describe, expect, test } from 'vite-plus/test' | ||
| import { block, createBlocks } from '../core/composer' | ||
| import { setLanguage, setVoice, speakAndWait } from './text2speech' | ||
|
|
||
| describe('blocks/text2speech', () => { | ||
| test('creates text to speech extension blocks', () => { | ||
| const blocks = createBlocks(() => { | ||
| block('event_whenflagclicked', { topLevel: true }) | ||
| setVoice('TENOR') | ||
| setLanguage('ja') | ||
| speakAndWait('hello') | ||
| }) | ||
|
|
||
| const opcodes = Object.values(blocks).map((b) => b.opcode) | ||
| expect(opcodes).toContain('text2speech_setVoice') | ||
| expect(opcodes).toContain('text2speech_setLanguage') | ||
| expect(opcodes).toContain('text2speech_speakAndWait') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { InputType } from 'sb3-types/enum' | ||
| import { fromPrimitiveSource } from '../core/block-helper' | ||
| import { block } from '../core/composer' | ||
| import type { HikkakuString, PrimitiveSource } from '../core/types' | ||
|
|
||
| export type TextToSpeechVoice = | ||
| | 'ALTO' | ||
| | 'TENOR' | ||
| | 'SQUEAK' | ||
| | 'GIANT' | ||
| | 'KITTEN' | ||
| | 'GOOGLE' | ||
|
|
||
| export const speakAndWait = (words: PrimitiveSource<HikkakuString>) => { | ||
| return block('text2speech_speakAndWait', { | ||
| inputs: { | ||
| WORDS: fromPrimitiveSource(InputType.String, words, 'hello'), | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| export const setVoice = (voice: PrimitiveSource<HikkakuString>) => { | ||
| return block('text2speech_setVoice', { | ||
| inputs: { | ||
| VOICE: fromPrimitiveSource(InputType.String, voice, 'ALTO'), | ||
| }, | ||
| }) | ||
|
Comment on lines
+22
to
+27
|
||
| } | ||
|
|
||
| export const setLanguage = (language: PrimitiveSource<HikkakuString>) => { | ||
| return block('text2speech_setLanguage', { | ||
| inputs: { | ||
| LANGUAGE: fromPrimitiveSource(InputType.String, language, 'en'), | ||
| }, | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { describe, expect, test } from 'vite-plus/test' | ||
| import { block, createBlocks } from '../core/composer' | ||
| import { say } from './looks' | ||
| import { getViewerLanguage, translate } from './translate' | ||
|
|
||
| describe('blocks/translate', () => { | ||
| test('creates translate extension blocks', () => { | ||
| const blocks = createBlocks(() => { | ||
| block('event_whenflagclicked', { topLevel: true }) | ||
| say(translate('hello', 'ja')) | ||
| say(getViewerLanguage()) | ||
| }) | ||
|
|
||
| const opcodes = Object.values(blocks).map((b) => b.opcode) | ||
| expect(opcodes).toContain('translate_getTranslate') | ||
| expect(opcodes).toContain('translate_getViewerLanguage') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { InputType } from 'sb3-types/enum' | ||
| import { fromPrimitiveSource } from '../core/block-helper' | ||
| import { valueBlock } from '../core/composer' | ||
| import type { HikkakuString, PrimitiveSource } from '../core/types' | ||
|
|
||
| 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'), | ||
| }, | ||
| }) | ||
|
Comment on lines
+6
to
+15
|
||
| } | ||
|
Comment on lines
+6
to
+16
|
||
|
|
||
| export const getViewerLanguage = () => { | ||
| return valueBlock<HikkakuString>('translate_getViewerLanguage', {}) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { describe, expect, test } from 'vite-plus/test' | ||
| import { block, createBlocks } from '../core/composer' | ||
| import { say } from './looks' | ||
| import { | ||
| setVideoTransparency, | ||
| videoOn, | ||
| videoToggle, | ||
| whenMotionGreaterThan, | ||
| } from './videosensing' | ||
|
|
||
| describe('blocks/videosensing', () => { | ||
| test('creates video sensing extension blocks', () => { | ||
| const blocks = createBlocks(() => { | ||
| block('event_whenflagclicked', { topLevel: true }) | ||
| whenMotionGreaterThan(10) | ||
| say(videoOn('motion', 'this sprite')) | ||
| videoToggle('on') | ||
| setVideoTransparency(50) | ||
| }) | ||
|
|
||
| const opcodes = Object.values(blocks).map((b) => b.opcode) | ||
| expect(opcodes).toContain('videoSensing_whenMotionGreaterThan') | ||
| expect(opcodes).toContain('videoSensing_videoOn') | ||
| expect(opcodes).toContain('videoSensing_videoToggle') | ||
| expect(opcodes).toContain('videoSensing_setVideoTransparency') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,52 @@ | ||||||||||||||||||||||||||||||
| import { InputType } from 'sb3-types/enum' | ||||||||||||||||||||||||||||||
| import { fromPrimitiveSource } from '../core/block-helper' | ||||||||||||||||||||||||||||||
| import { block, valueBlock } from '../core/composer' | ||||||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||||||
| HikkakuNumber, | ||||||||||||||||||||||||||||||
| HikkakuString, | ||||||||||||||||||||||||||||||
| PrimitiveSource, | ||||||||||||||||||||||||||||||
| } from '../core/types' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export type VideoSensingAttribute = 'motion' | 'direction' | ||||||||||||||||||||||||||||||
| export type VideoSensingSubject = 'this sprite' | 'stage' | ||||||||||||||||||||||||||||||
| export type VideoState = 'on' | 'off' | 'on-flipped' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export const whenMotionGreaterThan = ( | ||||||||||||||||||||||||||||||
| reference: PrimitiveSource<HikkakuNumber>, | ||||||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||||||
| return block('videoSensing_whenMotionGreaterThan', { | ||||||||||||||||||||||||||||||
| inputs: { | ||||||||||||||||||||||||||||||
| REFERENCE: fromPrimitiveSource(InputType.Number, reference, 10), | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+21
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+22
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export const videoOn = ( | ||||||||||||||||||||||||||||||
| 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'), | ||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+31
|
||||||||||||||||||||||||||||||
| 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], |
Copilot
AI
Apr 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 tomusic.ts/looks.ts) so generated docs remain consistent.