-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
clients/design-system/src/game-assets/IsometricCanvas/draw/DrawMeter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { MeterProps } from './MeterProps'; | ||
import { GRID_WIDTH } from '../utils/GridDimensions'; | ||
|
||
export function drawMeter(ctx: CanvasRenderingContext2D, props: MeterProps) { | ||
const x = props.x; | ||
const y = props.y; | ||
const width = props.width ?? GRID_WIDTH; | ||
const height = props.height ?? 5; | ||
const percent = props.percent ? props.percent * 0.01 : 1; | ||
const lineWidth = props.lineWidth ?? 2; | ||
const strokeColor = props.strokeColor ?? '#000'; | ||
const fillColor = props.fillColor ?? '#f00'; | ||
|
||
const startX = x - width / 2; | ||
const startY = y; | ||
|
||
ctx.lineWidth = lineWidth; | ||
ctx.strokeStyle = strokeColor; | ||
|
||
// Draw the background rectangle | ||
ctx.beginPath(); | ||
|
||
ctx.globalAlpha = 0.618; | ||
ctx.fillStyle = '#000'; | ||
ctx.rect(startX, startY, width, height); | ||
ctx.fill(); | ||
ctx.stroke(); | ||
ctx.globalAlpha = 1.0; | ||
|
||
// Draw the filled rectangle | ||
const filledWidth = width * percent; | ||
ctx.fillStyle = fillColor; | ||
ctx.fillRect(startX, startY, filledWidth, height); | ||
} |
10 changes: 10 additions & 0 deletions
10
clients/design-system/src/game-assets/IsometricCanvas/draw/MeterProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export type MeterProps = { | ||
x: number; | ||
y: number; | ||
percent: number; | ||
width?: number; | ||
height?: number; | ||
lineWidth?: number; | ||
strokeColor?: string; | ||
fillColor?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters