diff --git a/packages/client/src/App.tsx b/packages/client/src/App.tsx index 386ac76..be69287 100644 --- a/packages/client/src/App.tsx +++ b/packages/client/src/App.tsx @@ -68,7 +68,7 @@ function App() { const [selectedUnits, setSelectedUnits] = useState(new Set()); - const mapClick = useCallback((p: Position, button: number) => { + const mapClick = useCallback((p: Position, button: number, shift: boolean) => { if (selectedUnits.size === 0) return; @@ -78,17 +78,17 @@ function App() { if (!selectedAction) { break; } else if (selectedAction.action === 'Move') { - multiplayer.moveCommand(Array.from(selectedUnits), p); + multiplayer.moveCommand(Array.from(selectedUnits), p, shift); } else if (selectedAction.action === 'Attack') { - multiplayer.attackMoveCommand(Array.from(selectedUnits), p); + multiplayer.attackMoveCommand(Array.from(selectedUnits), p, shift); } else if (selectedAction.action === 'Build') { // Only send one harvester to build // TODO send the closest one - multiplayer.buildCommand([selectedUnits.keys().next().value], selectedAction.building, p); + multiplayer.buildCommand([selectedUnits.keys().next().value], selectedAction.building, p, shift); } break; case 2: - multiplayer.moveCommand(Array.from(selectedUnits), p); + multiplayer.moveCommand(Array.from(selectedUnits), p, shift); break; } @@ -137,29 +137,28 @@ function App() { } if (selectedAction.action === 'Move') { - multiplayer.followCommand(Array.from(selectedUnits), targetId); + multiplayer.followCommand(Array.from(selectedUnits), targetId, shift); } else if (selectedAction.action === 'Attack') { - multiplayer.attackCommand(Array.from(selectedUnits), targetId); + multiplayer.attackCommand(Array.from(selectedUnits), targetId, shift); } break; case 2: // TODO properly understand alliances if (target.owner === 0) { // neutral // TODO actually check if can harvest and is resource - multiplayer.harvestCommand(Array.from(selectedUnits), targetId); + multiplayer.harvestCommand(Array.from(selectedUnits), targetId, shift); } else if (target.owner === multiplayer.getPlayerIndex()) { - multiplayer.followCommand(Array.from(selectedUnits), targetId); + multiplayer.followCommand(Array.from(selectedUnits), targetId, shift); } else if (target.owner !== multiplayer.getPlayerIndex()) { - multiplayer.attackCommand(Array.from(selectedUnits), targetId); + multiplayer.attackCommand(Array.from(selectedUnits), targetId, shift); } break; } }, [lastUpdatePacket, selectedAction, selectedUnits]); const boardSelectUnits = (newUnits: Set, shift: boolean) => { - console.log("boardSelectUnits", newUnits) setSelectedAction(undefined); if (shift) { setSelectedUnits(units => new Set([...units, ...newUnits])); diff --git a/packages/client/src/Multiplayer.ts b/packages/client/src/Multiplayer.ts index 8fbb068..fa5b8c9 100644 --- a/packages/client/src/Multiplayer.ts +++ b/packages/client/src/Multiplayer.ts @@ -195,14 +195,14 @@ export class Multiplayer { this.channel.emit('chat message', 'msg') } - moveCommand(unitIds: UnitId[], target: Position) { + moveCommand(unitIds: UnitId[], target: Position, shift: boolean) { const cmd : CommandPacket = { action: { typ: 'Move', target }, unitIds, - shift: false, + shift, }; this.channel.emit('command', cmd) } @@ -218,38 +218,38 @@ export class Multiplayer { this.channel.emit('command', cmd) } - followCommand(unitIds: UnitId[], target: UnitId) { + followCommand(unitIds: UnitId[], target: UnitId, shift: boolean) { const cmd : CommandPacket = { action: { typ: 'Follow', target }, unitIds, - shift: false, + shift, }; this.channel.emit('command', cmd); } - attackCommand(unitIds: UnitId[], target: UnitId) { + attackCommand(unitIds: UnitId[], target: UnitId, shift: boolean) { const cmd : CommandPacket = { action: { typ: 'Attack', target }, unitIds, - shift: false, + shift, }; this.channel.emit('command', cmd); } - attackMoveCommand(unitIds: UnitId[], target: Position) { + attackMoveCommand(unitIds: UnitId[], target: Position, shift: boolean) { const cmd : CommandPacket = { action: { typ: 'AttackMove', target }, unitIds, - shift: false, + shift, }; this.channel.emit('command', cmd); } @@ -266,7 +266,7 @@ export class Multiplayer { this.channel.emit('command', cmd); } - buildCommand(unitIds: UnitId[], building: string, position: Position) { + buildCommand(unitIds: UnitId[], building: string, position: Position, shift: boolean) { const cmd : CommandPacket = { action: { typ: 'Build', @@ -274,19 +274,19 @@ export class Multiplayer { position }, unitIds, - shift: false, + shift, }; this.channel.emit('command', cmd); } - harvestCommand(unitIds: UnitId[], target: UnitId) { + harvestCommand(unitIds: UnitId[], target: UnitId, shift: boolean) { const cmd : CommandPacket = { action: { typ: 'Harvest', target, }, unitIds, - shift: false, + shift, }; this.channel.emit('command', cmd); } diff --git a/packages/client/src/gfx/Board3D.tsx b/packages/client/src/gfx/Board3D.tsx index f8ab34b..4d46abd 100644 --- a/packages/client/src/gfx/Board3D.tsx +++ b/packages/client/src/gfx/Board3D.tsx @@ -42,7 +42,7 @@ export interface Props { selectedAction: SelectedAction | undefined; select: (ids: Set, shift: boolean) => void; - mapClick: (p: Position, button: number) => void; + mapClick: (p: Position, button: number, shift: boolean) => void; unitClick: (u: UnitId, button: number, shift: boolean) => void; } @@ -78,7 +78,6 @@ export function Board3D(props: Props) { .filter(u => u.owner === props.playerIndex) .map(u => u.id); - console.log("select in box"); props.select(new Set(selection), shift); }; diff --git a/packages/client/src/gfx/Map3D.tsx b/packages/client/src/gfx/Map3D.tsx index d3b4785..004878b 100644 --- a/packages/client/src/gfx/Map3D.tsx +++ b/packages/client/src/gfx/Map3D.tsx @@ -9,7 +9,7 @@ import * as THREE from 'three'; import { Board, Unit, GameMap, UnitId, Position, UnitState } from 'server/types' -type Click = (p: Position, button: number) => void; +type Click = (p: Position, button: number, shift: boolean) => void; type RawClick = (e: ThreeEvent) => void; export type Box = { x1: number, y1: number, x2: number, y2: number }; @@ -26,7 +26,7 @@ export function Map3D(props: Map3DProps) { const rawClick = (e: ThreeEvent) => { e.stopPropagation(); // turn the 3D position into the 2D map position - props.click({x: e.point.x, y: e.point.z}, e.nativeEvent.button); + props.click({x: e.point.x, y: e.point.z}, e.nativeEvent.button, e.nativeEvent.shiftKey); }; // selection box