All files / ts/components/entities entityInput.ts

100% Statements 47/47
100% Branches 0/0
84.61% Functions 22/26
100% Lines 47/47

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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170    1x                                             1x                     46x 46x 46x 46x 46x 46x 46x 46x       3x 3x 3x       7x 7x 7x       2x 2x 2x       7x 7x 7x       5x 5x 5x       4x 4x 4x       2x 2x 2x       5x 5x 5x       1x 1x 1x       1x 1x 1x       1x 1x       1x 1x       2x 2x 2x                                                                                                    
import { EventKey } from "../../controller/input/events/eventKey.js";
import { IBounds2 } from "../../models/bounds2.js";
import { Entity, IEntity } from "./entity.js";
 
export interface IEntityInput extends IEntity {
    isHovered: boolean;
    isPointerEntered: boolean;
    isPointerPressed: boolean;
    isHitTestVisible: boolean;
    isTouchHitBoxDisabled: boolean;
    receivePointerInput: boolean;
    receiveKeyboardInput: boolean;
    pointerEnter(position: IBounds2): void;
    pointerLeave(position: IBounds2): void;
    pointerMove(position: IBounds2): void;
    pointerHover(position: IBounds2): void;
    pointerPressed(position: IBounds2): void;
    pointerReleased(position: IBounds2): void;
    pointerTapped(position: IBounds2): void;
    touchStart(positions: IBounds2[]): void;
    touchMove(positions: IBounds2[]): void;
    touchEnd(positions: IBounds2[]): void;
    keyDown(event: EventKey): void;
    keyUp(event: EventKey): void;
}
export class EntityInput extends Entity implements IEntityInput {
 
    public isHovered: boolean;
    public isPointerEntered: boolean;
    public isPointerPressed: boolean;
    public isHitTestVisible: boolean;
    public isTouchHitBoxDisabled: boolean;
    public receivePointerInput: boolean;
    public receiveKeyboardInput: boolean;
 
    public constructor() {
        super();
        this.isHovered = false;
        this.isPointerEntered = false;
        this.isPointerPressed = false;
        this.isHitTestVisible = true;
        this.isTouchHitBoxDisabled = false;
        this.receivePointerInput = false;
        this.receiveKeyboardInput = false;
    }
 
    public pointerEnter(position: IBounds2): void {
        position = this.getLocalPositionBounds(position);
        this.onPointerEnter(position);
        this.refresh();
    }
 
    public pointerLeave(position: IBounds2): void {
        position = this.getLocalPositionBounds(position);
        this.onPointerLeave(position);
        this.refresh();
    }
 
    public pointerMove(position: IBounds2): void {
        position = this.getLocalPositionBounds(position);
        this.onPointerMove(position);
        this.refresh();
    }
 
    public pointerHover(position: IBounds2): void {
        position = this.getLocalPositionBounds(position);
        this.onPointerHover(position);
        this.refresh();
    }
 
    public pointerPressed(position: IBounds2): void {
        position = this.getLocalPositionBounds(position);
        this.onPointerPressed(position);
        this.refresh();
    }
 
    public pointerReleased(position: IBounds2): void {
        position = this.getLocalPositionBounds(position);
        this.onPointerReleased(position);
        this.refresh();
    }
 
    public pointerTapped(position: IBounds2): void {
        position = this.getLocalPositionBounds(position);
        this.onPointerTapped(position);
        this.refresh();
    }
 
    public touchStart(positions: IBounds2[]): void {
        positions = this.getLocalPositionBounds(positions);
        this.onTouchStart(positions);
        this.refresh();
    }
 
    public touchMove(positions: IBounds2[]): void {
        positions = this.getLocalPositionBounds(positions);
        this.onTouchMove(positions);
        this.refresh();
    }
 
    public touchEnd(positions: IBounds2[]): void {
        positions = this.getLocalPositionBounds(positions);
        this.onTouchEnd(positions);
        this.refresh();
    }
 
    public keyDown(event: EventKey): void {
        this.onKeyDown(event);
        this.refresh();
    }
 
    public keyUp(event: EventKey): void {
        this.onKeyUp(event);
        this.refresh();
    }
 
    protected override onEnabledChanged(enabled: boolean): void {
        super.onEnabledChanged(enabled);
        this.invalidate();
        this.refresh();
    }
 
    protected onPointerEnter(position: IBounds2): void {
        //handle pointer enter
    }
 
    protected onPointerLeave(position: IBounds2): void {
        //handle pointer leave
    }
 
    protected onPointerMove(position: IBounds2): void {
        //handle pointer move
    }
 
    protected onPointerHover(position: IBounds2): void {
        //handle pointer hover
    }
 
    protected onPointerPressed(position: IBounds2): void {
        //handle pointer pressed
    }
 
    protected onPointerReleased(position: IBounds2): void {
        //handle pointer released
    }
 
    protected onPointerTapped(position: IBounds2): void {
        //handle pointer tapped
    }
 
    protected onTouchStart(position: IBounds2[]): void {
        //handle touch start
    }
 
    protected onTouchMove(position: IBounds2[]): void {
        //handle touch move
    }
 
    protected onTouchEnd(position: IBounds2[]): void {
        //handle touch end
    }
 
    protected onKeyDown(event: EventKey): void {
        //handle key down
    }
 
    protected onKeyUp(event: EventKey): void {
        //handle key up
    }
}