mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
Rename and initialize vars
This commit is contained in:
parent
c661ac7cce
commit
0a239005a9
1 changed files with 24 additions and 10 deletions
|
@ -15,6 +15,24 @@ class Scratch3SensingBlocks {
|
||||||
*/
|
*/
|
||||||
this._answer = '';
|
this._answer = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timer utility.
|
||||||
|
* @type {Timer}
|
||||||
|
*/
|
||||||
|
this._timer = new Timer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The stored microphone loudness measurement.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this._cachedLoudness = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time of the most recent microphone loudness measurement.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this._cachedLoudnessTimestamp = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of queued questions and respective `resolve` callbacks.
|
* The list of queued questions and respective `resolve` callbacks.
|
||||||
* @type {!Array}
|
* @type {!Array}
|
||||||
|
@ -24,8 +42,6 @@ class Scratch3SensingBlocks {
|
||||||
this.runtime.on('ANSWER', this._onAnswer.bind(this));
|
this.runtime.on('ANSWER', this._onAnswer.bind(this));
|
||||||
this.runtime.on('PROJECT_START', this._resetAnswer.bind(this));
|
this.runtime.on('PROJECT_START', this._resetAnswer.bind(this));
|
||||||
this.runtime.on('PROJECT_STOP_ALL', this._clearAllQuestions.bind(this));
|
this.runtime.on('PROJECT_STOP_ALL', this._clearAllQuestions.bind(this));
|
||||||
|
|
||||||
this.timer = new Timer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,16 +239,14 @@ class Scratch3SensingBlocks {
|
||||||
if (typeof this.runtime.currentStepTime === 'undefined') return -1;
|
if (typeof this.runtime.currentStepTime === 'undefined') return -1;
|
||||||
|
|
||||||
// Only measure loudness once per step
|
// Only measure loudness once per step
|
||||||
if (this.loudnessTime) {
|
const timeSinceLoudness = this._timer.time() - this._cachedLoudnessTimestamp;
|
||||||
const timeSinceLoudness = this.timer.time() - this.loudnessTime;
|
|
||||||
if (timeSinceLoudness < this.runtime.currentStepTime) {
|
if (timeSinceLoudness < this.runtime.currentStepTime) {
|
||||||
return this.loudness;
|
return this._cachedLoudness;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loudnessTime = this.timer.time();
|
this._cachedLoudnessTimestamp = this._timer.time();
|
||||||
this.loudness = this.runtime.audioEngine.getLoudness();
|
this._cachedLoudness = this.runtime.audioEngine.getLoudness();
|
||||||
return this.loudness;
|
return this._cachedLoudness;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAttributeOf (args) {
|
getAttributeOf (args) {
|
||||||
|
|
Loading…
Reference in a new issue