Feature/arrows#48
Conversation
kimgh06
commented
Sep 18, 2025
- show arrow in interaction canvas.
- fix drawCursor function for performance & looking good.
…for improved rendering - Adjusted JSON structure in renderPaths.json for better path and color management. - Removed device pixel ratio scaling in CanvasRenderComponent for simplified canvas setup. - Enhanced cursor drawing logic and improved handling of canvas references for better performance. - Streamlined path rendering and cursor movement logic to enhance overall rendering efficiency.
- Replaced for-loop with while-loop for improved readability and performance in closed tile updates. - Enhanced visibility management for closed tiles by streamlining the logic for setting visibility states. - Improved clarity in variable naming for better understanding of the tile update process.
…context retrieval - Renamed tile padding parameters to tilePadWidth and tilePadHeight for consistency. - Simplified context retrieval function name from getContext to getCtx for clarity. - Streamlined visibility management logic for closed tiles to enhance readability. - Optimized tile edge snapping logic to utilize updated parameter names.
There was a problem hiding this comment.
Pull Request Overview
This pull request implements arrow display functionality in the interaction canvas and improves the drawCursor function for better performance and visual quality. The changes primarily focus on rendering enhancements and code optimization.
- Adds arrow rendering at the end of drawn paths in the interaction canvas
- Optimizes drawCursor function by removing device pixel ratio scaling and simplifying calculations
- Refactors variable names for better consistency and readability
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/components/tilemap/index.tsx | Renames tilePadding props for consistency, optimizes loops and conditional logic, and improves code structure |
| src/components/canvas/index.tsx | Implements arrow rendering, removes device pixel ratio scaling, optimizes drawCursor function, and simplifies canvas setup |
| src/assets/renderPaths.json | Updates cursor path geometry and simplifies the countColors array formatting |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| neighbor.gScore = tempG; | ||
| neighbor.heuristic = Math.abs(neighbor.x - target.x) + Math.abs(neighbor.y - target.y); | ||
| neighbor.fTotal = neighbor.gScore + neighbor.heuristic; | ||
| const tempG = nowNode.gScore + (isDiagonal ? 14 : 10); |
There was a problem hiding this comment.
The magic numbers 14 and 10 should be defined as named constants to clarify their purpose in the A* pathfinding algorithm. Consider adding comments explaining that these represent the cost of diagonal vs. orthogonal movement.
| const [lastPointX, lastPointY] = [(last.x + beforeLast.x) / 2, (last.y + beforeLast.y) / 2]; | ||
| const pathRotate = Math.PI + Math.atan2(last.y - beforeLast.y, last.x - beforeLast.x); | ||
| interactionCtx.lineTo(lastPointX, lastPointY); | ||
| drawCursor(interactionCtx, lastPointX - tileSize / 2, lastPointY - tileSize / 2, cursorColor, 0, pathRotate, 0.6); |
There was a problem hiding this comment.
The magic number 0.6 for the cursor scale should be defined as a named constant to improve code readability and maintainability.
| const texture = numberTextures.get(+content); | ||
| if (!texture) continue; | ||
| // Number sprite elements | ||
| if (+content > 0) { | ||
| const num = +content; | ||
| const texture = numberTextures.get(num); | ||
| if (texture) { | ||
| const keyNum = `num${num}${tileSize}`; | ||
| const baseNum = numberCache.get(keyNum) ?? <Sprite cullable={true} roundPixels={true} eventMode="none" texture={texture} anchor={0.5} />; | ||
| numberCache.set(keyNum, baseNum); | ||
| const { width, height } = texture; | ||
| const scale = { x: w / width, y: h / height }; | ||
| textElements[textIdx++] = cloneElement(baseNum, { key: typeKeyBase + 4, x: startX + tileSize / 2, y: startY + tileSize / 2, scale }); | ||
| } | ||
| } | ||
| const keyNum = `num${+content}${tileSize}`; | ||
| const baseNum = numberCache.get(keyNum) ?? <Sprite cullable={true} roundPixels={true} eventMode="none" texture={texture} anchor={0.5} />; | ||
| numberCache.set(keyNum, baseNum); | ||
| const { width, height } = texture; | ||
| const scale = { x: w / width, y: h / height }; | ||
| textElements[textIdx++] = cloneElement(baseNum, { key: typeKeyBase + 4, x: startX + tileSize / 2, y: startY + tileSize / 2, scale }); |
There was a problem hiding this comment.
The number texture logic assumes content can be converted to a positive number, but this code block is reached for all tile content types. This should be wrapped in a condition to check if the content represents a valid number (1-8) to prevent unnecessary processing.