All files / ts/controller/surface surfaceSettings.ts

100% Statements 34/34
100% Branches 28/28
100% Functions 9/9
100% Lines 34/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81                1x 1x 1x 1x 1x               2x       2x 1x   1x 1x 1x       2x       2x 1x   1x 1x 1x       2x       2x   1x   1x 1x 1x       3x       4x   2x   2x 2x 2x       11x 11x 11x 11x 11x    
import { IVector2 } from "../../models/vector2.js";
 
export interface ISurfaceSettings extends EventTarget {
    frameRate: number;
    frameLimit: number;
    targetResolution: IVector2;
    maxResolution: IVector2 | undefined;
}
export class SurfaceSettings extends EventTarget implements ISurfaceSettings {
    public static readonly frameRateChangeEvent = "frameratechange";
    public static readonly frameLimitChangeEvent = "framelimitchange";
    public static readonly targetResolutionChangeEvent = "targetresolutionchange";
    public static readonly maxResolutionChangeEvent = "maxresolutionchange";
 
    private _frameRate: number;
    private _frameLimit: number;
    private _targetResolution: IVector2;
    private _maxResolution: IVector2 | undefined;
 
    public get frameRate(): number {
        return this._frameRate;
    }
 
    public set frameRate(value: number) {
        if (this._frameRate === value)
            return;
 
        this._frameRate = value;
        const event = new Event(SurfaceSettings.frameRateChangeEvent);
        this.dispatchEvent(event);
    }
 
    public get frameLimit(): number {
        return this._frameLimit;
    }
 
    public set frameLimit(value: number) {
        if (this._frameLimit === value)
            return;
 
        this._frameLimit = value;
        const event = new Event(SurfaceSettings.frameLimitChangeEvent);
        this.dispatchEvent(event);
    }
 
    public get targetResolution(): IVector2 {
        return this._targetResolution;
    }
 
    public set targetResolution(value: IVector2) {
        if (this._targetResolution.x === value.x &&
            this._targetResolution.y === value.y)
            return;
 
        this._targetResolution = value;
        const event = new Event(SurfaceSettings.targetResolutionChangeEvent);
        this.dispatchEvent(event);
    }
 
    public get maxResolution(): IVector2 | undefined {
        return this._maxResolution;
    }
 
    public set maxResolution(value: IVector2 | undefined) {
        if (this._maxResolution?.x === value?.x &&
            this._maxResolution?.y === value?.y)
            return;
 
        this._maxResolution = value;
        const event = new Event(SurfaceSettings.maxResolutionChangeEvent);
        this.dispatchEvent(event);
    }
 
    public constructor(frameRate: number, frameLimit: number, targetResolution: IVector2, maxResolution: IVector2 | undefined) {
        super();
        this._frameRate = frameRate;
        this._frameLimit = frameLimit;
        this._targetResolution = targetResolution;
        this._maxResolution = maxResolution;
    }
}