Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ondřej Bazala
PV247
Commits
85130e01
Unverified
Commit
85130e01
authored
Nov 29, 2021
by
Michal Čaniga
Browse files
Consume only one powerup with given id
parent
18392c4f
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/pages/Game/FoodPowerup.tsx
View file @
85130e01
...
...
@@ -5,7 +5,7 @@ import { maxHearts } from '../../data/constants';
import
{
Food
}
from
'
../../data/food
'
;
import
{
SetUserData
}
from
'
../../utils/commonTypes
'
;
import
{
Powerup
}
from
'
./Powerup
'
;
import
{
consumePowerup
,
Powerup
}
from
'
./Powerup
'
;
type
FoodPowerupProps
=
{
setHearts
:
(
hearts
:
number
)
=>
void
;
...
...
@@ -37,7 +37,7 @@ export const FoodPowerup = ({
prev
!==
undefined
?
{
...
prev
,
foodIds
:
prev
.
foodIds
.
filter
(
id
=>
id
!==
food
.
id
)
foodIds
:
consumePowerup
(
prev
.
pokeballIds
,
food
.
id
)
}
:
undefined
);
...
...
src/pages/Game/PokeballPowerup.tsx
View file @
85130e01
...
...
@@ -10,7 +10,7 @@ import {
}
from
'
../../utils/commonTypes
'
;
import
{
PokemonOnCanvas
}
from
'
../../utils/pokemonFetcher
'
;
import
{
Powerup
}
from
'
./Powerup
'
;
import
{
consumePowerup
,
Powerup
}
from
'
./Powerup
'
;
type
PokeballPowerupProps
=
{
pokeball
:
Pokeball
;
...
...
@@ -43,7 +43,7 @@ export const PokeballPowerup = ({
prev
!==
undefined
?
{
...
prev
,
pokeballIds
:
prev
.
pokeballIds
.
filter
(
id
=>
id
!==
pokeball
.
id
)
pokeballIds
:
consumePowerup
(
prev
.
pokeballIds
,
pokeball
.
id
)
}
:
undefined
);
...
...
src/pages/Game/Powerup.tsx
View file @
85130e01
...
...
@@ -7,6 +7,11 @@ type PowerupProps = {
style
?:
React
.
CSSProperties
;
};
export
const
consumePowerup
=
(
ids
:
number
[],
powerupId
:
number
)
=>
{
const
powerupIdx
=
ids
.
findIndex
(
id
=>
id
===
powerupId
);
return
[...
ids
.
slice
(
0
,
powerupIdx
),
...
ids
.
slice
(
powerupIdx
+
1
)];
};
export
const
Powerup
=
({
icon
,
onClick
,
style
}:
PowerupProps
)
=>
(
<
Button
shape
=
"circle"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment