This repository has been archived by the owner on Mar 7, 2022. It is now read-only.
/
loadout.go
100 lines (92 loc) · 2.09 KB
/
loadout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package app
import (
"regexp"
"strings"
"time"
)
//go:generate stringer -type SlotType
type SlotType int
const (
StUndef SlotType = iota
StFixed
StCore
StOptional
StHardpoint
StUtility
StDeco
)
type JeEngineering struct {
BlueprintName string
Level int
ExperimentalEffect string `json:",omitempty"`
}
type JeLdoModule struct {
Slot string
Item string
Engineering *JeEngineering `json:",omitempty"`
}
func (m *JeLdoModule) Type() SlotType {
if res, ok := jeSlotMap[m.Slot]; ok {
return res
}
// TODO do we need submatch
if match := jsOptRegex.FindStringSubmatch(m.Slot); match != nil {
return StOptional
}
if match := jsHardpRegex.FindStringSubmatch(m.Slot); match != nil {
if match[1] == "Tiny" {
return StUtility
}
return StHardpoint
}
switch {
case strings.HasPrefix(m.Slot, "Decal"):
return StDeco
case strings.HasPrefix(m.Slot, "ShipName"):
return StDeco
case strings.HasPrefix(m.Slot, "Bobble"):
return StDeco
case strings.HasPrefix(m.Slot, "ShipID"):
return StDeco
}
return StUndef
}
type JeLoadout struct {
Ts time.Time `json:"timestamp"`
CargoCapacity int
HullHealth int
HullValue int64
Rebuy int64
MaxJumpRange float64
Ship string
UnladenMass float64
ShipID int
ModulesValue int64
ShipIdent string
ShipName string
FuelCapacity struct {
Reserve float64
Main int
}
Modules []JeLdoModule
}
var (
jsOptRegex = regexp.MustCompile(`^Slot(\d+)_Size(\d+)$`)
jsHardpRegex = regexp.MustCompile(`^(.+)Hardpoint(\d+)$`)
jeSlotMap = map[string]SlotType{
"ShipCockpit": StFixed,
"CargoHatch": StFixed,
"PlanetaryApproachSuite": StFixed,
"Armour": StCore,
"PowerPlant": StCore,
"MainEngines": StCore,
"FrameShiftDrive": StCore,
"LifeSupport": StCore,
"PowerDistributor": StCore,
"Radar": StCore,
"FuelTank": StCore,
"WeaponColour": StDeco,
"EngineColour": StDeco,
"VesselVoice": StDeco,
}
)