Skip to content
filedom
Esc
↑↓navigate↵open⌘Jpreview
On this page

useGameOverlay

Manages help visibility and result configuration.

import { useGameOverlay } from 'filedom';

const overlay = useGameOverlay({
  instructions: ['R - RESTART', '? - CLOSE'],
});

Configuration is read once on mount. The hook does not listen to the keyboard. Pass normalized keys to overlay.onKey(key), or use useGameControls, which listens for you and builds the help lines.

Options

PropType
instructionsstring[]

Help panel lines.

Typestring[]
winEffect?WinEffectMode

'accent' (default) shows four accent icons on a win; 'none' turns them off.

TypeWinEffectMode
messages?Partial<GameResultMessages>

Overrides for the won, lost and draw text. Defaults: YOU WIN, GAME OVER, DRAW.

TypePartial<GameResultMessages>
help?TextStyle

How the ? help panel is drawn. Default { shape: { kind: 'sliced' }, onDemand: false }.

TypeTextStyle
banner?TextStyle

How the result banner is drawn. Default { shape: { kind: 'sliced' }, onDemand: false }.

TypeTextStyle

TextStyle

type TextStyle = {
  shape?: TextShape;   // 'sliced' (default), 'glyphs', or 'grid'
  onDemand?: boolean;  // create the tiles on show so they draw over dragged icons
};

shape sets how large the text reads and how many files it costs, and onDemand sets its z; see Text. In a drag-driven game such as solitaire or chess, set onDemand on the banner so it draws over dragged icons. A grid help panel avoids the problem a different way: the overlay anchors it at the bottom of the desktop, clear of the play area.

help: { shape: { kind: 'grid', charsPerCell: 3, linesPerCell: 2 } },
banner: { onDemand: true },

Returns

GameOverlayController: handle (the resolved configuration), showHelp, toggleHelp(), and onKey(key). onKey toggles help on ? and returns whether it handled the key. Pass the controller to GameOverlay.

Was this page helpful?