1.0.4 • Published 4 years ago

react-gamecube v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

react-gamecube

npm version Build Status License

React component for displaying Gamecube controller inputs

react-gamecube component screenshot example

For an interactive demo with examples, check out the storybook.

Installation

With NPM

npm install react-gamecube

With Yarn

yarn add react-gamecube

Usage

const { Controller } = require("react-gamecube");
// Or import like this:
// import { Controller } from "react-gamecube";

// Make the buttons Z, R, and A pressed
const value = {
  a: true,
  r: true,
  z: true,
}

// Also hide the analog sticks
<Controller value={value} hideAnalogSticks={true} />

Props

value

  • Type: object
  • Required: No

An object containing which buttons have been pressed. See below for all the different attributes.

ButtonTypeDescription
startbooleanStart button
abooleanA button
bbooleanB button
xbooleanX button
ybooleanY button
ddbooleanDpad down
dlbooleanDpad left
drbooleanDpad right
dubooleanDpad up
lbooleanLeft trigger
rbooleanRight trigger
zbooleanZ trigger
lValuenumberLeft trigger analog value. Must be between 0 and 1.
rValuenumberRight trigger analog value. Must be between 0 and 1.
controlXnumberAnalog stick X value. Must be between -1 and 1.
controlYnumberAnalog stick Y value. Must be between -1 and 1.
cStickXnumberC stick X value. Must be between -1 and 1.
cStickYnumberC stick Y value. Must be between -1 and 1.

hideAnalogSticks

  • Type: boolean
  • Required: No
  • Default: false

Hides both the analog stick and the C stick.

hideButtonText

  • Type: boolean
  • Required: No
  • Default: false

Hides the text on the buttons.

onClick

  • Type: (button: string) => void
  • Required: No

A function which determines what logic should occur when a particular button is pressed.

ButtonDescription
"START"Start button
"A"A button
"B"B button
"X"X button
"Y"Y button
"D_LEFT"Dpad left
"D_RIGHT"Dpad right
"D_DOWN"Dpad down
"D_UP"Dpad up
"L"L trigger
"R"R trigger
"Z"Z trigger

Development

Build

To build the component library, run:

yarn run build

To start the storybook server, run:

yarn run start

Test

To run the tests:

yarn run test

Export Storybook

To export the storybook as static files:

yarn run storybook

You can then serve the files under storybook-static for demonstration.

License

This software is released under the terms of MIT license.