Просмотр исходного кода

Merge pull request #1 from jsb5468/master

New Save/Load Options
tags/v0.2.9
Fen Dweller GitHub 6 лет назад
Родитель
Сommit
d36a6dcc73
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
4 измененных файлов: 83 добавлений и 7 удалений
  1. +12
    -0
      feast.css
  2. +13
    -3
      feast.html
  3. +58
    -0
      feast.js
  4. +0
    -4
      objects.js

+ 12
- 0
feast.css Просмотреть файл

@@ -65,6 +65,12 @@ button {
font-size: 18px; font-size: 18px;
user-select: none; user-select: none;
} }
.option-button {
width: 100px;
height: 50px;
font-size: 18px;
user-select: none;
}


#compass { #compass {
padding: 10px; padding: 10px;
@@ -149,6 +155,12 @@ button {
flex: 1; flex: 1;
} }


.options {
flex-wrap: wrap;
max-width: 100px;
height:50%;
}

#player-stats { #player-stats {
height: 75%; height: 75%;
} }


+ 13
- 3
feast.html Просмотреть файл

@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en"> <html lang="en">


<head> <head>
@@ -47,10 +47,17 @@
<div class="stat-line" id="stat-breasts">Fractal Prospectus: 99/100</div> <div class="stat-line" id="stat-breasts">Fractal Prospectus: 99/100</div>
<button class="stat-button" id="stat-button-status">Status</button> <button class="stat-button" id="stat-button-status">Status</button>
<button class="stat-button" id="log-button">Log: Enabled</button> <button class="stat-button" id="log-button">Log: Enabled</button>
</div> </div>
</div> </div>
<div id="log"> <div id="log">
</div>
<div class="options">
<div id="options">
<button class="option-button" id="save-button">Save Game</button>
<button class="option-button" id="load-button">Load Game</button>
<button class="option-button" id="inventory-button">Inventory</button>
</div>
</div> </div>
<div class="stats"> <div class="stats">
<div id="foe-stats"> <div id="foe-stats">
@@ -148,7 +155,10 @@
</p> </p>
<form id="character-form"> <form id="character-form">
<ul class="character-form-list" id="character-step-1"> <ul class="character-form-list" id="character-step-1">
<li>
<li>
<button type="button" id="character-load">Load Character</button>
</li>
<li>
<label for="character-name">Name</label> <label for="character-name">Name</label>
<input type="text" id="character-name" name="name" placeholder="Player"/> <input type="text" id="character-name" name="name" placeholder="Player"/>
</li> </li>


+ 58
- 0
feast.js Просмотреть файл

