Skip to content

Commit 585c82f

Browse files
authored
Merge pull request #88 from BaileyBrightman/healthAudit
Commenting and minor code changes
2 parents ad2bdd3 + ffebeb1 commit 585c82f

31 files changed

+843
-782
lines changed

.github/workflows/npm-deploy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: npm-deploy
33
on:
44
release:
55
types: [created]
6+
workflow_dispatch:
67

78
jobs:
89
publish-npm:

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [2.1.1] - UNRELEASED
7+
## [2.2.1] - 2021-03-04
8+
### Changed
9+
- socket.io dependency version bump
10+
11+
## [2.2.0] - 2021-02-19
812
### Added
13+
- Indexeddb additions to the userdata class
14+
15+
### Changed
16+
- update NPM modules to remove security vulnerabilities
917
- This CHANGELOG
1018
- Fullscreen Plugin. The ability to add in a fullscreen button within container
1119
- Fullscreen Plugin Automated Testing
1220
- Fullscreen Plugin Documentation
1321
- Indexeddb additions to the userdata class
14-
### Changed
1522
- update NPM modules to remove security vulnerabilities

README.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ Some games will support many of these features, some none at all. We doubt one g
202202

203203
Each plugin is responsible for one of the listed mechanics and should be provided a
204204
[HTML range input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range), and an optional default value.
205-
Each mechanic's value will range between 0 to 1, and the default initial value is aways 0.5.
205+
Each mechanic's value will range between 0 to 1, and the default initial value is always 0.5.
206206

207207
```javascript
208208
import {
209-
HitAreaScalePlugin, DragThresholdScalePlugin, HealtPlugin, ObjectCountPlugin,
209+
HitAreaScalePlugin, DragThresholdScalePlugin, HealthPlugin, ObjectCountPlugin,
210210
CompletionPercentagePlugin, SpeedScalePlugin, TimersScalePlugin, InputCountPlugin,
211211
Container
212212
} from 'springroll-container';
@@ -420,7 +420,7 @@ For example the SoundPlugin can accept more than one volume slider or button if
420420
musicSliders: '#musicSlider, #musicSliderTwo',
421421
});
422422
```
423-
As long as the string you pass to the constructor is a valid selector string the plugin will use anything you pass to it. The plugins will keep settings in sync across the controls if neccessary as well. Sliders will update each other, buttons will set a dataSet attribute or class (see individual plugin sections for the exact attribute), and any other controls will match each other appropriately.
423+
As long as the string you pass to the constructor is a valid selector string the plugin will use anything you pass to it. The plugins will keep settings in sync across the controls if necessary as well. Sliders will update each other, buttons will set a dataSet attribute or class (see individual plugin sections for the exact attribute), and any other controls will match each other appropriately.
424424

425425
*Note: at this time there is no support for multiple HTMLElements as parameters. If you are passing an HTMLElement as the parameter rather than a selector string you cannot pass multiple controls. If you do wish to use multiple controls, pass the plugin a selector string instead.
426426

@@ -485,7 +485,73 @@ import { SavedData } from 'springroll-container';
485485

