diff --git a/src/extension/extension.ts b/src/extension/extension.ts index 4f05b490..56280b80 100644 --- a/src/extension/extension.ts +++ b/src/extension/extension.ts @@ -239,7 +239,7 @@ async function handleRemovePetMessage( if (pet) { const panel = getPetPanel(); if (panel !== undefined) { - panel.deletePet(pet.name); + panel.deletePet(pet.name, pet.type, pet.color); const collection = petList .filter((item) => { return item.name !== pet.name; @@ -689,7 +689,7 @@ interface IPetPanel { throwBall(): void; resetPets(): void; spawnPet(spec: PetSpecification): void; - deletePet(petName: string): void; + deletePet(petName: string, petType: string, petColor: string): void; listPets(): void; rollCall(): void; themeKind(): vscode.ColorThemeKind; @@ -812,10 +812,12 @@ class PetWebviewContainer implements IPetPanel { void this.getWebview().postMessage({ command: 'roll-call' }); } - public deletePet(petName: string) { + public deletePet(petName: string, petType: string, petColor: string) { void this.getWebview().postMessage({ command: 'delete-pet', name: petName, + type: petType, + color: petColor }); } @@ -993,10 +995,12 @@ class PetPanel extends PetWebviewContainer implements IPetPanel { void this.getWebview().postMessage({ command: 'roll-call' }); } - public deletePet(petName: string): void { + public deletePet(petName: string, petType: string, petColor: string): void { void this.getWebview().postMessage({ command: 'delete-pet', name: petName, + type: petType, + color: petColor }); } diff --git a/src/panel/main.ts b/src/panel/main.ts index c3c75d15..a71a87db 100644 --- a/src/panel/main.ts +++ b/src/panel/main.ts @@ -91,10 +91,7 @@ function calculateFloor(size: PetSize, theme: Theme): number { function handleMouseOver(e: MouseEvent) { var el = e.currentTarget as HTMLDivElement; allPets.pets.forEach((element) => { - if (element.collision === el) { - if (!element.pet.canSwipe) { - return; - } + if (element.collision === el && element.pet.canSwipe) { element.pet.swipe(); } }); @@ -576,9 +573,9 @@ export function petPanelApp( }); }); case 'delete-pet': - var pet = allPets.locate(message.name); + var pet = allPets.locatePet(message.name, message.type, message.color); if (pet) { - allPets.remove(message.name); + allPets.remove(pet); saveState(stateApi); stateApi?.postMessage({ command: 'info', diff --git a/src/panel/pets.ts b/src/panel/pets.ts index c32e9f7c..428860a4 100644 --- a/src/panel/pets.ts +++ b/src/panel/pets.ts @@ -57,7 +57,8 @@ export interface IPetCollection { reset(): void; seekNewFriends(): string[]; locate(name: string): PetElement | undefined; - remove(name: string): void; + locatePet(name: string, type: string, color: string): PetElement | undefined; + remove(pet: PetElement): void; } export class PetCollection implements IPetCollection { @@ -88,14 +89,20 @@ export class PetCollection implements IPetCollection { }); } - remove(name: string): any { + locatePet(name: string, type: string, color: string): PetElement | undefined { + return this._pets.find((collection) => { + return collection.pet.name === name && collection.type === type && collection.color === color; + }); + } + + remove(targetPet: PetElement): any { this._pets.forEach((pet) => { - if (pet.pet.name === name) { + if (pet === targetPet) { pet.remove(); } }); this._pets = this._pets.filter((pet) => { - return pet.pet.name !== name; + return pet !== targetPet; }); }