Skip to content

Commit

Permalink
Remove new turn action logs (#499)
Browse files Browse the repository at this point in the history
* Remove new turn action logs

* Remove new turn action log from frontend

* Fix positioning of turn/phase dividers

Fix positioning of the turn/phase dividers in the notification list.

* Minor improvements to notification dividers
  • Loading branch information
iamlogand authored Jul 11, 2024
1 parent e463970 commit fa5045f
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 88 deletions.
2 changes: 1 addition & 1 deletion backend/rorapp/functions/forum_phase_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ def initiate_situation(action_id: int) -> dict:
messages_to_send.append(
generate_select_faction_leader_action(action.faction, new_step)
)
return Response({"message": "Situation initiated"}, status=200), messages_to_send
return Response({"message": "Initiated"}, status=200), messages_to_send
18 changes: 0 additions & 18 deletions backend/rorapp/functions/turn_starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,6 @@ def start_next_turn(game_id) -> List[dict]:
create_websocket_message("step", StepSerializer(new_step).data)
)

# Issue a notification to say that the next turn has started
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=new_step,
type="new_turn",
data={"turn_index": new_turn.index},
)
action_log.save()
messages_to_send.append(
create_websocket_message("action_log", ActionLogSerializer(action_log).data)
)

# Create actions for next mortality phase
factions = Faction.objects.filter(game__id=game.id)
for faction in factions:
Expand Down
15 changes: 15 additions & 0 deletions backend/rorapp/migrations/0061_remove_new_turn_actionlogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.db import migrations


class Migration(migrations.Migration):
def remove_new_turn_action_logs(apps, schema_editor):
ActionLog = apps.get_model("rorapp", "ActionLog")
ActionLog.objects.filter(type="new_turn").delete()

dependencies = [
("rorapp", "0060_faction_custom_name"),
]

operations = [
migrations.RunPython(remove_new_turn_action_logs, migrations.RunPython.noop),
]
2 changes: 1 addition & 1 deletion backend/rorapp/tests/mortality_phase_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
get_and_check_actions,
submit_actions,
)
from rorapp.models import ActionLog, Senator, Step, Title
from rorapp.models import ActionLog, Senator, Title


class MortalityPhaseTests(TestCase):
Expand Down
2 changes: 0 additions & 2 deletions frontend/components/ActionLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ActionLog from "@/classes/ActionLog"
import NewFactionLeaderActionLog from "@/components/actionLogs/NewFactionLeaderActionLog"
import MortalityActionLog from "@/components/actionLogs/MortalityActionLog"
import TemporaryRomeConsulActionLog from "@/components/actionLogs/TemporaryRomeConsulActionLog"
import NewTurnActionLog from "@/components/actionLogs/NewTurnActionLog"
import NewFamilyActionLog from "@/components/actionLogs/NewFamilyActionLog"
import NewWarActionLog from "@/components/actionLogs/NewWarActionLog"
import MatchedWarActionLog from "@/components/actionLogs/MatchedWarActionLog"
Expand All @@ -29,7 +28,6 @@ const notifications: { [key: string]: React.ComponentType<any> } = {
new_enemy_leader: NewEnemyLeaderActionLog,
new_family: NewFamilyActionLog,
new_secret: NewSecretActionLog,
new_turn: NewTurnActionLog,
new_war: NewWarActionLog,
personal_revenue: PersonalRevenueActionLog,
new_faction_leader: NewFactionLeaderActionLog,
Expand Down
8 changes: 2 additions & 6 deletions frontend/components/MetaSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@ const MetaSection = () => {
<h3 className="text-sm">Your Faction</h3>
<div className="flex items-center gap-3">
<div>
<FactionLink
faction={faction}
maxWidth={130}
includeIcon
/>
<FactionLink faction={faction} maxWidth={130} includeIcon />
</div>
<AttributeFlex attributes={attributeItems} />
</div>
Expand Down Expand Up @@ -191,7 +187,7 @@ const MetaSection = () => {
<b>Game over</b>
) : (
<span>
Turn {latestTurn?.index},{" "}
<TermLink name="Turn" /> {latestTurn?.index},{" "}
{latestPhase && getPhaseTerm(latestPhase.name)}
</span>
))}
Expand Down
70 changes: 41 additions & 29 deletions frontend/components/NotificationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Badge, IconButton } from "@mui/material"
import { useCallback, useEffect, useRef, useState } from "react"
import ActionLog from "@/components/ActionLog"
import ActionLogClass from "@/classes/ActionLog"
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft"
import TermLink from "@/components/TermLink"

