Spaces:
Running
Running
File size: 1,860 Bytes
4ee4376 |
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 |
import * as tools from './tools/';
import * as CONST from '../constants';
export default class events {
constructor(options) {
this.scene = options.scene;
//this.selectedTool = CONST.TOOL_CENTER;
//this.selectedTool = CONST.TOOL_QUERY;
this.selectedTool = CONST.TOOL_ROADS;
this.register();
this.tools = {};
Object.keys(tools).forEach((t) => {
this.tools[t] = new tools[t]({ scene: this.scene });
});
}
register () {
//window.addEventListener(CONST.E_RESIZE, () => {
// this.scene.game.scale.resize(window.innerWidth, window.innerHeight);
//});
this.scene.scale.on(CONST.E_RESIZE, this.resize, this);
this.scene.input.on(CONST.E_POINTER_OVER, this.onPointerOver, this);
this.scene.input.on(CONST.E_POINTER_OUT, this.onPointerOut, this);
this.scene.input.on(CONST.E_POINTER_MOVE, this.onPointerMove, this);
this.scene.input.on(CONST.E_POINTER_DOWN, this.onPointerDown, this);
this.scene.input.on(CONST.E_POINTER_UP, this.onPointerUp, this);
}
onPointerUp (pointer) {
if (this.selectedTool)
this.tools[this.selectedTool].onPointerUp(pointer);
}
onPointerDown (pointer, camera) {
if (this.selectedTool)
this.tools[this.selectedTool].onPointerDown(pointer, camera);
}
onPointerMove (pointer, localX, localY) {
this.scene.viewport.onPointerMove(pointer);
if (this.selectedTool)
this.tools[this.selectedTool].onPointerMove(pointer, localX, localY);
}
onPointerOver (pointer, localX, localY) {
if (this.selectedTool)
this.tools[this.selectedTool].onPointerOver(pointer, localX, localY);
}
onPointerOut (pointer) {
if (this.selectedTool)
this.tools[this.selectedTool].onPointerOut(pointer);
}
resize (gameSize) {
this.scene.cameras.resize(gameSize.width, gameSize.height);
}
} |