From 6892e932c9534d2f76adab5f428276b695cadcb3 Mon Sep 17 00:00:00 2001 From: cramerL Date: Fri, 27 Nov 2026 00:02:23 +0100 Subject: [PATCH 1/5] move entities with arrow keys --- .../phaser/entities/entity-manager.ts | 83 ++++++++++++++----- 1 file changed, 62 insertions(+), 21 deletions(-) diff --git a/webapp/src/app/services/phaser/entities/entity-manager.ts b/webapp/src/app/services/phaser/entities/entity-manager.ts index c42f3b19..3e6b9b6f 100644 --- a/webapp/src/app/services/phaser/entities/entity-manager.ts +++ b/webapp/src/app/services/phaser/entities/entity-manager.ts @@ -7,6 +7,13 @@ import { Vec2 } from '../vec2'; import { CCEntity } from './cc-entity'; import { SelectionBox } from './selection-box'; +const arrowDirections: Record = { + ArrowLeft: { x: -1, y: 0 }, + ArrowRight: { x: 1, y: 0 }, + ArrowUp: { x: 0, y: -1 }, + ArrowDown: { x: 0, y: 1 }, +}; + export class EntityManager extends BaseObject { // TODO: If ? is really required, add a description why. @@ -22,6 +29,7 @@ export class EntityManager extends BaseObject { private visibilityKey!: Phaser.Input.Keyboard.Key; private leftPointerDown = false; private rightPointerDown = false; + private arrowKeyMoved = false; private skipEdit = false; @@ -58,7 +66,7 @@ export class EntityManager extends BaseObject { prevEntity: undefined, entity: undefined, timer: 0, - pos: {x: 0, y: 0} + pos: { x: 0, y: 0 }, }; private selectedEntities: CCEntity[] = []; @@ -69,7 +77,7 @@ export class EntityManager extends BaseObject { constructor( scene: Phaser.Scene, - active = true + active = true, ) { super(scene, 'entityManager', active); } @@ -177,7 +185,7 @@ export class EntityManager extends BaseObject { this.selectionBox.onInputDown(pointer); } }, - emitter: this.scene.input + emitter: this.scene.input, }); const pointerUpFun = (pointer: Phaser.Input.Pointer, gameObject: Phaser.GameObjects.GameObject[]) => { @@ -199,7 +207,7 @@ export class EntityManager extends BaseObject { this.gameObjectDown = false; Globals.stateHistoryService.saveState({ name: 'Entity moved', - icon: 'open_with' + icon: 'open_with', }); } else { const entities = this.selectionBox.onInputUp(); @@ -217,7 +225,7 @@ export class EntityManager extends BaseObject { entity = gameObject[0].getData('entity'); } if (entity) { - const p = {x: pointer.worldX, y: pointer.worldY}; + const p = { x: pointer.worldX, y: pointer.worldY }; if (this.leftClickOpts.timer < 200 && Vec2.distance2(p, this.leftClickOpts.pos) < 10) { this.selectEntity(entity, this.multiSelectKey.isDown); @@ -235,13 +243,13 @@ export class EntityManager extends BaseObject { this.addKeybinding({ event: 'pointerup', fun: pointerUpFun, - emitter: this.scene.input + emitter: this.scene.input, }); this.addKeybinding({ event: 'pointerupoutside', fun: pointerUpFun, - emitter: this.scene.input + emitter: this.scene.input, }); this.addKeybinding({ @@ -253,9 +261,9 @@ export class EntityManager extends BaseObject { } Globals.gridSettings.update(settings => ({ ...settings, - enableGrid: !settings.enableGrid + enableGrid: !settings.enableGrid, })); - } + }, }); // TODO: still triggers when npc editor is open @@ -267,7 +275,7 @@ export class EntityManager extends BaseObject { return; } this.deleteSelectedEntities(); - } + }, }); this.addKeybinding({ @@ -278,7 +286,40 @@ export class EntityManager extends BaseObject { return; } this.hideEntities(); - } + }, + }); + + this.addKeybinding({ + event: 'keydown', + emitter: this.scene.input.keyboard!, + fun: (event: KeyboardEvent) => { + const dir = arrowDirections[event.key]; + if (!dir || Helper.isInputFocused() || this.selectedEntities.length === 0) { + return; + } + const grid = Globals.gridSettings(); + const step = grid.enableGrid ? grid.size : { x: 1, y: 1 }; + this.selectedEntities.forEach(entity => { + entity.addPosition(dir.x * step.x, dir.y * step.y); + entity.updateZIndex(); + }); + this.arrowKeyMoved = true; + }, + }); + + this.addKeybinding({ + event: 'keyup', + emitter: this.scene.input.keyboard!, + fun: (event: KeyboardEvent) => { + if (!this.arrowKeyMoved || !arrowDirections[event.key]) { + return; + } + this.arrowKeyMoved = false; + Globals.stateHistoryService.saveState({ + name: 'Entity moved', + icon: 'open_with', + }); + }, }); @@ -314,15 +355,15 @@ export class EntityManager extends BaseObject { for (const entity of map.entities) { promises.push(this.generateEntity(entity)); } - + const newEntities = await Promise.all(promises); - + if (entities === this._entities) { //Add at the start of the array, in case a user somehow managed to add a new entity while the map is loading - entities.unshift(...newEntities); + entities.unshift(...newEntities); } else { // Someone called `this.initialize` before we finished loading map. Destroy everything. - newEntities.forEach(e => e.destroy()); + newEntities.forEach(e => e.destroy()); } } @@ -365,7 +406,7 @@ export class EntityManager extends BaseObject { Globals.stateHistoryService.saveState({ name: 'Entity added', - icon: 'add' + icon: 'add', }, true); return e; @@ -375,10 +416,10 @@ export class EntityManager extends BaseObject { const entityClass = Globals.entityRegistry.getEntity(entity.type); console.assert(!!this.map, 'I dont think map is ever undefined, but if it ever happens check the TODO on private map?: CCMap;'); const map = this.map!; - + // Preload entities since we need it for loadJsonMergedSync in the entity's constructor await Globals.jsonLoader.loadJsonMerged('entities.json'); - + const ccEntity = new entityClass(this.scene, map, entity.x, entity.y, entity.type); if (!entity.settings.mapId) { entity.settings.mapId = map.getUniqueMapid(); @@ -395,7 +436,7 @@ export class EntityManager extends BaseObject { return; } await navigator.clipboard.writeText(JSON.stringify(entities)); - Globals.snackbar.open('copied entity to clipboard', undefined, {duration: 1000}); + Globals.snackbar.open('copied entity to clipboard', undefined, { duration: 1000 }); } @@ -418,7 +459,7 @@ export class EntityManager extends BaseObject { } catch (e) { Globals.snackbar.open('could not parse entities from clipboard', undefined, { duration: 2000, - panelClass: 'snackbar-error' + panelClass: 'snackbar-error', }); return; } @@ -475,7 +516,7 @@ export class EntityManager extends BaseObject { if (saveHistory) { Globals.stateHistoryService.saveState({ name: 'Entity deleted', - icon: 'delete' + icon: 'delete', }, true); } } From e4bffe9682e6af14e036baf37746fce607505ae1 Mon Sep 17 00:00:00 2001 From: cramerL Date: Fri, 27 Nov 2026 00:08:04 +0100 Subject: [PATCH 2/5] added changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32628b4c..a442a321 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added +- Selected entities can be moved with the arrow keys (Shift for 5x) + ### Fixed - Event steps now format array properties (e.g. enemies of START_PVP_BATTLE) instead of [object Object] - Fixed an issue where keyboard shortcuts conflicted with input elements [#364](https://github.com/CCDirectLink/crosscode-map-editor/issues/364) From 0edf7851492e2a95f33a5e735bf7f3e3418a4b1e Mon Sep 17 00:00:00 2001 From: cramerL Date: Fri, 27 Nov 2026 00:09:11 +0100 Subject: [PATCH 3/5] move entities by 5x when holding shift --- webapp/src/app/services/phaser/entities/entity-manager.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webapp/src/app/services/phaser/entities/entity-manager.ts b/webapp/src/app/services/phaser/entities/entity-manager.ts index 3e6b9b6f..3156b36c 100644 --- a/webapp/src/app/services/phaser/entities/entity-manager.ts +++ b/webapp/src/app/services/phaser/entities/entity-manager.ts @@ -298,7 +298,11 @@ export class EntityManager extends BaseObject { return; } const grid = Globals.gridSettings(); - const step = grid.enableGrid ? grid.size : { x: 1, y: 1 }; + const step = grid.enableGrid ? { ...grid.size } : { x: 1, y: 1 }; + if (this.multiSelectKey.isDown) { + step.x *= 5; + step.y *= 5; + } this.selectedEntities.forEach(entity => { entity.addPosition(dir.x * step.x, dir.y * step.y); entity.updateZIndex(); From 2c0e4b70f78bad1715460ac26d0c0689142293bb Mon Sep 17 00:00:00 2001 From: cramerL Date: Mon, 30 Nov 2026 09:55:53 +0100 Subject: [PATCH 4/5] change step to 4 so it's more useful without grid mode --- webapp/src/app/services/phaser/entities/entity-manager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/app/services/phaser/entities/entity-manager.ts b/webapp/src/app/services/phaser/entities/entity-manager.ts index 3156b36c..8617fa94 100644 --- a/webapp/src/app/services/phaser/entities/entity-manager.ts +++ b/webapp/src/app/services/phaser/entities/entity-manager.ts @@ -300,8 +300,8 @@ export class EntityManager extends BaseObject { const grid = Globals.gridSettings(); const step = grid.enableGrid ? { ...grid.size } : { x: 1, y: 1 }; if (this.multiSelectKey.isDown) { - step.x *= 5; - step.y *= 5; + step.x *= 4; + step.y *= 4; } this.selectedEntities.forEach(entity => { entity.addPosition(dir.x * step.x, dir.y * step.y); From abd7b98ed2ae903df75f6345fb7db558c1fa5b6c Mon Sep 17 00:00:00 2001 From: cramerL Date: Mon, 30 Nov 2026 09:57:43 +0100 Subject: [PATCH 5/5] replaced forEach with simple for loop because no one likes forEach --- webapp/src/app/services/phaser/entities/entity-manager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/app/services/phaser/entities/entity-manager.ts b/webapp/src/app/services/phaser/entities/entity-manager.ts index 8617fa94..c385dca7 100644 --- a/webapp/src/app/services/phaser/entities/entity-manager.ts +++ b/webapp/src/app/services/phaser/entities/entity-manager.ts @@ -303,10 +303,10 @@ export class EntityManager extends BaseObject { step.x *= 4; step.y *= 4; } - this.selectedEntities.forEach(entity => { + for (const entity of this.selectedEntities) { entity.addPosition(dir.x * step.x, dir.y * step.y); entity.updateZIndex(); - }); + } this.arrowKeyMoved = true; }, });