OLD | NEW |
---|---|
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 (function() { | 4 (function() { |
5 'use strict'; | 5 'use strict'; |
6 /** | 6 /** |
7 * T-Rex runner. | 7 * T-Rex runner. |
8 * @param {string} outerContainerId Outer containing element id. | 8 * @param {string} outerContainerId Outer containing element id. |
9 * @param {object} opt_config | 9 * @param {object} opt_config |
10 * @constructor | 10 * @constructor |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 // Sound FX. | 54 // Sound FX. |
55 this.audioBuffer = null; | 55 this.audioBuffer = null; |
56 this.soundFx = {}; | 56 this.soundFx = {}; |
57 | 57 |
58 // Global web audio context for playing sounds. | 58 // Global web audio context for playing sounds. |
59 this.audioContext = null; | 59 this.audioContext = null; |
60 | 60 |
61 // Images. | 61 // Images. |
62 this.images = {}; | 62 this.images = {}; |
63 this.imagesLoaded = 0; | 63 this.imagesLoaded = 0; |
64 this.loadImages(); | 64 |
65 if (this.isDisabled()) { | |
66 this.setupDisabledRunner(); | |
67 console.log(this.isDisabled()); | |
arv (Not doing code reviews)
2015/03/25 09:36:03
remove debug log?
edwardjung
2015/03/25 11:05:50
Done.
| |
68 } else { | |
69 this.loadImages(); | |
70 } | |
65 } | 71 } |
66 window['Runner'] = Runner; | 72 window['Runner'] = Runner; |
67 | 73 |
68 | 74 |
69 /** | 75 /** |
70 * Default game width. | 76 * Default game width. |
71 * @const | 77 * @const |
72 */ | 78 */ |
73 var DEFAULT_WIDTH = 600; | 79 var DEFAULT_WIDTH = 600; |
74 | 80 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 | 134 |
129 /** | 135 /** |
130 * CSS class names. | 136 * CSS class names. |
131 * @enum {string} | 137 * @enum {string} |
132 */ | 138 */ |
133 Runner.classes = { | 139 Runner.classes = { |
134 CANVAS: 'runner-canvas', | 140 CANVAS: 'runner-canvas', |
135 CONTAINER: 'runner-container', | 141 CONTAINER: 'runner-container', |
136 CRASHED: 'crashed', | 142 CRASHED: 'crashed', |
137 ICON: 'icon-offline', | 143 ICON: 'icon-offline', |
144 SNACKBAR: 'snackbar', | |
145 SNACKBAR_SHOW: 'snackbar-show', | |
138 TOUCH_CONTROLLER: 'controller' | 146 TOUCH_CONTROLLER: 'controller' |
139 }; | 147 }; |
140 | 148 |
141 | 149 |
142 /** | 150 /** |
143 * Image source urls. | 151 * Image source urls. |
144 * @enum {array<object>} | 152 * @enum {array<object>} |
145 */ | 153 */ |
146 Runner.imageSources = { | 154 Runner.imageSources = { |
147 LDPI: [ | 155 LDPI: [ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 TOUCHSTART: 'touchstart', | 211 TOUCHSTART: 'touchstart', |
204 VISIBILITY: 'visibilitychange', | 212 VISIBILITY: 'visibilitychange', |
205 BLUR: 'blur', | 213 BLUR: 'blur', |
206 FOCUS: 'focus', | 214 FOCUS: 'focus', |
207 LOAD: 'load' | 215 LOAD: 'load' |
208 }; | 216 }; |
209 | 217 |
210 | 218 |
211 Runner.prototype = { | 219 Runner.prototype = { |
212 /** | 220 /** |
221 * Whether the easter egg has been disabled. CrOS enterprise enrolled devices. | |
222 * @return {boolean} | |
223 */ | |
224 isDisabled: function() { | |
225 return loadTimeData && loadTimeData.valueExists('disabledEasterEgg'); | |
226 }, | |
227 | |
228 /** | |
229 * For disabled instances, set up a snackbar with the disabled message. | |
230 */ | |
231 setupDisabledRunner: function() { | |
232 this.containerEl = document.createElement('div'); | |
233 this.containerEl.className = Runner.classes.SNACKBAR; | |
234 this.containerEl.textContent = loadTimeData.getValue('disabledEasterEgg'); | |
235 this.outerContainerEl.appendChild(this.containerEl); | |
236 | |
237 // Show notification when the activation key is pressed. | |
238 document.addEventListener(Runner.events.KEYDOWN, function(e) { | |
239 if (Runner.keycodes.JUMP[e.keyCode]) { | |
arv (Not doing code reviews)
2015/03/25 09:36:03
wrong indentation
edwardjung
2015/03/25 11:05:50
Done.
| |
240 this.containerEl.classList.add(Runner.classes.SNACKBAR_SHOW); | |
241 document.querySelector('.icon').classList.add('icon-disabled'); | |
242 } | |
243 }.bind(this)); | |
244 }, | |
245 | |
246 /** | |
213 * Setting individual settings for debugging. | 247 * Setting individual settings for debugging. |
214 * @param {string} setting | 248 * @param {string} setting |
215 * @param {*} value | 249 * @param {*} value |
216 */ | 250 */ |
217 updateConfigSetting: function(setting, value) { | 251 updateConfigSetting: function(setting, value) { |
218 if (setting in this.config && value != undefined) { | 252 if (setting in this.config && value != undefined) { |
219 this.config[setting] = value; | 253 this.config[setting] = value; |
220 | 254 |
221 switch (setting) { | 255 switch (setting) { |
222 case 'GRAVITY': | 256 case 'GRAVITY': |
(...skipping 2026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2249 | 2283 |
2250 /** | 2284 /** |
2251 * Add a new cloud to the horizon. | 2285 * Add a new cloud to the horizon. |
2252 */ | 2286 */ |
2253 addCloud: function() { | 2287 addCloud: function() { |
2254 this.clouds.push(new Cloud(this.canvas, this.cloudImg, | 2288 this.clouds.push(new Cloud(this.canvas, this.cloudImg, |
2255 this.dimensions.WIDTH)); | 2289 this.dimensions.WIDTH)); |
2256 } | 2290 } |
2257 }; | 2291 }; |
2258 })(); | 2292 })(); |
OLD | NEW |