gamepad 0.1.0-dev+1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 40

gamepad

UNRELEASED: Not currently ready for use.

A cross-platform Dart API for virtual and physical gamepad access in Dart.

Directory

lib/
  drivers/       | Libraries to initialize before using in a game
  
    browser.dart | Drivers that must be used within the browser
    flutter.dart | Drivers that must be used within Flutter[1]
    virtual.dart | Drivers that have no dependencies on a platform
  
  src/           | Internals. Should not be imported
    drivers/
      browser/
        ...
      flutter/
        ...
      virtual/
        ...
  
  gamepad.dart   | Generic interfaces for use to build a game

[1]: https://flutter.io, runs compiled Dart on Android/iOS

Concepts

Loosely based on the W3C Gamepad API which is supported, but also with support for a combination of virtual gamepads (i.e. presents itself in the UI), for device features like accelerometers, and even for completely custom implementations (could be VR, remote, or something else).

There are a few concepts that should be understood when using the API below:

  • Gamepad: Frontend API that developers are expected to code against
  • Driver: Backend API that in turn is used by the package to produce gamepads
  • VirtualDriver: A synthetic backend that is implemented at runtime

Virtualization

One of the benefits of this library is that new gamepads can be created at runtime; this can be used to drive end-to-end testing of your application or even to create gamepads within the UI itself, or perhaps even controlled remotely by another device. The following is provided to help:

  • VirtualAxes: Can simulate multi-directional sticks
    • Directional: A mixin that provides simple directional support
  • VirtualButton: Can simulate a toggleable or pressable button
    • Toggle: A mixin that reports the button pressed until it is pressed again

An example of creating a virtual driver based on the W and S keys:

import 'dart:async';
import 'dart:html';

import 'package:gamepad/drivers/virtual.dart';

class WasdVirtualDriver extends VirtualDriver implements HasAxesSupport {
  Axes createAxes() => new WasdVirtualAxes(); 
}

class WasdVirtualAxes extends VirtualAxes<Element> with TriggerDirection {
  StreamSubscription _listener;

  @override
  Future<Null> activate(Element context) async {
    _listener = element.onKeyDown.listen((event) {
      if (event.key == 'W') {
        triggerUp();
      } else if (event.key =='S') {
        triggerDown();
      }
    });
  }

  @override
  Future<Null> deactivate() async {
    await _listener.cancel();
  }
}

UNRELEASED

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  gamepad: "^0.1.0-dev+1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:gamepad/gamepad.dart';
        
Version Uploaded Documentation Archive
0.1.0-dev+1 Dec 27, 2016 Go to the documentation of gamepad 0.1.0-dev+1 Download gamepad 0.1.0-dev+1 archive
0.1.0-dev Dec 27, 2016 Go to the documentation of gamepad 0.1.0-dev Download gamepad 0.1.0-dev archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
89 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
65 / 100
Overall score:
Weighted score of the above. [more]
40
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:gamepad/gamepad.dart.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 3 errors 6 hints.

    Strong-mode analysis of lib/src/internal/async.dart failed with the following error:

    line: 7 col: 8
    Target of URI doesn't exist: 'package:collection/collection.dart'.

    Run dartfmt to format lib/src/drivers/api/axes.dart.

  • Package is pre-release.

    Pre-release versions should be used with caution, their API may change in breaking ways.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use gamepad.dart.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.21.0 <2.0.0
meta ^1.0.4 1.1.2
quiver >=0.22.0 <0.25.0 0.24.0 0.29.0+1
Transitive dependencies
matcher 0.12.2
path 1.5.1
stack_trace 1.9.2
Dev dependencies
test ^0.12.18+1