Skip to content

Commit b07b06e

Browse files
committed
simplify processModelPreCacheUpdate()
- use map instead of anonymous struct - move to stringtables.go to reduce files
1 parent 3aeb632 commit b07b06e

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

model_precache.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

stringtables.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"encoding/binary"
66
"io"
77
"strconv"
8+
"strings"
89

910
bit "github.com/markus-wa/demoinfocs-golang/bitread"
11+
common "github.com/markus-wa/demoinfocs-golang/common"
1012
events "github.com/markus-wa/demoinfocs-golang/events"
1113
msg "github.com/markus-wa/demoinfocs-golang/msg"
1214
)
@@ -50,8 +52,8 @@ func (p *Parser) parseStringTables() {
5052
}
5153

5254
func (p *Parser) parseSingleStringTable(name string) {
53-
strings := p.bitReader.ReadSignedInt(16)
54-
for i := 0; i < strings; i++ {
55+
nStrings := p.bitReader.ReadSignedInt(16)
56+
for i := 0; i < nStrings; i++ {
5557
stringName := p.bitReader.ReadString()
5658
if len(stringName) >= 100 {
5759
panic("Someone said that Roy said I should panic")
@@ -246,3 +248,23 @@ func parsePlayerInfo(reader io.Reader) *playerInfo {
246248
br.Pool()
247249
return res
248250
}
251+
252+
var modelPreCacheSubstringToEq = map[string]common.EquipmentElement{
253+
"flashbang_dropped": common.EqFlash,
254+
"fraggrenade_dropped": common.EqHE,
255+
"smokegrenade_thrown": common.EqSmoke,
256+
"molotov_dropped": common.EqMolotov,
257+
"incendiarygrenade_dropped": common.EqIncendiary,
258+
"decoy_dropped": common.EqDecoy,
259+
// @micvbang TODO: add all other weapons too.
260+
}
261+
262+
func (p *Parser) processModelPreCacheUpdate() {
263+
for i, name := range p.modelPreCache {
264+
for eqName, eq := range modelPreCacheSubstringToEq {
265+
if strings.Contains(name, eqName) {
266+
p.grenadeModelIndices[i] = eq
267+
}
268+
}
269+
}
270+
}

0 commit comments

Comments
 (0)