npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gamepad-icons

v1.2.2

Published

A gamepads library extension offering icons mapped to common gamepad buttons.

Downloads

14

Readme

Gamepad Icons Module

Gamepad Icons is an extension to Gamepads.js offering gamepad icons for common gamepad mappings. This package is independant from the main package. See the main package on GitHub or on npm.

Installation

Via npm

npm install gamepad-icons

To make the button images available in your app, copy the node_modules/gamepad-icons/buttons folder into a location accessible from your code. See this Stack Overflow answer showing how to configure Webpack to copy the button assets over automatically.

Then, tell the module where to find the button images:

import GamepadIcons from 'gamepad-icons';

GamepadIcons.buttonsPath = 'my/path';

Alternatively, you can use jsDelivr CDN for accessing button images:

GamepadIcons.buttonsPath = 'https://cdn.jsdelivr.net/gh/FThompson/[email protected]/gamepad-icons/buttons';

Via script tag

Add the script via jsDelivr or direct download.

<script src='https://cdn.jsdelivr.net/gh/FThompson/[email protected]/gamepad-icons/gamepad-icons.min.js'></script>

You can download the full extension, gamepad-icons.js.zip in the Releases tab here. This ZIP archive contains the script and a folder containing the button images. Copy the buttons folder to your project and configure the module to find the images.

GamepadIcons.buttonsPath = 'my/path';

Alternatively, you can use jsDelivr CDN for accessing button images:

GamepadIcons.buttonsPath = 'https://cdn.jsdelivr.net/gh/FThompson/[email protected]/gamepad-icons/buttons';

Usage

Gamepads.addEventListener('connect', e => {
    console.log('Gamepad connected');
    console.log(e.gamepad);
    e.gamepad.addEventListener('buttonpress', e => {
        let button = GamepadIcons.getButton('Xbox One', e.index);
        console.log(button);
    });
});

You must specify one of the following supported mapping names as the first parameter to getButton:

  • "Xbox One"
  • "Xbox 360"
  • "PS4"
  • "PS3"

The gamepadMappings.getButton function returns an object containing mappingName, buttonName (such as "Y"), and buttonImageSrc, which is the URL for the button's image starting with the default path /buttons. You can change the root path of buttonImageSrc by setting gamepadMappings.buttonsPath.

Detecting Gamepad Model

Gamepad objects contain an id property that can offer clues to what brand of gamepad is connected, but you cannot rely on this value because some drivers map gamepads to Xbox 360 layouts for compatibility. Instead, you should give users the option to choose which mapping to display and use their selected mapping in GamepadIcons.getButton calls throughout your application.

API Reference

GamepadIconHandler object

GamepadIcons

A GamepadIconHandler singleton is exposed as GamepadIcons. This object takes care of querying supported gamepad mappings.

Methods

GamepadIcons.getButton(mappingName, index)

Gets the given mapping's button at the given index. Returns an object containing mappingName (e.g. 'Xbox One'), buttonName (e.g. 'Y'), and buttonImageSrc.

You can use the following mappings:

  • Xbox 360
  • Xbox One
  • PS3
  • PS4

Properties

GamepadIcons.buttonsPath

The root path to find button images in. Change this property if you wish to store button image assets somewhere other than as a sibling to gamepad-icons.js. Defaults to /buttons.

GamepadIcons.mappings

A dictionary of all supported mappings.

Gamepad Icon Credits

Gamepad button icon assets courtesy of Nicolae Berbece "Xelu" and are released in the public domain under Creative Commons 0 (CC0).