@@ -365,6 +365,7 @@ function next_step(stage) {


window.addEventListener('load', function(event) { window.addEventListener('load', function(event) {
document.getElementById("character-step-1-next").addEventListener("click", function() { next_step(2); }); document.getElementById("character-step-1-next").addEventListener("click", function() { next_step(2); });
document.getElementById("character-load").addEventListener("click", startLoaded, false);
document.getElementById("start-button").addEventListener("click", start, false); document.getElementById("start-button").addEventListener("click", start, false);
}); });


@@ -375,6 +376,8 @@ function start() {
document.getElementById("game").style.display = "block"; document.getElementById("game").style.display = "block";
document.getElementById("stat-button-status").addEventListener("click", status, false); document.getElementById("stat-button-status").addEventListener("click", status, false);
document.getElementById("log-button").addEventListener("click", toggleLog, false); document.getElementById("log-button").addEventListener("click", toggleLog, false);
document.getElementById("load-button").addEventListener("click", loadGameButton, false);
document.getElementById("save-button").addEventListener("click", saveGameButton, false);
loadCompass(); loadCompass();
loadDialog(); loadDialog();
world = createWorld(); world = createWorld();
@@ -519,6 +522,7 @@ function changeMode(newMode) {
mode = newMode; mode = newMode;
let body = document.querySelector("body"); let body = document.querySelector("body");
document.getElementById("foe-stats").style.display = "none"; document.getElementById("foe-stats").style.display = "none";
document.getElementById("options").style.display = "block";
body.className = ""; body.className = "";
switch(mode) { switch(mode) {
case "explore": case "explore":
@@ -528,9 +532,11 @@ function changeMode(newMode) {
case "combat": case "combat":
body.classList.add("combat"); body.classList.add("combat");
document.getElementById("foe-stats").style.display = "block"; document.getElementById("foe-stats").style.display = "block";
document.getElementById("options").style.display = "none";
break; break;
case "eaten": case "eaten":
body.classList.add("eaten"); body.classList.add("eaten");
document.getElementById("options").style.display = "none";
document.getElementById("foe-stats").style.display = "block"; document.getElementById("foe-stats").style.display = "block";
break; break;
} }
@@ -930,6 +936,8 @@ function saveGame() {
let stringified = JSON.stringify(save); let stringified = JSON.stringify(save);


window.localStorage.setItem("save", stringified); window.localStorage.setItem("save", stringified);
update(["Game saved."]);
updateDisplay();
} }


function loadGame() { function loadGame() {
@@ -952,8 +960,58 @@ function loadGame() {


clearScreen(); clearScreen();
moveToByName(save.position, ""); moveToByName(save.position, "");
update(["Game loaded."]);
updateDisplay();
}

function startLoaded() { //used to load the game via the main menu
start();
loadGame();
}

//these work in conjunction with buttonConfirm/buttonConfirmEnd and any functions that call them.
var confirmTimer; //this is areference to the active setTimeout, only used to allow clearTimeout to know thich timeout to clear
let confirmState = ""; //this records which function is asking for confirmation "" means nothing is asking for confirmation.
let confirmStateText = ""; //this is where the original button text is stored when the button reads "Confirm?"

function buttonConfirm(targetedButton, buttonText){ //starts a timer and requests the playter click the button again to confirm that they want to take the action
if(confirmState != ""){
buttonConfirmEnd();
}
document.getElementById([targetedButton]).innerHTML = "Confirm?"; //changes button text to "Confirm?"
confirmState = targetedButton; //copies data to global variable to make sure only one button is requesting confirmation at any given time
confirmStateText = buttonText; //copies data to global variable to make sure only one button is requesting confirmation at any given time
confirmTimer = setTimeout(buttonConfirmEnd, 5000); //5000 is 5 seconds
}

function buttonConfirmEnd(){ //this resets the button once the request for confirmation has no longer active
document.getElementById([confirmState]).innerHTML = [confirmStateText]; //resets text
confirmState = ""; //resets confirmation state
clearTimeout(confirmTimer); //keeps function from being called again if a timer is running
} }


function saveGameButton(){//activates if the "Save Game" button is pressed
let targetedButton = "save-button";
if (confirmState === targetedButton){//if the confirm timer is active for this function, actually saves game
buttonConfirmEnd();
saveGame();
}else{
buttonConfirm(targetedButton, "Save Game"); //starts confirm timer for this function
}
}

function loadGameButton(){//activates if the "Load Game" button is pressed
let targetedButton = "load-button";
if (confirmState === targetedButton){//if the confirm timer is active for this function, actually loads game
buttonConfirmEnd();
loadGame();
}else{ //starts confirm timer for this function
buttonConfirm(targetedButton, "Load Game");
}
}



// wow polyfills // wow polyfills


if (![].includes) { if (![].includes) {


+ 0
- 4
objects.js Просмотреть файл

@@ -105,16 +105,12 @@ function Bed() {
"name": "Save Game", "name": "Save Game",
"action": function() { "action": function() {
saveGame(); saveGame();
update(["Game saved."]);
updateDisplay();
} }
}); });
this.actions.push({ this.actions.push({
"name": "Load Game", "name": "Load Game",
"action": function() { "action": function() {
loadGame(); loadGame();
update(["Game loaded."]);
updateDisplay();
} }
}); });
this.actions.push({ this.actions.push({


Загрузка…
Отмена
Сохранить