486486
// Firstly, construct the SavedData object. This is only needed for IndexedDB work
487487
savedData = new SavedData('dbName');
488+
489+
// Then, open a connection to the database. All changes to the structure of the database should be passed in here
490+
```
491+
Additions is an optional parameter expecting a JSON object with any additions to the databases structure namely new [stores](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/createObjectStore) and [indexes](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex). These are placed inside of an array
492+
493+
Deletions is an optional parameter used to delete any [indexes](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/deleteIndex) or [stores](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/deleteObjectStore)
494+
495+
``` javascript
496+
497+
let additions = {
498+
stores: [{
499+
storeName: 'storeOne',
500+
// optionally define a keyPath and/or set autoIncrement to true or false
501+
options: { keyPath: "taskTitle" }
502+
},
503+
{
504+
storeName: 'storeTwo'
505+
}],
506+
indexes: [{
507+
indexName: 'newIndex',
508+
keyPath: 'key',
509+
// Any objectParameters for the Index
510+
options: {
511+
unique: false
512+
}
513+
}]
514+
};
515+
516+
// Deletions is an optional parameter used to delete any indexes or stores
517+
let deletions = {
518+
stores: ['storeOne', 'storeTwo'],
519+
indexes: ['newIndex']
520+
};
521+
522+
// Optionally pass in the new database version. Set to true to increment the database version.
523+
// Leave this parameter out or pass in false to connect without making any changes to the structure of the database
524+
let dbVersion = 1
525+
526+
// The name of the database to connect to
527+
let dbName = 'dbName';
528+
529+
// Finally, pass these parameters in to establish a connection with the database
530+
savedData.onOpenDb(dbName, dbVersion, additions, deletions);
488531
```
532+
533+
There are other methods currently supported to interact with the database. These allow you to [Add a record](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/add), [Deleting a record](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/delete), [Reading](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/get), [reading all records](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/getAll) Each will return a success, or on failure, an error message
534+
535+
``` javascript
536+
537+
//Delete a record by the key in a specific store
538+
savedData.IDBRemove('storeName', 'key');
539+
540+
// add a record to a store. The record can be any type of object accepted by indexedDB
541+
savedData.IDBAdd('storeName', 'record');
542+
543+
// returns the record with the given key from the store with the given storeName
544+
savedData.IDBRead('storeName', 'key');
545+
546+
// Finally, close the connection to the database
547+
savedData.closeDb();
548+
549+
// Return all records from a database or optionally a specified amount defined by the second parameter
550+
savedData.IDBReadAll('storeName');
551+
savedData.IDBReadAll('storeName', 5);
552+
553+
554+
489555
All other methods will work the same as the documentation [here](https://github.com/SpringRoll/SpringRoll/tree/main/src/state#userdata);
490556

491557

dist/SpringRoll-Container-umd.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/SpringRoll-Container-umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "springroll-container",
3-
"version": "2.1.0",
3+
"version": "2.2.1",
44
"description": "The iframe controller for interacting with SpringRoll applications",
55
"main": "./dist/index.js",
66
"license": "MIT",
@@ -72,4 +72,4 @@
7272
"url": "https://github.com/SpringRoll/SpringRollContainer/issues"
7373
},
7474
"homepage": "https://github.com/SpringRoll/SpringRollContainer"
75-
}
75+
}

