|
| 1 | +import { InputType } from 'sb3-types/enum' |
| 2 | +import { fromPrimitiveSource } from '../core/block-helper' |
| 3 | +import { block, valueBlock } from '../core/composer' |
| 4 | +import type { |
| 5 | + HikkakuNumber, |
| 6 | + HikkakuString, |
| 7 | + PrimitiveSource, |
| 8 | +} from '../core/types' |
| 9 | + |
| 10 | +export type VideoSensingAttribute = 'motion' | 'direction' |
| 11 | +export type VideoSensingSubject = 'this sprite' | 'stage' |
| 12 | +export type VideoState = 'on' | 'off' | 'on-flipped' |
| 13 | + |
| 14 | +export const whenMotionGreaterThan = ( |
| 15 | + reference: PrimitiveSource<HikkakuNumber>, |
| 16 | +) => { |
| 17 | + return block('videoSensing_whenMotionGreaterThan', { |
| 18 | + inputs: { |
| 19 | + REFERENCE: fromPrimitiveSource(InputType.Number, reference, 10), |
| 20 | + }, |
| 21 | + }) |
| 22 | +} |
| 23 | + |
| 24 | +export const videoOn = ( |
| 25 | + attribute: PrimitiveSource<HikkakuString>, |
| 26 | + subject: PrimitiveSource<HikkakuString>, |
| 27 | +) => { |
| 28 | + return valueBlock<HikkakuNumber>('videoSensing_videoOn', { |
| 29 | + inputs: { |
| 30 | + ATTRIBUTE: fromPrimitiveSource(InputType.String, attribute, 'motion'), |
| 31 | + SUBJECT: fromPrimitiveSource(InputType.String, subject, 'this sprite'), |
| 32 | + }, |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +export const videoToggle = (state: PrimitiveSource<HikkakuString>) => { |
| 37 | + return block('videoSensing_videoToggle', { |
| 38 | + inputs: { |
| 39 | + VIDEO_STATE: fromPrimitiveSource(InputType.String, state, 'on'), |
| 40 | + }, |
| 41 | + }) |
| 42 | +} |
| 43 | + |
| 44 | +export const setVideoTransparency = ( |
| 45 | + transparency: PrimitiveSource<HikkakuNumber>, |
| 46 | +) => { |
| 47 | + return block('videoSensing_setVideoTransparency', { |
| 48 | + inputs: { |
| 49 | + TRANSPARENCY: fromPrimitiveSource(InputType.Number, transparency, 50), |
| 50 | + }, |
| 51 | + }) |
| 52 | +} |
0 commit comments