1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- class Curtain {
- constructor() {
- this.system = null;
- this.canvas = null;
- this.duration = 5000;
- this.timer = 0;
- this.opacity = 0;
- this.onComplete = null;
- this.state = "idle";
- }
- init(systemObject, canvas) {
- this.system = systemObject;
- this.canvas = canvas;
- }
- close(duration, onComplete) {
- this.duration = duration;
- this.onComplete = onComplete;
- this.opacity = 1;
- this.timer = 0;
- this.state = "closing";
- }
- open(duration, onComplete) {
- this.duration = duration;
- this.onComplete = onComplete;
- this.opacity = 0;
- this.timer = 0;
- this.state = "opening";
- }
- updateDelta(delta) {
- if (this.state == "idle") {
- return;
- }
- this.timer += delta * (1000 / 60);
- if (this.timer - (this.duration / 8) >= this.duration) {
- this.state = "idle";
- this.onComplete();
- return;
- }
- this.opacity = (this.timer / (this.duration - (this.duration / 8)));
- }
- draw(context) {
- if (this.state == "idle") {
- return;
- }
- if (this.state == "closing") {
- context.fillStyle = "#000000";
- context.globalAlpha = Math.min(1, Math.max(0, this.opacity));
- context.beginPath();
- context.rect(0, 0, this.canvas.width, this.canvas.height);
- context.fill();
- }
- if (this.state == "opening") {
- context.fillStyle = "#000000";
- context.globalAlpha = Math.min(1, Math.max(0, 1 - this.opacity));
- context.beginPath();
- context.rect(0, 0, this.canvas.width, this.canvas.height);
- context.fill();
- }
- context.globalAlpha = 1;
- }
- };
|