Skip to content

Commit

Permalink
add SET and GO buttons and move actions to application controller
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyknown committed Dec 18, 2015
1 parent fd95301 commit dd6ecee
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
40 changes: 39 additions & 1 deletion app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
});
26 changes: 0 additions & 26 deletions app/routes/application.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
});
18 changes: 15 additions & 3 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<div id="display">
{{#if isOn}}
{{format-operator operator}}
L
{{level}}
{{#if (eq mode 'settings')}}
{{format-operator operator}}
L
{{level}}
{{else if (eq mode 'game')}}
GAME
{{/if}}
{{else}}
&nbsp;
{{/if}}
Expand All @@ -20,6 +24,14 @@
LEVEL
</button>

<button {{action 'playGame'}}>
GO
</button>

<button {{action 'changeSettings'}}>
SET
</button>

{{change-operator-button operator='+' onClick=(action 'changeOperator')}}

{{change-operator-button operator='-' onClick=(action 'changeOperator')}}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit dd6ecee

Please sign in to comment.