UNPKG

the-world-engine

Version:

three.js based, unity like game engine for browser

47 lines (45 loc) 1.3 kB
import { Component } from "../../hierarchy_object/Component"; import { PlayerGridMovementController } from "../controller/PlayerGridMovementController"; export class PlayerGridEventInvoker extends Component { disallowMultipleComponent=true; requiredComponents=[ PlayerGridMovementController ]; Ph=.5; eo=null; ro=[]; no=(e, t) => { const o = this.eo.gridCenter; const r = this.eo.gridCellWidth; const i = this.eo.gridCellHeight; const n = o.x + e * r; const l = o.y + t * i; const s = this.ro; for (let e = 0; e < s.length; ++e) { s[e].tryInvokeEvent(n, l, this.Ph, this.Ph, this.gameObject); } }; awake() { this.eo = this.gameObject.getComponent(PlayerGridMovementController); this.eo.onMoveToTarget.addListener(this.no); } onDestroy() { this.eo.onMoveToTarget.removeListener(this.no); } addGridEventMap(e) { this.ro.push(e); } removeGridEventMap(e) { const t = this.ro.indexOf(e); if (t >= 0) { this.ro.splice(t, 1); } } removeAllGridEventMap() { this.ro.length = 0; } get collideSize() { return this.Ph; } set collideSize(e) { this.Ph = e; } }