(v0.5.7) Bumped gulp-shenanigans to 0.5.20

Also removed the LevelEditrGenerator since it's not being used.
This commit is contained in:
Josh Goldberg
2016-12-02 18:35:15 -08:00
parent e8b7ce1d29
commit 2e4e71fdbd
51 changed files with 420 additions and 15812 deletions
+3 -3
View File
@@ -1,10 +1,10 @@
docs/**
lib/**
src/**/*.css
src/**/*.d.ts
src/**/*.js*
~src/main.js
test/**/*.js
test/index.html
test/utils/**
!test/utils/mocks.ts
test/**/*.d.ts
node_modules/
npm-debug.log
+1
View File
@@ -5,6 +5,7 @@
A user interface wrapper for configurable HTML displays over GameStartr games.
## Build Process
UserWrappr uses [Gulp](http://gulpjs.com/) to automate building, which requires [Node.js](http://node.js.org).
+14 -16
View File
@@ -1,7 +1,7 @@
{
"name": "userwrappr",
"description": "A user interface wrapper for configurable HTML displays over GameStartr games.",
"version": "0.5.6",
"version": "0.5.7",
"author": {
"name": "Josh Goldberg",
"email": "joshuakgoldberg@outlook.com"
@@ -15,41 +15,39 @@
},
"license": "MIT",
"dependencies": {
"areaspawnr": "^0.5.2",
"audioplayr": "^0.5.1",
"battlemovr": "^0.5.2",
"changelinr": "^0.5.3",
"stringfilr": "^0.5.2",
"mapscreenr": "^0.5.2",
"itemsholdr": "^0.5.2",
"battlemovr": "^0.5.2",
"devicelayr": "^0.5.1",
"eightbittr": "^0.5.2",
"audioplayr": "^0.5.1",
"fpsanalyzr": "^0.5.1",
"gamesrunnr": "^0.5.4",
"gamestartr": "^0.5.3",
"groupholdr": "^0.5.1",
"inputwritr": "^0.5.2",
"itemsholdr": "^0.5.2",
"js-beautify": "^1.6.3",
"leveleditr": "^0.5.1",
"mapscreatr": "^0.5.4",
"mapscreenr": "^0.5.2",
"mathdecidr": "^0.5.1",
"menugraphr": "^0.5.4",
"modattachr": "^0.5.1",
"numbermakr": "^0.5.1",
"objectmakr": "^0.5.2",
"pixeldrawr": "^0.5.1",
"pixelrendr": "^0.5.2",
"quadskeepr": "^0.5.2",
"areaspawnr": "^0.5.2",
"pixelrendr": "^0.5.2",
"pixeldrawr": "^0.5.1",
"sceneplayr": "^0.5.2",
"stateholdr": "^0.5.1",
"stringfilr": "^0.5.2",
"thinghittr": "^0.5.2",
"timehandlr": "^0.5.2",
"touchpassr": "^0.5.1",
"userwrappr": "^0.5.5",
"worldseedr": "^0.5.1"
"worldseedr": "^0.5.1",
"gamestartr": "^0.5.3",
"menugraphr": "^0.5.4",
"js-beautify": "^1.6.3"
},
"devDependencies": {
"gulp-shenanigans": "^0.5.15",
"gulp-shenanigans": "^0.5.20",
"@types/js-beautify": "0.0.27"
}
}
+1 -2
View File
@@ -12,7 +12,6 @@
"GamesRunnr": "^0.5.4",
"GroupHoldr": "^0.5.1",
"InputWritr": "^0.5.2",
"LevelEditr": "^0.5.1",
"MapsCreatr": "^0.5.4",
"MathDecidr": "^0.5.1",
"ModAttachr": "^0.5.1",
@@ -48,6 +47,6 @@
"package": {
"description": "A user interface wrapper for configurable HTML displays over GameStartr games.",
"name": "UserWrappr",
"version": "0.5.6"
"version": "0.5.7"
}
}
+8 -8
View File
@@ -14,7 +14,7 @@ export interface IOptionsButtonsSchema extends ISchema {
/**
* A general, default callback for when a button is clicked.
*/
callback: (GameStarter: IGameStartr, ...args: any[]) => void;
callback: (gameStarter: IGameStartr, ...args: any[]) => void;
/**
* A key to add to buttons when they're active.
@@ -34,7 +34,7 @@ export interface IOptionsButtonSchema extends IOption {
/**
* A callback for when this specific button is pressed.
*/
callback?: (GameStarter: IGameStartr, ...args: any[]) => void;
callback?: (gameStarter: IGameStartr, ...args: any[]) => void;
/**
* A source for the button's initial value.
@@ -66,7 +66,7 @@ export class ButtonsGenerator extends OptionsGenerator implements IOptionsGenera
public generate(schema: IOptionsButtonsSchema): HTMLDivElement {
const output: HTMLDivElement = document.createElement("div");
const options: IOptionsButtonSchema[] = schema.options instanceof Function
? (schema.options as IOptionSource).call(self, this.GameStarter)
? (schema.options as IOptionSource).call(self, this.gameStarter)
: schema.options;
output.className = "select-options select-options-buttons";
@@ -105,19 +105,19 @@ export class ButtonsGenerator extends OptionsGenerator implements IOptionsGenera
*/
protected ensureLocalStorageButtonValue(child: HTMLDivElement, details: IOptionsButtonSchema, schema: IOptionsButtonsSchema): void {
const key: string = schema.title + "::" + details.title;
const valueDefault: string = details.source.call(this, this.GameStarter).toString();
const valueDefault: string = details.source.call(this, this.gameStarter).toString();
child.setAttribute("localStorageKey", key);
this.GameStarter.ItemsHolder.addItem(key, {
this.gameStarter.ItemsHolder.addItem(key, {
"storeLocally": true,
"valueDefault": valueDefault
});
const value: string = this.GameStarter.ItemsHolder.getItem(key);
const value: string = this.gameStarter.ItemsHolder.getItem(key);
if (value.toString().toLowerCase() === "true") {
(details as any)[schema.keyActive || "active"] = true;
schema.callback.call(this, this.GameStarter, schema, child);
schema.callback.call(this, this.gameStarter, schema, child);
}
}
@@ -134,7 +134,7 @@ export class ButtonsGenerator extends OptionsGenerator implements IOptionsGenera
return;
}
schema.callback.call(this, this.GameStarter, schema, element, (enabled: boolean): void => {
schema.callback.call(this, this.gameStarter, schema, element, (enabled: boolean): void => {
element.setAttribute("option-enabled", enabled.toString());
element.className = "select-option options-button-option option-" + (enabled ? "enabled" : "disabled");
});
-236
View File
@@ -1,236 +0,0 @@
import { IOptionsGenerator } from "../IUserWrappr";
import { ISchema } from "../UISchemas";
import { IMapSelectionCallback, IOptionsMapGridSchema } from "./MapsGridGenerator";
import { OptionsGenerator } from "./OptionsGenerator";
/**
* Description of a user control for a level editor.
*/
export interface IOptionsEditorSchema extends ISchema {
/**
* Map names the user may load into the editor.
*/
maps: IOptionsMapGridSchema;
/**
* Loads a built-in map into the editor after the user has clicked a button.
*/
callback: IMapSelectionCallback;
}
/**
* Options generator for a LevelEditr dialog.
*/
export class LevelEditorGenerator extends OptionsGenerator implements IOptionsGenerator {
/**
* Generates a control for a level editor based on the provided schema.
*
* @param schema The overall description of the editor control.
* @returns An HTML element representing the schema.
*/
public generate(schema: IOptionsEditorSchema): HTMLDivElement {
const output: HTMLDivElement = document.createElement("div");
const starter: HTMLDivElement = document.createElement("div");
const betweenOne: HTMLDivElement = document.createElement("div");
const betweenTwo: HTMLDivElement = document.createElement("div");
const uploader: HTMLDivElement = this.createUploaderDiv();
const mapper: HTMLDivElement = this.createMapSelectorDiv(schema);
output.className = "select-options select-options-level-editor";
starter.className = "select-option select-option-large options-button-option";
starter.innerHTML = "Start the <br /> Level Editor!";
starter.onclick = (): void => this.GameStarter.LevelEditor.enable();
betweenOne.className = betweenTwo.className = "select-option-title";
betweenOne.innerHTML = betweenTwo.innerHTML = "<em>- or -</em><br />";
output.appendChild(starter);
output.appendChild(betweenOne);
output.appendChild(uploader);
output.appendChild(betweenTwo);
output.appendChild(mapper);
return output;
}
/**
* Creates an HTML element that can be clicked or dragged on to upload a JSON file
* into the level editor.
*
* @returns An element containing the uploader div.
*/
protected createUploaderDiv(): HTMLDivElement {
const uploader: HTMLDivElement = document.createElement("div");
const input: HTMLInputElement = document.createElement("input");
uploader.className = "select-option select-option-large options-button-option";
uploader.innerHTML = "Continue an<br />editor file!";
uploader.setAttribute("textOld", uploader.textContent);
input.type = "file";
input.className = "select-upload-input";
input.onchange = this.handleFileDrop.bind(this, input, uploader);
uploader.ondragenter = this.handleFileDragEnter.bind(this, uploader);
uploader.ondragover = this.handleFileDragOver.bind(this, uploader);
uploader.ondragleave = input.ondragend = this.handleFileDragLeave.bind(this, uploader);
uploader.ondrop = this.handleFileDrop.bind(this, input, uploader);
uploader.onclick = input.click.bind(input);
uploader.appendChild(input);
return uploader;
}
/**
* Creates an HTML element that allows a user to choose between maps to load into
* the level editor.
*
* @param schema The overall description of the container user control.
* @returns An element containing the map selector.
*/
protected createMapSelectorDiv(schema: IOptionsEditorSchema): HTMLDivElement {
const generatorName: string = "MapsGrid";
const container: HTMLDivElement = this.GameStarter.utilities.createElement("div", {
className: "select-options-group select-options-editor-maps-selector"
});
const toggler: HTMLDivElement = this.GameStarter.utilities.createElement("div", {
className: "select-option select-option-large options-button-option"
});
const mapsOut: HTMLDivElement = this.GameStarter.utilities.createElement("div", {
className: "select-options-holder select-options-editor-maps-holder"
});
const mapsIn: HTMLDivElement = this.UserWrapper.getGenerators()[generatorName].generate(
this.GameStarter.utilities.proliferate(
{
callback: schema.callback
},
schema.maps));
let expanded: boolean = true;
toggler.onclick = (event?: Event): void => {
expanded = !expanded;
if (expanded) {
toggler.textContent = "(cancel)";
mapsOut.style.position = "";
mapsIn.style.height = "";
} else {
toggler.innerHTML = "Edit a <br />built-in map!";
mapsOut.style.position = "absolute";
mapsIn.style.height = "0";
}
if (!container.parentElement) {
return;
}
[].slice.call(container.parentElement.children)
.forEach(function (element: HTMLElement): void {
if (element !== container) {
element.style.display = (expanded ? "none" : "block");
}
});
};
toggler.onclick(undefined);
mapsOut.appendChild(mapsIn);
container.appendChild(toggler);
container.appendChild(mapsOut);
return container;
}
/**
* Handles a dragged file entering a map selector. Visual styles are updated.
*
* @param uploader The element being dragged onto.
* @param event The event caused by the dragging.
*/
protected handleFileDragEnter(uploader: HTMLDivElement, event: LevelEditr.IDataMouseEvent): void {
if (event.dataTransfer) {
event.dataTransfer.dropEffect = "copy";
}
uploader.className += " hovering";
}
/**
* Handles a dragged file moving over a map selector.
*
* @param uploader The element being dragged onto.
* @param event The event caused by the dragging.
*/
protected handleFileDragOver(uploader: HTMLElement, event: MouseEvent): boolean {
event.preventDefault();
return false;
}
/**
* Handles a dragged file leaving a map selector. Visual styles are updated.
*
* @param uploader The element being dragged onto.
* @param event The event caused by the dragging.
*/
protected handleFileDragLeave(uploader: HTMLElement, event: LevelEditr.IDataMouseEvent): void {
if (event.dataTransfer) {
event.dataTransfer.dropEffect = "none";
}
uploader.className = uploader.className.replace(" hovering", "");
}
/**
* Handles a dragged file being dropped onto a map selector. The file is read, and
* events attached to its progress.
*
* @param input The HTMLInputElement triggering the file event.
* @param uploader The element being dragged onto.
* @param event The event caused by the dragging.
*/
protected handleFileDrop(input: HTMLInputElement, uploader: HTMLDivElement, event: LevelEditr.IDataMouseEvent): void {
const files: FileList = input.files || event.dataTransfer.files;
const reader: FileReader = new FileReader();
this.handleFileDragLeave(input, event);
event.preventDefault();
event.stopPropagation();
reader.onprogress = this.handleFileUploadProgress.bind(this, files[0], uploader);
reader.onloadend = this.handleFileUploadCompletion.bind(this, files[0], uploader);
reader.readAsText(files[0]);
}
/**
* Handles a file upload reporting some amount of progress.
*
* @param file The file being uploaded.
* @param uploader The element the file was being dragged onto.
* @param event The event caused by the progress.
*/
protected handleFileUploadProgress(file: File, uploader: HTMLDivElement, event: LevelEditr.IDataProgressEvent): void {
if (!event.lengthComputable) {
return;
}
let percent: number = Math.max(Math.round((event.loaded / event.total) * 100), 100);
uploader.innerText = "Uploading '" + file.name + "' (" + percent + "%)...";
}
/**
* Handles a file upload completing. The file's contents are loaded into
* the level editor.
*
* @param file The file being uploaded.
* @param uploader The element the file was being dragged onto.
* @param event The event caused by the upload completing.
*/
protected handleFileUploadCompletion(file: File, uploader: HTMLDivElement, event: LevelEditr.IDataProgressEvent): void {
this.GameStarter.LevelEditor.handleUploadCompletion(event);
uploader.innerText = uploader.getAttribute("textOld");
}
}
+13 -7
View File
@@ -11,7 +11,7 @@ import { OptionsGenerator } from "./OptionsGenerator";
* @param event The event associated with the user clicking the button.
*/
export interface IMapSelectionCallback {
(GameStarter: IGameStartr, schema: IOptionsMapGridSchema, button: HTMLElement, event: Event): void;
(gameStarter: IGameStartr, schema: IOptionsMapGridSchema, button: HTMLElement, event: Event): void;
}
/**
@@ -94,9 +94,7 @@ export class MapsGridGenerator extends OptionsGenerator implements IOptionsGener
output.appendChild(this.generateRangedTable(schema));
}
if (schema.extras) {
this.appendExtras(output, schema);
}
this.appendExtras(output, schema);
return output;
}
@@ -108,6 +106,10 @@ export class MapsGridGenerator extends OptionsGenerator implements IOptionsGener
* @returns An HTMLTableElement with a grid of map selection buttons.
*/
public generateRangedTable(schema: IOptionsMapGridSchema): HTMLTableElement {
if (!schema.rangeX || !schema.rangeY) {
throw new Error("Invalid schema for a ranged table.");
}
const table: HTMLTableElement = document.createElement("table");
for (let i: number = schema.rangeY[0]; i <= schema.rangeY[1]; i += 1) {
@@ -122,7 +124,7 @@ export class MapsGridGenerator extends OptionsGenerator implements IOptionsGener
if (this.getParentControlElement(cell).getAttribute("active") === "on") {
callback();
}
}).bind(this, schema.callback.bind(this, this.GameStarter, schema, cell));
}).bind(this, schema.callback.bind(this, this.gameStarter, schema, cell));
row.appendChild(cell);
}
@@ -139,19 +141,23 @@ export class MapsGridGenerator extends OptionsGenerator implements IOptionsGener
* @param schema The overall discription of the editor control.
*/
public appendExtras(output: HTMLDivElement, schema: IOptionsMapGridSchema): void {
if (!schema.extras) {
return;
}
for (const extra of schema.extras) {
const element: HTMLDivElement = document.createElement("div");
element.className = "select-option maps-grid-option maps-grid-option-extra";
element.textContent = extra.title;
element.setAttribute("value", extra.title);
element.onclick = extra.callback.bind(this, this.GameStarter, schema, element);
element.onclick = extra.callback.bind(this, this.gameStarter, schema, element);
output.appendChild(element);
if (extra.extraElements) {
for (const extraElement of extra.extraElements) {
output.appendChild(
this.GameStarter.utilities.createElement(
this.gameStarter.utilities.createElement(
extraElement.tag,
extraElement.options));
}
+5 -5
View File
@@ -9,21 +9,21 @@ export abstract class OptionsGenerator implements IOptionsGenerator {
/**
* The container UserWrappr using this generator.
*/
protected UserWrapper: IUserWrappr;
protected userWrapper: IUserWrappr;
/**
* The container UserWrappr's GameStartr instance.
*/
protected GameStarter: IGameStartr;
protected gameStarter: IGameStartr;
/**
* Initializes a new instance of the OptionsGenerator class.
*
* @param UserWrappr The container UserWrappr using this generator.
*/
constructor(UserWrapper: IUserWrappr) {
this.UserWrapper = UserWrapper;
this.GameStarter = this.UserWrapper.getGameStarter();
constructor(userWrapper: IUserWrappr) {
this.userWrapper = userWrapper;
this.gameStarter = this.userWrapper.getGameStarter();
}
/**
+48 -55
View File
@@ -31,7 +31,7 @@ export interface IOptionsTableAction {
*
* @param GameStarter The GameStarter this option is controlling.
*/
action: (GameStarter: IGameStartr) => void;
action: (gameStarter: IGameStartr) => void;
}
/**
@@ -58,14 +58,14 @@ export interface IOptionsTableBooleanOption extends IOptionsTableOption {
*
* @param GameStarter The GameStarter this option is controlling.
*/
disable: (GameStarter: IGameStartr) => void;
disable: (gameStarter: IGameStartr) => void;
/**
* Callback for when the value becomes true.
*
* @param GameStarter The GameStarter this option is controlling.
*/
enable: (GameStarter: IGameStartr) => void;
enable: (gameStarter: IGameStartr) => void;
/**
* A key to add to the button's className when the value is true.
@@ -87,14 +87,14 @@ export interface IOptionsTableKeysOption extends IOptionsTableOption {
*
* @param GameStarter The GameStarter this option is controlling.
*/
callback: (GameStarter: IGameStartr) => void;
callback: (gameStarter: IGameStartr) => void;
/**
* A source for the allowed keys in the option.
*
* @returns The allowed keys in the option.
*/
source: (GameStarter: IGameStartr) => string[];
source: (gameStarter: IGameStartr) => string[];
}
/**
@@ -116,7 +116,7 @@ export interface IOptionsTableNumberOption extends IOptionsTableOption {
*
* @param GameStarter The GameStarter this option is controlling.
*/
update: (GameStarter: IGameStartr) => void;
update: (gameStarter: IGameStartr) => void;
}
/**
@@ -129,7 +129,7 @@ export interface IOptionsTableSelectOption extends IOptionsTableOption {
* @param GameStarter The GameStarter this option is controlling.
* @returns The allowed keys in the option.
*/
options: (GameStarter: IGameStartr) => string[];
options: (gameStarter: IGameStartr) => string[];
/**
* A source for the initially selected value.
@@ -137,7 +137,7 @@ export interface IOptionsTableSelectOption extends IOptionsTableOption {
* @param GameStarter The GameStarter this option is controlling.
* @returns The allowed keys in the option.
*/
source: (GameStarter: IGameStartr) => string;
source: (gameStarter: IGameStartr) => string;
/**
* Callback for when the value changes.
@@ -145,7 +145,7 @@ export interface IOptionsTableSelectOption extends IOptionsTableOption {
* @param GameStarter The GameStarter this option is controlling.
* @param value A new value, if this is triggered via a code callback.
*/
update: (GameStarter: IGameStartr, value?: any) => void;
update: (gameStarter: IGameStartr, value?: any) => void;
}
/**
@@ -158,7 +158,7 @@ export interface IOptionsTableScreenSizeOption extends IOptionsTableOption {
* @param GameStarter The GameStarter this option is controlling.
* @returns Names of the allowed screen sizes.
*/
options: (GameStarter: IGameStartr) => string[];
options: (gameStarter: IGameStartr) => string[];
/**
* A source for the initially selected value.
@@ -166,7 +166,7 @@ export interface IOptionsTableScreenSizeOption extends IOptionsTableOption {
* @param GameStarter The GameStarter this option is controlling.
* @returns The allowed keys in the option.
*/
source: (GameStarter: IGameStartr) => string;
source: (gameStarter: IGameStartr) => string;
/**
* Callback for when the value changes.
@@ -174,7 +174,7 @@ export interface IOptionsTableScreenSizeOption extends IOptionsTableOption {
* @param GameStarter The GameStarter this option is controlling.
* @param value The newly selected size information.
*/
update: (GameStarter: IGameStartr, value: ISizeSummary) => void;
update: (gameStarter: IGameStartr, value: ISizeSummary) => void;
}
/**
@@ -243,7 +243,7 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
row.className = "select-option options-button-option";
row.textContent = action.title;
row.onclick = action.action.bind(this, this.GameStarter);
row.onclick = action.action.bind(this, this.gameStarter);
output.appendChild(row);
}
@@ -257,11 +257,10 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
*
* @param input An input that will contain a boolean value.
* @param details Details for this individual value.
* @param schema Details for the overall table schema.
* @returns An HTML element containing the input.
*/
protected setBooleanInput(input: IInputElement, details: IOptionsTableBooleanOption, schema: ISchema): IInputElement {
const status: boolean = details.source.call(this, this.GameStarter);
protected setBooleanInput(input: IInputElement, details: IOptionsTableBooleanOption): IInputElement {
const status: boolean = details.source.call(this, this.gameStarter);
const statusClass: string = status ? "enabled" : "disabled";
input.className = "select-option options-button-option option-" + statusClass;
@@ -279,11 +278,11 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
}
if (newStatus) {
details.enable.call(this, this.GameStarter);
details.enable.call(this, this.gameStarter);
input.textContent = "on";
input.className = input.className.replace("disabled", "enabled");
} else {
details.disable.call(this, this.GameStarter);
details.disable.call(this, this.gameStarter);
input.textContent = "off";
input.className = input.className.replace("enabled", "disabled");
}
@@ -301,12 +300,11 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
*
* @param input An input that will contain a keyboard key value.
* @param details Details for this individual value.
* @param schema Details for the overall table schema.
* @returns An HTML element containing the input.
*/
protected setKeyInput(input: IInputElement, details: IOptionsTableKeysOption, schema: ISchema): ISelectElement[] {
const values: string[] = details.source.call(this, this.GameStarter);
const possibleKeys: string[] = this.UserWrapper.getAllPossibleKeys();
protected setKeyInput(input: IInputElement, details: IOptionsTableKeysOption): ISelectElement[] {
const values: string[] = details.source.call(this, this.gameStarter);
const possibleKeys: string[] = this.userWrapper.getAllPossibleKeys();
const children: ISelectElement[] = [];
for (const value of values) {
@@ -326,7 +324,7 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
}
child.onchange = ((child: ISelectElement): void => {
details.callback.call(this, this.GameStarter, child.valueOld, child.value);
details.callback.call(this, this.gameStarter, child.valueOld, child.value);
if (details.storeLocally) {
this.storeLocalStorageValue(child, child.value);
}
@@ -344,20 +342,19 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
*
* @param input An input that will contain a numeric value.
* @param details Details for this individual value.
* @param schema Details for the overall table schema.
* @returns An HTML element containing the input.
*/
protected setNumberInput(input: IInputElement, details: IOptionsTableNumberOption, schema: ISchema): IInputElement {
protected setNumberInput(input: IInputElement, details: IOptionsTableNumberOption): IInputElement {
const child: IInputElement = document.createElement("input") as IInputElement;
child.type = "number";
child.value = parseFloat(details.source.call(this, this.GameStarter)).toString();
child.value = parseFloat(details.source.call(this, this.gameStarter)).toString();
child.min = (details.minimum || 0).toString();
child.max = (details.maximum || Math.max(details.minimum + 10, 10)).toString();
child.onchange = child.oninput = (): void => {
if (child.checkValidity()) {
details.update.call(this, this.GameStarter, child.value);
details.update.call(this, this.gameStarter, child.value);
}
if (details.storeLocally) {
this.storeLocalStorageValue(child, child.value);
@@ -374,21 +371,20 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
*
* @param input An input that will contain a value with multiple present options.
* @param details Details for this individual value.
* @param schema Details for the overall table schema.
* @returns An HTML element containing the input.
*/
protected setSelectInput(input: ISelectElement, details: IOptionsTableSelectOption, schema: ISchema): ISelectElement {
protected setSelectInput(input: ISelectElement, details: IOptionsTableSelectOption): ISelectElement {
const child: ISelectElement = document.createElement("select") as ISelectElement;
const options: string[] = details.options(this.GameStarter);
const options: string[] = details.options(this.gameStarter);
for (const option of options) {
child.appendChild(new Option(option));
}
child.value = details.source.call(this, this.GameStarter);
child.value = details.source.call(this, this.gameStarter);
child.onchange = (): void => {
details.update.call(this, this.GameStarter, child.value);
details.update.call(this, this.gameStarter, child.value);
child.blur();
if (details.storeLocally) {
@@ -406,23 +402,20 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
*
* @param input An input that will set a GameStartr's screen size.
* @param details Details for this individual value.
* @param schema Details for the overall table schema.
* @returns An HTML element containing the input.
*/
protected setScreenSizeInput(input: ISelectElement, details: IOptionsTableScreenSizeOption, schema: ISchema): ISelectElement {
details.options = (): string[] => Object.keys(this.UserWrapper.getSizes());
protected setScreenSizeInput(input: ISelectElement, details: IOptionsTableScreenSizeOption): ISelectElement {
details.options = (): string[] => Object.keys(this.userWrapper.getSizes());
details.source = (): string => this.UserWrapper.getCurrentSize().name;
details.source = (): string => this.userWrapper.getCurrentSize().name!;
details.update = (GameStarter: IGameStartr, value: ISizeSummary | string): ISelectElement => {
if (value === this.UserWrapper.getCurrentSize()) {
return undefined;
details.update = (_gameStarter: IGameStartr, value: ISizeSummary | string): void => {
if (value !== this.userWrapper.getCurrentSize()) {
this.userWrapper.setCurrentSize(value);
}
this.UserWrapper.setCurrentSize(value);
};
return this.setSelectInput(input, details, schema);
return this.setSelectInput(input, details);
}
/**
@@ -443,24 +436,24 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
const child: IInputElement | ISelectElement = childRaw as IInputElement | ISelectElement;
const key: string = schema.title + "::" + details.title;
const valueDefault: string = details.source.call(this, this.GameStarter).toString();
const valueDefault: string = details.source.call(this, this.gameStarter).toString();
child.setAttribute("localStorageKey", key);
this.GameStarter.ItemsHolder.addItem(key, {
this.gameStarter.ItemsHolder.addItem(key, {
"storeLocally": true,
"valueDefault": valueDefault
});
const value: string = this.GameStarter.ItemsHolder.getItem(key);
const value: string = this.gameStarter.ItemsHolder.getItem(key);
if (value !== "" && value !== child.value) {
child.value = value;
if (child.setValue) {
child.setValue(value);
} else if (child.onchange) {
child.onchange(undefined);
child.onchange(undefined!);
} else if (child.onclick) {
child.onclick(undefined);
child.onclick(undefined!);
}
}
}
@@ -476,26 +469,26 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
*/
protected ensureLocalStorageValues(children: (IInputElement | ISelectElement)[], details: IOption, schema: ISchema): void {
const keyGeneral: string = schema.title + "::" + details.title;
const values: any[] = details.source.call(this, this.GameStarter);
const values: any[] = details.source.call(this, this.gameStarter);
for (let i: number = 0; i < children.length; i += 1) {
const key: string = keyGeneral + "::" + i;
const child: IInputElement | ISelectElement = children[i];
child.setAttribute("localStorageKey", key);
this.GameStarter.ItemsHolder.addItem(key, {
this.gameStarter.ItemsHolder.addItem(key, {
"storeLocally": true,
"valueDefault": values[i]
});
const value: string = this.GameStarter.ItemsHolder.getItem(key);
const value: string = this.gameStarter.ItemsHolder.getItem(key);
if (value !== "" && value !== child.value) {
child.value = value;
if (child.onchange) {
child.onchange(undefined);
child.onchange(undefined!);
} else if (child.onclick) {
child.onclick(undefined);
child.onclick(undefined!);
}
}
}
@@ -509,11 +502,11 @@ export class TableGenerator extends OptionsGenerator implements IOptionsGenerato
* @param {Mixed} value What value is to be stored under the key.
*/
protected storeLocalStorageValue(child: IInputElement | ISelectElement, value: any): void {
const key: string = child.getAttribute("localStorageKey");
const key: string | null = child.getAttribute("localStorageKey");
if (key) {
this.GameStarter.ItemsHolder.setItem(key, value);
this.GameStarter.ItemsHolder.saveItem(key);
this.gameStarter.ItemsHolder.setItem(key, value);
this.gameStarter.ItemsHolder.saveItem(key);
}
}
}
+14 -66
View File
@@ -1,11 +1,14 @@
/// <reference path="../typings/DeviceLayr.d.ts" />
/// <reference path="../typings/GamesRunnr.d.ts" />
/// <reference path="../typings/ItemsHoldr.d.ts" />
/// <reference path="../typings/InputWritr.d.ts" />
/// <reference path="../typings/LevelEditr.d.ts" />
import { GameStartr } from "gamestartr/lib/GameStartr";
import { IGameStartrSettings, IPageStyles } from "gamestartr/lib/IGameStartr";
import { ISchema } from "./UISchemas";
export interface IGameStartr extends GameStartr { }
export interface IGameStartrCreator {
(settings: IGameStartrSettings): IGameStartr;
}
export interface IHTMLElement extends HTMLElement {
requestFullScreen: () => void;
webkitRequestFullScreen: () => void;
@@ -22,51 +25,6 @@ export interface IEvent {
target: HTMLElement;
}
/**
* The class of game being controlled by the UserWrappr. This will normally
* be implemented by the GameStartr project itself.
*/
export interface IGameStartr {
DeviceLayer: DeviceLayr.IDeviceLayr;
GamesRunner: GamesRunnr.IGamesRunnr;
ItemsHolder: ItemsHoldr.IItemsHoldr;
InputWriter: InputWritr.IInputWritr;
LevelEditor: LevelEditr.ILevelEditr;
UserWrapper: IUserWrappr;
container: HTMLElement;
gameplay: IGameStartrGameplay;
utilities: IGameStartrUtilities;
}
/**
*
*/
export interface IGameStartrGameplay {
gameStart(): void;
}
/**
*
*/
export interface IGameStartrUtilities {
addPageStyles(styles: StyleSheet): void;
createElement(tag: string, ...args: any[]): HTMLElement;
createElement(tag: "div", ...args: any[]): HTMLDivElement;
proliferate(recipient: any, donor: any, noOverride?: boolean): any;
}
/**
* Custom settings for an individual IGameStartr instance, such as size info.
*/
export type IGameStartrCustoms = any;
/**
* Initializes a new instance of the IGameStartr interface.
*/
export interface IGameStartrConstructor {
new (...args: any[]): IGameStartr;
}
/**
* Generator for a user-facing HTML control.
*
@@ -120,11 +78,6 @@ export interface ISizeSummaries {
* Settings to initialize a new IUserWrappr.
*/
export interface IUserWrapprSettings {
/**
* What the global object is called, such as "window".
*/
globalName: string;
/**
* Allowed sizes for the game.
*/
@@ -163,17 +116,17 @@ export interface IUserWrapprSettings {
/**
* Custom arguments to be passed to the IGameStartr's modules.
*/
customs?: IGameStartrCustoms;
gameStarterSettings?: IGameStartrSettings;
/**
* Any additional CSS styles to be applied to the page.
*/
styleSheet?: StyleSheet;
styleSheet?: IPageStyles;
/**
* The constructor for the IGameStartr implementation.
*/
GameStartrConstructor: IGameStartrConstructor;
GameStartrConstructor: IGameStartrCreator;
}
/**
@@ -188,7 +141,7 @@ export interface IUserWrappr {
* @param settings Settings for the GameStartr constructor.
* @param customs Additional settings for sizing information.
*/
resetGameStarter(settings: IUserWrapprSettings, customs?: IGameStartrCustoms): void;
resetGameStarter(settings: IUserWrapprSettings, customs?: IGameStartrSettings): void;
/**
* Resets the visual aspect of the controls so they are updated with the
@@ -199,18 +152,13 @@ export interface IUserWrappr {
/**
* @returns The GameStartr implementation this is wrapping around.
*/
getGameStartrConstructor(): IGameStartrConstructor;
getGameStartrCreator(): IGameStartrCreator;
/**
* @returns The GameStartr instance created by GameStartrConstructor.
*/
getGameStarter(): IGameStartr;
/**
* @returns The ItemsHoldr used to store UI settings.
*/
getItemsHolder(): ItemsHoldr.IItemsHoldr;
/**
* @returns The settings used to construct this UserWrappr.
*/
@@ -219,7 +167,7 @@ export interface IUserWrappr {
/**
* @returns The customs used to construct the IGameStartr.
*/
getCustoms(): IGameStartrCustoms;
getGameStartrSettings(): IGameStartrSettings;
/**
* @returns All the keys the user is allowed to pick from in UI controls.
+59 -98
View File
@@ -1,17 +1,11 @@
/// <reference path="../typings/DeviceLayr.d.ts" />
/// <reference path="../typings/GamesRunnr.d.ts" />
/// <reference path="../typings/InputWritr.d.ts" />
/// <reference path="../typings/ItemsHoldr.d.ts" />
/// <reference path="../typings/LevelEditr.d.ts" />
import { IGameStartrSettings } from "gamestartr/lib/IGameStartr";
import { ButtonsGenerator } from "./Generators/ButtonsGenerator";
import { LevelEditorGenerator } from "./Generators/LevelEditrGenerator";
import { MapsGridGenerator } from "./Generators/MapsGridGenerator";
import { TableGenerator } from "./Generators/TableGenerator";
import {
IGameStartr, IGameStartrConstructor, IGameStartrCustoms, IHTMLElement,
IOptionsGenerator, IOptionsGenerators, ISizeSummaries, ISizeSummary,
IUserWrappr, IUserWrapprSettings
IGameStartr, IGameStartrCreator, IHTMLElement, IOptionsGenerator, IOptionsGenerators,
ISizeSummaries, ISizeSummary, IUserWrappr, IUserWrapprSettings
} from "./IUserWrappr";
import { ISchema } from "./UISchemas";
@@ -29,21 +23,15 @@ export class UserWrappr implements IUserWrappr {
];
/**
* The GameStartr implementation this is wrapping around, such as
* FullScreenMario or FullScreenPokemon.
* The GameStartr implementation this is wrapping around.
*/
private GameStartrConstructor: IGameStartrConstructor;
private gameStartrCreator: IGameStartrCreator;
/**
* The GameStartr instance created by GameStartrConstructor and stored
* under window.
*/
private GameStarter: IGameStartr;
/**
* A ItemsHoldr used to store UI settings.
*/
private ItemsHolder: ItemsHoldr.IItemsHoldr;
private gameStarter: IGameStartr;
/**
* The settings used to construct the UserWrappr.
@@ -55,12 +43,6 @@ export class UserWrappr implements IUserWrappr {
*/
private customs: any;
/**
* What the global object is called (typically "window" for browser
* environments and "global" for node-style environments).
*/
private globalName: string;
/**
* All the keys the user is allowed to pick from as key bindings.
*/
@@ -124,9 +106,7 @@ export class UserWrappr implements IUserWrappr {
|| (this.documentElement as IHTMLElement).webkitRequestFullScreen
|| (this.documentElement as IHTMLElement).mozRequestFullScreen
|| (this.documentElement as IHTMLElement).msRequestFullscreen
|| function (): void {
alert("Not able to request full screen...");
});
|| ((): void => alert("Not able to request full screen...")));
/**
* A browser-dependent method for request to exit full screen mode.
@@ -136,9 +116,7 @@ export class UserWrappr implements IUserWrappr {
|| (this.documentElement as IHTMLElement).webkitCancelFullScreen
|| (this.documentElement as IHTMLElement).mozCancelFullScreen
|| (this.documentElement as IHTMLElement).msCancelFullScreen
|| function (): void {
alert("Not able to cancel full screen...");
});
|| ((): void => alert("Not able to cancel full screen...")));
/**
* Initializes a new instance of the UserWrappr class.
@@ -152,9 +130,6 @@ export class UserWrappr implements IUserWrappr {
if (typeof settings.GameStartrConstructor === "undefined") {
throw new Error("No GameStartrConstructor given to UserWrappr.");
}
if (typeof settings.globalName === "undefined") {
throw new Error("No globalName given to UserWrappr.");
}
if (typeof settings.sizes === "undefined") {
throw new Error("No sizes given to UserWrappr.");
}
@@ -166,12 +141,11 @@ export class UserWrappr implements IUserWrappr {
}
this.settings = settings;
this.GameStartrConstructor = settings.GameStartrConstructor;
this.globalName = settings.globalName;
this.gameStartrCreator = settings.GameStartrConstructor;
this.sizes = this.importSizes(settings.sizes);
this.customs = settings.customs || {};
this.customs = settings.gameStarterSettings || {};
this.gameElementSelector = settings.gameElementSelector || "#game";
this.gameControlsSelector = settings.gameControlsSelector || "#controls";
this.logger = settings.logger || console.log.bind(console);
@@ -197,24 +171,23 @@ export class UserWrappr implements IUserWrappr {
* and setting additional CSS styles and page visiblity.
*
* @param settings Settings for the GameStartr constructor.
* @param customs Additional settings for sizing information.
* @param settings Additional settings for sizing information.
*/
public resetGameStarter(settings: IUserWrapprSettings, customs: IGameStartrCustoms = {}): void {
this.loadGameStarter(this.fixCustoms(customs));
public resetGameStarter(settings: IUserWrapprSettings, customs: any = {}): void {
this.loadGameStarter(this.fixGameStartrSettings(customs));
(window as any)[settings.globalName] = this.GameStarter;
this.GameStarter.UserWrapper = this;
(this.gameStarter as any).UserWrapper = this;
this.loadGenerators();
this.resetControls();
if (settings.styleSheet) {
this.GameStarter.utilities.addPageStyles(settings.styleSheet);
this.gameStarter.utilities.addPageStyles(settings.styleSheet);
}
this.resetPageVisibilityHandlers();
this.GameStarter.gameplay.gameStart();
this.gameStarter.gameplay.gameStart();
this.startCheckingDevices();
}
@@ -230,22 +203,15 @@ export class UserWrappr implements IUserWrappr {
/**
* @returns The GameStartr implementation this is wrapping around.
*/
public getGameStartrConstructor(): IGameStartrConstructor {
return this.GameStartrConstructor;
public getGameStartrCreator(): IGameStartrCreator {
return this.gameStartrCreator;
}
/**
* @returns The GameStartr instance created by GameStartrConstructor.
*/
public getGameStarter(): IGameStartr {
return this.GameStarter;
}
/**
* @returns The ItemsHoldr used to store UI settings.
*/
public getItemsHolder(): ItemsHoldr.IItemsHoldr {
return this.ItemsHolder;
return this.gameStarter;
}
/**
@@ -258,7 +224,7 @@ export class UserWrappr implements IUserWrappr {
/**
* @returns The customs used to construct the IGameStartr.
*/
public getCustoms(): IGameStartrCustoms {
public getGameStartrSettings(): IGameStartrSettings {
return this.customs;
}
@@ -356,7 +322,7 @@ export class UserWrappr implements IUserWrappr {
size = this.sizes[size as string];
}
this.customs = this.fixCustoms(this.customs);
this.customs = this.fixGameStartrSettings(this.customs);
if ((size as ISizeSummary).full) {
this.requestFullScreen();
@@ -368,8 +334,8 @@ export class UserWrappr implements IUserWrappr {
this.currentSize = size as ISizeSummary;
if (this.GameStarter) {
this.GameStarter.container.parentNode.removeChild(this.GameStarter.container);
if (this.gameStarter) {
this.gameStarter.container.parentNode.removeChild(this.gameStarter.container);
this.resetGameStarter(this.settings, this.customs);
}
}
@@ -388,12 +354,12 @@ export class UserWrappr implements IUserWrappr {
private checkDevices(): void {
this.deviceChecker = setTimeout(
this.checkDevices.bind(this),
this.GameStarter.GamesRunner.getPaused()
this.gameStarter.GamesRunner.getPaused()
? 117
: this.GameStarter.GamesRunner.getInterval() / this.GameStarter.GamesRunner.getSpeed());
: this.gameStarter.GamesRunner.getInterval() / this.gameStarter.GamesRunner.getSpeed());
this.GameStarter.DeviceLayer.checkNavigatorGamepads();
this.GameStarter.DeviceLayer.activateAllGamepadTriggers();
this.gameStarter.DeviceLayer.checkNavigatorGamepads();
this.gameStarter.DeviceLayer.activateAllGamepadTriggers();
}
/**
@@ -424,42 +390,42 @@ export class UserWrappr implements IUserWrappr {
* Creates a copy of the given customs and adjusts sizing information,
* such as for infinite width or height.
*
* @param customsRaw Raw, user-provided customs.
* @param settingsRaw Raw, user-provided customs.
*/
private fixCustoms(customsRaw: IGameStartrCustoms): any {
const customs: IGameStartrCustoms = {};
private fixGameStartrSettings(settingsRaw: IGameStartrSettings): any {
const settings: IGameStartrSettings = {};
for (const i in customsRaw) {
if (customsRaw.hasOwnProperty(i)) {
customs[i] = customsRaw[i];
for (const i in settingsRaw) {
if (settingsRaw.hasOwnProperty(i)) {
(settings as any)[i] = (settingsRaw as any)[i];
}
}
for (const i in this.currentSize) {
if (this.currentSize.hasOwnProperty(i)) {
customs[i] = (this.currentSize as any)[i];
(settings as any)[i] = (this.currentSize as any)[i];
}
}
if (!isFinite(customs.width)) {
customs.width = document.body.clientWidth;
if (!settings.width || !isFinite(settings.width)) {
settings.width = document.body.clientWidth;
}
if (!isFinite(customs.height)) {
if (customs.full) {
customs.height = screen.height;
if (!settings.height || !isFinite(settings.height)) {
if (settings.full) {
settings.height = screen.height;
} else if (this.isFullScreen) {
// Guess for browser window...
// @todo Actually compute this!
customs.height = window.innerHeight - 140;
settings.height = window.innerHeight - 140;
} else {
customs.height = window.innerHeight;
settings.height = window.innerHeight;
}
// 49px from header, 77px from menus
customs.height -= 126;
settings.height -= 126;
}
return customs;
return settings;
}
/**
@@ -491,9 +457,9 @@ export class UserWrappr implements IUserWrappr {
* Reacts to the page becoming hidden by pausing the GameStartr.
*/
private onPageHidden(): void {
if (!this.GameStarter.GamesRunner.getPaused()) {
if (!this.gameStarter.GamesRunner.getPaused()) {
this.isPageHidden = true;
this.GameStarter.GamesRunner.pause();
this.gameStarter.GamesRunner.pause();
}
}
@@ -503,7 +469,7 @@ export class UserWrappr implements IUserWrappr {
private onPageVisible(): void {
if (this.isPageHidden) {
this.isPageHidden = false;
this.GameStarter.GamesRunner.play();
this.gameStarter.GamesRunner.play();
}
}
@@ -511,29 +477,29 @@ export class UserWrappr implements IUserWrappr {
* Loads the internal GameStarter, resetting it with the given customs
* and attaching handlers to document.body and the holder elements.
*
* @param customs Custom arguments to pass to this.GameStarter.
* @param settings Custom arguments to pass to this.GameStarter.
*/
private loadGameStarter(customs: IGameStartrCustoms): void {
private loadGameStarter(gameStartrSettings: IGameStartrSettings): void {
const section: HTMLElement = document.querySelector(this.gameElementSelector) as HTMLElement;
if (this.GameStarter) {
this.GameStarter.GamesRunner.pause();
if (this.gameStarter) {
this.gameStarter.GamesRunner.pause();
}
this.GameStarter = new this.GameStartrConstructor(customs);
this.GameStarter.UserWrapper = this;
this.gameStarter = this.gameStartrCreator(gameStartrSettings);
(this.gameStarter as any).UserWrapper = this;
section.textContent = "";
section.appendChild(this.GameStarter.container);
section.appendChild(this.gameStarter.container);
this.GameStarter.utilities.proliferate(document.body, {
onkeydown: this.GameStarter.InputWriter.makePipe("onkeydown", "keyCode"),
onkeyup: this.GameStarter.InputWriter.makePipe("onkeyup", "keyCode")
this.gameStarter.utilities.proliferate(document.body, {
onkeydown: this.gameStarter.InputWriter.makePipe("onkeydown", "keyCode"),
onkeyup: this.gameStarter.InputWriter.makePipe("onkeyup", "keyCode")
});
this.GameStarter.utilities.proliferate(section, {
onmousedown: this.GameStarter.InputWriter.makePipe("onmousedown", "which"),
oncontextmenu: this.GameStarter.InputWriter.makePipe("oncontextmenu", undefined, true)
this.gameStarter.utilities.proliferate(section, {
onmousedown: this.gameStarter.InputWriter.makePipe("onmousedown", "which"),
oncontextmenu: this.gameStarter.InputWriter.makePipe("oncontextmenu", "", true)
});
}
@@ -544,7 +510,6 @@ export class UserWrappr implements IUserWrappr {
this.generators = {
OptionsButtons: new ButtonsGenerator(this),
OptionsTable: new TableGenerator(this),
LevelEditor: new LevelEditorGenerator(this),
MapsGrid: new MapsGridGenerator(this)
};
}
@@ -558,10 +523,6 @@ export class UserWrappr implements IUserWrappr {
private loadControls(schemas: ISchema[]): void {
const section: HTMLElement = document.querySelector(this.gameControlsSelector) as HTMLElement;
this.ItemsHolder = new ItemsHoldr.ItemsHoldr({
"prefix": this.globalName + "::UserWrapper::ItemsHolder"
});
section.textContent = "";
section.className = "length-" + length;
-5
View File
@@ -1,8 +1,3 @@
/// <reference path="../../node_modules/@types/chai/index.d.ts" />
/// <reference path="../../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../utils/MochaLoader.ts" />
import { mochaLoader } from "../main";
import { mocks } from "../utils/mocks";
mochaLoader.it("_", (): void => { });
+68
View File
@@ -0,0 +1,68 @@
<!-- This file was auto-generated by gulp-shenanigans -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>UserWrappr Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<!-- Dependencies: Begin -->
<script type="text/javascript">
window.testDependencies = [
"ChangeLinr",
"StringFilr",
"MapScreenr",
"ItemsHoldr",
"BattleMovr",
"DeviceLayr",
"EightBittr",
"AudioPlayr",
"FPSAnalyzr",
"GamesRunnr",
"GroupHoldr",
"InputWritr",
"MapsCreatr",
"MathDecidr",
"ModAttachr",
"NumberMakr",
"ObjectMakr",
"QuadsKeepr",
"AreaSpawnr",
"PixelRendr",
"PixelDrawr",
"ScenePlayr",
"StateHoldr",
"ThingHittr",
"TimeHandlr",
"TouchPassr",
"WorldSeedr",
"GameStartr",
"MenuGraphr"
];
</Script>
<!-- Dependencies: End -->
<!-- Externals: Begin -->
<script src="../node_modules/js-beautify/js/lib/beautify.js"></script>
<!-- Externals: End -->
<!-- Tests: Begin -->
<script type="text/javascript">
window.testPaths = [
"main",
"UserWrappr/_",
"utils/fakes",
"utils/MochaLoader"
];
</script>
<!-- Tests: End -->
<script src="../node_modules/chai/chai.js" type="text/javascript"></script>
<script src="../node_modules/mocha/mocha.js" type="text/javascript"></script>
<script data-main="main.js" src="../node_modules/requirejs/require.js" type="text/javascript"></script>
</body>
</html>
+30 -10
View File
@@ -2,11 +2,27 @@
import { MochaLoader } from "./utils/MochaLoader";
declare var require: any;
declare var testPaths: any;
declare var requirejs: any;
declare var testDependencies: string[];
declare var testPaths: string[];
export const mochaLoader: MochaLoader = new MochaLoader(mocha);
/**
* Informs RequireJS of the file location for a test dependency.
*
* @param testDependencies Modules depended upon for tests.
*/
function redirectTestDependencies(dependencies: string[]): void {
for (const dependency of dependencies) {
requirejs.config({
paths: {
[dependency.toLowerCase() + "/lib"]: `../node_modules/${dependency.toLowerCase()}/src`
}
});
}
}
/**
* Recursively loads test paths under mocha loader.
*
@@ -23,17 +39,21 @@ function loadTestPaths(loadingPaths: string[], i: number, onComplete: () => void
}
mochaLoader.setTestPath(loadingPaths[i]);
require(
requirejs(
[loadingPaths[i]],
(): void => {
loadTestPaths(loadingPaths, i + 1, onComplete);
});
}
loadTestPaths(
testPaths,
0,
(): void => {
mochaLoader.describeTests();
mochaLoader.run();
});
((): void => {
redirectTestDependencies(testDependencies);
loadTestPaths(
testPaths,
0,
(): void => {
mochaLoader.describeTests();
mochaLoader.run();
});
})();
+12 -6
View File
@@ -1,13 +1,19 @@
{
"compilerOptions": {
"declaration": false,
"declaration": true,
"module": "amd",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "..",
"rootDir": "..",
"strictNullChecks": true,
"target": "es3"
},
"files": [
"main.ts",
"utils/mocks.ts",
"utils/MochaLoader.ts",
"UserWrappr/_.ts"
"include": [
"./**/*.ts"
]
}
+124
View File
@@ -0,0 +1,124 @@
/* This file was auto-generated by gulp-shenanigans */
/// <reference path="../../node_modules/@types/chai/index.d.ts" />
/// <reference path="../../node_modules/@types/mocha/index.d.ts" />
/**
* Grouping of mocha describe() tests.
*/
interface ITestHierarchy {
/**
* Hierarchical children within this describe() group.
*/
children: {
[i: string]: ITestHierarchy;
};
/**
* Tests run in this describe().
*/
tests: {
[i: string]: (done: Function) => void;
};
}
/**
* Combines mocha tests into their describe() groups.
*/
export class MochaLoader {
/**
* The underlying mocha instance.
*/
private mocha: Mocha;
/**
* Root grouping of test hierarchies.
*/
private testHierarchy: ITestHierarchy = {
children: {},
tests: {}
};
/**
* Mocha describe() path for the next test to be added.
*/
private currentTestPath: string[];
/**
* Initializes a new instance of the MochaLoader class.
*
* @param mocha The underlying mocha instance.
*/
public constructor(mocha: Mocha) {
this.mocha = mocha;
this.mocha.setup("bdd");
}
/**
* Sets the current test path.
*
* @param rawPath A new current test path.
*/
public setTestPath(rawPath: string): void {
this.currentTestPath = rawPath.split("/");
}
/**
* Adds a new test under the current test path.
*
* @param testName The name of the test.
* @param test A new test.
*/
public it(testName: string, test: (done: Function) => void): void {
if (!this.currentTestPath) {
throw new Error(`No test path defined before adding test '${testName}'.`);
}
let testHierarchy: ITestHierarchy = this.testHierarchy;
for (const part of this.currentTestPath) {
if (!testHierarchy.children[part]) {
testHierarchy = testHierarchy.children[part] = {
children: {},
tests: {}
};
} else {
testHierarchy = testHierarchy.children[part];
}
}
testHierarchy.tests[testName] = test;
}
/**
* Finalizes the tests' describe() hierarchy.
*/
public describeTests(): void {
this.describeTestHierarchy(this.testHierarchy);
}
/**
* Runs tests using mocha.
*/
public run(): void {
this.mocha.run();
}
/**
* Recursively describes a test hierarchy and its children hierarchies.
*
* @param testHierarchy A test hierarchy to describe.
*/
private describeTestHierarchy(testHierarchy: ITestHierarchy): void {
for (const testName in testHierarchy.tests) {
if (testName in testHierarchy.tests) {
it(testName, testHierarchy.tests[testName]);
}
}
for (const childName in testHierarchy.children) {
if (childName in testHierarchy.children) {
describe(childName, (): void => this.describeTestHierarchy(testHierarchy.children[childName]));
}
}
}
}
+9
View File
@@ -0,0 +1,9 @@
import { IUserWrappr, IUserWrapprSettings } from "../../src/IUserWrappr";
import { UserWrappr } from "../../src/UserWrappr";
/**
*
*/
export function mockUserWrappr(settings: IUserWrapprSettings): IUserWrappr {
return new UserWrappr(settings);
}
-15
View File
@@ -1,15 +0,0 @@
import { IUserWrappr, IUserWrapprSettings } from "../../src/IUserWrappr";
import { UserWrappr } from "../../src/UserWrappr";
export const mocks = {
/**
*
*/
mockUserWrappr: (settings: IUserWrapprSettings = mocks.mockUserWrapprSettings()): IUserWrappr => {
return new UserWrappr(settings);
},
mockUserWrapprSettings: (): IUserWrapprSettings => {
return {} as any;
}
};
+11 -13
View File
@@ -1,19 +1,17 @@
{
"compilerOptions": {
"module": "amd",
"target": "es3",
"noImplicitAny": true,
"declaration": true,
"outDir": "lib"
"module": "amd",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictNullChecks": true,
"target": "es3"
},
"files": [
"src/IUserWrappr.ts",
"src/UISchemas.ts",
"src/UserWrappr.ts",
"src/Generators/OptionsGenerator.ts",
"src/Generators/ButtonsGenerator.ts",
"src/Generators/LevelEditrGenerator.ts",
"src/Generators/MapsGridGenerator.ts",
"src/Generators/TableGenerator.ts"
"include": [
"./src/**/*.ts"
]
}
-11
View File
@@ -15,7 +15,6 @@
"interface-name": [true, "always-prefix"],
"jsdoc-format": true,
"label-position": true,
"label-undefined": true,
"max-line-length": [true, 140],
"member-access": true,
"member-ordering": [
@@ -38,9 +37,7 @@
"trace"
],
"no-construct": true,
"no-constructor-vars": true,
"no-debugger": true,
"no-duplicate-key": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-eval": true,
@@ -50,14 +47,11 @@
"no-string-literal": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unreachable": true,
"no-unsafe-finally": true,
"no-unused-expression": true,
"no-unused-variable": true,
"no-unused-new": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"no-var-requires": true,
"one-line": [
true,
"check-catch",
@@ -92,11 +86,6 @@
}
],
"use-isnan": true,
"use-strict": [
true,
"check-module",
"check-function"
],
"whitespace": [
true,
"check-branch",

Some files were not shown because too many files have changed in this diff Show More