@google/model-viewer
Version:
Easily display interactive 3D models on the web and in AR!
79 lines • 2.17 kB
JavaScript
/*
* Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const $time = Symbol('time');
const $duration = Symbol('duration');
/**
* The Timer class can be used power delays and animations
*/
class Timer {
/**
* Creates a new timer
*
* @param duration the total duration for the timer
*/
constructor(duration) {
this[$duration] = duration;
this[$time] = 0;
}
/**
* total time incremented by the tick method. time is initialized to 0
*/
get time() {
return this[$time];
}
/**
* a calculation of `time / duration` which can be used for animations
*/
get timeScale() {
return this[$time] / this[$duration];
}
/**
* duration of the timer
*/
get duration() {
return this[$duration];
}
/**
* whether the timer has run fully or stop has been called
*/
get hasStopped() {
return this[$time] >= this[$duration];
}
/**
* reset the time back to 0
*/
reset() {
this[$time] = 0;
}
/**
* sets time to duration meaning the timer has completed and hasStopped will return true
*/
stop() {
this[$time] = this[$duration];
}
/**
* pass deltaTime to the tick method to tick/increment the timer forward
*
* @param deltaTime delta time since last tick was called
*/
tick(deltaTime) {
this[$time] += deltaTime;
if (this.time >= this[$duration]) {
this[$time] = this[$duration];
}
}
}
export default Timer;
//# sourceMappingURL=timer.js.map