Skip to content

Commit

Permalink
Small touch interaction improvements.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 878914824b64cf1a74bda4e7d4f2d958abd999a3
  • Loading branch information
cpojer committed Jan 24, 2025
1 parent c74659f commit e93809e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
4 changes: 3 additions & 1 deletion hera/GameMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,9 @@ export default class GameMap extends Component<Props, State> {
if (
vector &&
behavior?.type === 'move' &&
(vector === selectedPosition || radius?.fields.has(vector))
radius &&
!radius.locked &&
(vector === selectedPosition || radius.fields.has(vector))
) {
event.preventDefault();
}
Expand Down
7 changes: 5 additions & 2 deletions hera/Mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,16 @@ export default memo(function Mask({
const onTouchEnd = useCallback(() => {
if (lastVectors.current.length >= 2) {
const lastVector = lastVectors.current.at(-1)!;
if (radius?.fields.has(lastVector) || attackable?.has(lastVector)) {
if (
!radius?.locked &&
(radius?.fields.has(lastVector) || attackable?.has(lastVector))
) {
select(lastVector);
}
}

lastVectors.current = [];
}, [attackable, radius?.fields, select]);
}, [attackable, radius?.fields, radius?.locked, select]);

return useMemo(() => {
const defaultOffsets: Offsets = [0, 0, 0, 0, Priority.None];
Expand Down
26 changes: 21 additions & 5 deletions hera/behavior/Move.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,32 @@ export default class Move {
confirmAction,
currentViewer,
map,
radius,
selectedPosition,
selectedUnit,
vision,
} = state;

if (currentViewer && radius && selectedPosition && selectedUnit) {
if (currentViewer && state.radius && selectedPosition && selectedUnit) {
let radius = state.radius;
if (!isPlayable(map, currentViewer, selectedUnit)) {
return selectFallback(vector, state, actions);
}

if (confirmAction) {
return confirmAction.position.equals(vector)
? confirmAction.onAction(state)
: selectFallback(vector, state, actions);
if (confirmAction?.position.equals(vector)) {
return confirmAction.onAction(state);
} else {
const enterState = this.enter(vector, {
...state,
radius: { ...radius, locked: false },
});

if (enterState?.radius) {
radius = enterState.radius;
} else {
return selectFallback(vector, state, actions);
}
}
}

if (attackable?.has(vector)) {
Expand Down Expand Up @@ -346,6 +357,7 @@ export default class Move {
...(!selectedUnit.isCapturing()
? {
behavior: new MenuBehavior(),
position: vector,
selectedPosition,
selectedUnit,
}
Expand Down Expand Up @@ -425,6 +437,10 @@ export default class Move {
position: vector,
showComplete,
},
// Update `navigationDirection` and `position` if `confirmAction` was previously set but
// a different position was selected (See `enterState` above).
navigationDirection: null,
position: vector,
radius: {
...radius,
locked: true,
Expand Down

0 comments on commit e93809e

Please sign in to comment.