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 <p.hanusiak@workadventu.re>
This commit is contained in:
Piotr Hanusiak 2022-05-05 11:44:33 +02:00 committed by GitHub
parent 9c5fcd2fd8
commit 76bf7b9c74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {