-
Notifications
You must be signed in to change notification settings - Fork 673
Move warship by a touch (of magic) #2408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
WalkthroughAdds a new exported Changes
Sequence Diagram(s)sequenceDiagram
participant User as User (touch)
participant Input as InputHandler
participant Layer as UnitLayer
participant Game as Game Logic
User->>Input: pointer up (touch)
alt short tap (dist < 10)
Input->>Input: create TouchEvent(x,y)
Input->>Layer: emit TouchEvent
Layer->>Layer: screen→world coords → clickRef
alt valid clickRef & nearby warships
Layer->>Layer: call onMouseUp(clickRef, nearbyWarships)
alt unit selected
Layer->>Game: MoveWarshipIntentEvent
Layer->>Layer: deselect unit
else select nearest warship
Layer->>Layer: select warship
end
else no actionable warships
Layer->>Game: ContextMenuEvent (radial)
end
else long press / drag
Input->>Game: other pointer handling
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes Potential focus areas:
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/client/graphics/layers/UnitLayer.ts (1)
161-174: Consider simplifying the delegation pattern.Lines 163 and 170-171 create
MouseUpEventobjects that are immediately passed toonMouseUp, but the event coordinates are ignored sinceclickRef(and optionallynearbyWarships) are provided.This pattern is a bit confusing. Consider either:
- Extracting the shared logic into a helper method that takes
clickRefandnearbyWarshipsdirectly- Or documenting why the event object is necessary
Example refactoring:
private handleWarshipInteraction( clickRef: TileRef, nearbyWarships?: UnitView[] ) { if (this.selectedUnit) { this.eventBus.emit( new MoveWarshipIntentEvent(this.selectedUnit.id(), clickRef), ); this.eventBus.emit(new UnitSelectionEvent(this.selectedUnit, false)); return; } nearbyWarships ??= this.findWarshipsNearCell(clickRef); if (nearbyWarships.length > 0) { this.eventBus.emit(new UnitSelectionEvent(nearbyWarships[0], true)); } } private onTouch(event: TouchEvent) { // ... validation ... if (this.selectedUnit || nearbyWarships.length > 0) { this.handleWarshipInteraction(clickRef, nearbyWarships); } else { this.eventBus.emit(new ContextMenuEvent(event.x, event.y)); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/client/InputHandler.ts(2 hunks)src/client/graphics/layers/UnitLayer.ts(4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-18T11:00:57.142Z
Learnt from: NewYearNewPhil
Repo: openfrontio/OpenFrontIO PR: 2230
File: src/client/graphics/GameRenderer.ts:269-277
Timestamp: 2025-10-18T11:00:57.142Z
Learning: In src/client/graphics/GameRenderer.ts, the GameRecapCapture implementation does not use setCaptureRenderEnabled on layers. Instead, it uses RecapCaptureSurface.capture() to render capture layers (TerrainLayer, TerritoryLayer, RailroadLayer, StructureIconsLayer, UnitLayer) directly to an off-screen canvas without requiring layer-level capture mode methods.
Applied to files:
src/client/graphics/layers/UnitLayer.ts
📚 Learning: 2025-06-22T21:51:14.990Z
Learnt from: devalnor
Repo: openfrontio/OpenFrontIO PR: 1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
Applied to files:
src/client/graphics/layers/UnitLayer.ts
🧬 Code graph analysis (2)
src/client/InputHandler.ts (1)
src/core/EventBus.ts (1)
GameEvent(1-1)
src/client/graphics/layers/UnitLayer.ts (3)
src/client/InputHandler.ts (4)
TouchEvent(21-26)MouseUpEvent(8-13)UnitSelectionEvent(31-36)ContextMenuEvent(52-57)src/core/game/GameMap.ts (1)
TileRef(3-3)src/client/Transport.ts (1)
MoveWarshipIntentEvent(164-169)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Deploy to openfront.dev
🔇 Additional comments (4)
src/client/InputHandler.ts (2)
21-26: LGTM! Clean event class definition.The
TouchEventclass follows the same pattern as other event classes in this file. The structure is simple and type-safe.Note: While the name could theoretically conflict with the native DOM
TouchEvent, this shouldn't cause issues in practice due to module scoping.
474-474: Coordinate properties are handled correctly.ContextMenuEvent class stores coordinates as
xandyproperties. UnitLayer's new onTouch handler correctly creates ContextMenuEvent withevent.xandevent.yfrom TouchEvent, matching how TouchEvent itself is created. Consumers like PlayerInfoOverlay and MainRadialMenu both access the normalizedxandyproperties, so the coordinate mapping is transparent and consistent.src/client/graphics/layers/UnitLayer.ts (2)
10-12: LGTM! Event wiring follows existing patterns.The imports and event handler registration are clean and consistent with the existing
MouseUpEventhandler.Also applies to: 78-78
87-90: Good refactoring to use TileRef.Changing from a cell object to a
TileRefmakes the signature cleaner and more type-safe. The JSDoc is correctly updated to match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/client/InputHandler.ts (1)
21-26: Consider renaming to avoid collision with native DOM TouchEvent.The name
TouchEventconflicts with the native DOM API'sTouchEventtype. This could cause confusion when importing or debugging. A more specific name likeTouchTapEventorGameTouchEventwould clarify its purpose and avoid potential naming conflicts.Apply this diff to rename the class:
-export class TouchEvent implements GameEvent { +export class TouchTapEvent implements GameEvent { constructor( public readonly x: number, public readonly y: number, ) {} }Then update line 485:
- this.eventBus.emit(new TouchEvent(event.x, event.y)); + this.eventBus.emit(new TouchTapEvent(event.x, event.y));
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/client/InputHandler.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/client/InputHandler.ts (1)
src/core/EventBus.ts (1)
GameEvent(1-1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Deploy to openfront.dev
evanpelle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description:
This adds moving warships by tapping them on a touchscreen. Now you can steer them just like you already could with a mouse.
Also has some earlier returns, doing checks only when needed, prevent as much duplicate checks and a bugfix.
In onMouseUp:
Getting a valid clickRef for this.selectedUnit fixes: Runtime error when clicking outside the map after selecting a warship. The isValidCoord/Ref check was missing for this.selectedUnit.
For findWarshipsNearCell:
Added onTouch:
Screencap on mobile, shows selecting and moving warships, no runtime error when clicking outside the map after selecting a warship, while radial menu still opens as normal:
Warship.move.on.mobile.Radial.menu.keeps.working.mp4
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
tryout33