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

✨ feat(app): now, confetti have game shapes #77

Merged
merged 1 commit into from
Mar 13, 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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
"no-duplicate-imports": "warn",
"no-multiple-empty-lines": ["warn", { "max": 1 }],
"space-before-blocks": ["warn", "always"],
"newline-before-return": ["warn"]
"newline-before-return": ["warn"],
"curly": ["warn"]
}
},
{
Expand Down
6 changes: 2 additions & 4 deletions apps/app/src/app/pages/game/game.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
}
</section>

<!-- @if (remainingCardsCount() === 0 && cardsInSets().length === 0) { -->
@if (remainingCardsCount() === 0 && cardsInSets().length === 0) {
<set-you-won (playAgain)="newGame()"></set-you-won>
<!-- } -->

<div id="confetti"></div>
}
</main>
5 changes: 0 additions & 5 deletions apps/app/src/app/pages/game/game.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ main {
min-height: 100%;
background-color: rgb(255 255 255 / 90%);

#confetti {
position: relative;
z-index: 100;
}

.info {
min-height: 40px;
}
Expand Down
54 changes: 49 additions & 5 deletions apps/app/src/app/pages/game/game.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ export default class GamePage implements OnInit {
showSets = signal<number>(0);
message = signal<string>('');

constructor() {
this.startConfetti();
}

ngOnInit(): void {
this.prepareNewGame();

Expand Down Expand Up @@ -70,7 +66,7 @@ export default class GamePage implements OnInit {
for (let j = i + 1; j < cards.length - 1; j++) {
for (let k = j + 1; k < cards.length; k++) {
if (this.isSet(cards[i], cards[j], cards[k])) {
// this.cardsInSets.update((cards) => [...cards, cards[i], cards[j], cards[k]]);
this.cardsInSets.update((cards) => [...cards, cards[i], cards[j], cards[k]]);
this.cardsInSets.set([cards[i], cards[j], cards[k]]);
}
}
Expand Down Expand Up @@ -278,6 +274,20 @@ export default class GamePage implements OnInit {

private startConfetti(): void {
confetti('confetti', {
shapes: ['image'],
shapeOptions: {
image: [
this.getConfettiShapeConfig('oval', 'red'),
this.getConfettiShapeConfig('oval', 'purple'),
this.getConfettiShapeConfig('oval', 'green'),
this.getConfettiShapeConfig('squiggle', 'red'),
this.getConfettiShapeConfig('squiggle', 'purple'),
this.getConfettiShapeConfig('squiggle', 'green'),
this.getConfettiShapeConfig('diamond', 'red'),
this.getConfettiShapeConfig('diamond', 'purple'),
this.getConfettiShapeConfig('diamond', 'green'),
],
},
count: 500, // number of confetti particles; default: 50
angle: 90, // angle of the burst; default: 90
spread: 180, // spread of confetti particles in degrees; default 45, try 360 for fun
Expand All @@ -290,4 +300,38 @@ export default class GamePage implements OnInit {
},
});
}

private getConfettiShapeConfig(
shape: keyof typeof CardShapeEnum,
color: keyof typeof CardColorEnum,
) {
let width;
let height;

switch (shape) {
case 'oval':
width = 54;
height = 111;
break;
case 'diamond':
width = 57;
height = 116;
break;
case 'squiggle':
width = 52;
height = 105;
break;
}

return {
src: `/assets/icons/${shape}-solid-${color}.png`,
width,
height,
particles: {
size: {
value: 4,
},
},
};
}
}
Binary file added apps/app/src/assets/icons/diamond-solid-green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/app/src/assets/icons/diamond-solid-red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/app/src/assets/icons/oval-solid-green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/app/src/assets/icons/oval-solid-purple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/app/src/assets/icons/oval-solid-red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/app/src/assets/icons/squiggle-solid-red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions apps/app/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ h5 {
h6 {
font-size: var(--font-size-sm);
}

#confetti {
position: relative;
z-index: 100;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"migration:create": "mikro-orm migration:create",
"migration:execute": "mikro-orm migration:up",
"prettier": "prettier -c --loglevel warn",
"lint": "lint-staged",
"prettier:fix": "prettier -w --loglevel warn",
"eslint": "eslint --max-warnings 0",
"eslint:fix": "npm run eslint --fix",
Expand Down