From 76bf7b9c74e04afcd2527cef77631f3a966e3386 Mon Sep 17 00:00:00 2001 From: Piotr Hanusiak Date: Thu, 5 May 2022 11:44:33 +0200 Subject: [PATCH] fix broken custom scene if wrong characterLayers were loaded (#2164) * fix broken custom scene if wrong characterLayers were loaded * be sure to initialize selectedLayers Co-authored-by: Piotr 'pwh' Hanusiak --- front/src/Phaser/Login/CustomizeScene.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/front/src/Phaser/Login/CustomizeScene.ts b/front/src/Phaser/Login/CustomizeScene.ts index f07014b9..77e119f7 100644 --- a/front/src/Phaser/Login/CustomizeScene.ts +++ b/front/src/Phaser/Login/CustomizeScene.ts @@ -94,6 +94,7 @@ export class CustomizeScene extends AbstractCharacterScene { } public create(): void { + this.selectedLayers = [0, 0, 0, 0, 0, 0]; this.tryLoadLastUsedWokaLayers(); waScaleManager.zoomModifier = 1; this.createSlotBackgroundTextures(); @@ -154,11 +155,10 @@ export class CustomizeScene extends AbstractCharacterScene { try { const savedWokaLayers = gameManager.getCharacterLayers(); if (savedWokaLayers && savedWokaLayers.length !== 0) { - this.selectedLayers = []; for (let i = 0; i < savedWokaLayers.length; i += 1) { - this.selectedLayers.push( - this.layers[i].findIndex((item) => item.id === gameManager.getCharacterLayers()[i]) - ); + const index = this.layers[i].findIndex((item) => item.id === gameManager.getCharacterLayers()[i]); + // set first item as default if not found + this.selectedLayers[i] = index !== -1 ? index : 0; } } } catch {