Skip to content

Commit

Permalink
Merge branch 'main' into 0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
jgss-gabriel-sousa authored Apr 11, 2024
2 parents 5e71345 + b2c7454 commit 8e22cca
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 38 deletions.
4 changes: 2 additions & 2 deletions data/gameData.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const game = {
villageName: "",
gameTick: 0,
gameStarted: false,
gamePaused: true,
isStarted: false,
isPaused: true,
gameOver: false,
gameSurrender: false,
destroyBuildingCheck: false,
Expand Down
Binary file removed img/delete.webp
Binary file not shown.
Binary file added img/destroy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/destroy1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions scripts/buildings.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function generalUpdate(){
}

export function buildBuilding(id){
if(!game.gameStarted) return;
if(game.gamePaused){
if(!game.isStarted) return;
if(game.isPaused){
pauseError();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function gameBootstrap(){
}gameBootstrap();


export function gameStartItems(){
export function initGameItems(){
if(game.gameDifficulty == "easy"){
game.lumbermill = 1;
game.cropField = 2;
Expand Down Expand Up @@ -123,6 +123,6 @@ export function newTurn(){

gameTick();

if(!game.gameOver && !game.gamePaused)
if(!game.gameOver && !game.isPaused)
game.gameTick = window.setTimeout(newTurn, game.gameSpeed);
}
4 changes: 2 additions & 2 deletions scripts/gameTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function setGameSpeed(speed){
}

clearTimeout(game.gameTick);
game.gamePaused = false;
game.isPaused = false;
game.gameTick = setTimeout(newTurn, game.gameSpeed);
speedBtnsClassReset();
document.getElementById(speed).classList.add("btn-active");
Expand All @@ -25,7 +25,7 @@ export function setGameSpeed(speed){
export function pauseGame(){
clearTimeout(game.gameTick);
speedBtnsClassReset();
game.gamePaused = true;
game.isPaused = true;
document.getElementById("pause").classList.add("btn-active");
}

Expand Down
57 changes: 37 additions & 20 deletions scripts/handleInput.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { checkGameOver, gameStartItems } from "./game.js";
import { checkGameOver, initGameItems } from "./game.js";
import { game } from "../data/gameData.js";
import { deleteGame, loadGame, saveGame } from "./load-save.js";
import { setGameSpeed, pauseGame } from "./gameTime.js";

import { popBootstrap } from "./ui/popUI.js";
import { initPopulation } from "./ui/popUI.js";
import { updateDataInfo } from "./ui/ui.js";
import { selectGameDifficultyUI, gameOptionsUI } from "./ui/options.js";
import { buildingsBootstrap, updateMapItemsScale } from "./ui/buildingsUI.js";
Expand All @@ -12,7 +12,6 @@ import { jobs } from "./jobs.js";
import { buildBuilding, destroyBuilding } from "./buildings.js";

import { buildingsData } from "../data/buildingsData.js";
import { populationStart } from "./population.js";

//Cancel reload of the page
window.addEventListener("beforeunload", function (event) {
Expand Down Expand Up @@ -117,29 +116,47 @@ for(let i = 0; i < document.querySelectorAll(".professions-slider").length; i++)
});
}

async function startSequence(type){
if(type == "new-game")
async function startSequence(type) {
if(type == "new-game"){
await selectGameDifficultyUI();
}

gameStartItems();
buildingsBootstrap();
initGameItems();
initBuildings();
initPopulation();
updateDataInfo();
popBootstrap();
populationStart();
updateMapItemsScale();

game.gameStarted = true;
game.gamePaused = true;
game.isStarted = true;
game.isPaused = true;

hideElement("start-game");
removeElement("game-version");
showElement("pause", "btn-active");
showElement("buildings-menu", "flex");
showElement("1x");
showElement("5x");
showElement("10x");
showElement("left-section", "flex");
showElement("info-section", "flex");
showElement("map", "flex");
}

function hideElement(id) {
document.getElementById(id).classList.add("hidden");
}

function removeElement(id) {
const element = document.getElementById(id);
if (element) {
element.parentNode.removeChild(element);
}
}

document.getElementById("start-game").classList.add("hidden");
document.getElementById("game-version").remove();
document.getElementById("pause").classList.add("btn-active");
document.getElementById("buildings-menu").classList.remove("hidden");
document.getElementById("pause").classList.remove("hidden");
document.getElementById("1x").classList.remove("hidden");
document.getElementById("5x").classList.remove("hidden");
document.getElementById("10x").classList.remove("hidden");
document.getElementById("left-section").style.display = "flex";
document.getElementById("info-section").style.display = "flex";
document.getElementById("map").style.display = "flex";
function showElement(id, display = "block") {
const element = document.getElementById(id);
element.classList.remove("hidden");
element.style.display = display;
}
6 changes: 2 additions & 4 deletions scripts/population.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { popDeathsUI } from "./ui/ui.js";

let difficulty;

export function populationStart(){
export function populationUpdate(){
if(game.gameDifficulty == "hard") difficulty = 1;
if(game.gameDifficulty == "normal") difficulty = 0.75;
if(game.gameDifficulty == "easy") difficulty = 0.5;
}

export function populationUpdate(){

popsUpdate(difficulty);
popGrowth();
popDeaths();
Expand Down
3 changes: 1 addition & 2 deletions scripts/sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const NUMBER_OF_SONGS = 7;

export function soundStart(){
if(!localStorage.getItem("mv-volume"))
localStorage.setItem("mv-volume", "0.5");
localStorage.setItem("mv-volume", "0.2");
}

export function soundtrack(){
Expand All @@ -24,7 +24,6 @@ export function soundtrack(){
});

audio.addEventListener('ended', setTimeout(soundtrack, rand(500,4000)));

}, 1000);
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/ui/buildingsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function buildingHTML(id){
if(building.spritePlace == "manufactories") manufactories.innerHTML += buildingHTML;
}

export function buildingsBootstrap(){
export function initBuildings(){
for(const b in buildingsData){
const count = document.querySelectorAll("map-"+b).length;

Expand Down Expand Up @@ -218,6 +218,7 @@ export function buildinglisteners(){

document.getElementById("rmv-building").addEventListener("click", () => {
if(game.destroyBuildingCheck){
//document.querySelector("*").style.cursor = `not-allowed`;
game.destroyBuildingCheck = false;
document.getElementById("rmv-building").classList.remove("rmv-active");
}else{
Expand Down
6 changes: 3 additions & 3 deletions scripts/ui/popUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { game } from "../../data/gameData.js";

export function popUpdate(){
return;
if(game.gamePaused) return;
if(!game.gameStarted) return;
if(game.isPaused) return;
if(!game.isStarted) return;

const popCount = document.querySelectorAll(".pop").length;

Expand All @@ -22,7 +22,7 @@ export function popUpdate(){
}
}

export function popBootstrap(){
export function initPopulation(){
for(let i = 0; i < game.population; i++){
addPop(true);
}
Expand Down

0 comments on commit 8e22cca

Please sign in to comment.