fixing mood block (#349)
This commit is contained in:
37
libs/ev3/docs/reference/brick/show-mood.md
Normal file
37
libs/ev3/docs/reference/brick/show-mood.md
Normal file
@ -0,0 +1,37 @@
|
||||
# show Mood
|
||||
|
||||
Show a mood on the brick. A mood will have a image on the display along with a sound and solid or flashing light.
|
||||
|
||||
```sig
|
||||
brick.showMood(moods.sleeping)
|
||||
```
|
||||
You can choose one of several moods to show on the display. Use a mood to help show what your @boardname@ is doing at the moment.
|
||||
|
||||
## Parameters
|
||||
|
||||
**mood**: A mood to show on the brick. Choose one of these moods:
|
||||
>* ``sleeping``
|
||||
* ``awake``
|
||||
* ``tired``
|
||||
* ``angry``
|
||||
* ``sad``
|
||||
* ``dizzy``
|
||||
* ``knockedOut``
|
||||
* ``middleLeft``
|
||||
* ``middleRight``
|
||||
* ``love``
|
||||
* ``winking``
|
||||
* ``neutral``
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
Show a ``winking`` mood on the brick.
|
||||
|
||||
```blocks
|
||||
brick.showMood(moods.winking)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[show image](/reference/brick/show-image)
|
126
libs/ev3/mood.ts
Normal file
126
libs/ev3/mood.ts
Normal file
@ -0,0 +1,126 @@
|
||||
namespace brick {
|
||||
/**
|
||||
* Show a mood on the brick's screen
|
||||
*/
|
||||
//% weight=90
|
||||
//% blockId=moodShow block="show mood %mood=mood_image_picker"
|
||||
//% help=brick/show-mood
|
||||
//% weight=101 group="Screen" blockGap=8
|
||||
export function showMood(mood: Mood) {
|
||||
if(mood)
|
||||
mood.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* A mood
|
||||
*/
|
||||
//% fixedInstances
|
||||
export class Mood {
|
||||
private image: Image;
|
||||
private sound: Sound;
|
||||
private light: StatusLight;
|
||||
|
||||
constructor(image: Image, sound: Sound, light: StatusLight) {
|
||||
this.image = image;
|
||||
this.sound = sound;
|
||||
this.light = light;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the mood on the EV3
|
||||
*/
|
||||
show() {
|
||||
brick.setStatusLight(this.light);
|
||||
brick.showImage(this.image);
|
||||
music.playSoundEffectUntilDone(this.sound);
|
||||
pause(20);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An image
|
||||
* @param image the image
|
||||
*/
|
||||
//% blockId=mood_image_picker block="%mood" shim=TD_ID
|
||||
//% mood.fieldEditor="images"
|
||||
//% mood.fieldOptions.columns=4
|
||||
//% mood.fieldOptions.width=400
|
||||
//% group="Screen" weight=0 blockHidden=1
|
||||
export function __moodImagePicker(mood: Mood): Mood {
|
||||
return mood;
|
||||
}
|
||||
}
|
||||
|
||||
namespace moods {
|
||||
/**
|
||||
* A sleeping mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesSleeping
|
||||
export const sleeping = new brick.Mood(images.eyesSleeping, sounds.expressionsSnoring, StatusLight.OrangePulse);
|
||||
|
||||
/**
|
||||
* A awake mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesAwake
|
||||
export const awake = new brick.Mood(images.eyesAwake, sounds.informationActivate, StatusLight.Orange);
|
||||
|
||||
/**
|
||||
* A tired mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesTiredMiddle
|
||||
export const tired = new brick.Mood(images.eyesTiredMiddle, sounds.expressionsSneezing, StatusLight.OrangeFlash);
|
||||
|
||||
/**
|
||||
* An angry mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesAngry
|
||||
export const angry = new brick.Mood(images.eyesAngry, sounds.animalsDogGrowl, StatusLight.RedPulse);
|
||||
|
||||
/**
|
||||
* A sad mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesTear
|
||||
export const sad = new brick.Mood(images.eyesTear, sounds.animalsDogWhine, StatusLight.Red);
|
||||
|
||||
/**
|
||||
* A dizzy mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesDizzy
|
||||
export const dizzy = new brick.Mood(images.eyesDizzy, sounds.expressionsUhOh, StatusLight.OrangeFlash);
|
||||
|
||||
/**
|
||||
* A knocked out mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesKnockedOut
|
||||
export const knockedOut = new brick.Mood(images.eyesKnockedOut, sounds.informationError, StatusLight.RedFlash);
|
||||
|
||||
/**
|
||||
* Looking around left
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesMiddleLeft
|
||||
export const middleLeft = new brick.Mood(images.eyesMiddleLeft, sounds.informationAnalyze, StatusLight.Off);
|
||||
|
||||
/**
|
||||
* Looking around right
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesMiddleRight
|
||||
export const middleRight = new brick.Mood(images.eyesMiddleRight, sounds.informationAnalyze, StatusLight.Off);
|
||||
|
||||
/**
|
||||
* In love mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesLove
|
||||
export const love = new brick.Mood(images.eyesLove, sounds.expressionsMagicWand, StatusLight.GreenPulse);
|
||||
|
||||
/**
|
||||
* In laughing mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesWinking
|
||||
export const winking = new brick.Mood(images.eyesWinking, sounds.expressionsLaughing1, StatusLight.GreenFlash);
|
||||
|
||||
/**
|
||||
* In a neutral mood
|
||||
*/
|
||||
//% fixedInstance jres=images.eyesNeutral
|
||||
export const neutral = new brick.Mood(images.eyesNeutral, undefined, StatusLight.Green);
|
||||
}
|
@ -6,7 +6,8 @@
|
||||
"ns.ts",
|
||||
"startup.ts",
|
||||
"images.jres",
|
||||
"images.ts"
|
||||
"images.ts",
|
||||
"mood.ts"
|
||||
],
|
||||
"dependencies": {
|
||||
"base": "file:../base",
|
||||
@ -17,8 +18,7 @@
|
||||
"touch-sensor": "file:../touch-sensor",
|
||||
"ultrasonic-sensor": "file:../ultrasonic-sensor",
|
||||
"gyro-sensor": "file:../gyro-sensor",
|
||||
"infrared-sensor": "file:../infrared-sensor",
|
||||
"mood": "file:../mood"
|
||||
"infrared-sensor": "file:../infrared-sensor"
|
||||
},
|
||||
"public": true
|
||||
}
|
||||
|
Reference in New Issue
Block a user