From 703ff84bb849baf1d5587b5a7598190be0a4cdc3 Mon Sep 17 00:00:00 2001 From: Jason Reed Date: Sat, 4 Nov 2023 13:20:14 -0400 Subject: [PATCH] Add appropriate cursors for tools (fix #52) --- public/assets/dynamite-cursor.png | Bin 0 -> 402 bytes src/app.tsx | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 public/assets/dynamite-cursor.png diff --git a/public/assets/dynamite-cursor.png b/public/assets/dynamite-cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..f27068617c58cf4a44062e983ddde8fe30d6f16c GIT binary patch literal 402 zcmV;D0d4+?P)zG{_seze0&qGWpy?9C z%8YlAniJn2Y6Umm0X--XRZN$oiUTQCsb{%)MF3P)E@SB* wK!Bmkveo|LX0$*g_6E`cyZkl#1N;=g3$S6Gx1S1)9smFU07*qoM6N<$g5OM^i2wiq literal 0 HcmV?d00001 diff --git a/src/app.tsx b/src/app.tsx index be3c89e..b4cda3c 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -2,7 +2,8 @@ import * as React from 'react'; import { useEffect } from 'react'; import { Action, Dispatch, Effect } from './core/action'; import { reduce } from './core/reduce'; -import { GameState, MouseState, SceneState, mkSceneState } from './core/state'; +import { GameState, SceneState, mkSceneState } from './core/state'; +import { currentTool } from './core/tools'; import { Instructions } from './ui/instructions'; import { key } from './ui/key'; import { paintWithScale } from './ui/render'; @@ -129,8 +130,15 @@ export function Game(props: GameProps): JSX.Element { }, []); type CursorType = React.CSSProperties['cursor']; - function cursorOfMouseState(ms: MouseState): CursorType { - switch (ms.t) { + function cursorOfState(state: GameState): CursorType { + const tool = currentTool(state); + if (tool == 'dynamite') { + return 'url(/assets/dynamite-cursor.png) 16 16, pointer'; + } + if (tool == 'hand') { + return 'grab'; + } + switch (state.mouseState.t) { case 'up': return undefined; case 'drag_world': return 'grab'; case 'drag_tile': return 'pointer'; @@ -138,7 +146,9 @@ export function Game(props: GameProps): JSX.Element { } const style: React.CSSProperties = - { cursor: cursorOfMouseState(state.mouseState) }; + { + cursor: cursorOfState(state) + }; return