Skip to content

Commit

Permalink
Handle situations where the dropped unit is not available.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: db782946b9fbe98f1049af2c22c457eee797eb58
  • Loading branch information
cpojer committed May 25, 2024
1 parent 98b195d commit 3ddb233
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hera/behavior/drop/dropUnitAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ export default function dropUnitAction(
const { from, to } = actionResponse;
const { vision } = state;
const originalUnitA = state.map.units.get(from)!;
const newUnitB = map.units.get(to);
const unitB = originalUnitA.getTransportedUnit(actionResponse.index)!;
if (!newUnitB) {
return {
map,
...resetBehavior(),
};
}

return {
animations: addMoveAnimation(state.animations, {
from,
Expand Down Expand Up @@ -47,7 +55,7 @@ export default function dropUnitAction(
map: map.copy({
units: map.units
.set(from, originalUnitA.drop(unitB).recover())
.set(to, map.units.get(to)!.recover()),
.set(to, newUnitB.recover()),
}),
...resetBehavior(),
behavior: new NullBehavior(),
Expand Down

0 comments on commit 3ddb233

Please sign in to comment.