Skip to content

Commit

Permalink
Fix show badge before hero badge earned (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dianna Faulk authored Oct 28, 2019
1 parent 0176c8b commit 4fabdba
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/2019-disaster-game/src/components/Game/TaskScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
completeTask,
getSaveYourselfCompleted
} from "../../../state/tasks";
import { addBadge, getAllBadges, addSaved } from "../../../state/user";
import { addBadge, getHeroBadge, addSaved } from "../../../state/user";
import { getPlayerKitItems } from "../../../state/kit";
import usePrevious from "../../../state/hooks/usePrevious";
import { SOLVING, VOTING, MOVING_MAP } from "../../../constants/actions";
Expand Down Expand Up @@ -47,7 +47,7 @@ const TaskScreenContainer = ({
saveYourselfCompleted,
endChapter,
completeActiveTask,
badges,
latestHeroBadge,
addNextTask,
tasksForEnvironment,
activeEnvironment,
Expand All @@ -72,7 +72,7 @@ const TaskScreenContainer = ({
// Track previous values
const prevActiveTaskIndex = usePrevious(activeTaskIndex);
const prevTaskPhase = usePrevious(taskPhase);
const prevBadgesAcquired = usePrevious(badges.badgesAcquired);
const prevHeroBadgeAcquired = usePrevious(latestHeroBadge);

const onTaskSelection = orbModel => {
const voteCount = taskVotes[orbModel.type]
Expand Down Expand Up @@ -215,28 +215,28 @@ const TaskScreenContainer = ({

// If the player just acquired a hero badge, delay ending the solve screen to show new badge
useEffect(() => {
const earnedNewBadge =
badges.badgesAcquired &&
prevBadgesAcquired !== badges.badgesAcquired &&
const earnedNewHeroBadge =
latestHeroBadge &&
prevHeroBadgeAcquired !== latestHeroBadge &&
!shouldEndChapter;
const earnedFinalBadge = shouldEndChapter && finishedFinalSolvePhase;

if (earnedNewBadge || earnedFinalBadge) {
if (earnedNewHeroBadge || earnedFinalBadge) {
setDisplayBadge(true);
}
if (earnedFinalBadge) {
setDisplayedFinalBadge(true);
startTimer(5, false);
}
}, [
badges,
endChapter,
finishedFinalSolvePhase,
phaseTimer,
prevBadgesAcquired,
shouldEndChapter,
startTimer,
taskPhase
taskPhase,
latestHeroBadge,
prevHeroBadgeAcquired
]);

// Audio
Expand Down Expand Up @@ -306,10 +306,10 @@ TaskScreenContainer.propTypes = {
completeActiveTask: PropTypes.func,
activeEnvironment: PropTypes.string,
tasksForEnvironment: PropTypes.shape({}),
badges: PropTypes.shape({}),
saveYourselfCompleted: PropTypes.bool,
addHeroBadge: PropTypes.func,
addToSaved: PropTypes.func
addToSaved: PropTypes.func,
latestHeroBadge: PropTypes.oneOf([PropTypes.shape({}), null])
};

const mapStateToProps = state => ({
Expand All @@ -320,7 +320,7 @@ const mapStateToProps = state => ({
weightedPlayerKitItems: getPlayerKitItems(state),
activeEnvironment: getActiveEnvironment(state),
tasksForEnvironment: getTasksForEnvironment(state),
badges: getAllBadges(state),
latestHeroBadge: getHeroBadge(state),
saveYourselfCompleted: getSaveYourselfCompleted(state)
});

Expand Down

0 comments on commit 4fabdba

Please sign in to comment.