src/plugins/ButtonSizePlugin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { SliderPlugin } from '../base-plugins';
33
/**
44
* @export
55
* @class ButtonSizePlugin
6+
* @property {object[]} sliders An array of slider objects given to ButtonSizePlugin
7+
* @property {number} currentValue The current button size value
68
* @extends {SliderPlugin}
7-
*
89
*/
910
export class ButtonSizePlugin extends SliderPlugin {
1011
/**
11-
*Creates an instance of ButtonSizePlugin.
12-
* @param {string | HTMLElement} buttonSliders selector string for the inputs
12+
* Creates an instance of ButtonSizePlugin.
13+
* @param {string | HTMLElement} buttonSliders selector string or html element(s) for the inputs
1314
* @param {object} options
1415
* @param {number} [options.defaultButtonSize=0.5]
1516
* @memberof ButtonSizePlugin
@@ -32,9 +33,11 @@ export class ButtonSizePlugin extends SliderPlugin {
3233
}
3334

3435
/**
36+
* Get ButtonSize Key
3537
* @readonly
3638
* @static
3739
* @memberof ButtonSizePlugin
40+
* @returns {string}
3841
*/
3942
static get buttonSizeKey() {
4043
return 'buttonSize';

src/plugins/CaptionsStylePlugin.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { SavedData } from '../SavedData';
22
import { ButtonPlugin } from '../base-plugins';
33
import { RadioGroup } from '../ui-elements';
44

5-
// Private Variables
6-
const CAPTIONS_STYLES = 'captionsStyles';
75
const DEFAULT_CAPTIONS_STYLES = {
86
size: 'medium',
97
background: 'black',
@@ -29,17 +27,20 @@ const ALIGN_VALUES = ['top', 'bottom'];
2927
* @property {Object[]} fontSizeRadios array that contains each radio group
3028
* @property {Object[]} colorRadios array that contains each radio group
3129
* @property {Object[]} alignmentRadios array that contains each radio group
32-
* @property {number} fontSizeRadiosLength
33-
* @property {number} colorRadiosLength
34-
* @property {number} alignmentRadiosLength
30+
* @property {number} fontSizeRadiosLength Length of the fontSizeRadios array
31+
* @property {number} colorRadiosLength Length of the colorRadios array
32+
* @property {number} alignmentRadiosLength Length of the alignmentRadios array
3533
* @extends {ButtonPlugin}
3634
*/
3735
export class CaptionsStylePlugin extends ButtonPlugin {
3836
/**
39-
*Creates an instance of CaptionsStylePlugin.
40-
* @param {string } fontSizeRadios selector string for one or more radio groups for caption font size
41-
* @param {string } colorRadios selector string for one or more radio groups for caption font/background colors
42-
* @param {string } alignmentRadios selector string for one or more radio groups for caption position
37+
* Creates an instance of CaptionsStylePlugin.
38+
* @param {string} fontSizeRadios selector string for one or more radio groups for caption font size
39+
* @param {string} colorRadios selector string for one or more radio groups for caption font/background colors
40+
* @param {string} alignmentRadios selector string for one or more radio groups for caption position
41+
* @param {string} [defaultFontSize='medium'] Default selected font size
42+
* @param {string} [defaultColor='default'] Default selected color
43+
* @param {string} [defaultAlignment='top'] Default selected alignment
4344
* @memberof CaptionsStylePlugin
4445
*/
4546
constructor(fontSizeRadios, colorRadios, alignmentRadios,
@@ -50,7 +51,7 @@ export class CaptionsStylePlugin extends ButtonPlugin {
5051
this.captionsStyles = Object.assign(
5152
{},
5253
DEFAULT_CAPTIONS_STYLES,
53-
SavedData.read(CAPTIONS_STYLES) || {}
54+
SavedData.read(CaptionsStylePlugin.captionStyleKey) || {}
5455
);
5556

5657
//split the selector strings into individual selectors.
@@ -230,7 +231,7 @@ export class CaptionsStylePlugin extends ButtonPlugin {
230231
* @memberof CaptionsStylePlugin
231232
*/
232233
start() {
233-
this.setCaptionsStyles(SavedData.read(CAPTIONS_STYLES));
234+
this.setCaptionsStyles(SavedData.read(CaptionsStylePlugin.captionStyleKey));
234235

235236
this.client.on('loaded', this.sendAllProperties);
236237
this.client.on('loadDone', this.sendAllProperties);
@@ -242,7 +243,7 @@ export class CaptionsStylePlugin extends ButtonPlugin {
242243
* @memberof CaptionsStylePlugin
243244
*/
244245
sendAllProperties() {
245-
this.sendProperty(CAPTIONS_STYLES, this.captionsStyles);
246+
this.sendProperty(CaptionsStylePlugin.captionStyleKey, this.captionsStyles);
246247
}
247248
/**
248249
* Fired whenever the font size radios are updated
@@ -330,9 +331,9 @@ export class CaptionsStylePlugin extends ButtonPlugin {
330331
this.captionsStyles[styles] = value;
331332
}
332333

333-
SavedData.write(CAPTIONS_STYLES, this.captionsStyles);
334+
SavedData.write(CaptionsStylePlugin.captionStyleKey, this.captionsStyles);
334335
if (this.client) {
335-
this.client.send(CAPTIONS_STYLES, this.captionsStyles);
336+
this.client.send(CaptionsStylePlugin.captionStyleKey, this.captionsStyles);
336337
}
337338
}
338339

@@ -346,4 +347,15 @@ export class CaptionsStylePlugin extends ButtonPlugin {
346347
.concat(this.alignmentRadios)
347348
.concat(this.fontSizeRadios);
348349
}
350+
/**
351+
* Get captionStyle Key
352+
* @readonly
353+
* @static
354+
* @memberof CaptionStyleKey
355+
* @returns {string}
356+
*/
357+
static get captionStyleKey() {
358+
return 'captionsStyles';
359+
}
360+
349361
}

src/plugins/CaptionsTogglePlugin.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import { SavedData } from '../SavedData';
22
import { ButtonPlugin } from '../base-plugins';
33
import { Button } from '../ui-elements';
44

5-
// Private Variables
6-
const CAPTIONS_MUTED = 'captionsMuted';
7-
85
/**
96
* @export
107
* @class CaptionsTogglePlugin
11-
* @property {Button[]} _captionsButtons array of caption mute buttons
12-
* @property {number} captionsButtonsLength
8+
* @property {Button[]} _captionsButtons An array of caption mute buttons
9+
* @property {boolean} _captionsMuted True if captions are muted
10+
* @property {number} captionsButtonLength The length of the captionsButtons array
1311
* @extends {ButtonPlugin}
1412
*/
1513
export class CaptionsTogglePlugin extends ButtonPlugin {
@@ -63,11 +61,11 @@ export class CaptionsTogglePlugin extends ButtonPlugin {
6361
this._captionsButtons[i].displayButton($event.data);
6462
}
6563

66-
if (null === SavedData.read(CAPTIONS_MUTED)) {
64+
if (null === SavedData.read(CaptionsTogglePlugin.captionsToggleKey)) {
6765
return;
6866
}
6967

70-
this.captionsMuted = !!SavedData.read(CAPTIONS_MUTED);
68+
this.captionsMuted = !!SavedData.read(CaptionsTogglePlugin.captionsToggleKey);
7169

7270
}.bind(this)
7371
);
@@ -76,7 +74,7 @@ export class CaptionsTogglePlugin extends ButtonPlugin {
7674
* @memberof CaptionsTogglePlugin
7775
*/
7876
start() {
79-
this.captionsMuted = !!SavedData.read(CAPTIONS_MUTED);
77+
this.captionsMuted = !!SavedData.read(CaptionsTogglePlugin.captionsToggleKey);
8078

8179
this.client.on('loaded', this.sendAllProperties);
8280
this.client.on('loadDone', this.sendAllProperties);
@@ -88,7 +86,7 @@ export class CaptionsTogglePlugin extends ButtonPlugin {
8886
* @memberof CaptionsTogglePlugin
8987
*/
9088
sendAllProperties() {
91-
this.sendProperty(CAPTIONS_MUTED, this.captionsMuted);
89+
this.sendProperty(CaptionsTogglePlugin.captionsToggleKey, this.captionsMuted);
9290
}
9391

9492
/**
@@ -118,4 +116,15 @@ export class CaptionsTogglePlugin extends ButtonPlugin {
118116
this._captionsMuted
119117
);
120118
}
119+
120+
/**
121+
* Get CaptionToggle Key
122+
* @readonly
123+
* @static
124+
* @memberof captionsToggleKey
125+
* @returns {string}
126+
*/
127+
static get captionsToggleKey() {
128+
return 'captionsMuted';
129+
}
121130
}

src/plugins/ColorVisionPlugin.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ const COLOR_BLIND_TYPES = [
1212
/**
1313
* @export
1414
* @class ColorVisionPlugin
15+
* @property {boolean} sendAfterFetch Whether to send the properties after fetch or not
16+
* @property {boolean} canEmit Whether or not the plugin can send properties
17+
* @property {string} colors
1518
* @extends {RadioGroupPlugin}
1619
*/
1720
export class ColorVisionPlugin extends RadioGroupPlugin {
1821
/**
19-
*Creates an instance of ColorVisionPlugin.
20-
* @param {object} params
21-
* @param {string | HTMLElement} params.colorSelects
22+
* Creates an instance of ColorVisionPlugin.
23+
* @param {string | HTMLElement} colorSelects
24+
* @param {string } [defaultValue] Default selected value
2225
* @memberof ColorVision
2326
*/
2427
constructor(colorVisionRadios, { defaultValue = COLOR_BLIND_TYPES[0] } = {}) {
@@ -133,9 +136,11 @@ export class ColorVisionPlugin extends RadioGroupPlugin {
133136
}
134137

135138
/**
139+
* Get the ColorVisionPlugin key
136140
* @readonly
137141
* @static
138142
* @memberof ColorVisionPlugin
143+
* @returns {string}
139144
*/
140145
static get colorVisionKey() {
141146
return 'colorVision';

src/plugins/CompletionPercentagePlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { SliderPlugin } from '../base-plugins';
33
/**
44
* @export
55
* @class CompletionPercentagePlugin
6+
* @property {object[]} sliders an array of all slider objects attached to CompletePercentagePlugin
67
* @extends {SliderPlugin}
78
*/
89
export class CompletionPercentagePlugin extends SliderPlugin {
910
/**
10-
*Creates an instance of CompletionPercentagePlugin.
11-
* @param {object} params
12-
* @param {string | HTMLElement} params.completionPercentageSliders
13-
* @param {number} [params.defaultCompletionPercentage=0.5]
11+
* Creates an instance of CompletionPercentagePlugin.
12+
* @param {string | HTMLElement} completionPercentageSliders The selector or HTMLSliderElement of the slider
13+
* @param {number} [defaultCompletionPercentage=0.5] Default selected completion percentage
1414
* @memberof CompletionPercentagePlugin
1515
*/
1616
constructor(completionPercentageSliders, { defaultCompletionPercentage = 0.5 } = {}) {
@@ -23,8 +23,7 @@ export class CompletionPercentagePlugin extends SliderPlugin {
2323

2424
/**
2525
* @memberof CompletionPercentagePlugin
26-
* @param {Event} target
27-
* @param {string} control
26+
* @param {Event} e
2827
*/
2928
onCompletionPercentageChange(e) {
3029
this.currentValue = e.target.value;
@@ -35,6 +34,7 @@ export class CompletionPercentagePlugin extends SliderPlugin {
3534
* @readonly
3635
* @static
3736
* @memberof CompletionPercentagePlugin
37+
* @returns {string}
3838
*/
3939
static get completionPercentageKey() {
4040
return 'completionPercentage';

0 commit comments

Comments
 (0)