populate grid on resize

This commit is contained in:
Piotr 'pwh' Hanusiak 2022-03-17 16:48:40 +01:00
parent 744c15920b
commit 9a7e5cae4c

View File

@ -261,6 +261,7 @@ export class CustomizeScene extends AbstractCharacterScene {
.setStrokeStyle(4, 0xaaaaaa); .setStrokeStyle(4, 0xaaaaaa);
this.bodyPartsDraggableGrid.changeDraggableSpacePosAndSize(gridPos, { x: gridWidth, y: gridHeight }, gridPos); this.bodyPartsDraggableGrid.changeDraggableSpacePosAndSize(gridPos, { x: gridWidth, y: gridHeight }, gridPos);
this.populateGrid();
this.bodyPartsDraggableGrid.moveContentToBeginning(); this.bodyPartsDraggableGrid.moveContentToBeginning();
} }
@ -315,7 +316,7 @@ export class CustomizeScene extends AbstractCharacterScene {
this.selectedBodyPartType = bodyPart as CustomWokaBodyPart; this.selectedBodyPartType = bodyPart as CustomWokaBodyPart;
this.deselectAllSlots(); this.deselectAllSlots();
slot.select(true); slot.select(true);
this.populateGrid(bodyPart as CustomWokaBodyPart); this.populateGrid();
} else { } else {
this.selectedBodyPartType = undefined; this.selectedBodyPartType = undefined;
slot.select(false); slot.select(false);
@ -345,18 +346,21 @@ export class CustomizeScene extends AbstractCharacterScene {
this.selectedLayers[CustomWokaBodyPartOrder[this.selectedBodyPartType]] = index; this.selectedLayers[CustomWokaBodyPartOrder[this.selectedBodyPartType]] = index;
} }
private populateGrid(bodyParts: CustomWokaBodyPart): void { private populateGrid(): void {
if (this.selectedBodyPartType === undefined) {
return;
}
const slotDimension = (innerHeight * (this.isVertical ? 0.125 : 0.15)) / waScaleManager.getActualZoom(); const slotDimension = (innerHeight * (this.isVertical ? 0.125 : 0.15)) / waScaleManager.getActualZoom();
const slotScale = slotDimension / this.customWokaPreviewer.SIZE; const slotScale = slotDimension / this.customWokaPreviewer.SIZE;
const bodyPartsLayer = this.layers[CustomWokaBodyPartOrder[bodyParts]]; const bodyPartsLayer = this.layers[CustomWokaBodyPartOrder[this.selectedBodyPartType]];
this.bodyPartsDraggableGrid.clearAllItems(); this.bodyPartsDraggableGrid.clearAllItems();
for (let i = 0; i < bodyPartsLayer.length; i += 1) { for (let i = 0; i < bodyPartsLayer.length; i += 1) {
const slot = new WokaBodyPartSlot(this, 0, 0, this.getDefaultWokaBodyPartSlotConfig(), i).setScale( const slot = new WokaBodyPartSlot(this, 0, 0, this.getDefaultWokaBodyPartSlotConfig(), i).setScale(
slotScale slotScale
); );
if (bodyParts === CustomWokaBodyPart.Body) { if (this.selectedBodyPartType === CustomWokaBodyPart.Body) {
slot.setBodyTexture(bodyPartsLayer[i].id); slot.setBodyTexture(bodyPartsLayer[i].id);
slot.setImageTexture(); slot.setImageTexture();
} else { } else {