From dd6ecee00a6c7bb36c13819a67bd9bca919b7367 Mon Sep 17 00:00:00 2001 From: Sean Devine Date: Fri, 18 Dec 2015 11:40:34 -0500 Subject: [PATCH] add SET and GO buttons and move actions to application controller --- app/controllers/application.js | 40 +++++++++++++++++++++++++++++++++- app/routes/application.js | 26 ---------------------- app/templates/application.hbs | 18 ++++++++++++--- package.json | 3 ++- 4 files changed, 56 insertions(+), 31 deletions(-) diff --git a/app/controllers/application.js b/app/controllers/application.js index f5fda01..f886a86 100644 --- a/app/controllers/application.js +++ b/app/controllers/application.js @@ -1,15 +1,53 @@ import Ember from 'ember'; export default Ember.Controller.extend({ + levels: [1,2,3,4], + isOn: null, level: null, + mode: null, + actions: { + turnOn() { + this.set('isOn', true); + this.set('level', this.get('levels').objectAt(0)); + this.set('operator', '+'); + this.set('mode', 'settings'); + }, + + turnOff() { + this.set('isOn', false); + }, + changeOperator(operator) { - if (this.get('isOn')) { + if (this.get('isOn') && this.get('mode') === 'settings') { this.set('operator', operator); } + }, + + playGame() { + if (this.get('isOn') && this.get('mode') === 'settings') { + this.set('mode', 'game'); + } + }, + + changeSettings() { + if (this.get('isOn') && this.get('mode') === 'game') { + this.set('mode', 'settings'); + } + }, + + nextLevel() { + if (this.get('isOn') && this.get('mode') === 'settings') { + const level = this.get('level'); + const levelIndex = this.get('levels').indexOf(level); + const nextLevel = this.get('levels').objectAt( + (levelIndex + 1) % this.get('levels').length + ); + this.set('level', nextLevel); + } } } }); diff --git a/app/routes/application.js b/app/routes/application.js index c3f8c06..524fee7 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -1,33 +1,7 @@ import Ember from 'ember'; export default Ember.Route.extend({ - levels: [1,2,3,4], - setupController(controller) { controller.set('isOn', false); - }, - - actions: { - turnOn() { - const c = this.controllerFor('application'); - c.set('isOn', true); - c.set('level', this.get('levels').objectAt(0)); - c.set('operator', '+'); - }, - turnOff() { - const c = this.controllerFor('application'); - c.set('isOn', false); - }, - nextLevel() { - const c = this.controllerFor('application'); - if (c.get('isOn')) { - const level = c.get('level'); - const levelIndex = this.get('levels').indexOf(level); - const nextLevel = this.get('levels').objectAt( - (levelIndex + 1) % this.get('levels').length - ); - c.set('level', nextLevel); - } - } } }); diff --git a/app/templates/application.hbs b/app/templates/application.hbs index b985e64..60b60b6 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -1,8 +1,12 @@
{{#if isOn}} - {{format-operator operator}} - L - {{level}} + {{#if (eq mode 'settings')}} + {{format-operator operator}} + L + {{level}} + {{else if (eq mode 'game')}} + GAME + {{/if}} {{else}}   {{/if}} @@ -20,6 +24,14 @@ LEVEL + + + + {{change-operator-button operator='+' onClick=(action 'changeOperator')}} {{change-operator-button operator='-' onClick=(action 'changeOperator')}} diff --git a/package.json b/package.json index 7c57f7b..4bc2664 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "ember-cli-uglify": "^1.2.0", "ember-data": "2.2.1", "ember-disable-proxy-controllers": "^1.0.1", - "ember-export-application-global": "^1.0.4" + "ember-export-application-global": "^1.0.4", + "ember-truth-helpers": "1.2.0" } }