Skip to content

Commit

Permalink
Add a notification for when nobody dies (#270)
Browse files Browse the repository at this point in the history
Add a notification for when nobody dies during the mortality phase
  • Loading branch information
iamlogand authored Oct 1, 2023
1 parent 12b230d commit 6c01670
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
19 changes: 18 additions & 1 deletion backend/rorapp/functions/face_mortality.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def face_mortality(game, faction, potential_action, step):
}
})

# Create a action_log and action_log relations
# Create an action_log and action_log relations
new_action_log_index = ActionLog.objects.filter(step__phase__turn__game=game).order_by('-index')[0].index + 1
action_log = ActionLog(
index=new_action_log_index,
Expand Down Expand Up @@ -161,6 +161,23 @@ def face_mortality(game, faction, potential_action, step):
"data": SenatorActionLogSerializer(heir_senator_action_log).data
}
})

# If nobody dies, issue a notification to say so
else:
new_action_log_index = ActionLog.objects.filter(step__phase__turn__game=game).order_by('-index')[0].index + 1
action_log = ActionLog(
index=new_action_log_index,
step=step,
type="face_mortality"
)
action_log.save()
messages_to_send.append({
"operation": "create",
"instance": {
"class": "action_log",
"data": ActionLogSerializer(action_log).data
}
})

# Update senator ranks
messages_to_send.extend(rank_senators_and_factions(game.id))
Expand Down
20 changes: 10 additions & 10 deletions frontend/components/actionLogs/ActionLog_FaceMortality.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const FaceMortalityNotification = ({ notification, senatorDetails } : Notificati

// Get notification-specific data
const faction: Faction | null = notification.faction ? allFactions.byId[notification.faction] ?? null : null
const senator: Senator | null = notification.data.senator ? allSenators.byId[notification.data.senator] ?? null : null
const heir: Senator | null = notification.data.senator ? allSenators.byId[notification.data.heir_senator] ?? null : null
const majorOfficeName: string = notification.data.major_office
const senator: Senator | null = notification.data?.senator ? allSenators.byId[notification.data.senator] ?? null : null
const heir: Senator | null = notification.data?.senator ? allSenators.byId[notification.data.heir_senator] ?? null : null
const majorOfficeName: string = notification.data?.major_office ?? null

const getIcon = () => (
<div className={styles.icon}>
Expand All @@ -32,28 +32,28 @@ const FaceMortalityNotification = ({ notification, senatorDetails } : Notificati

// Get the text for the notification (tense sensitive)
const getText = () => {
if (!faction || !senator) return null
if (!senator) {
return <p>All senators have survived the Mortality Phase.</p>
}

return (
<p>
{majorOfficeName || heir ? <span>The</span> : null}
{majorOfficeName && <span> {majorOfficeName}</span>}
{majorOfficeName && heir ? <span> and</span> : null}
{heir && <span> <FactionLink faction={faction} /> Leader</span>}
{heir && faction && <span> <FactionLink faction={faction} /> Leader</span>}
{majorOfficeName || heir ? <span>, </span> : null}
<SenatorLink senator={senator} />
{!heir && <span> of the <FactionLink faction={faction} /></span>}
{!heir && faction && <span> of the <FactionLink faction={faction} /></span>}
<span> {!senatorDetails && "has"} passed away.</span>
{heir && <span> His heir <SenatorLink senator={heir} /> {!senatorDetails && "has"} replaced him as Faction Leader.</span>}
</p>
)
}

if (!faction || !senator) return null

return (
<Alert icon={getIcon()} style={{backgroundColor: faction.getColor("textBg")}}>
<b>Mortality</b>
<Alert icon={getIcon()} style={ faction ? {backgroundColor: faction.getColor("textBg")} : {backgroundColor: 'var(--background-color-neutral)'}}>
<b>{!senator && "No "}Mortality </b>
{getText()}
</Alert>
)
Expand Down

0 comments on commit 6c01670

Please sign in to comment.