Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonAlling committed Jun 3, 2016
2 parents 16dbce7 + 9d17f87 commit c131576
Show file tree
Hide file tree
Showing 15 changed files with 435 additions and 41 deletions.
7 changes: 7 additions & 0 deletions ZATACKA.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,20 @@
<span id="debug_blue"></span>
</div>

<script src="js/strings.js"></script>
<script src="js/lib/Queue.js"></script>
<script src="js/lib/mainloop.min.js"></script>
<script src="js/lib/Utilities.js"></script>
<script src="js/lib/Message.js"></script>
<script src="js/lib/InfoMessage.js"></script>
<script src="js/lib/WarningMessage.js"></script>
<script src="js/locales/Zatacka.en_US.properties"></script>
<script src="js/lib/preferences/Preference.js"></script>
<script src="js/lib/preferences/MultichoicePreference.js"></script>
<script src="js/lib/preferences/BooleanPreference.js"></script>
<script src="js/lib/preferences/RangePreference.js"></script>
<script src="js/lib/preferences/IntegerRangePreference.js"></script>
<script src="js/lib/preferences/PreferenceManager.js"></script>
<script src="js/Player.js"></script>
<script src="js/Round.js"></script>
<script src="js/Renderer.js"></script>
Expand Down
23 changes: 14 additions & 9 deletions Zatacka.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ input[type="checkbox"]:checked + label::before {
background-repeat: no-repeat;
}

.nocursor {
cursor: none;
}

#debug {
background-color: black;
border: 1px white solid;
Expand Down Expand Up @@ -139,7 +143,7 @@ input[type="checkbox"]:checked + label::before {

#lobby #controls {
list-style-type: none;
margin-left: 81px;
margin-left: 80px;
margin-top: 50px;
}

Expand All @@ -154,7 +158,7 @@ input[type="checkbox"]:checked + label::before {

#lobby #controls .controls {
background-image: url("resources/kurve-lobby-controls-ready.png");
width: 159px;
width: 160px;
}

#lobby #controls .ready {
Expand All @@ -168,17 +172,17 @@ input[type="checkbox"]:checked + label::before {
}

#lobby #controls .red.controls { background-position: 0px 0px; }
#lobby #controls .red.ready { background-position: -159px 0px; }
#lobby #controls .red.ready { background-position: -160px 0px; }
#lobby #controls .yellow.controls { background-position: 0px -50px; }
#lobby #controls .yellow.ready { background-position: -159px -50px; }
#lobby #controls .yellow.ready { background-position: -160px -50px; }
#lobby #controls .orange.controls { background-position: 0px -100px; }
#lobby #controls .orange.ready { background-position: -159px -100px; }
#lobby #controls .orange.ready { background-position: -160px -100px; }
#lobby #controls .green.controls { background-position: 0px -150px; }
#lobby #controls .green.ready { background-position: -159px -150px; }
#lobby #controls .green.ready { background-position: -160px -150px; }
#lobby #controls .pink.controls { background-position: 0px -200px; }
#lobby #controls .pink.ready { background-position: -159px -200px; }
#lobby #controls .pink.ready { background-position: -160px -200px; }
#lobby #controls .blue.controls { background-position: 0px -250px; }
#lobby #controls .blue.ready { background-position: -159px -250px; }
#lobby #controls .blue.ready { background-position: -160px -250px; }

