Skip to content
wilderzonePublic

About

An implementation of the Voice Game System from Tribes: Ascend.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

17 Commits

Folders and files

Repository files navigation

VGS

Voice Game System

npm install @wilderzone/vgs

# or

deno add @wilderzone/vgs

Usage

Create and configure a VGS instance.

import { VGS } from '@wilderzone/vgs';
import type { VGSConfig, VGSMatch, VGSOption } from '@wilderzone/vgs';

// Configure categories and voice lines.
const options: Record<string, VGSOption> = {
	V:   { type: 'category', name: 'Voice Commands'                                   },
	VG:  { type: 'category', name: 'Global',                                          },
	VGS: { type: 'line',     name: "Shazbot", file: 'AUD_VGS.ogg', phrase: "Shazbot!" },
	VGW: { type: 'line',     name: "Woohoo",  file: 'AUD_VGW.ogg', phrase: "Woohoo!"  },
	VA:  { type: 'category', name: 'Attack'                                           },
	VAA: { type: 'line',     name: "Attack",  file: 'AUD_VAA.ogg', phrase: "Attack!"  },
	// ...
};

// Configure the VGS.
const config: VGSConfig = {
	trigger: 'V',
	timeout: 3000,
	options
};

// Create a new VGS instance.
const vgs = new VGS(config);

Connect callbacks with .on.

import { onCancel, onOptions, onMatch } from './your/logic';

vgs.on('cancel', onCancel);
vgs.on('options', onOptions);
vgs.on('match', onMatch);

Then send keypresses to the system with .press.

vgs.press('V');
vgs.press('G');
vgs.press('W');

When the VGS finds a match, it will call your 'match' callback so you can play the appropriate voice line.

Parsing

Alternatively, you can directly parse a VGS key sequence into its matching VGS command with the .parse method.

const match = vgs.parse('VGW');

This simply returns a VGSMatch object, or undefined if no command matched the provided sequence. This method doesn't trigger any events.

Configuration

Option Required Default Description
options ✓ The voice lines to include in the VGS.
timeout 3000 The duration (in ms) to wait for further keypresses before timing out. Set this to 0 to disable the timeout.
trigger "V" The key used to trigger VGS.
cancel "Escape" The key used to cancel the current VGS sequence.

Methods

Method Description
on Listen to VGS events.
parse Directly parse a VGS key sequence.
press Send a keypress to the VGS. Keys are case insensitive.
cancel Cancel the current VGS sequence.

Events

Event Payload Description
trigger Fired when a new VGS sequence is started (after a trigger keypress is detected).
options VGSMatch[] Fired when the VGS produces the next set of options in the current sequence.
match VGSMatch Fired when the sequence matches a single voice line. The sequence is then reset.
cancel Fired when the sequence is cancelled by the cancel key or .cancel() method.
timeout Fired when the sequence times out.

About

An implementation of the Voice Game System from Tribes: Ascend.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages