Skip to content

Commit

Permalink
Merge pull request #16 from FirstLegoLeagueIL/version-1.2.4
Browse files Browse the repository at this point in the history
Version 1.2.4
  • Loading branch information
idanstark42 authored Jan 25, 2018
2 parents 75de658 + 5d2acc4 commit 88c3fb0
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 29 deletions.
5 changes: 4 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ var clockConfig = {
node: 'default',
seconds: 150,
tracks: [{
name: '30secs_left_track',
source: '30SecstoGo.mp3',
start: '30 seconds before stop'
start: '120 seconds after start'
},{
name: 'end_track',
source: 'End.mp3',
start: 'on stop'
},{
name: 'start_track',
source: 'Start.mp3',
start: 'on start',
}]
Expand Down
9 changes: 4 additions & 5 deletions js/ClockControlsCtrl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('Clock',['ngStorage'])
angular.module('Clock',[])
.factory('$opener',[
'$window',
function($window) {
Expand All @@ -10,10 +10,9 @@ angular.module('Clock',['ngStorage'])
}
])
.controller('ClockControlsCtrl',[
'$scope','$timeout','$opener','$localStorage',
function($scope,$timeout,$opener,$localStorage) {

$scope.config = $localStorage.config;
'$scope','$timeout','$opener','$config',
function($scope,$timeout,$opener,$config) {
$scope.config = $config.get();

// For backwards compatibility
$scope.config.tracks = $scope.config.tracks || [];
Expand Down
2 changes: 1 addition & 1 deletion js/helpers/ClockModule.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
angular.module('Clock',['ngStorage']);
angular.module('Clock',[]);
9 changes: 2 additions & 7 deletions js/helpers/ng-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('Clock').service('$config',['$localStorage' ,'$q', '$window' ,function($localStorage, $q, $window) {
angular.module('Clock').service('$config',['$q', '$window' ,function($q, $window) {
var _config;

function params() {
Expand All @@ -23,12 +23,7 @@ angular.module('Clock').service('$config',['$localStorage' ,'$q', '$window' ,fun
//no url Config
}

//config from localStorage, then url, then defaults from config
var $storage = $localStorage.$default({
config: urlConfig || clockConfig
});

_config = $storage.config;
_config = urlConfig || clockConfig;
}
return _config;
},
Expand Down
30 changes: 17 additions & 13 deletions js/helpers/ng-tracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@

function set(listener, time) {
let event = Math.floor(time / 1000) - listener.timeAfterEvent;
listeners.push({
event: event.toString(),
track: listener.track,
action: listener.metaAction
});
let newListenerName = listener.name + '_set';
if(!listeners.find(listener => listener.name === newListenerName)) {
listeners.push({
name: newListenerName,
event: event.toString(),
track: listener.track,
action: listener.metaAction
});
}
}

function resolveTimeEvent(str, config) {
Expand All @@ -60,13 +64,11 @@
// With the option for xxx after yyy
// Where xxx is the original number-unit trigger, and the yyy is a
// reference to another trigger
if(match = str.match(/^(\d+)(s| secs| seconds|%| percents)( (after|before) (.+))?$/)) {
if(match = str.match(/^(\d+)(s| secs| seconds|%| percents)( (after) (.+))?$/)) {
let quantity = parseInt(match[1]);
let unit = match[2];
let direction = 1; // Counting forward
let startCountingAt = config.seconds; // Start from the beginning
if(match[3]) { // Start at a specific time
direction = (match[4] === 'before') ? -1 : 1;
startCountingAt = resolveTimeEvent(match[5], config);
}
let time;
Expand All @@ -79,16 +81,16 @@

if(isFinite(startCountingAt)) {
startCountingAt = parseInt(startCountingAt);
let time = startCountingAt - direction * quantity;
let time = startCountingAt - quantity;
return time.toString();
} else {
if(startCountingAt.match(/^(after|before)/)) {
if(startCountingAt.match(/^(after)/)) {
console.error(`Illegal trigger: ${str}`);
return undefined;
}
return {
event: startCountingAt,
timeAfter: direction * quantity
timeAfter: quantity
};
}

Expand Down Expand Up @@ -148,7 +150,6 @@
});
}
});
console.log(listeners);
return listeners;
}

Expand All @@ -162,9 +163,12 @@

config.tracks.forEach(function(trackConfig) {
$audio.init(`mp3/${trackConfig.source}`,function(track) {
listeners = listeners.concat(resolveListeners(trackConfig, track, config));
if(!listeners.find(listener => listener.name === trackConfig.name)) {
listeners = listeners.concat(resolveListeners(trackConfig, track, config));
}
});
});
console.log(listeners);
},
trigger: trigger,
pause: function() {
Expand Down
1 change: 0 additions & 1 deletion js/ngStorage.min.js

This file was deleted.

2 changes: 2 additions & 0 deletions localserver.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
var connect = require('connect');
var serveStatic = require('serve-static');
var argv = require('minimist')(process.argv.slice(2));
var morgan = require('morgan');

var fs = require('fs');

var port = 1392;
connect()
.use(morgan('DEBUG [:date[iso]]: :method :url - :status in :response-time ms'))
.use('/config.js', function(req, res, next) {
if(argv.c) {
fs.readFile(argv.c, function(err, data) {
Expand Down
223 changes: 223 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@first-lego-league/clock",
"version": "1.2.3",
"version": "1.2.4",
"description": "Clock\r =====",
"main": "config.js",
"scripts": {
Expand All @@ -19,6 +19,7 @@
"dependencies": {
"connect": "^3.4.0",
"minimist": "^1.1.0",
"morgan": "^1.9.0",
"serve-static": "^1.10.0"
},
"devDependencies": {}
Expand Down

0 comments on commit 88c3fb0

Please sign in to comment.