...
 
Commits (3)
Version 3.1 October 2018
Version 3.5 October 2018
TTS Speech now stops when an option in the main menu is selected.
Fixed a bad problem with playSync
Added new minigame pack quizz.
Version 3.0 September 2018
- Added first letter navigation in the main menu.
......
const electron = require('electron');
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
......@@ -21,7 +21,7 @@ function createWindow() {
protocol: 'file:',
slashes: true
}));
//selectDirectory();
// SelectDirectory();
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
......@@ -53,4 +53,4 @@ app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
\ No newline at end of file
});
This diff is collapsed.
......@@ -16,16 +16,16 @@ class SoundHandler {
this.directional = directional;
}
playStatic(file, loop = 1, slot = -1,stream=false) {
playStatic(file, loop = 1, slot = -1, stream = false) {
if (slot = -1) {
slot = this.findFreeStaticSlot();
}
this.staticSounds[slot] = new SoundItem(file, this.directional,stream);
this.staticSounds[slot] = new SoundItem(file, this.directional, stream);
if (loop == 1) {
this.staticSounds[slot].sound.loop = true;
}
this.staticSounds[slot].sound.play();
return slot;
return slot;
}
findFreeStaticSlot() {
......@@ -79,11 +79,11 @@ class SoundHandler {
if (typeof this.dynamicSounds[slot] === 'undefined') {
if (reuse == false) {
this.dynamicSounds[slot] = new SoundItem(file, this.directional);
}
}
} else if (reuse == false) {
this.dynamicSounds[slot].sound.destroy();
this.dynamicSounds[slot] = new SoundItem(file, directional);
}
}
this.dynamicSounds[slot].sound.play();
}
......@@ -108,13 +108,13 @@ class SoundHandler {
}
}
class SoundItem {
constructor(file, threeD = false,stream=false) {
constructor(file, threeD = false, stream = false) {
this.file = file;
this.threeD = threeD;
if (this.threeD == true) {
this.sound = new SoundSource(file, 0, 0, 0);
} else {
this.sound = so.create(file,stream);
this.sound = so.create(file, stream);
}
}
......
......@@ -8,7 +8,7 @@ class KeyboardInput {
this.chars = [];
this.justReleased = [];
this.justPressedEventCallback = null;
this.charEventCallback=null;
this.charEventCallback = null;
}
init() {
......@@ -38,15 +38,14 @@ this.justPressedEventCallback(event.which);
}
handleChar(char) {
if (char.which<48 || char.which > 122) {
return;
}
if (char.which < 48 || char.which > 122) {
return;
}
if (String.fromCharCode(char.which) != '') {
this.chars += String.fromCharCode(char.which);
if (typeof this.charEventCallback !== 'undefined' && this.charEventCallback != null) {
this.charEventCallback(String.fromCharCode(char.which));
}
}
}
......@@ -96,7 +95,7 @@ this.charEventCallback(String.fromCharCode(char.which));
}
keysPressed() {
const kd = [];
const kd = [];
this.justPressed.forEach((v, i) => {
if (v) {
kd.push(i);
......
'use strict';
var KeyEvent = {
DOM_VK_CANCEL: 3,
DOM_VK_HELP: 6,
DOM_VK_BACK_SPACE: 8,
DOM_VK_TAB: 9,
DOM_VK_CLEAR: 12,
DOM_VK_RETURN: 13,
DOM_VK_ENTER: 14,
DOM_VK_SHIFT: 16,
DOM_VK_CONTROL: 17,
DOM_VK_ALT: 18,
DOM_VK_PAUSE: 19,
DOM_VK_CAPS_LOCK: 20,
DOM_VK_ESCAPE: 27,
DOM_VK_SPACE: 32,
DOM_VK_PAGE_UP: 33,
DOM_VK_PAGE_DOWN: 34,
DOM_VK_END: 35,
DOM_VK_HOME: 36,
DOM_VK_LEFT: 37,
DOM_VK_UP: 38,
DOM_VK_RIGHT: 39,
DOM_VK_DOWN: 40,
DOM_VK_PRINTSCREEN: 44,
DOM_VK_INSERT: 45,
DOM_VK_DELETE: 46,
DOM_VK_0: 48,
DOM_VK_1: 49,
DOM_VK_2: 50,
DOM_VK_3: 51,
DOM_VK_4: 52,
DOM_VK_5: 53,
DOM_VK_6: 54,
DOM_VK_7: 55,
DOM_VK_8: 56,
DOM_VK_9: 57,
DOM_VK_SEMICOLON: 59,
DOM_VK_EQUALS: 61,
DOM_VK_A: 65,
DOM_VK_B: 66,
DOM_VK_C: 67,
DOM_VK_D: 68,
DOM_VK_E: 69,
DOM_VK_F: 70,
DOM_VK_G: 71,
DOM_VK_H: 72,
DOM_VK_I: 73,
DOM_VK_J: 74,
DOM_VK_K: 75,
DOM_VK_L: 76,
DOM_VK_M: 77,
DOM_VK_N: 78,
DOM_VK_O: 79,
DOM_VK_P: 80,
DOM_VK_Q: 81,
DOM_VK_R: 82,
DOM_VK_S: 83,
DOM_VK_T: 84,
DOM_VK_U: 85,
DOM_VK_V: 86,
DOM_VK_W: 87,
DOM_VK_X: 88,
DOM_VK_Y: 89,
DOM_VK_Z: 90,
DOM_VK_CONTEXT_MENU: 93,
DOM_VK_NUMPAD0: 96,
DOM_VK_NUMPAD1: 97,
DOM_VK_NUMPAD2: 98,
DOM_VK_NUMPAD3: 99,
DOM_VK_NUMPAD4: 100,
DOM_VK_NUMPAD5: 101,
DOM_VK_NUMPAD6: 102,
DOM_VK_NUMPAD7: 103,
DOM_VK_NUMPAD8: 104,
DOM_VK_NUMPAD9: 105,
DOM_VK_MULTIPLY: 106,
DOM_VK_ADD: 107,
DOM_VK_SEPARATOR: 108,
DOM_VK_SUBTRACT: 109,
DOM_VK_DECIMAL: 110,
DOM_VK_DIVIDE: 111,
DOM_VK_F1: 112,
DOM_VK_F2: 113,
DOM_VK_F3: 114,
DOM_VK_F4: 115,
DOM_VK_F5: 116,
DOM_VK_F6: 117,
DOM_VK_F7: 118,
DOM_VK_F8: 119,
DOM_VK_F9: 120,
DOM_VK_F10: 121,
DOM_VK_F11: 122,
DOM_VK_F12: 123,
DOM_VK_F13: 124,
DOM_VK_F14: 125,
DOM_VK_F15: 126,
DOM_VK_F16: 127,
DOM_VK_F17: 128,
DOM_VK_F18: 129,
DOM_VK_F19: 130,
DOM_VK_F20: 131,
DOM_VK_F21: 132,
DOM_VK_F22: 133,
DOM_VK_F23: 134,
DOM_VK_F24: 135,
DOM_VK_NUM_LOCK: 144,
DOM_VK_SCROLL_LOCK: 145,
DOM_VK_COMMA: 188,
DOM_VK_PERIOD: 190,
DOM_VK_SLASH: 191,
DOM_VK_BACK_QUOTE: 192,
DOM_VK_OPEN_BRACKET: 219,
DOM_VK_BACK_SLASH: 220,
DOM_VK_CLOSE_BRACKET: 221,
DOM_VK_QUOTE: 222,
DOM_VK_META: 224
};
const KeyEvent = {
DOM_VK_CANCEL: 3,
DOM_VK_HELP: 6,
DOM_VK_BACK_SPACE: 8,
DOM_VK_TAB: 9,
DOM_VK_CLEAR: 12,
DOM_VK_RETURN: 13,
DOM_VK_ENTER: 14,
DOM_VK_SHIFT: 16,
DOM_VK_CONTROL: 17,
DOM_VK_ALT: 18,
DOM_VK_PAUSE: 19,
DOM_VK_CAPS_LOCK: 20,
DOM_VK_ESCAPE: 27,
DOM_VK_SPACE: 32,
DOM_VK_PAGE_UP: 33,
DOM_VK_PAGE_DOWN: 34,
DOM_VK_END: 35,
DOM_VK_HOME: 36,
DOM_VK_LEFT: 37,
DOM_VK_UP: 38,
DOM_VK_RIGHT: 39,
DOM_VK_DOWN: 40,
DOM_VK_PRINTSCREEN: 44,
DOM_VK_INSERT: 45,
DOM_VK_DELETE: 46,
DOM_VK_0: 48,
DOM_VK_1: 49,
DOM_VK_2: 50,
DOM_VK_3: 51,
DOM_VK_4: 52,
DOM_VK_5: 53,
DOM_VK_6: 54,
DOM_VK_7: 55,
DOM_VK_8: 56,
DOM_VK_9: 57,
DOM_VK_SEMICOLON: 59,
DOM_VK_EQUALS: 61,
DOM_VK_A: 65,
DOM_VK_B: 66,
DOM_VK_C: 67,
DOM_VK_D: 68,
DOM_VK_E: 69,
DOM_VK_F: 70,
DOM_VK_G: 71,
DOM_VK_H: 72,
DOM_VK_I: 73,
DOM_VK_J: 74,
DOM_VK_K: 75,
DOM_VK_L: 76,
DOM_VK_M: 77,
DOM_VK_N: 78,
DOM_VK_O: 79,
DOM_VK_P: 80,
DOM_VK_Q: 81,
DOM_VK_R: 82,
DOM_VK_S: 83,
DOM_VK_T: 84,
DOM_VK_U: 85,
DOM_VK_V: 86,
DOM_VK_W: 87,
DOM_VK_X: 88,
DOM_VK_Y: 89,
DOM_VK_Z: 90,
DOM_VK_CONTEXT_MENU: 93,
DOM_VK_NUMPAD0: 96,
DOM_VK_NUMPAD1: 97,
DOM_VK_NUMPAD2: 98,
DOM_VK_NUMPAD3: 99,
DOM_VK_NUMPAD4: 100,
DOM_VK_NUMPAD5: 101,
DOM_VK_NUMPAD6: 102,
DOM_VK_NUMPAD7: 103,
DOM_VK_NUMPAD8: 104,
DOM_VK_NUMPAD9: 105,
DOM_VK_MULTIPLY: 106,
DOM_VK_ADD: 107,
DOM_VK_SEPARATOR: 108,
DOM_VK_SUBTRACT: 109,
DOM_VK_DECIMAL: 110,
DOM_VK_DIVIDE: 111,
DOM_VK_F1: 112,
DOM_VK_F2: 113,
DOM_VK_F3: 114,
DOM_VK_F4: 115,
DOM_VK_F5: 116,
DOM_VK_F6: 117,
DOM_VK_F7: 118,
DOM_VK_F8: 119,
DOM_VK_F9: 120,
DOM_VK_F10: 121,
DOM_VK_F11: 122,
DOM_VK_F12: 123,
DOM_VK_F13: 124,
DOM_VK_F14: 125,
DOM_VK_F15: 126,
DOM_VK_F16: 127,
DOM_VK_F17: 128,
DOM_VK_F18: 129,
DOM_VK_F19: 130,
DOM_VK_F20: 131,
DOM_VK_F21: 132,
DOM_VK_F22: 133,
DOM_VK_F23: 134,
DOM_VK_F24: 135,
DOM_VK_NUM_LOCK: 144,
DOM_VK_SCROLL_LOCK: 145,
DOM_VK_COMMA: 188,
DOM_VK_PERIOD: 190,
DOM_VK_SLASH: 191,
DOM_VK_BACK_QUOTE: 192,
DOM_VK_OPEN_BRACKET: 219,
DOM_VK_BACK_SLASH: 220,
DOM_VK_CLOSE_BRACKET: 221,
DOM_VK_QUOTE: 222,
DOM_VK_META: 224
};
export {KeyEvent};
This diff is collapsed.
......@@ -11,11 +11,11 @@ import {KeyboardInput} from './input';
class Menu {
constructor(name, menuData, music) {
this.menuData = menuData;
this.first=true;
this.first = true;
this.cursor = 0;
this.name = name;
let dir=so.directory;
so.directory="./sounds/";
const dir = so.directory;
so.directory = './sounds/';
this.sndKeyChar = so.create('ui/keyChar');
this.sndKeyDelete = so.create('ui/keyDelete');
this.sndSliderLeft = so.create('ui/menuSliderLeft');
......@@ -26,7 +26,7 @@ class Menu {
this.sndOpen = so.create('ui/menuOpen');
this.sndSelector = so.create('ui/menuSelector');
this.sndWrap = so.create('ui/menuWrap');
so.directory=dir;
so.directory = dir;
this.selectCallback = null;
if (typeof music !== 'undefined') {
this.music = music;
......@@ -37,36 +37,32 @@ class Menu {
nextItem() {
if (!this.first) {
if (this.cursor < this.menuData.length - 1) {
if (this.cursor < this.menuData.length - 1) {
this.sndMove.play();
this.cursor++;
}
else {
} else {
this.sndWrap.play();
this.cursor=0;
}
}
else {
this.cursor = 0;
}
} else {
this.sndMove.play();
this.first=false;
this.first = false;
}
this.menuData[this.cursor].speak();
}
previousItem() {
if (this.first) {
this.first=false;
if (this.first) {
this.first = false;
this.sndMove.play();
}
}
if (this.cursor > 0) {
this.sndMove.play();
this.cursor--;
}
else {
this.cursor=this.menuData.length-1;
this.cursor--;
} else {
this.cursor = this.menuData.length - 1;
this.sndWrap.play();
}
this.menuData[this.cursor].speak();
}
......@@ -97,26 +93,25 @@ class Menu {
if (this.menuData[this.cursor].type == MenuTypes.EDIT) {
this.menuData[this.cursor].addChar(String.fromCharCode(char));
this.sndKeyChar.play();
}
else {
//char navigation code
for (let i=this.cursor+1;i<this.menuData.length;i++) {
if (this.menuData[i].name.toLowerCase().substr(0,1)==String.fromCharCode(char).toLowerCase()) {
this.cursor=i;
} else {
// Char navigation code
for (let i = this.cursor + 1; i < this.menuData.length; i++) {
if (this.menuData[i].name.toLowerCase().substr(0, 1) == String.fromCharCode(char).toLowerCase()) {
this.cursor = i;
this.menuData[this.cursor].speak();
this.first=false;
return;
}
}
for (let i=0;i<this.menuData.length;i++) {
console.log("ran second loop");
if (this.menuData[i].name.toLowerCase().substr(0,1)==String.fromCharCode(char).toLowerCase()) {
this.cursor=i;
this.first = false;
return;
}
}
for (let i = 0; i < this.menuData.length; i++) {
console.log('ran second loop');
if (this.menuData[i].name.toLowerCase().substr(0, 1) == String.fromCharCode(char).toLowerCase()) {
this.cursor = i;
this.menuData[this.cursor].speak();
this.first=false;
this.first = false;
return;
}
}
}
}
}
......@@ -153,10 +148,10 @@ this.music.unload();
await utils.sleep(50);
}
this.music.unload();
//this.destroy();
// This.destroy();
}
destroy() {
destroy() {
$(document).off('keydown');
$(document).off('keypress');
// This.hammer.destroy();
......@@ -201,13 +196,22 @@ destroy() {
}
}
async runSync() {
return new Promise((resolve, reject) => {
this.run(s => {
resolve(s.selected);
this.destroy();
});
});
}
run(callback) {
if (typeof this.music === 'object') {
this.music.volume = 0.5;
this.music.loop = true;
this.music.play();
} else if (typeof this.music === 'string') {
this.music = so.create(this.music,true);
this.music = so.create(this.music, true);
this.music.volume = 0.5;
this.music.loop = true;
this.music.play();
......@@ -258,10 +262,10 @@ destroy() {
for (let i = 0; i < this.menuData.length; i++) {
let addItem = null;
if (this.menuData[i].type == MenuTypes.SLIDER) {
addItem = {
addItem = {
id: this.menuData[i].id,
value: this.menuData[i].currentValue,
//name: this.menuData[i].options[this.menuData[i].currentValue]
value: this.menuData[i].currentValue
// Name: this.menuData[i].options[this.menuData[i].currentValue]
};
}
if (this.menuData[i].type == MenuTypes.EDIT) {
......@@ -289,11 +293,13 @@ destroy() {
this.sndChoose.play();
$(document).off('keydown');
$(document).off('keypress');
this.musicDuration=0;
this.musicDuration=this.sndChoose.duration
if (this.musicDuration>3000) this.musicDuration=3000;
if (typeof this.music !== 'undefined') {
this.musicDuration = 0;
this.musicDuration = this.sndChoose.duration;
if (this.musicDuration > 3000) {
this.musicDuration = 3000;
}
if (typeof this.music !== 'undefined') {
this.fade();
}
const that = this;
......
'use strict';
const {dialog} = require('electron').remote;
const electron = require('electron')
const remote = electron.remote
const electron = require('electron');
const remote = electron.remote;
import {utils} from './utilities';
import {ScrollingText} from './scrollingText';
import {speech} from './tts';
import {so} from './soundObject';
import {version,version2,save,data,browseAch,editPack,minituts,minigames,buySafeguards} from './main';
import {checkPack,packDirectory,version, version2, save, data, browseAch, editPack, minituts, minigames, buySafeguards} from './main';
import {langs, lang} from './main';
import {st} from './stateMachine';
import {strings} from './strings';
......@@ -15,33 +17,42 @@ import {pack, packdir, rebuildHashes, downloadPacks} from './main';
import {KeyboardInput} from './input.js';
import {KeyEvent} from './keycodes';
import {Menu} from './menu';
export async function mainMenu() {
const fs=require('fs');
const items = new Array();
items.push(new MenuItem(0, strings.get( 'mStart')));
if (version2!="" && version!=version2) {
items.push(new MenuItem(-1000,strings.get("newUpdate",[version,version2])));
const fs = require('fs');
const items = new Array();
items.push(new MenuItem(0, strings.get('mStart')));
if (version2 != '' && version != version2) {
items.push(new MenuItem(-1000, strings.get('newUpdate', [version, version2])));
}
if (speech.webTTS) {
items.push(new MenuItem(33, strings.get('mReader')));
}
if (!speech.webTTS) {
items.push(new MenuItem(34, strings.get('mSapi')));
}
if (speech.webTTS) items.push(new MenuItem(33,strings.get("mReader")));
if (!speech.webTTS) items.push(new MenuItem(34,strings.get("mSapi")));
if (speech.webTTS) items.push(new MenuItem(32,strings.get("mRate")));
items.push(new MenuItem(13, strings.get( 'mRev')));
items.push(new MenuItem(8, strings.get( 'mSafeguards',[data.safeguards])));
items.push(new MenuItem(1, strings.get( 'mLearn')));
items.push(new MenuItem(12, strings.get( 'mAch')));
items.push(new MenuItem(11, strings.get( 'mEdit')));
items.push(new MenuItem(9, strings.get( 'mGames',)));
items.push(new MenuItem(2, strings.get( 'mBrowse',[data.beatcoins])));
items.push(new MenuItem(5, strings.get( 'mBrowseUnlocked')));
items.push(new MenuItem(7, strings.get( 'mBrowseIncompleted')));
items.push(new MenuItem(4, strings.get( 'mDownload')));
items.push(new MenuItem(6, strings.get( 'mUnlocked',[data.unlocks[pack]["level"]])));
items.push(new MenuItem(10, strings.get( 'mGameTuts',)));
items.push(new MenuItem(3, strings.get( 'mHashes')));
if (speech.webTTS) {
items.push(new MenuItem(32, strings.get('mRate')));
}
items.push(new MenuItem(13, strings.get('mRev')));
items.push(new MenuItem(8, strings.get('mSafeguards', [data.safeguards])));
items.push(new MenuItem(1, strings.get('mLearn')));
items.push(new MenuItem(12, strings.get('mAch')));
items.push(new MenuItem(11, strings.get('mEdit')));
items.push(new MenuItem(9, strings.get('mGames',)));
items.push(new MenuItem(2, strings.get('mBrowse', [data.beatcoins])));
items.push(new MenuItem(5, strings.get('mBrowseUnlocked')));
items.push(new MenuItem(7, strings.get('mBrowseIncompleted')));
items.push(new MenuItem(4, strings.get('mDownload')));
items.push(new MenuItem(6, strings.get('mUnlocked', [data.unlocks[pack].level])));
items.push(new MenuItem(10, strings.get('mGameTuts',)));
items.push(new MenuItem(1234, strings.get('mLang',)));
items.push(new MenuItem(69, strings.get('mDir',[packDirectory])));
items.push(new MenuItem(3, strings.get('mHashes')));
so.directory = './sounds/';
const mainMenu = new Menu(strings.get("mainmenu"), items);
const mainMenu = new Menu(strings.get('mainmenu'), items);
so.directory = '';
mainMenu.music = packdir + 'loop';
if (fs.existsSync(packdir + 'select.ogg')) {
......@@ -53,18 +64,23 @@ if (fs.existsSync(packdir + 'select.ogg')) {
so.directory = './sounds/';
mainMenu.destroy();
switch (s.selected) {
case 1234:
languageSelect();
break;
case 32:
changeRate();
break;
break;
case 33:
if (process.platform=='darwin') await new ScrollingText(strings.get("macwarning"));
speech.webTTS=false;
if (process.platform == 'darwin') {
await new ScrollingText(strings.get('macwarning'));
}
speech.webTTS = false;
st.setState(2);
break;
break;
case 34:
speech.webTTS=true;
speech.webTTS = true;
st.setState(2);
break;
break;
case 0: st.setState(3); break;
case 1: st.setState(4); break;
......@@ -74,55 +90,95 @@ if (fs.existsSync(packdir + 'select.ogg')) {
case 4: downloadPacks(); break;
case 5:
st.setState(6); break;
case 6:
case 6:
st.setState(7); break;
case 7:
case 7:
st.setState(8); break;
case 8: buySafeguards(); break;
case 8: buySafeguards(); break;
case 9: minigames(); break;
case 10: minituts(); break;
case 69:
let dir=await changeDir();
console.log(dir);
if (typeof dir !== 'undefined' && dir != '') {
packDirectory=dir+"/";
packdir =packDirectory + pack + '/';
window.localStorage.setItem("path",packDirectory);
}
checkPack();
break;
case 11:
const {dialog} = require('electron').remote
let stuff=dialog.showOpenDialog({
title:strings.get("selectPack"),
properties: ['openDirectory']
},function(path){
const stuff = dialog.showOpenDialog({
title: strings.get('selectPack'),
properties: ['openDirectory']
}, path => {
editPack(path);
});
break;
});
break;
case 12:
browseAch();
break;
break;
case 13:
st.setState(21);
break;
break;
case -1000:
const {shell} = require('electron').remote
shell.openExternal('http://oriolgomez.com')
const {shell} = require('electron').remote;
shell.openExternal('http://oriolgomez.com');
st.setState(2);
break;
break;
}
});
}
export async function changeRate() {
let rate=speech.rate;
let inp=new KeyboardInput();
let rate = speech.rate;
const inp = new KeyboardInput();
inp.init();
strings.speak("rating");
strings.speak('rating');
while (!inp.isJustPressed(KeyEvent.DOM_VK_RETURN)) {
await utils.sleep(5);
if (inp.isJustPressed(KeyEvent.DOM_VK_RIGHT)) {
rate=rate+0.25;
speech.rate=rate;
strings.speak("newRate");
}
if (inp.isJustPressed(KeyEvent.DOM_VK_LEFT)) {
rate=rate-0.25;
speech.rate=rate;
strings.speak("newRate");
await utils.sleep(5);
if (inp.isJustPressed(KeyEvent.DOM_VK_RIGHT)) {
rate += 0.25;
speech.rate = rate;
strings.speak('newRate');
}
if (inp.isJustPressed(KeyEvent.DOM_VK_LEFT)) {
rate -= 0.25;
speech.rate = rate;
strings.speak('newRate');
}
}
}
data.rate=speech.rate;
data.rate = speech.rate;
save();
st.setState(2);
}
export function languageSelect() {
let str = '';
for (const i in strings.strings) {
str += strings.strings[i].langs + '. ';
}
const items = [];
let counter = 1;
for (const i in strings.strings) {
items.push(new MenuItem(counter, strings.strings[i].lang));
counter++;
}
const lm = new Menu(str, items);
lm.run(s => {
lang = s.selected;
data.lang = lang;
save();
st.setState(2);
lm.destroy();
});
}
export async function changeDir() {
await new Promise((resolve,reject)=> {
const stuff = dialog.showOpenDialog({
title: strings.get('selectPath'),
properties: ['openDirectory']
}, path => {
resolve(path);
});
});
}
\ No newline at end of file
......@@ -64,14 +64,14 @@ class SelectorItem extends MenuItem {
}
class SliderItem extends MenuItem {
constructor(id, name, from, to, currentValue = 0,increaseBy=1) {
constructor(id, name, from, to, currentValue = 0, increaseBy = 1) {
super();
this.id = id;
this.name = name;
this.minValue = from;
this.maxValue = to;
this.currentValue = currentValue;
this.increaseBy=increaseBy;
this.increaseBy = increaseBy;
this.type = MenuTypes.SLIDER;
}
......@@ -81,17 +81,21 @@ class SliderItem extends MenuItem {
increase() {
if (this.currentValue < this.maxValue) {
this.currentValue+=this.increaseBy;
this.currentValue += this.increaseBy;
}
if (this.currentValue > this.maxValue) {
this.currentValue = this.maxValue;
}
if (this.currentValue>this.maxValue) this.currentValue=this.maxValue;
speech.speak(this.currentValue);
}
decrease() {
if (this.currentValue > this.minValue) {
this.currentValue-=this.increaseBy;
this.currentValue -= this.increaseBy;
}
if (this.currentValue < this.minValue) {
this.currentValue = this.minValue;
}
if (this.currentValue<this.minValue) this.currentValue=this.minValue;
speech.speak(this.currentValue);
}
......@@ -127,4 +131,4 @@ class EditItem extends MenuItem {
return this.text;
}
}
export {MenuItem,SliderItem,SelectorItem,MenuTypes};
export {MenuItem, SliderItem, SelectorItem, MenuTypes};
This diff is collapsed.
......@@ -30,7 +30,8 @@ class OldTimer {
this.paused = false;
this.started = true;
}
restart() {
restart() {
this.lastTime = performance.now();
this.pauseWhen = 0;
this.paused = false;
......
......@@ -9,16 +9,16 @@ class Player {
constructor() {
this.beatcoins = 0,
this.pack = 'default',
this.allowSave=false;
this.save={}
this.allowSave = false;
this.save = {};
this.actionKeys = [0, 0, KeyEvent.DOM_VK_SPACE, KeyEvent.DOM_VK_TAB, KeyEvent.DOM_VK_RETURN, KeyEvent.DOM_VK_BACK_SPACE, KeyEvent.DOM_VK_UP, KeyEvent.DOM_VK_DOWN, KeyEvent.DOM_VK_RIGHT, KeyEvent.DOM_VK_LEFT];
this.unlocks = {}
this.unlocks["default"]={
"level":0,
"fails":0,
"win":false,
"average":0,
};
this.unlocks = {};
this.unlocks.default = {
level: 0,
fails: 0,
win: false,
average: 0
};
}
}
export {Player};
......@@ -3,13 +3,14 @@ import $ from 'jquery';
import {KeyEvent} from './keycodes';
import {so} from './soundObject';
import {speech} from './tts';
if (runningText == undefined) {
if (runningText == undefined) {
var runningText = 0;
}
class ScrollingText {
constructor(text, delimiter = '\n', callback = 0) {
this.callback = callback;
this.callback = callback;
this.text = text;
this.delimiter = delimiter;
this.splitText = this.text.split(delimiter);
......@@ -20,12 +21,12 @@ class ScrollingText {
const id = document.getElementById('touchArea');
// This.hammer = new Hammer(id);
this.init();
if (this.callback==0) {
return this.prom=new Promise((resolve,reject)=> {
this.res=resolve;
});
}
if (this.callback == 0) {
return this.prom = new Promise((resolve, reject) => {
this.res = resolve;
});
}
}
init() {
const that = this;
......@@ -63,15 +64,14 @@ class ScrollingText {
}
readCurrentLine() {
if (this.splitText[this.currentLine][0]=="!") {
let str=this.splitText[this.currentLine].substr(1);
let snd=so.create(str,true);
if (this.splitText[this.currentLine][0] == '!') {
const str = this.splitText[this.currentLine].substr(1);
const snd = so.create(str, true);
snd.play();
snd.sound.once("end",()=> {
snd.sound.once('end', () => {
this.advance();
});
}
else {
} else {
speech.speak(this.splitText[this.currentLine]);
}
}
......@@ -90,8 +90,7 @@ document.removeEventListener('keydown', this.handleKeys);
// This.hammer.unload();
if (this.callback != 0) {
this.callback();
}
else {
} else {
this.res();
}
}
......
......@@ -197,8 +197,9 @@ class SoundObject {
}
return returnObject;
}
load(file) {
const fs=require('fs');
load(file) {
const fs = require('fs');
file = this.directory + file + this.extension;
if (fs.exists(file)) {
this.queue.push(file);
......@@ -206,7 +207,6 @@ const fs=require('fs');
}
}
enqueue(file) {
file = this.directory + file + this.extension;
this.queue.push(file);
......@@ -299,7 +299,7 @@ toDestroy.push(i);
for (var i = 0; i < toDestroy.length; i++) {
if (that.oneShotSounds[i].playing == false) {
that.oneShotSounds.splice(toDestroy[i], 1);
}
}
}
});
}
......
import {Howl, Howler,Spatial} from './howler';
import {Howl, Howler, Spatial} from './howler';
import {KeyboardInput} from './input';
import {KeyEvent} from './keycodes';
import {utils} from './utilities';
const isElectron = true;
let playOnceTimer;
class SoundObjectItem {
constructor(file, callback = 0, tag = 0,stream=false) {
constructor(file, callback = 0, tag = 0, stream = false) {
const that = this;
this.fileName = file;
this.sound = new Howl({
src: file,
html5:stream,
html5: stream,
onload() {
that.doneLoading();
}
......@@ -46,30 +47,29 @@ class SoundObjectItem {
play() {
this.sound.play();
}
playSync() {
let inp=new KeyboardInput();
playSync() {
const inp = new KeyboardInput();
inp.init();
this.sound.play();
inp.justPressedEventCallback=((evt)=> {
if (evt==KeyEvent.DOM_VK_Q || evt==KeyEvent.DOM_VK_X) {
inp.justPressedEventCallback = (evt => {
if (evt == KeyEvent.DOM_VK_Q || evt == KeyEvent.DOM_VK_X) {
this.sound.stop();
inp.justPressedEventCallback=null;
}
inp.justPressedEventCallback = null;
}
});
return new Promise((resolve,reject)=>{
this.sound.once("end",()=> {
this.sound.unload();
resolve("ok");
inp.justPressedEventCallback=null;
});//end
this.sound.once("stop",()=> {
this.sound.unload();
resolve("ok");
inp.justPressedEventCallback=null;
});//stop
});//promise
return new Promise((resolve, reject) => {
this.sound.once('end', () => {
resolve('ok');
inp.justPressedEventCallback = null;
});// End
this.sound.once('stop', () => {
resolve('ok');
inp.justPressedEventCallback = null;
});// Stop
});// Promise
}
stop() {
this.sound.stop();
}
......@@ -91,9 +91,10 @@ inp.init();
}
set volume(v) {
return this.sound.volume(v);
return this.sound.volume(v);
}
get pan() {
get pan() {
return this.sound.stereo();
}
......@@ -104,17 +105,27 @@ get pan() {
set loop(v) {
return this.sound.loop(v);
}
get active() {
if (this.sound.state()=="unloaded") return false;
if (this.sound.state()=="loaded") return true;
if (this.sound.state()=="loading") return true;
}
get active() {
if (this.sound.state() == 'unloaded') {
return false;
}
if (this.sound.state() == 'loaded') {
return true;
}
if (this.sound.state() == 'loading') {
return true;
}
}
get loop() {
return this.sound.loop();
}
get playing() {
return this.sound.playing();
}
get playbackRate() {
return this.sound.rate();
}
......@@ -122,7 +133,8 @@ if (this.sound.state()=="loading") return true;
set playbackRate(v) {
return this.sound.rate(v);
}
get pitch() {
get pitch() {
return this.sound.rate();
}
......@@ -135,7 +147,7 @@ get pitch() {
}
get duration() {
return this.sound.duration()*1000;
return this.sound.duration() * 1000;
}
get position() {
......@@ -217,16 +229,17 @@ class SoundObject {
this.statusCallback = null;
}
create(file,stream=false) {
create(file, stream = false) {
file = this.directory + file + this.extension;
let returnObject = null;
const that = this;
returnObject = new SoundObjectItem(file, (() => {
that.doneLoading();
}),0,stream);
}), 0, stream);
this.sounds.push(returnObject);
return returnObject;
return returnObject;
}
enqueue(file) {
file = this.directory + file + this.extension;
console.log(file);
......@@ -264,18 +277,16 @@ class SoundObject {
this.sounds.push(new SoundObjectItem(this.queue[0], (() => {
that.handleQueue();
}), 1));
}
catch(err) {
console.log("error");
}
finally {
} catch (err) {
console.log('error');
} finally {
this.queue.splice(0, 1);
}
} else {
this.loadingQueue = false;
if (typeof this.queueCallback !== 'undefined' && this.queueCallback != 0) {
if (typeof this.queueCallback !== 'undefined' && this.queueCallback != 0) {
this.queueCallback();
}
}
}
}
......@@ -327,7 +338,7 @@ toDestroy.push(i);
for (var i = 0; i < toDestroy.length; i++) {
if (that.oneShotSounds[i].playing == false) {
that.oneShotSounds.splice(toDestroy[i], 1);
}
}
}
});
}
......@@ -337,12 +348,12 @@ toDestroy.push(i);
const filename = this.directory + file + this.extension;
while (!noMore) {
const found = this.findSoundIndex(filename);
if (found == -1) {
noMore = true;
} else {
if (found == -1) {
noMore = true;
} else {
this.sounds[found].sound.unload();
this.sounds.splice(found, 1);
}
}
}
if (callback != 0) {
callback();
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
let event = new KeyboardInput();
import {KeyboardInput} from './input';
import {credits,listenPack,checkPack, learnPack, browsePacks} from './main';
import {credits, listenPack, checkPack, learnPack, browsePacks} from './main';
import {Menu} from './menuHandler';
import $ from 'jquery';
import {so} from './soundObject';
......@@ -29,7 +29,7 @@ class StateMachine {
that.setState(2);
});
$(document).keydown(event => {
if (event.which == KeyEvent.DOM_VK_SPACE || event.which == KeyEvent.DOM_VK_ESCAPE || event.which==KeyEvent.DOM_VK_RETURN) {
if (event.which == KeyEvent.DOM_VK_SPACE || event.which == KeyEvent.DOM_VK_ESCAPE || event.which == KeyEvent.DOM_VK_RETURN) {
intro.unload();
$(document).off('keydown');
that.setState(20);
......@@ -40,35 +40,29 @@ class StateMachine {
event = null;
checkPack();
this.state = state;
}
else if (state == 21) {
this.currentState = new Game(credits,2);
} else if (state == 21) {
this.currentState = new Game(credits, 2);
this.state = state;
}
else if (state == 3) {
} else if (state == 3) {
this.currentState = new Game(credits);
this.state = state;
}
else if (state == 20) {
} else if (state == 20) {
event = null;
checkPack(false);
this.state = state;
}
else if (state == 4) {
} else if (state == 4) {
learnPack();
} else if (state == 7) {
listenPack();
}
else if (state==7) { listenPack(); }
// New states
else if (state == 5) {
browsePacks();
this.state = state;
}
else if (state == 6) {
} else if (state == 6) {
browsePacks(2);
this.state = state;
}
else if (state == 8) {
} else if (state == 8) {
browsePacks(3);
this.state = state;
}
......
This diff is collapsed.
'use strict';
import {utils} from './utilities';
const useWebTTS = true;
import {ttsVoice,ttsRate} from './main';
import {ttsVoice, ttsRate} from './main';
class TTS {
constructor(webTTS = false) {
this.synth = window.speechSynthesis;
this.webTTS = webTTS;
this.rate=1;
this.rate = 1;
}
async speak(text) {
if (this.webTTS) {
const utterThis = new SpeechSynthesisUtterance(text);
if (typeof ttsVoice!=="undefined") utterThis.voice=ttsVoice;
utterThis.rate=this.rate;
const utterThis = new SpeechSynthesisUtterance(text);
if (typeof ttsVoice !== 'undefined') {
utterThis.voice = ttsVoice;
}
utterThis.rate = this.rate;
this.synth.cancel();
if (process.platform!='darwin') await utils.sleep(150);
if (process.platform != 'darwin') {
await utils.sleep(150);
}
this.synth.speak(utterThis);
} else {
document.getElementById('speech').innerHTML = '';
......@@ -28,10 +34,15 @@ utterThis.rate=this.rate;
setWebTTS(tts) {
this.webTTS = tts;
}
stop() {
if (this.webTTS) this.synth.cancel();
if (this.webTTS) {
this.synth.cancel();
}
}
} // End class
var speech = new TTS(false);
if (process.platform=='darwin') speech.webTTS=true;
export {TTS, speech};
\ No newline at end of file
const speech = new TTS(false);
if (process.platform == 'darwin') {
speech.webTTS = true;
}
export {TTS, speech};
'use strict';
class GameUtils {
progressPan(current, max) {
return ((current*200/max)-100)/100;
}
progressPitch(current,min,max,minPitch,maxPitch) {
return (current/(min+max))*(maxPitch-minPitch)+minPitch;
}
progressVolume(current,min,max,minVolume,maxVolume) {
if (current>max) return 0;
return (current/(min+max))*(maxVolume-minVolume)+minVolume;
}
getProportion(current,min,max,minVolume,maxVolume) {
if (current>max) return 0;
return (current/(min+max))*(maxVolume-minVolume)+minVolume;
}
progressPan(current, max) {
return ((current * 200 / max) - 100) / 100;
}
progressPitch(current, min, max, minPitch, maxPitch) {
return (current / (min + max)) * (maxPitch - minPitch) + minPitch;
}
progressVolume(current, min, max, minVolume, maxVolume) {
if (current > max) {
return 0;
}
return (current / (min + max)) * (maxVolume - minVolume) + minVolume;
}
getProportion(current, min, max, minVolume, maxVolume) {
if (current > max) {
return 0;
}
return (current / (min + max)) * (maxVolume - minVolume) + minVolume;
}
distance3D(x1, y1, z1, x2, y2, z2) {
return Math.sqrt((x2 - x1) * (x2 - x1) +
......@@ -52,54 +59,64 @@ return (current/(min+max))*(maxVolume-minVolume)+minVolume;
percent(int1, int2) {
return int1 * 100 / int2;
}
percentOf(int1, int2) {
return int2 * int1 / 100;
}
average(arr,startIndex=0) {
let len=arr.length;
let val=0;
let average=0;
if (arr.length<startIndex) return -1;
for (let i=startIndex;i<arr.length;i++) {
val+=arr[i];
}
average=val/(len-startIndex);
return average;
}
averageInt(arr,startIndex=0) {
let len=arr.length;
let val=0;
let average=0;
if (arr.length<startIndex) return -1;
for (let i=startIndex;i<arr.length;i++) {
val+=arr[i];
}
average=val/(len-startIndex);
return Math.floor(average);
}
neg(num) {
return (num>=0?(num==0?0:1):-1)
}
average(arr, startIndex = 0) {
const len = arr.length;
let val = 0;
let average = 0;
if (arr.length < startIndex) {
return -1;
}
for (let i = startIndex; i < arr.length; i++) {
val += arr[i];
}
average = val / (len - startIndex);
return average;
}
numericSort(a, b) {
return (a<b?-1:(a==b?0:1))
}
shuffle(a) {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
objSize(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
}
averageInt(arr, startIndex = 0) {
const len = arr.length;
let val = 0;
let average = 0;
if (arr.length < startIndex) {
return -1;
}
for (let i = startIndex; i < arr.length; i++) {
val += arr[i];
}
average = val / (len - startIndex);
return Math.floor(average);
}
neg(num) {
return (num >= 0 ? (num == 0 ? 0 : 1) : -1);
}
numericSort(a, b) {
return (a < b ? -1 : (a == b ? 0 : 1));
}
shuffle(a) {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
objSize(obj) {
let size = 0,
key;