All files / ts/components/entities/base entityBase.ts

100% Statements 25/25
100% Branches 10/10
100% Functions 7/7
100% Lines 25/25

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  1x             1x               13x       9x 1x   8x 8x       40x       11x 2x   9x 7x   9x 9x 9x       78x       16x 1x   15x 15x       144x 144x 144x 144x 144x            
import { IEntity } from "../entity.js";
import { IEntityParent, EntityParent } from "./entityParent.js";
 
export interface IEntityBase extends IEntityParent<IEntity> {
    isActive: boolean;
    isVisible: boolean;
    isEnabled: boolean;
}
export abstract class EntityBase extends EntityParent<IEntity> implements IEntityBase {
 
    private _isActive: boolean;
    private _isVisible: boolean;
    private _isEnabled: boolean;
    private _isEnabledVisible: boolean;
 
    public get isActive(): boolean {
        return this._isActive;
    }
 
    public set isActive(value: boolean) {
        if (this._isActive === value)
            return;
 
        this._isActive = value;
        this.isActiveChanged(value);
    }
 
    public get isVisible(): boolean {
        return this._isVisible;
    }
 
    public set isVisible(value: boolean) {
        if (this._isVisible === value)
            return;
 
        if (this._isVisible) {
            this._isEnabledVisible = this._isEnabled;
        }
        this._isVisible = value;
        this.isEnabled = value ? this._isEnabledVisible : value;
        this.isVisibleChanged(value);
    }
 
    public get isEnabled(): boolean {
        return this._isEnabled;
    }
 
    public set isEnabled(value: boolean) {
        if (this._isEnabled === value)
            return;
 
        this._isEnabled = value;
        this.isEnabledChanged(value);
    }
 
    public constructor() {
        super();
        this._isActive = true;
        this._isVisible = true;
        this._isEnabled = true;
        this._isEnabledVisible = true;
    }
 
    protected abstract isActiveChanged(value: boolean): void;
    protected abstract isVisibleChanged(value: boolean): void;
    protected abstract isEnabledChanged(value: boolean): void;
}