class LoadingScreen extends PH.Layer {
    ctx: CanvasRenderingContext2D;
    tenths: number = 0;

    constructor(ctx: CanvasRenderingContext2D) {
        super();
        this.ctx = ctx;
    }

    draw() {
        let canvas = this.ctx.canvas
        let w = canvas.width;
        let h = canvas.height;
        let scale = Math.min(w / 20, h / 20);

        for(let k = 0; k < 10; k++) {
            if(k < this.tenths) {
                this.ctx.fillStyle = "#80f";
            }
            else {
                this.ctx.fillStyle = "#408";
            }
            let midx = w / 2 + scale * (k - 4.5);
            let midy = h / 2;
            this.ctx.fillRect(midx - scale / 4, midy - scale/2, scale / 2, scale);
        }
    }

    setProgress(bytes: number, totalBytes: number) {
        this.tenths = Math.floor(10 * bytes / totalBytes);
    }
}