| | |
| | | export default class Player { |
| | | |
| | | constructor(dom, dark, didClickSprite) { |
| | | // not dynamic |
| | | this.darkModel = dark; |
| | | this.didClickSprite = didClickSprite; // not dynamic |
| | | this.didClickSprite = didClickSprite; |
| | | // init |
| | | this.app = generatePixiApp(dark); |
| | | dom.appendChild(this.app.view); |
| | |
| | | event.preventDefault(); |
| | | }); |
| | | |
| | | this.pan = false; // 平移 |
| | | |
| | | this.activateMapEvent(null, Utils.MapEvent.PAN); |
| | | // this.activateMapEvent(null); |
| | | this.activateMapScale(); |
| | | this.activateMapPan(); |
| | | this.showCoordinates(); |
| | | this.appTicker(); |
| | | } |
| | | |
| | | activateMapEvent = (leftEvent, rightEvent) => { |
| | | if (this.mapEvent) { |
| | | this.app.view.removeEventListener('mousedown', this.mapEvent); |
| | | this.mapContainer.parent.off('mousedown', this.mapEvent); |
| | | } |
| | | |
| | | this.mapEvent = (event) => { |
| | | // left |
| | | if (event.button === 0 && leftEvent) { |
| | |
| | | // right |
| | | if (event.button === 2 && rightEvent) { |
| | | switch (rightEvent) { |
| | | case Utils.MapEvent.PAN: |
| | | this.mapPan(event); |
| | | break |
| | | default: |
| | | break |
| | | } |
| | | } |
| | | } |
| | | |
| | | this.app.view.addEventListener('mousedown', this.mapEvent) |
| | | this.mapContainer.parent.on('mousedown', this.mapEvent) |
| | | } |
| | | |
| | | mapSelect = (event) => { |
| | |
| | | } |
| | | } |
| | | |
| | | this.app.view.addEventListener('mousemove', handleMouseMove); |
| | | this.mapContainer.parent.on('mousemove', handleMouseMove); |
| | | |
| | | this.app.view.addEventListener('mouseup', (event) => { |
| | | this.mapContainer.parent.on('mouseup', (event) => { |
| | | if (isSelecting) { |
| | | if (this.selectedSprites && this.selectedSprites.length > 0) { |
| | | this.selectedSprites.forEach(child => { |
| | |
| | | }) |
| | | isSelecting = false; |
| | | selectionBox.clear(); |
| | | |
| | | } |
| | | |
| | | this.app.view.removeEventListener('mousemove', handleMouseMove); |
| | | this.mapContainer.parent.off('mousemove', handleMouseMove); |
| | | }); |
| | | } |
| | | |
| | | mapPan = (event) => { |
| | | this.pan = true; |
| | | let previousPosition = { x: event.clientX, y: event.clientY }; |
| | | const mouseMoveHandler = (event) => { |
| | | if (this.pan) { |
| | | const dx = event.clientX - previousPosition.x; |
| | | const dy = event.clientY - previousPosition.y; |
| | | activateMapPan = () => { |
| | | const mapPanHandle = (event) => { |
| | | if (event.button === 2) { |
| | | this.pan = true; |
| | | let previousPosition = { x: event.clientX, y: event.clientY }; |
| | | const mouseMoveHandler = (event) => { |
| | | if (this.pan) { |
| | | const dx = event.clientX - previousPosition.x; |
| | | const dy = event.clientY - previousPosition.y; |
| | | |
| | | this.mapContainer.position.x += dx; |
| | | this.mapContainer.position.y += dy; |
| | | this.mapContainer.position.x += dx; |
| | | this.mapContainer.position.y += dy; |
| | | |
| | | previousPosition = { x: event.clientX, y: event.clientY }; |
| | | previousPosition = { x: event.clientX, y: event.clientY }; |
| | | } |
| | | }; |
| | | this.app.view.addEventListener('mousemove', mouseMoveHandler); |
| | | this.app.view.addEventListener('mouseup', () => { |
| | | this.app.view.removeEventListener('mousemove', mouseMoveHandler); |
| | | this.pan = false; |
| | | }); |
| | | } |
| | | }; |
| | | this.app.view.addEventListener('mousemove', mouseMoveHandler); |
| | | this.app.view.addEventListener('mouseup', () => { |
| | | this.app.view.removeEventListener('mousemove', mouseMoveHandler); |
| | | this.pan = false; |
| | | }); |
| | | } |
| | | this.app.view.addEventListener('mousedown', mapPanHandle); |
| | | } |
| | | |
| | | activateMapScale = () => { |