Catalog npm
PACKAGE EXPLORERView in registry

2048-board-renderer

npm

2048 board renderer

2048boardgameguirenderer
Versions collected2
Direct dependencies6From release 0.1.0
Last observed20 Oct, 18:55 UTC

README

Current package documentation

2048 board renderer

Build

Package for easily rendering boards from the game 2048. Uses data in the format provided from 2048-engine to render the board.

See 2048-react for a convenient wrapper for use in React.

API

The package exposes one method.

createBoard(boardData)

It takes one argument, boardData, which is a Board object from 2048-engine.

The function returns an object with the following properties:

  • htmlElement: A HTMLElement containing the rendered board.
  • update: A function that takes an updated boardData Board object and modifies htmlElement to match the new state.

Any updates to the board should be made using the update function for animations to be played. New games should create new boards using createBoard to avoid weird animations.

Usage

import { createBoard } from '2048-board-renderer';
import { createGame, Direction } from '2048-engine';

const game = createGame();

const board = createBoard(game.currentState.board);
document.getElementById('game')?.appendChild(board.htmlElement);

const move = (direction: Direction) => {
  const gameState = game.move(direction);
  board.update(gameState.board);
};

move(Direction.UP);

For a playable example see example directory

Notes on the board HTMLElement

The board HTMLElement is a div with no styling regarding width. The width of the board is therefore determined by its parent container.

The height of the board is determined based on width and the aspect ratio of the board.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 2

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.0Registry latest13 Jul 20226
0.0.1-security13 Jul 20220

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
npm/security-holder

Shared repository data · GitHub

License detected in repository
Not collected

Repository

PENDING
eikhr/react-2048

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:55 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:0ead58ac681d91037621b9e588adecdb75c2ea83c04e05c4bab18fac155be247