Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Unified Diff: components/neterror/resources/offline.js

Issue 2955153002: Add arcade mode to chrome://dino (Closed)
Patch Set: Fix incorrect scaling on wide screens and overflow Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/neterror/resources/offline.js
diff --git a/components/neterror/resources/offline.js b/components/neterror/resources/offline.js
index ed3582f278dc2c95983dc03cb8070ae23cba0f60..b4edc9cba0d10eb6396dfd2ee0d0c0e756be56df 100644
--- a/components/neterror/resources/offline.js
+++ b/components/neterror/resources/offline.js
@@ -96,6 +96,9 @@ var IS_MOBILE = /Android/.test(window.navigator.userAgent) || IS_IOS;
/** @const */
var IS_TOUCH_ENABLED = 'ontouchstart' in window;
+/** @const */
+var ARCADE_MODE_URL = 'chrome://dino/';
+
/**
* Default game configuration.
* @enum {number}
@@ -121,7 +124,9 @@ Runner.config = {
MOBILE_SPEED_COEFFICIENT: 1.2,
RESOURCE_TEMPLATE_ID: 'audio-resources',
SPEED: 6,
- SPEED_DROP_COEFFICIENT: 3
+ SPEED_DROP_COEFFICIENT: 3,
+ TOP_MARGIN: 35,
+ TOP_POSITION_WEIGHT: 10
mmenke 2017/07/05 18:51:29 Should document these, and name them so it's clear
edwardjung 2017/07/06 19:33:19 Done.
};
@@ -140,6 +145,7 @@ Runner.defaultDimensions = {
* @enum {string}
*/
Runner.classes = {
+ ARCADE_MODE: 'arcade-mode',
CANVAS: 'runner-canvas',
CONTAINER: 'runner-container',
CRASHED: 'crashed',
@@ -225,7 +231,6 @@ Runner.events = {
LOAD: 'load'
};
-
Runner.prototype = {
/**
* Whether the easter egg has been disabled. CrOS enterprise enrolled devices.
@@ -418,6 +423,12 @@ Runner.prototype = {
boxStyles.paddingLeft.length - 2));
this.dimensions.WIDTH = this.outerContainerEl.offsetWidth - padding * 2;
+ if (this.isArcadeMode()) {
+ this.dimensions.WIDTH = Math.min(DEFAULT_WIDTH, this.dimensions.WIDTH);
+ if (this.activated) {
+ this.setContainerScale();
+ }
+ }
// Redraw the elements back onto the canvas.
if (this.canvas) {
@@ -486,6 +497,7 @@ Runner.prototype = {
* Update the game status to started.
*/
startGame: function() {
+ this.setArcadeMode();
this.runningTime = 0;
this.playingIntro = false;
this.tRex.playingIntro = false;
@@ -825,6 +837,38 @@ Runner.prototype = {
}
},
+ /**
+ * Whether the game should go into arcade mode.
+ * @return {boolean}
+ */
+ isArcadeMode: function() {
+ return document.title == ARCADE_MODE_URL;
+ },
+
+ /**
+ * Hides offline messaging for a fullscreen game only experience.
+ */
+ setArcadeMode: function() {
+ if (this.isArcadeMode()) {
mmenke 2017/07/05 18:51:29 I'd suggest moving this to the callsite, to make i
edwardjung 2017/07/06 19:33:20 Done.
+ document.body.classList.add(Runner.classes.ARCADE_MODE);
+ this.setContainerScale();
+ }
+ },
+
+ /**
+ * Sets the scaling for arcade mode.
+ */
+ setContainerScale: function() {
mmenke 2017/07/05 18:51:29 setContainerScaleForArcadeMode?
edwardjung 2017/07/06 19:33:19 Changed to: setArcadeModeContainerScale
+ var windowHeight = window.innerHeight;
+ var scaleHeight = windowHeight / this.dimensions.HEIGHT;
+ var scaleWidth = window.innerWidth / this.dimensions.WIDTH;
+ var scale = Math.max(1, Math.min(scaleHeight, scaleWidth));
mmenke 2017/07/05 18:51:29 So does this mean you can see farther if you make
edwardjung 2017/07/06 19:33:19 No, this just scales up the game container in the
+ var position = Math.max(-Runner.config.TOP_MARGIN, (windowHeight -
+ (this.dimensions.HEIGHT * scale)) / Runner.config.TOP_POSITION_WEIGHT);
mmenke 2017/07/05 18:51:29 So I guess this is figuring out how much extra hei
edwardjung 2017/07/06 19:33:20 Did you mean" Math.max(-Runner.config.TOP_MARGI
mmenke 2017/07/07 16:28:10 No, I did not - dividing by percents generally mea
edwardjung 2017/07/10 15:17:11 Aaah, got it. Switched to to 0.1.
+ this.containerEl.style.transform = 'scale(' + scale + ') translateY(' +
+ position + 'px)';
+ },
+
/**
* Pause the game if the tab is not in focus.
*/
« components/neterror/resources/neterror.css ('K') | « components/neterror/resources/neterror.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698