Skip to content

Commit

Permalink
Add appropriate cursors for tools (fix #52)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcreedcmu committed Nov 4, 2023
1 parent d52e4ed commit 703ff84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Binary file added public/assets/dynamite-cursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 14 additions & 4 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -129,16 +130,25 @@ 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';
}
}

const style: React.CSSProperties =
{ cursor: cursorOfMouseState(state.mouseState) };
{
cursor: cursorOfState(state)
};
return <div>
<canvas
style={style}
Expand Down

0 comments on commit 703ff84

Please sign in to comment.