gamepad 0.1.0-dev+1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 0

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

Use this package as a library

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

Alternatively, your editor might support pub 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
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.21.0 <2.0.0