File size: 1,507 Bytes
670a607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Base from '../base/Base.js';
import { Lines } from '../utils/Geoms.js';

class Box extends Base {
    constructor(scene, config) {
        super(scene, config);
        this.type = 'rexSpinnerCube';
    }

    buildShapes() {
        this.addShape((new Lines()).setName('border'));
        this.addShape((new Lines()).setName('fill'));
    }

    updateShapes() {
        var centerX = this.centerX;
        var centerY = this.centerY;
        var radius = this.radius;

        var halfWidth = radius * 0.7;
        var left = centerX - halfWidth,
            top = centerY - halfWidth,
            width = halfWidth * 2;

        this.getShape('border')
            .lineStyle(2, this.color, 1)
            .startAt(left, top).lineTo(width, 0, true)
            .lineTo(0, width, true).lineTo(-width, 0, true)
            .lineTo(0, -width, true).close();

        if (this.value < 0.5) {
            var t = (0.5 - this.value) * 2;
            var height = width * t;
            this.getShape('fill')
                .fillStyle(this.color, 1)
                .startAt(left, top).lineTo(width, 0, true)
                .lineTo(0, height, true).lineTo(-width, 0, true)
                .lineTo(0, -height, true).close();

        } else { // Rotate
            var t = (this.value - 0.5) * 2;
            var angle = 180 * t;

            this.getShape('border').rotateAround(centerX, centerY, angle);
            this.getShape('fill').fillStyle().lineStyle();
        }
    }
}

export default Box;