Skip to content
This repository was archived by the owner on Jul 31, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 4 additions & 45 deletions examples/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import * as WebSocket from 'ws';
import {
GameClient,
IButton,
IButtonData,
IControlData,
IParticipant,
setWebSocket,
} from '../lib';

import { makeControls } from './util';

if (process.argv.length < 4) {
console.log('Usage gameClient.exe <token> <versionId>');
process.exit();
Expand All @@ -28,47 +28,6 @@ client.on('message', (err: any) => console.log('<<<', err));
client.on('send', (err: any) => console.log('>>>', err));
// client.on('error', (err: any) => console.log(err));

/**
* This makes button objects, it will make the amount of buttons we tell it to
* we'll use it to create controls dynamically!
*/
function makeControls(amount: number): IControlData[] {
const controls: IButtonData[] = [];
const size = 10;
for (let i = 0; i < amount; i++) {
controls.push({
controlID: `${i}`,
kind: 'button',
text: `Button ${i}`,
cost: 1,
position: [
{
size: 'large',
width: size,
height: size / 2,
x: i * size,
y: 1,
},
{
size: 'small',
width: size,
height: size / 2,
x: i * size,
y: 1,
},
{
size: 'medium',
width: size,
height: size,
x: i * size,
y: 1,
},
],
},
);
}
return controls;
}
// Now we open the connection passing in our authentication details and an experienceId.
client.open({
authToken: process.argv[2],
Expand All @@ -78,7 +37,7 @@ client.open({
// Every Interactive Experience has a "default" scene so we'll add them there there.
return client.createControls({
sceneID: 'default',
controls: makeControls(5),
controls: makeControls(5, i => `Button ${i}`),
});
}).then(controls => {

Expand All @@ -103,7 +62,7 @@ client.open({
});
});
// Controls don't appear unless we tell Interactive that we are ready!
client.ready(true);
return client.ready(true);
});

client.state.on('participantJoin', participant => {
Expand Down
49 changes: 4 additions & 45 deletions examples/dynamicControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import * as faker from 'faker';
import {
delay,
GameClient,
IButtonData,
IControlData,
IParticipant,
setWebSocket,
} from '../lib';

import { makeControls } from './util';

if (process.argv.length < 4) {
console.log('Usage gameClient.exe <token> <versionId>');
process.exit();
Expand All @@ -30,47 +30,6 @@ client.on('open', () => console.log('Connected to interactive'));
// client.on('send', (err: any) => console.log('>>>', err));
// client.on('error', (err: any) => console.log(err));

/**
* This makes button objects, it will make the amount of buttons we tell it to
* we'll use it to create controls dynamically!
*/
function makeControls(amount: number): IControlData[] {
const controls: IButtonData[] = [];
const size = 10;
for (let i = 0; i < amount; i++) {
controls.push({
controlID: `${i}`,
kind: 'button',
text: faker.name.firstName(),
cost: 1,
position: [
{
size: 'large',
width: size,
height: size / 2,
x: i * size,
y: 1,
},
{
size: 'small',
width: size,
height: size / 2,
x: i * size,
y: 1,
},
{
size: 'medium',
width: size,
height: size,
x: i * size,
y: 1,
},
],
},
);
}
return controls;
}
const delayTime = 2000;

/* Loop creates 5 controls and adds them to the default scene.
Expand All @@ -79,7 +38,7 @@ const delayTime = 2000;
*/
function loop() {
const scene = client.state.getScene('default');
scene.createControls(makeControls(5))
scene.createControls(makeControls(5, () => faker.name.firstName()))
.then(() => delay(delayTime))
.then(() => scene.deleteAllControls())
.then(() => delay(delayTime))
Expand All @@ -92,7 +51,7 @@ client.open({
versionId: parseInt(process.argv[3], 10),
})
.then(() => {
/* Pull in the scenes stored on the server
/* Pull in the state stored on the server
* then call ready so our controls show up.
* then call loop() to begin our loop.
*/
Expand Down
51 changes: 6 additions & 45 deletions examples/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import * as WebSocket from 'ws';

import {
GameClient,
IButtonData,
IControlData,
ISceneDataArray,
Group,
IParticipant,
ISceneDataArray,
setWebSocket,
Group
} from '../lib';

import { makeControls } from './util';

if (process.argv.length < 4) {
console.log('Usage gameClient.exe <token> <versionId>');
console.log(process.argv);
Expand All @@ -37,45 +37,6 @@ const delayTime = 2000;
// client.on('send', (err: any) => console.log('>>>', err));
// client.on('error', (err: any) => console.log(err));

/**
* This makes button objects with the text set to the name of the scene.
*/
function makeControls(scene: string): IControlData[] {
const controls: IButtonData[] = [];
const size = 30;
controls.push({
controlID: 'control0',
kind: 'button',
text: `Scene: ${scene}`,
cost: 1,
position: [
{
size: 'large',
width: size,
height: size / 2,
x: 1,
y: 1,
},
{
size: 'small',
width: size,
height: size / 2,
x: 1,
y: 1,
},
{
size: 'medium',
width: size,
height: size,
x: 1,
y: 1,
},
],
},
);
return controls;
}

/**
* Swaps the group the current participant is in between secondGroup and default.
*/
Expand Down Expand Up @@ -106,11 +67,11 @@ function removeParticipant(participantSessionId: string): void {
*/
function createScenes(): Promise<ISceneDataArray> {
const defaultScene = client.state.getScene('default');
defaultScene.createControls(makeControls('default'));
defaultScene.createControls(makeControls(1, () => 'Scene: default'));

const secondScene = {
sceneID: 'secondScene',
controls: makeControls('second')
controls: makeControls(1, () => 'Scene: second'),
};

return client.createScenes({
Expand Down
30 changes: 2 additions & 28 deletions examples/keyboardControls.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* tslint:disable:no-console */
import * as WebSocket from 'ws';
import { getGridPlacement } from './util';

import {
GameClient,
IButton,
IButtonData,
IGridPlacement,
setWebSocket,
} from '../lib';

Expand All @@ -23,33 +23,7 @@ const client = new GameClient();
// Log when we're connected to interactive
client.on('open', () => console.log('Connected to interactive'));

// This makes grid placement objects dynamically, to be used for our controls below.
function getGridPlacement(x: number, y: number): IGridPlacement[] {
const size = 10;
return [
{
size: 'large',
width: size,
height: size,
x: x * size,
y: y * size,
},
{
size: 'medium',
width: size,
height: size,
x: x * size,
y: y * size,
},
{
size: 'small',
width: size,
height: size,
x: x * size,
y: y * size,
},
];
}


/**
* These are our controls. The "keyCode" property is the JavaScript key code associated
Expand Down
47 changes: 3 additions & 44 deletions examples/updateControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import * as WebSocket from 'ws';
import {
GameClient,
IButton,
IButtonData,
IControlData,
IParticipant,
setWebSocket,
} from '../lib';

import { makeControls } from './util';

if (process.argv.length < 4) {
console.log('Usage gameClient.exe <token> <url> <experienceId>');
process.exit();
Expand All @@ -28,47 +28,6 @@ client.on('message', (err: any) => console.log('<<<', err));
client.on('send', (err: any) => console.log('>>>', err));
// client.on('error', (err: any) => console.log(err));

/**
* This makes button objects, it will make the amount of buttons we tell it to
* we'll use it to create controls dynamically!
*/
function makeControls(amount: number): IControlData[] {
const controls: IButtonData[] = [];
const size = 10;
for (let i = 0; i < amount; i++) {
controls.push({
controlID: `${i}`,
kind: 'button',
text: `Button ${i}`,
cost: 1,
position: [
{
size: 'large',
width: size,
height: size / 2,
x: i * size,
y: 1,
},
{
size: 'small',
width: size,
height: size / 2,
x: i * size,
y: 1,
},
{
size: 'medium',
width: size,
height: size,
x: i * size,
y: 1,
},
],
},
);
}
return controls;
}
// Now we open the connection passing in our authentication details and an experienceId.
client.open({
authToken: process.argv[2],
Expand All @@ -79,7 +38,7 @@ client.open({
// Every Interactive Experience has a "default" scene so we'll add them there there.
return client.createControls({
sceneID: 'default',
controls: makeControls(5),
controls: makeControls(5, i => `Button ${i}`),
});
})
.then(controls => {
Expand Down
Loading