Skip to content

Commit

Permalink
improvement: extract playerid from extra player list, overwrite name
Browse files Browse the repository at this point in the history
  • Loading branch information
PBug90 committed Feb 18, 2020
1 parent 46b4228 commit 2efe873
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/W3GReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
CommandDataBlock,
ParserOutput,
PlayerChatMessageBlock,
Platform
Platform,
ExtraPlayerListEntry
} from './types'
import { sortPlayers } from './sort'

Expand Down Expand Up @@ -91,18 +92,23 @@ class W3GReplay extends ReplayParser {
return this.finalize()
}

handleMetaData (metaData: GameMetaDataDecoded) {
handleMetaData (metaData: GameMetaDataDecoded): void {
this.slots = metaData.playerSlotRecords
this.playerList = [metaData.player, ...metaData.playerList]
this.meta = metaData
const tempPlayers: {[key: string]: GameMetaDataDecoded['player'] } = {}
this.teams = []
this.players = {}

this.playerList.forEach((player: GameMetaDataDecoded['player']): void => {
tempPlayers[player.playerId] = player
})

if (metaData.extraPlayerList) {
metaData.extraPlayerList.forEach((extraPlayer: ExtraPlayerListEntry) => {
tempPlayers[extraPlayer.playerId].playerName = extraPlayer.name
})
}

this.slots.forEach((slot: SlotRecord) => {
if (slot.slotStatus > 1) {
this.teams[slot.teamId] = this.teams[slot.teamId] || []
Expand All @@ -115,7 +121,7 @@ class W3GReplay extends ReplayParser {
})
}

processGameDataBlock (block: GameDataBlock) {
processGameDataBlock (block: GameDataBlock): void {
switch (block.type) {
case 31:
case 30:
Expand Down Expand Up @@ -143,7 +149,7 @@ class W3GReplay extends ReplayParser {
})
}

processCommandDataBlock (block: CommandDataBlock) {
processCommandDataBlock (block: CommandDataBlock): void {
const currentPlayer = this.players[block.playerId]
currentPlayer.currentTimePlayed = this.totalTimeTracker
currentPlayer._lastActionWasDeselect = false
Expand All @@ -156,7 +162,7 @@ class W3GReplay extends ReplayParser {
}
}

handleActionBlock (action: ActionBlock, currentPlayer: Player) {
handleActionBlock (action: ActionBlock, currentPlayer: Player): void {
this.playerActionTracker[currentPlayer.id] = this.playerActionTracker[currentPlayer.id] || []
this.playerActionTracker[currentPlayer.id].push(action)

Expand Down
5 changes: 4 additions & 1 deletion src/parsers/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ const GameMetaDataReforged = (buildNo: number) => new Parser()
.array('extraPlayerList', {
type: new Parser()
.int8('preVars1')
.buffer('pre', { length: 4 })
.int8('pre1')
.int8('pre2')
.int8('playerId')
.int8('pre4')
.int8('nameLength')
.string('name', { length: 'nameLength' })
.skip(1)
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export interface SlotRecord {
handicapFlag: number;
}

export interface ExtraPlayerListEntry{
nameLength: number;
name: string;
playerId: number;
}

export interface GameMetaDataDecoded {
player: {
hasRecord?: number;
Expand Down Expand Up @@ -65,6 +71,7 @@ export interface GameMetaDataDecoded {
mapChecksum: string;
mapName: string;
creator: string;
extraPlayerList?: ExtraPlayerListEntry[];
}

export interface ActionBlock{
Expand Down

0 comments on commit 2efe873

Please sign in to comment.