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 } else { |
| 68 this.loadImages(); |
| 69 } |
65 } | 70 } |
66 window['Runner'] = Runner; | 71 window['Runner'] = Runner; |
67 | 72 |
68 | 73 |
69 /** | 74 /** |
70 * Default game width. | 75 * Default game width. |
71 * @const | 76 * @const |
72 */ | 77 */ |
73 var DEFAULT_WIDTH = 600; | 78 var DEFAULT_WIDTH = 600; |
74 | 79 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 133 |
129 /** | 134 /** |
130 * CSS class names. | 135 * CSS class names. |
131 * @enum {string} | 136 * @enum {string} |
132 */ | 137 */ |
133 Runner.classes = { | 138 Runner.classes = { |
134 CANVAS: 'runner-canvas', | 139 CANVAS: 'runner-canvas', |
135 CONTAINER: 'runner-container', | 140 CONTAINER: 'runner-container', |
136 CRASHED: 'crashed', | 141 CRASHED: 'crashed', |
137 ICON: 'icon-offline', | 142 ICON: 'icon-offline', |
| 143 SNACKBAR: 'snackbar', |
| 144 SNACKBAR_SHOW: 'snackbar-show', |
138 TOUCH_CONTROLLER: 'controller' | 145 TOUCH_CONTROLLER: 'controller' |
139 }; | 146 }; |
140 | 147 |
141 | 148 |
142 /** | 149 /** |
143 * Image source urls. | 150 * Image source urls. |
144 * @enum {array<object>} | 151 * @enum {array<object>} |
145 */ | 152 */ |
146 Runner.imageSources = { | 153 Runner.imageSources = { |
147 LDPI: [ | 154 LDPI: [ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 TOUCHSTART: 'touchstart', | 210 TOUCHSTART: 'touchstart', |
204 VISIBILITY: 'visibilitychange', | 211 VISIBILITY: 'visibilitychange', |
205 BLUR: 'blur', | 212 BLUR: 'blur', |
206 FOCUS: 'focus', | 213 FOCUS: 'focus', |
207 LOAD: 'load' | 214 LOAD: 'load' |
208 }; | 215 }; |
209 | 216 |
210 | 217 |
211 Runner.prototype = { | 218 Runner.prototype = { |
212 /** | 219 /** |
| 220 * Whether the easter egg has been disabled. CrOS enterprise enrolled devices. |
| 221 * @return {boolean} |
| 222 */ |
| 223 isDisabled: function() { |
| 224 return loadTimeData && loadTimeData.valueExists('disabledEasterEgg'); |
| 225 }, |
| 226 |
| 227 /** |
| 228 * For disabled instances, set up a snackbar with the disabled message. |
| 229 */ |
| 230 setupDisabledRunner: function() { |
| 231 this.containerEl = document.createElement('div'); |
| 232 this.containerEl.className = Runner.classes.SNACKBAR; |
| 233 this.containerEl.textContent = loadTimeData.getValue('disabledEasterEgg'); |
| 234 this.outerContainerEl.appendChild(this.containerEl); |
| 235 |
| 236 // Show notification when the activation key is pressed. |
| 237 document.addEventListener(Runner.events.KEYDOWN, function(e) { |
| 238 if (Runner.keycodes.JUMP[e.keyCode]) { |
| 239 this.containerEl.classList.add(Runner.classes.SNACKBAR_SHOW); |
| 240 document.querySelector('.icon').classList.add('icon-disabled'); |
| 241 } |
| 242 }.bind(this)); |
| 243 }, |
| 244 |
| 245 /** |
213 * Setting individual settings for debugging. | 246 * Setting individual settings for debugging. |
214 * @param {string} setting | 247 * @param {string} setting |
215 * @param {*} value | 248 * @param {*} value |
216 */ | 249 */ |
217 updateConfigSetting: function(setting, value) { | 250 updateConfigSetting: function(setting, value) { |
218 if (setting in this.config && value != undefined) { | 251 if (setting in this.config && value != undefined) { |
219 this.config[setting] = value; | 252 this.config[setting] = value; |
220 | 253 |
221 switch (setting) { | 254 switch (setting) { |
222 case 'GRAVITY': | 255 case 'GRAVITY': |
(...skipping 2026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2249 | 2282 |
2250 /** | 2283 /** |
2251 * Add a new cloud to the horizon. | 2284 * Add a new cloud to the horizon. |
2252 */ | 2285 */ |
2253 addCloud: function() { | 2286 addCloud: function() { |
2254 this.clouds.push(new Cloud(this.canvas, this.cloudImg, | 2287 this.clouds.push(new Cloud(this.canvas, this.cloudImg, |
2255 this.dimensions.WIDTH)); | 2288 this.dimensions.WIDTH)); |
2256 } | 2289 } |
2257 }; | 2290 }; |
2258 })(); | 2291 })(); |
OLD | NEW |