Skip to content

Commit

Permalink
Merge pull request #648 from thuynguyenbm/fix/issue-647
Browse files Browse the repository at this point in the history
Fix/issue 647 + add snail
  • Loading branch information
tonybaloney authored Dec 31, 2024
2 parents cd3b4af + d6a74d9 commit 64870b8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Set a default color, size, pet type, position, and theme when you open a Pet Pan

* Pet Color: black, brown, green, yellow, gray, purple, red, white, orange
* Pet Size: nano, small, medium, large
* Pet Type: cat, chicken, crab, clippy, cockatiel, dog, horse, mod, rocky, rubber duck, snake, totoro, turtle, zappy
* Pet Type: cat, chicken, crab, clippy, cockatiel, dog, horse, mod, rocky, rubber duck, snake, totoro, turtle, zappy, snail

.. image:: _static/screenshot-2.gif
:alt: Usage screenshot
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
"snake",
"totoro",
"turtle",
"zappy"
"zappy",
"snail"
],
"default": "cat",
"description": "Pet type",
Expand Down
12 changes: 8 additions & 4 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
});
}

Expand Down Expand Up @@ -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,
});
}

Expand Down
13 changes: 7 additions & 6 deletions src/panel/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -576,9 +573,13 @@ 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',
Expand Down
27 changes: 23 additions & 4 deletions src/panel/pets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ 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 {
Expand Down Expand Up @@ -88,14 +93,28 @@ 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;
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ suite('Pets Test Suite', () => {
collection.push(testPetElement);
assert.strictEqual(collection.locate('Jerry'), testPetElement);

collection.remove('Jerry');
collection.remove(testPetElement);
assert.strictEqual(collection.locate('Jerry'), undefined);
});

Expand Down

0 comments on commit 64870b8

Please sign in to comment.