Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of the Ghost balloon #340

Merged
merged 10 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ title Balloon spawn chances
"Confetti" : 0.10
"Fast": 0.10
"Gold": 0.05
"Ghost": 0.10
```

## Inheritance Tree
Expand All @@ -291,6 +292,7 @@ Default --|> Balloon
Confetti --|> Default
Fast --|> Default
Gold --|> Default
Ghost --|> Default
Splitter --|> Default
```

Expand Down
21 changes: 21 additions & 0 deletions docs/balloons/ghost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Ghost

This is a balloon spawned from the spiritworld. Just like a ghost this balloon sways from side to side en turns slightly invisible.

```mermaid
classDiagram
direction LR
class Balloon { <<Abstract>> }
click Balloon href "#abstract-balloon-class" "Abstract balloon class"

class Ghost {
+spawn_chance: number$
+<< get >>name: string
+<< get >>options: BalloonOptions
}
Ghost --|> Balloon
```

Has a custom image resource in [`/resources/balloons/ghost/balloon.svg`](/resources/balloons/ghost/balloon.svg).

![Ghost balloon](/resources/balloons/ghost/balloon.svg)
51 changes: 51 additions & 0 deletions resources/balloons/ghost/balloon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions resources/balloons/ghost/ghost.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@keyframes fade {
0% {
opacity: 0.2;
}

100% {
opacity: 0.8;
}
}

.balloon[data-balloon="ghost"] img {
animation-name: fade;
animation-duration: var(--animation-speed, 3000ms);
animation-iteration-count: infinite;
animation-direction: alternate;
animation-timing-function: ease-in-out;
}
2 changes: 1 addition & 1 deletion src/balloons/fast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Fast extends Default {
return {
...super.options,
imageUrl: 'balloon.svg',
riseDuration: [5000, 7500],
riseDuration: [4000, 6500],
size: [65, 75],
};
}
Expand Down
36 changes: 36 additions & 0 deletions src/balloons/ghost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Default, { BalloonOptions } from './default';
import { random } from '@/utils';

type GhostOptions = BalloonOptions & {
fadeSpeed: number | [number, number];
};

export default class Ghost extends Default {
public static readonly spawn_chance: number = 0.1;
// @ts-ignore
public get name(): 'ghost' {
return 'ghost';
}

public get options(): GhostOptions {
return {
...super.options,
imageUrl: 'balloon.svg',
riseDuration: [18000, 21000],
swingDuration: [3, 4],
swingOffset: 70,
fadeSpeed: [2000, 3000],
};
}

public build(): void {
super.build();
this.importStylesheet('ghost.css');

const animationSpeed =
typeof this.options.fadeSpeed === 'number'
? this.options.fadeSpeed
: random(this.options.fadeSpeed[0], this.options.fadeSpeed[1]);
this.element.style.setProperty('--animation-speed', `${animationSpeed}ms`);
}
}
3 changes: 2 additions & 1 deletion src/balloons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export { default as Default } from './default';
export { default as Confetti } from './confetti';
export { default as Gold } from './gold';
export { default as Splitter } from './splitter';
export { default as Fast } from './fast';
export { default as Fast } from './fast';
export { default as Ghost } from './ghost';
2 changes: 1 addition & 1 deletion src/popup/pages/Discovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default () => {
balloon: new balloon(),
};
}),
...new Array(1).fill({
...new Array(0).fill({
name: 'default',
count: 0,
balloon: new Balloons.Default(),
Expand Down
23 changes: 23 additions & 0 deletions tests/balloons/ghost.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Ghost } from '@/balloons';
import fetchMock from 'jest-fetch-mock';

fetchMock.enableMocks();

describe('Ghost Balloon', () => {
let balloon: Ghost;

beforeEach(() => {
balloon = new Ghost();

fetchMock.resetMocks();
});

test('name should be "ghost"', () => {
expect(balloon.name).toBe('ghost');
});

test('name should be the same as the class name', () => {
expect(balloon.name).toBe('ghost');
expect(balloon.name).toBe(Ghost.name.toLowerCase());
});
});
Loading