Files
CINC/systems/CommandSystem.js
T
2025-12-31 00:30:38 +08:00

37 lines
978 B
JavaScript

// systems/CommandSystem.js
import { activeUnit, selectedUnits } from './ControlMode.js';
export class CommandSystem {
constructor(scene) {
this.scene = scene;
scene.events.on('move-relative', this.onMoveRelative, this);
scene.events.on('move-to-point', this.onMoveToPoint, this);
scene.events.on('select-unit', this.onSelectUnit, this);
}
onMoveRelative(dir) {
const targets = selectedUnits.length > 0 ? selectedUnits : (activeUnit ? [activeUnit] : []);
targets.forEach(unit => {
unit.moveRelative(dir.x, dir.y);
});
}
onMoveToPoint(x, y) {
const targets = selectedUnits.length > 0 ? selectedUnits : (activeUnit ? [activeUnit] : []);
targets.forEach(unit => {
unit.setTarget(x, y); // ← 使用新接口
});
}
onSelectUnit(unit) {
// 切换单位
import('./ControlMode.js').then(mod => {
mod.setActiveUnit(unit);
this.scene.events.emit('unit-activated', unit);
});
}
}