const NotificationList = () => {
const { actionLogs, steps, phases, turns } = useGameContext()
Expand Down Expand Up @@ -72,6 +72,27 @@ const NotificationList = () => {
setInitiateScrollDown(false)
}, [initiateScrollDown, scrollToBottom])

const dividerLine = (
<div className="grow h-[2px] bg-tyrian-200 dark:bg-tyrian-500" />
)

const renderDivider = (phaseName: string, turnIndex: number | null) => {
return (
<div className="w-full flex items-center">
{dividerLine}
<span className="text-sm px-3 py-0.5 rounded bg-tyrian-200 dark:bg-tyrian-500 flex flex-col">
{turnIndex !== null && (
<span className="text-center px-2 text-lg">
<TermLink name="Turn" /> {turnIndex}
</span>
)}
<TermLink name={`${phaseName} Phase`} />
</span>
{dividerLine}
</div>
)
}

return (
<div className="flex-1 flex flex-col overflow-y-auto relative">
<h3 className="leading-lg m-2 ml-2 text-base text-neutral-600 dark:text-neutral-100">
Expand All @@ -83,37 +104,28 @@ const NotificationList = () => {
>
{actionLogs &&
sortedActionLogs.map((actionLog, index) => {
const previous = index > 0 ? sortedActionLogs[index - 1] : null
const previousStep = previous ? steps.byId[previous.step] : null
const currentStep = steps.byId[actionLog.step]
const previousPhase = previousStep
? phases.byId[previousStep.phase]
const previousLog = index > 0 ? sortedActionLogs[index - 1] : null
const previousLogStep = previousLog
? steps.byId[previousLog.step]
: null
const currentPhase = phases.byId[currentStep.phase]
const showPhase = previousPhase?.id !== currentPhase.id
const previousTurn = previousPhase
? turns.byId[previousPhase.turn]
const currentLogStep = steps.byId[actionLog.step]
const previousLogPhase = previousLogStep
? phases.byId[previousLogStep.phase]
: null
const currentTurn = turns.byId[currentPhase.turn]
const showTurn = previousTurn?.id !== currentTurn.id
const currentLogPhase = phases.byId[currentLogStep.phase]
const showPhase = previousLogPhase?.id !== currentLogPhase.id
const previousLogTurn = previousLogPhase
? turns.byId[previousLogPhase.turn]
: null
const currentLogTurn = turns.byId[currentLogPhase.turn]
const showTurn = previousLogTurn?.id !== currentLogTurn.id
return (
<div key={index}>
{showPhase && (
<div className="w-full flex items-end pb-2">
<div className="grow mb-[11px] h-[2px] bg-tyrian-200 dark:bg-tyrian-500" />

<span className="text-sm px-3 py-0.5 rounded bg-tyrian-200 dark:bg-tyrian-500 flex flex-col">
{showTurn && (
<span className="text-center px-2 text-lg">
Turn {currentTurn.index}
</span>
)}
{currentPhase.name} Phase
</span>
<div className="grow mb-[11px] h-[2px] bg-tyrian-200 dark:bg-tyrian-500" />
</div>
)}

<div key={index} className="flex flex-col gap-2">
{showPhase &&
renderDivider(
currentLogPhase.name,
showTurn ? currentLogTurn.index : null
)}
<div className="px-2">
<ActionLog key={actionLog.id} notification={actionLog} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/actionLogs/NewEnemyLeaderActionLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const NewEnemyLeaderActionLog = ({ notification }: ActionLogProps) => {
)}
.{" "}
<i>
Situation initiated by <FactionLink faction={initiatingFaction} />
Initiated by <FactionLink faction={initiatingFaction} />
</i>
.
</p>
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/actionLogs/NewFamilyActionLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const NewFamilyActionLog = ({
<SenatorLink senator={newSenator} /> {senatorDetails ? "" : "has "}
joined the Senate as an Unaligned <TermLink name="Senator" />.{" "}
<i>
Situation initiated by <FactionLink faction={initiatingFaction} />
Initiated by <FactionLink faction={initiatingFaction} />
</i>
.
</p>
Expand Down
28 changes: 0 additions & 28 deletions frontend/components/actionLogs/NewTurnActionLog.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/components/actionLogs/NewWarActionLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const NewWarActionLog = ({ notification }: ActionLogProps) => {
Rome faces a new threat in the <FormattedWarName war={newWar} />. This{" "}
<TermLink name="War" /> is {getStatusAndExplanation()}.{" "}
<i>
Situation initiated by <FactionLink faction={initiatingFaction} />
Initiated by <FactionLink faction={initiatingFaction} />
</i>
.
</p>
Expand Down

0 comments on commit fa5045f

Please sign in to comment.