Skip to content

Commit

Permalink
Orientation Info (#6)
Browse files Browse the repository at this point in the history
* Add orientation info

* amend some text
  • Loading branch information
shaunanoordin authored Jan 31, 2022
1 parent d809892 commit 10212f3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 44 deletions.
29 changes: 29 additions & 0 deletions app/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/main.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/main.js

Large diffs are not rendered by default.

47 changes: 5 additions & 42 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,7 @@ <h1>Chinese New Year 2022 - Year of the Tiger</h1>
<div id="banner">
<img id="card" src="assets/cny2022.png">
</div>
<ul id="levels-list">
<li>
<button>Level 1</button>
<span>Score: 0</span>
</li>
<li>
<button>Level 2</button>
<span>New level</span>
</li>
<li>
<button>Level 3</button>
<span>New level</span>
</li>
<li>
<button>Level 4</button>
<span>New level</span>
</li>
<li>
<button>Level 5</button>
<span>New level</span>
</li>
<li>
<button>Level 6</button>
<span>New level</span>
</li>
<li>
<button>Level 7</button>
<span>New level</span>
</li>
<li>
<button>Level 8</button>
<span>New level</span>
</li>
<li>
<button>Level 9</button>
<span>New level</span>
</li>
<li>
<button>Level 10</button>
<span>New level</span>
</li>
</ul>
<ul id="levels-list"></ul>
</div>
</div>
<button id="button-home" class="ui-button"><img src="./assets/icon-menu-white.svg" alt="Home Menu"></button>
Expand All @@ -88,6 +47,10 @@ <h1>Chinese New Year 2022 - Year of the Tiger</h1>
<footer>
<div><a href="https://shaunanoordin.com" target="_blank">shaunanoordin.com</a> / 2022 / <a href="https://github.com/shaunanoordin/cny2022/" target="_blank">source code on Github</a></div>
</footer>
<div id="orientation-info">
<span>This game is best played in <b>landscape view</b> and in <b>full screen mode</b></span>
<button id="orientation-close">Close</button>
</div>
</div><!--/#app-->
</body>
</html>
15 changes: 15 additions & 0 deletions src/avo/avo.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class AvO {
buttonHome: document.getElementById('button-home'),
buttonFullscreen: document.getElementById('button-fullscreen'),
buttonReload: document.getElementById('button-reload'),
orientationInfo: document.getElementById('orientation-info'),
orientationClose: document.getElementById('orientation-close'),
}

this.homeMenu = false
Expand Down Expand Up @@ -399,6 +401,7 @@ export default class AvO {
this.html.buttonHome.addEventListener('click', this.buttonHome_onClick.bind(this))
this.html.buttonFullscreen.addEventListener('click', this.buttonFullscreen_onClick.bind(this))
this.html.buttonReload.addEventListener('click', this.buttonReload_onClick.bind(this))
this.html.orientationClose.addEventListener('click', this.orientationClose_onClick.bind(this))

this.html.main.addEventListener('keydown', this.onKeyDown.bind(this))
this.html.main.addEventListener('keyup', this.onKeyUp.bind(this))
Expand Down Expand Up @@ -434,6 +437,14 @@ export default class AvO {
this.html.interactionMenu.style.height = `${canvasBounds.height}px`
this.html.interactionMenu.style.top = `${canvasBounds.top - mainDivBounds.top}px`
this.html.interactionMenu.style.left = `${canvasBounds.left}px`

// Show or hide the orientation info
const width = mainDivBounds?.width || 1
const height = mainDivBounds?.height || 1
const screenRatio = width / height
this.html.orientationInfo.className = (screenRatio < 1)
? 'portrait'
: ''
}

setHomeMenu (homeMenu) {
Expand Down Expand Up @@ -579,6 +590,10 @@ export default class AvO {
this.levels.reload()
}

orientationClose_onClick () {
this.html.orientationInfo.style.visibility = 'hidden'
}

/*
Section: Gameplay
----------------------------------------------------------------------------
Expand Down
33 changes: 33 additions & 0 deletions src/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,39 @@ table {
}
}

#app > #orientation-info {
position: fixed;
bottom: 2em;
left: 5%;
width: 90%;
padding: 1em;
background: $light;
color: $dark;
border: 2px solid $dark;
display: none;

&.portrait {
display: block;
}

> button {
cursor: pointer;
color: #fff;
background: #c44;
border: 2px solid #ccc;
border-radius: 1rem;
box-shadow: 0.1rem 0.1rem 0 rgba(0, 0, 0, 0.5);

&:hover {
border: 2px solid #fff;
}

&:active {
border: 2px solid #888;
}
}
}

#app > main {
background: $dark url("../assets/simple-bg.png");
display: flex;
Expand Down

0 comments on commit 10212f3

Please sign in to comment.