From 5be416da86f540c283029ce29cd7167e43c22a87 Mon Sep 17 00:00:00 2001 From: Josef Stips Date: Wed, 27 Mar 2024 18:05:19 +0100 Subject: [PATCH] bug fixes and optimizations --- src/script/public/App/GameSetUp.js | 35 ++++- .../public/App/features/Achievements.js | 2 +- src/script/public/App/script.js | 2 + src/script/public/Game/CreateGame.js | 30 +++- src/script/public/Game/Game.js | 144 ++++++++++-------- src/script/public/serverHandler.js | 16 +- 6 files changed, 155 insertions(+), 74 deletions(-) diff --git a/src/script/public/App/GameSetUp.js b/src/script/public/App/GameSetUp.js index 09df696..a0a9b6d 100644 --- a/src/script/public/App/GameSetUp.js +++ b/src/script/public/App/GameSetUp.js @@ -363,6 +363,12 @@ function UserCreateRoom(readOnlyLevel, Data1, Data2, UserName, thirdplayerRequir curr_form1 = "fontawesome"; // later it will check if it has this value and do the required things }; + // costum x and y + let costumX; + let costumY; + + let costumPatterns; + // set data: either extern data or intern data if (Data1) Check[2] = Data1; if (Data2) Check[3] = Data2; @@ -370,14 +376,37 @@ function UserCreateRoom(readOnlyLevel, Data1, Data2, UserName, thirdplayerRequir if (thirdplayerRequired) thirdPlayer_required = thirdplayerRequired; if (PointsToWinGame) UserSetPointsToWinGameInput.value = PointsToWinGame; if (patterns) allowedPatternsFromUser = patterns; - if (PlayingInCreatedLevel) Check[2] = NewCreativeLevel.Settings["playertimer"][NewCreativeLevel.selectedLevel[3]]; - // console.log(UserSetPointsToWinGameInput.value, PointsToWinGame) + if (PlayingInCreatedLevel) { + Check[2] = NewCreativeLevel.Settings["playertimer"][NewCreativeLevel.selectedLevel[3]]; + + // set up x and y coordinates. case: default field is choosen + if (NewCreativeLevel.selectedLevel[16] == {}) { + costumX = NewCreativeLevel.Settings.cellgrid[NewCreativeLevel.selectedLevel[7]]; + costumY = NewCreativeLevel.Settings.cellgrid[NewCreativeLevel.selectedLevel[7]]; + + } else { + costumX = NewCreativeLevel.selectedLevel[16]["x"]; + costumY = NewCreativeLevel.selectedLevel[16]["y"]; + }; + + if (costumX == undefined || costumY == undefined) { + costumX = xyCell_Amount; + costumY = xyCell_Amount; + }; + + costumPatterns = NewCreativeLevel.selectedLevel[15]; + + allowedPatternsFromUser = NewCreativeLevel.selectedLevel[6]; + }; + + console.log(UserSetPointsToWinGameInput.value, PointsToWinGame, costumX, costumY); // GameData: Sends PlayerClock, InnerGameMode and xyCellAmount ; PlayerData: sends player name and icon => requests room id socket.emit('create_room', [Check[2], Check[3], xyCell_Amount, Player1_NameInput.value, curr_form1, fieldIndex, fieldTitle, localStorage.getItem('userInfoClass'), - localStorage.getItem('userInfoColor'), thirdPlayer_required, UserSetPointsToWinGameInput.value, allowedPatternsFromUser + localStorage.getItem('userInfoColor'), thirdPlayer_required, UserSetPointsToWinGameInput.value, allowedPatternsFromUser, [costumX, costumY], costumPatterns ], message => { + Lobby_GameCode_display.textContent = `Game Code: ${message}`; Lobby_GameCode_display.style.userSelect = 'text'; diff --git a/src/script/public/App/features/Achievements.js b/src/script/public/App/features/Achievements.js index 621ccec..37ec2bf 100644 --- a/src/script/public/App/features/Achievements.js +++ b/src/script/public/App/features/Achievements.js @@ -391,7 +391,7 @@ class Achievements { // delete img element from list element in achievement pop up + manipulate other things newAchievementUnlockedPopUp.querySelector("li").querySelector("img").remove(); - newAchievementUnlockedPopUp.querySelector("li").querySelector(".achievement_check_icon").remove(); + newAchievementUnlockedPopUp.querySelector("li").querySelector(".achievement_check_icon") && newAchievementUnlockedPopUp.querySelector("li").querySelector(".achievement_check_icon").remove(); newAchievementUnlockedPopUp.querySelector("li").querySelector("div").style.display = "flex"; newAchievementUnlockedPopUp.querySelector("li").querySelector("div").style.flexDirection = "column"; newAchievementUnlockedPopUp.querySelector("li").querySelector("div").style.alignItems = "center"; diff --git a/src/script/public/App/script.js b/src/script/public/App/script.js index b03d9d4..ef080a2 100644 --- a/src/script/public/App/script.js +++ b/src/script/public/App/script.js @@ -1020,6 +1020,8 @@ gameMode_KI_card.addEventListener('click', () => { goToAdvancedFields.classList = "fa-solid fa-caret-down"; secondTierModes.style.marginBottom = "0"; isInAdvancedGameModes = false; + bossModeIsActive = false; + // other thing ChooseFieldDisplay.style.opacity = "0"; }; diff --git a/src/script/public/Game/CreateGame.js b/src/script/public/Game/CreateGame.js index 23ba13e..a023894 100644 --- a/src/script/public/Game/CreateGame.js +++ b/src/script/public/Game/CreateGame.js @@ -959,6 +959,8 @@ class NewLevel { }; }; + this.SaveInHistory("costumPatterns", this.CurrentSelectedSetting.costumPatterns); + console.log(this.CurrentSelectedSetting.costumPatterns); }; @@ -981,6 +983,8 @@ class NewLevel { this.CurrentSelectedSetting.costumField = {}; }; + this.SaveInHistory("costumField", this.CurrentSelectedSetting.costumField); + console.log(this.CurrentSelectedSetting.costumField); }; @@ -1030,8 +1034,16 @@ class NewLevel { }; // add user costum pattern to win conditions -const NewCreativeLevel_GenerateCostumPatterns = () => { - let patterns = NewCreativeLevel.selectedLevel[15]; +const NewCreativeLevel_GenerateCostumPatterns = (costumPatternsFromThirdParty, costumXCoordFromThirdParty) => { // costumPatternsFromThirdParty : from database for online game + console.log(costumPatternsFromThirdParty, NewCreativeLevel); + + let patterns; + if (NewCreativeLevel) { + patterns = NewCreativeLevel.selectedLevel[15]; + + } else { + patterns = costumPatternsFromThirdParty; + }; if (patterns && NewCreativeLevel) { // generate @@ -1043,6 +1055,20 @@ const NewCreativeLevel_GenerateCostumPatterns = () => { console.log(structure, xCellAmount); + CostumWinPattern(structure, xCellAmount, xCellAmount); + }; + + } else if (costumPatternsFromThirdParty) { + + // generate + for (const [pattern, index] of Object.entries(patterns)) { + console.log(pattern, index); + + let structure = index[pattern]["structure"] + let xCellAmount = costumXCoordFromThirdParty; + + console.log(structure, xCellAmount); + CostumWinPattern(structure, xCellAmount, xCellAmount); }; }; diff --git a/src/script/public/Game/Game.js b/src/script/public/Game/Game.js index 488cf0b..8bcbc09 100644 --- a/src/script/public/Game/Game.js +++ b/src/script/public/Game/Game.js @@ -98,7 +98,8 @@ let board_size; // Initialize Game // Allowed_Patterns = array with names of the allowed patterns -function initializeGame(field, onlineGame, OnlineGameDataArray, Allowed_Patterns, mapLevelName, required_amount_to_win, AdvantureLevel_InnerGameMode, maxAmoOfMoves, costumCoords) { +function initializeGame(field, onlineGame, OnlineGameDataArray, Allowed_Patterns, mapLevelName, required_amount_to_win, AdvantureLevel_InnerGameMode, maxAmoOfMoves, costumCoords, + CreativeLevel_from_onlineMode_costumPatterns) { // Define field data for game // If online game set online game data, if not set normal data let fieldIndex = Array.isArray(OnlineGameDataArray) ? OnlineGameDataArray[0] : field.getAttribute('index'); @@ -180,9 +181,9 @@ function initializeGame(field, onlineGame, OnlineGameDataArray, Allowed_Patterns CreateWinConditions(xCell_Amount, Allowed_Patterns); // user costum patterns are only availible in user costum levels - if (NewCreativeLevel) { + if (NewCreativeLevel || CreativeLevel_from_onlineMode_costumPatterns) { // check and initialize user costum patterns - NewCreativeLevel_GenerateCostumPatterns(); + NewCreativeLevel_GenerateCostumPatterns(CreativeLevel_from_onlineMode_costumPatterns, costumCoords[0]); }; // for KI Mode @@ -679,74 +680,87 @@ const SetBGColorForCurrentField = (xy) => { // every card field has its own img icon or fontawesome icon const SetGameFieldIconForCurrentField = (xy, fieldIndex) => { - switch (xy) { - case 5: - if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); - let img = document.createElement("img"); - img.src = "./assets/game/warlord-helmet.svg"; - img.width = "35"; - img.height = "35"; - img.style.margin = "7px 0 0 0"; - img.style.transform = "rotate(90deg)"; - Game_Upper_Field_Icon.appendChild(img); - Game_Upper_Field_Icon.classList = ""; - break; + if (!NewCreativeLevel) { + switch (xy) { + case 5: + if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); + let img = document.createElement("img"); + img.src = "./assets/game/warlord-helmet.svg"; + img.width = "35"; + img.height = "35"; + img.style.margin = "7px 0 0 0"; + img.style.transform = "rotate(90deg)"; + Game_Upper_Field_Icon.appendChild(img); + Game_Upper_Field_Icon.classList = ""; + break; - case 10: - if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); - let img1 = document.createElement("img"); - img1.src = "./assets/game/wolf-head.svg"; - img1.width = "35"; - img1.height = "35"; - img1.style.margin = "7px 0 0 0"; - Game_Upper_Field_Icon.appendChild(img1); - Game_Upper_Field_Icon.classList = ""; - break; + case 10: + if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); + let img1 = document.createElement("img"); + img1.src = "./assets/game/wolf-head.svg"; + img1.width = "35"; + img1.height = "35"; + img1.style.margin = "7px 0 0 0"; + Game_Upper_Field_Icon.appendChild(img1); + Game_Upper_Field_Icon.classList = ""; + break; - case 15: - if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); - let img3 = document.createElement("img"); - img3.src = "./assets/game/shattered-sword.svg"; - img3.width = "31"; - img3.height = "31"; - img3.style.margin = "7px 4px 0 0"; - img3.style.transform = "scaleX(-1)"; - Game_Upper_Field_Icon.appendChild(img3); - Game_Upper_Field_Icon.classList = ""; - break; + case 15: + if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); + let img3 = document.createElement("img"); + img3.src = "./assets/game/shattered-sword.svg"; + img3.width = "31"; + img3.height = "31"; + img3.style.margin = "7px 4px 0 0"; + img3.style.transform = "scaleX(-1)"; + Game_Upper_Field_Icon.appendChild(img3); + Game_Upper_Field_Icon.classList = ""; + break; - case 20: - if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); - let img2 = document.createElement("img"); - img2.src = "./assets/game/dragon-head.svg"; - img2.width = "35"; - img2.height = "35"; - img2.style.margin = "7px 0 0 0"; - img2.style.transform = "rotate(90deg) scaleY(-1)"; - Game_Upper_Field_Icon.appendChild(img2); - Game_Upper_Field_Icon.classList = ""; - break; + case 20: + if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); + let img2 = document.createElement("img"); + img2.src = "./assets/game/dragon-head.svg"; + img2.width = "35"; + img2.height = "35"; + img2.style.margin = "7px 0 0 0"; + img2.style.transform = "rotate(90deg) scaleY(-1)"; + Game_Upper_Field_Icon.appendChild(img2); + Game_Upper_Field_Icon.classList = ""; + break; - case 25: - if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); - Game_Upper_Field_Icon.classList = `${Fields[fieldIndex].icon} field-card-header-icon`; - break; + case 25: + if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); + Game_Upper_Field_Icon.classList = `${Fields[fieldIndex].icon} field-card-header-icon`; + break; - case 30: - if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); - Game_Upper_Field_Icon.classList = `${Fields[fieldIndex].icon} field-card-header-icon`; - break; + case 30: + if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); + Game_Upper_Field_Icon.classList = `${Fields[fieldIndex].icon} field-card-header-icon`; + break; - case 40: - if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); - let img4 = document.createElement("img"); - img4.src = "./assets/game/semi-closed-eye.svg"; - img4.width = "40"; - img4.height = "40"; - img4.style.margin = "2px 0 0 0"; - Game_Upper_Field_Icon.appendChild(img4); - Game_Upper_Field_Icon.classList = ""; - break; + case 40: + if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); + let img4 = document.createElement("img"); + img4.src = "./assets/game/semi-closed-eye.svg"; + img4.width = "40"; + img4.height = "40"; + img4.style.margin = "2px 0 0 0"; + Game_Upper_Field_Icon.appendChild(img4); + Game_Upper_Field_Icon.classList = ""; + break; + }; + + } else { + + if (Game_Upper_Field_Icon.querySelector("img")) Game_Upper_Field_Icon.querySelector("img").remove(); + let img5 = document.createElement("img"); + img5.src = NewCreativeLevel.Settings.levelicon[NewCreativeLevel.selectedLevel[4]]; + img5.width = "31"; + img5.height = "31"; + img5.style.margin = "4px 0 0 0"; + Game_Upper_Field_Icon.appendChild(img5); + Game_Upper_Field_Icon.classList = ""; }; }; diff --git a/src/script/public/serverHandler.js b/src/script/public/serverHandler.js index c19917f..a0d54c3 100644 --- a/src/script/public/serverHandler.js +++ b/src/script/public/serverHandler.js @@ -1113,6 +1113,7 @@ socket.on('StartGame', (RoomData) => { // RoomData clearTimer(); // many data about the room from the database + // game data let FieldIndex = RoomData[0].fieldIndex; let FieldTitle = RoomData[0].fieldTitle; @@ -1139,14 +1140,23 @@ socket.on('StartGame', (RoomData) => { // RoomData // required points to win a game let required_points_to_win = parseInt(Lobby_PointsToWin.textContent); + // user costum data (NewCreativeLevel stuff) + + console.log(RoomData[0].costumPatterns, RoomData[0].costumField[0], RoomData[0].costumField[1]); + // user costum coord in new creative level - let costumX; - let costumY; + let costumX = parseInt(JSON.parse(RoomData[0].costumField)[0]); + let costumY = parseInt(JSON.parse(RoomData[0].costumField)[1]); + + // user costum created patterns + let costumPatterns = JSON.parse(RoomData[0].costumPatterns); + + console.log(costumPatterns, costumX, costumY); // initialize game with given data initializeGame(curr_field_ele, 'OnlineMode', [FieldIndex, FieldTitle, options, player1, player2, player1_icon, player2_icon, PlayerTimer, player1_advancedIcon, player2_advancedIcon, player1_SkinColor, player2_SkinColor, player3_name - ], allowed_patterns, undefined, required_points_to_win, undefined, undefined, [costumX, costumY]); + ], allowed_patterns, undefined, required_points_to_win, undefined, undefined, [costumX, costumY], costumPatterns); // play theme music PauseMusic();