#lobby footer {
padding: 0 80px;
Expand All @@ -191,7 +195,8 @@ input[type="checkbox"]:checked + label::before {
.message {
font-size: 8px;
padding: 2px 80px;
background-color: rgba(0, 0, 0, 0.5);
text-align: center;
text-shadow: 0 0 2px black, 0 0 2px black, 0 0 4px black, 0 0 4px black, 0 0 4px black, 0 0 4px black, 0 0 8px black, 0 0 8px black, 0 0 8px black, 0 0 8px black;
}

.info.message {
Expand Down
72 changes: 66 additions & 6 deletions js/GUIController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

function GUIController(cfg) {

const CLASS_ACTIVE = "active";
const CLASS_HIDDEN = "hidden";
const CURSOR_VISIBLE = "visible";
const CURSOR_HIDDEN_ON_CANVAS = "hidden_on_canvas";
const CURSOR_HIDDEN = "hidden";

const config = cfg;
const lobby = byID("lobby");
Expand All @@ -25,7 +26,12 @@ function GUIController(cfg) {

function hideLobby() {
log("Hiding lobby.");
lobby.classList.add(CLASS_HIDDEN);
lobby.classList.add(STRINGS.class_hidden);
}

function showLobby() {
log("Showing lobby.");
lobby.classList.remove(STRINGS.class_hidden);
}

function isLobbyEntry(element) {
Expand All @@ -40,6 +46,31 @@ function GUIController(cfg) {
Array.from(scoreboard.children).forEach(resetScoreboardEntry);
}

function resetResults() {
Array.from(results.children).forEach(resetScoreboardEntry);
}

function setCursorBehavior(behavior) {
switch (behavior) {
case CURSOR_VISIBLE:
document.body.classList.remove(STRINGS.class_nocursor);
break;
case CURSOR_HIDDEN_ON_CANVAS:
canvas_main.classList.add(STRINGS.class_nocursor);
canvas_overlay.classList.add(STRINGS.class_nocursor);
break;
case CURSOR_HIDDEN:
document.body.classList.add(STRINGS.class_nocursor);
break;
default:
logError(`Cannot set cursor behavior to '${behavior}'.`);
}
}

function resetCursorBehavior() {
setCursorBehavior(CURSOR_VISIBLE);
}


// PUBLIC API

Expand All @@ -53,7 +84,7 @@ function GUIController(cfg) {
if (!isLobbyEntry(entry)) {
logWarning(`Cannot mark player ${id} as ready because controls.children[${index}] (${controls.children[index]}) is not a valid lobby entry.`);
} else {
entry.children[1].classList.add(CLASS_ACTIVE);
entry.children[1].classList.add(STRINGS.class_active);
}
}

Expand All @@ -63,19 +94,43 @@ function GUIController(cfg) {
if (!isLobbyEntry(entry)) {
logWarning(`Cannot mark player ${id} as unready because controls.children[${index}] (${controls.children[index]}) is not a valid lobby entry.`);
} else {
entry.children[1].classList.remove(CLASS_ACTIVE);
entry.children[1].classList.remove(STRINGS.class_active);
}
}

function allPlayersUnready() {
for (let id = 1; id <= controls.children.length; id++) {
playerUnready(id);
}
}

function gameStarted() {
hideLobby();
}

function gameQuit() {
hideKonecHry();
showLobby();
clearMessages();
resetScoreboard();
resetResults();
allPlayersUnready();
resetCursorBehavior();
}

function konecHry() {
KONEC_HRY.classList.remove("hidden");
showKonecHry();
resetScoreboard();
}

function showKonecHry() {
KONEC_HRY.classList.remove(STRINGS.class_hidden);
}

function hideKonecHry() {
KONEC_HRY.classList.add(STRINGS.class_hidden);
}

function showMessage(message) {
if (!currentMessages.includes(message)) {
currentMessages.push(message);
Expand Down Expand Up @@ -135,15 +190,20 @@ function GUIController(cfg) {
}

return {
CURSOR_VISIBLE,
CURSOR_HIDDEN_ON_CANVAS,
CURSOR_HIDDEN,
playerReady,
playerUnready,
gameStarted,
gameQuit,
konecHry,
updateScoreOfPlayer,
updateMessages,
showMessage,
hideMessage,
clearMessages,
setCursorBehavior,
setEdgePadding
};

Expand Down
25 changes: 12 additions & 13 deletions js/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,6 @@ class Game {
this.beginNewRound();
}

/** Quits the game. */
quit() {
document.location.reload();
}

/** Announce KONEC HRY, show results etc. */
konecHry() {
log(this.constructor.KONEC_HRY);
Expand All @@ -356,6 +351,11 @@ class Game {
this.quitHintTimer = setTimeout(this.showQuitHint.bind(this), this.config.hintDelay);
}

quit() {
clearTimeout(this.quitHintTimer);
clearTimeout(this.proceedHintTimer);
}

clearField() {
this.pixels.fill(0);
this.Render_clearField();
Expand Down Expand Up @@ -562,10 +562,7 @@ class Game {
proceedKeyPressed() {
this.hideProceedHint();
this.hideQuitHint();
if (this.isEnded()) {
// The game is ended, so a proceed key press should quit:
this.quit();
} else if (this.isGameOver()) {
if (this.isGameOver()) {
// The game is over, so we should show KONEC HRY:
this.konecHry();
} else if (this.isPostRound()) {
Expand All @@ -574,10 +571,12 @@ class Game {
}
}

quitKeyPressed() {
if (this.isPostRound() && !this.isGameOver()) {
this.quit();
}
shouldQuitOnQuitKey() {
return this.isPostRound() && !this.isGameOver();
}

shouldQuitOnProceedKey() {
return this.isEnded();
}


Expand Down
4 changes: 4 additions & 0 deletions js/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class Player {
|| this.R_keys.includes(button));
}

usesAnyMouseButton() {
return MOUSE_BUTTONS.some((button) => this.hasMouseButton(button));
}

hasKey(key) {
return this.L_keys.includes(key)
|| this.R_keys.includes(key);
Expand Down
Loading

0 comments on commit c131576

Please sign in to comment.