mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-14 15:03:59 -04:00
Implementation + tests for loud? block
This commit is contained in:
parent
23e72525bf
commit
8e271c70d0
3 changed files with 30 additions and 0 deletions
|
@ -65,6 +65,7 @@ class Scratch3SensingBlocks {
|
||||||
sensing_current: this.current,
|
sensing_current: this.current,
|
||||||
sensing_dayssince2000: this.daysSince2000,
|
sensing_dayssince2000: this.daysSince2000,
|
||||||
sensing_loudness: this.getLoudness,
|
sensing_loudness: this.getLoudness,
|
||||||
|
sensing_loud: this.isLoud,
|
||||||
sensing_askandwait: this.askAndWait,
|
sensing_askandwait: this.askAndWait,
|
||||||
sensing_answer: this.getAnswer
|
sensing_answer: this.getAnswer
|
||||||
};
|
};
|
||||||
|
@ -249,6 +250,10 @@ class Scratch3SensingBlocks {
|
||||||
return this._cachedLoudness;
|
return this._cachedLoudness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isLoud () {
|
||||||
|
return this.getLoudness() > 10;
|
||||||
|
}
|
||||||
|
|
||||||
getAttributeOf (args) {
|
getAttributeOf (args) {
|
||||||
let attrTarget;
|
let attrTarget;
|
||||||
|
|
||||||
|
|
|
@ -964,6 +964,11 @@ const specMap = {
|
||||||
argMap: [
|
argMap: [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
'isLoud': {
|
||||||
|
opcode: 'sensing_loud',
|
||||||
|
argMap: [
|
||||||
|
]
|
||||||
|
},
|
||||||
// 'senseVideoMotion': {
|
// 'senseVideoMotion': {
|
||||||
// opcode: 'sensing_videoon',
|
// opcode: 'sensing_videoon',
|
||||||
// argMap: [
|
// argMap: [
|
||||||
|
|
|
@ -123,3 +123,23 @@ test('get loudness with caching', t => {
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('loud? boolean', t => {
|
||||||
|
const rt = new Runtime();
|
||||||
|
const sensing = new Sensing(rt);
|
||||||
|
|
||||||
|
// The simplest way to test this is to actually override the getLoudness
|
||||||
|
// method, which isLoud uses.
|
||||||
|
let simulatedLoudness = 0;
|
||||||
|
sensing.getLoudness = () => simulatedLoudness;
|
||||||
|
t.false(sensing.isLoud());
|
||||||
|
|
||||||
|
// Check for GREATER than 10, not equal.
|
||||||
|
simulatedLoudness = 10;
|
||||||
|
t.false(sensing.isLoud());
|
||||||
|
|
||||||
|
simulatedLoudness = 11;
|
||||||
|
t.true(sensing.isLoud());
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue