Skip to content

Commit

Permalink
add flag progression markers
Browse files Browse the repository at this point in the history
  • Loading branch information
bananahampster committed Apr 6, 2024
1 parent 0d1fb4d commit a165860
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 51 deletions.
22 changes: 22 additions & 0 deletions parsedlogs/hamp2.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ body {
font-size: .875rem;
--team-a-color: rgba(175, 141, 195, 0.65);
--team-b-color: rgba(127, 191, 123, 0.65);
--flag-pickup: rgb(17, 7, 38, 1);
--flag-fragged: rgba(81, 142, 166, 1);
--flag-thrown: rgb(180, 210, 217, 1);
--flag-dropped: rgba(217, 175, 139, 1);
--flag-returned: rgba(166, 109, 3, 1);
--flag-captured: rgb(17, 7, 38, 1);
}

.sidebar {
Expand Down Expand Up @@ -272,6 +278,22 @@ td.team-deaths, th.team-deaths,
padding-left: 10px;
}

.toggles {
user-select: none;
}

#flag-pace .chart .markers circle {
stroke: rgba(255, 255, 255, 0.3);
}

#flag-pace .chart g.touch-labels text {
text-anchor: middle;
fill: white;
font-size: 12px;
cursor: pointer;
user-select: none;
}

/** team styles */

.team1 {
Expand Down
34 changes: 26 additions & 8 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,37 @@ export interface ScoringActivity {
game_time_as_seconds: number;
}

export interface FlagMovement {
player: string; // steamID
export type FlagMovement = FlagMovementBase & (FlagMovementReturn | FlagMovementFrag | FlagMovementOther);

type FlagMovementBase = {
current_score: number;
game_time_as_seconds: number,
current_score: number,
how_dropped: FlagDrop;
}

export const enum FlagDrop {
Fragged = 0,
Captured,
Thrown,
type FlagMovementOther = {
type: FlagMovementType;
carrier: string; //alias
}

export type FlagMovementFrag = {
type: FlagMovementType.Fragged,
carrier: string; // alias
fragger: string; // alias
}

type FlagMovementReturn = {
type: FlagMovementType.Returned,
}

export enum FlagMovementType {
Pickup,
Fragged,
Thrown,
Dropped,
Returned,
Captured
};

export type TeamsOutputStatsDetailed = { [team in TeamColor]?: TeamOutputStatsDetailed; }

export interface TeamOutputStatsDetailed {
Expand Down
90 changes: 66 additions & 24 deletions src/flagMovementTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import EventType from './eventType.js';
import { EventSubscriber, EventHandlingPhase, HandlerRequest } from "./eventSubscriberManager.js";
import { RoundState } from "./roundState.js";
import { TeamScore } from "./parserUtils.js";
import { FlagDrop, FlagMovement, ParsingError, PlayerClass, TeamColor, TeamFlagMovements } from "./constants.js";
import { FlagMovement, FlagMovementType, ParsingError, TeamColor, TeamFlagMovements } from "./constants.js";
import Player from "./player.js";
import { PlayerRoundStats } from "./player.js";

class TeamFlagRoundStats {
public numberOfCaps: number = 0;
Expand Down Expand Up @@ -158,8 +157,7 @@ export class FlagMovementTracker extends EventSubscriber {
break;
case EventType.PlayerPickedUpBonusFlag:
{
this.flagRoundStatsByTeam[event.playerFrom!.team].flagEvents.push(event);

// don't record this fact; just update flag status
let flagStatusToUpdate = this.currentFlagStatusByTeam[event.data!.team!];
if (!flagStatusToUpdate.carrier || !flagStatusToUpdate.carrier.matches(event.playerFrom!)) {
console.error("Bonus flag pickup seen by a player (" + event.playerFrom!.name + ") which wasn't carrying the flag"
Expand Down Expand Up @@ -319,39 +317,83 @@ export class FlagMovementTracker extends EventSubscriber {


const flagEvents = this.flagRoundStatsByTeam[team].flagEvents;
flagEvents.forEach(event => {
const teamFlagMovements = flagMovements[team] as FlagMovement[];
flagEvents.forEach((event: Event) => {
const player = event.playerFrom;
let howFlagWasDropped = FlagDrop.Fragged;
switch (event.eventType) {
case EventType.TeamFlagHoldBonus:
runningScore[team] += this.pointsPerTeamFlagHoldBonus;
howFlagWasDropped = FlagDrop.Captured;
teamFlagMovements.push({
type: FlagMovementType.Captured,
carrier: "<Team>",
current_score: runningScore[team],
game_time_as_seconds: event.gameTimeAsSeconds!,
});
break;
case EventType.PlayerCapturedBonusFlag:
runningScore[team] += this.pointsPerBonusCap;
howFlagWasDropped = FlagDrop.Captured;
case EventType.PlayerPickedUpFlag:
teamFlagMovements.push({
type: FlagMovementType.Pickup,
carrier: player!.name,
current_score: runningScore[team],
game_time_as_seconds: event.gameTimeAsSeconds!,
});
break;
case EventType.PlayerCapturedFlag:
runningScore[team] += this.pointsPerCap;
howFlagWasDropped = FlagDrop.Captured;
case EventType.PlayerPickedUpBonusFlag:
return; // do nothing
case EventType.FlagReturn:
teamFlagMovements.push({
type: FlagMovementType.Returned,
current_score: runningScore[team],
game_time_as_seconds: event.gameTimeAsSeconds!,
});
break;
case EventType.PlayerThrewFlag:
howFlagWasDropped = FlagDrop.Thrown;
teamFlagMovements.push({
type: FlagMovementType.Thrown,
carrier: player!.name,
current_score: runningScore[team],
game_time_as_seconds: event.gameTimeAsSeconds!,
});
break;
case EventType.PlayerFraggedPlayer:
howFlagWasDropped = FlagDrop.Fragged;
case EventType.PlayerCommitSuicide:
teamFlagMovements.push({
type: FlagMovementType.Fragged,
fragger: player!.name,
carrier: event.playerTo!.name,
current_score: runningScore[team],
game_time_as_seconds: event.gameTimeAsSeconds!,
});
break;
default:
case EventType.PlayerLeftServer:
teamFlagMovements.push({
type: FlagMovementType.Dropped,
carrier: player!.name,
current_score: runningScore[team],
game_time_as_seconds: event.gameTimeAsSeconds!,
});
break;
case EventType.PlayerCapturedBonusFlag:
runningScore[team] += this.pointsPerBonusCap;
teamFlagMovements.push({
type: FlagMovementType.Captured,
carrier: player!.name,
current_score: runningScore[team],
game_time_as_seconds: event.gameTimeAsSeconds!,
});
break;
case EventType.PlayerCapturedFlag:
runningScore[team] += this.pointsPerCap;
teamFlagMovements.push({
type: FlagMovementType.Captured,
carrier: player!.name,
current_score: runningScore[team],
game_time_as_seconds: event.gameTimeAsSeconds!,
});
break;
default:
return;
}
const flagMovement: FlagMovement = {
game_time_as_seconds: event.gameTimeAsSeconds!,
player: player ? player.name : "<Team>",
current_score: runningScore[team],
how_dropped: howFlagWasDropped,
// TODO: add _who/what_ they were fragged by.
}
flagMovements[team].push(flagMovement);
});

if (needToComputeTeamScore) { // only overwrite the team score if there was no teamScore event
Expand Down
Loading

0 comments on commit a165860

Please sign in to comment.