Commit ecc1f452 authored by insert's avatar insert

Add a way to check whether the user is in-game.

parent ec6f8a29
const MumbleLink = require('../');
const mumbleLink = new MumbleLink();
if (!mumbleLink.init()) {
console.log('Could not create shared memory location!');
process.exit(1);
}
if (!mumbleLink.isGuildWars2()) {
console.log('Guild Wars 2 not detected or user has not entered the world at least once!');
process.exit(1);
}
if (!mumbleLink.hasCharacterSelected()) {
console.log('Player has not selected a character yet!');
process.exit(1);
}
console.log('The player is currently in-game and has selected a character!');
\ No newline at end of file
......@@ -42,6 +42,23 @@ class MumbleLink {
init() {
return this.mL.init();
}
/**
* Checks if the client is connected to GW2.
* @returns {boolean} Whether it is connected or not.
*/
isGuildWars2() {
// I know it looks ugly, but this was the best solution.
// Neither .includes, /Guild Wars 2/, /Guild\wWars\w2/ or /Guild*Wars*2/ wanted to work. :/
return /Guild/.test(this.getName()) && /Wars/.test(this.getName()) && /2/.test(this.getName());
}
/**
* Checks if the user has selected a character yet.
* Needed to call getIdentity without error.
* @return {boolean} Whether the user has selected a character.
*/
hasCharacterSelected() {
return collectWChar(this.mL, "Identity") != "";
}
/**
* Get the current link name.
* @returns {string} Should be 'Guild Wars 2'.
......
{
"name": "gw2mumblelink",
"version": "1.0.0",
"version": "1.0.1",
"description": "Guild Wars 2 Mumble Link integration for Node.js",
"main": "index.js",
"scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment