From 48a6c5774151003f3c40d637bcf07ac6b9e9911e Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Thu, 8 Jul 2021 00:09:08 +0300 Subject: [PATCH] setOrientation() --- js/engine.js | 16 ++++++++++++++++ js/index.js | 8 ++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/js/engine.js b/js/engine.js index 600f29c..f81653f 100644 --- a/js/engine.js +++ b/js/engine.js @@ -1,3 +1,5 @@ +import config from '../app/config.json'; + export function imagePreloader(images, callback) { let counter = 0; @@ -19,3 +21,17 @@ export function shuffle(array) { [array[i], array[j]] = [array[j], array[i]]; } } + +export function setOrientation(canvas) { + let landscape_orientation = null; + + if (canvas.width >= canvas.height) landscape_orientation = true; + else landscape_orientation = false; + + if (config.debug) + console.log(landscape_orientation ? + 'Canvas orientation set to landscape' : + 'Canvas orientation set to portrait'); + + return landscape_orientation; +} diff --git a/js/index.js b/js/index.js index 5346b77..db173f9 100644 --- a/js/index.js +++ b/js/index.js @@ -37,11 +37,8 @@ window.onload = function() { console.log(`Canvas size ${cW} x ${cH}`); // set screen orientation by carculate canvas width & height - if (cW >= cH) { landscape_orientation = true; } - else { landscape_orientation = false; } - if (DEBUG) - console.log(landscape_orientation ? "Canvas orientation set to landscape" : "Canvas orientation set to portrait"); - + landscape_orientation = Engine.setOrientation(canvas) + let imageLogo = new Image(); imageLogo.src = "assets/logo.png"; images.logo = imageLogo; @@ -75,7 +72,6 @@ window.onload = function() { Engine.shuffle(quest.answer); }); - // set all quest status 'not answered' gameData.questions.forEach(element => element.status = null);