-
Notifications
You must be signed in to change notification settings - Fork 1
/
shiparch.go
143 lines (121 loc) · 4.43 KB
/
shiparch.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package ship_mapped
import (
"github.com/darklab8/fl-configs/configs/configs_mapped/parserutils/filefind/file"
"github.com/darklab8/fl-configs/configs/configs_mapped/parserutils/iniload"
"github.com/darklab8/fl-configs/configs/configs_mapped/parserutils/semantic"
"github.com/darklab8/fl-configs/configs/settings/logus"
"github.com/darklab8/go-typelog/typelog"
)
type Ship struct {
semantic.Model
Nickname *semantic.String // matches value `ship` in goods
ShipClass *semantic.Int
Type *semantic.String
IdsName *semantic.Int
IdsInfo *semantic.Int
IdsInfo1 *semantic.Int
IdsInfo2 *semantic.Int
IdsInfo3 *semantic.Int
Nanobots *semantic.Int
Batteries *semantic.Int
Mass *semantic.Float
LinearDrag *semantic.Float
HoldSize *semantic.Int
HitPts *semantic.Int
NudgeForce *semantic.Float
StrafeForce *semantic.Float
ShieldLink *ShieldLink
HpTypes []*HpType
SteeringTorque *semantic.Vect
AngularDrag *semantic.Vect
RotationIntertia *semantic.Vect
/*
Some info in Goods with category shiphull, it has link from [Ship] to hulll
Some is good ship, it has stuff leading to [Power], [Engine], [Scanner] and [ShieldGenerator]
*/
}
type HpType struct {
semantic.Model
Nickname *semantic.String
AllowedEquipments []*semantic.String
}
type ShieldLink struct {
semantic.Model
ShieldClass *semantic.String
}
type Config struct {
Files []*iniload.IniLoader
Ships []*Ship
ShipsMap map[string]*Ship
}
func Read(files []*iniload.IniLoader) *Config {
frelconfig := &Config{Files: files}
frelconfig.Ships = make([]*Ship, 0, 100)
frelconfig.ShipsMap = make(map[string]*Ship)
for _, Iniconfig := range files {
for _, section := range Iniconfig.SectionMap["[Ship]"] {
ship := &Ship{
Nickname: semantic.NewString(section, "nickname", semantic.WithLowercaseS(), semantic.WithoutSpacesS()),
Type: semantic.NewString(section, "type"),
ShipClass: semantic.NewInt(section, "ship_class"),
IdsName: semantic.NewInt(section, "ids_name"),
IdsInfo: semantic.NewInt(section, "ids_info"),
IdsInfo1: semantic.NewInt(section, "ids_info1"),
IdsInfo2: semantic.NewInt(section, "ids_info2"),
IdsInfo3: semantic.NewInt(section, "ids_info3"),
Nanobots: semantic.NewInt(section, "nanobot_limit"),
Batteries: semantic.NewInt(section, "shield_battery_limit"),
Mass: semantic.NewFloat(section, "mass", semantic.Precision(2)),
LinearDrag: semantic.NewFloat(section, "linear_drag", semantic.Precision(2)),
HoldSize: semantic.NewInt(section, "hold_size"),
NudgeForce: semantic.NewFloat(section, "nudge_force", semantic.Precision(2)),
StrafeForce: semantic.NewFloat(section, "strafe_force", semantic.Precision(2)),
ShieldLink: &ShieldLink{
ShieldClass: semantic.NewString(section, "shield_link", semantic.WithLowercaseS(), semantic.WithoutSpacesS()),
},
HitPts: semantic.NewInt(section, "hit_pts"),
SteeringTorque: semantic.NewVector(section, "steering_torque", semantic.Precision(2)),
AngularDrag: semantic.NewVector(section, "angular_drag", semantic.Precision(2)),
RotationIntertia: semantic.NewVector(section, "rotation_inertia", semantic.Precision(2)),
}
ship.Map(section)
ship.ShieldLink.Map(section)
for index, param := range section.ParamMap["hp_type"] {
hp_type := &HpType{
Nickname: semantic.NewString(section, "hp_type",
semantic.OptsS(semantic.Index(index)),
semantic.WithLowercaseS(), semantic.WithoutSpacesS()),
}
for order_i, _ := range param.Values[1:] {
hp_type.AllowedEquipments = append(hp_type.AllowedEquipments,
semantic.NewString(section, "hp_type",
semantic.OptsS(semantic.Index(index), semantic.Order(order_i+1)),
semantic.WithLowercaseS(), semantic.WithoutSpacesS()),
)
}
hp_type.Map(section)
ship.HpTypes = append(ship.HpTypes, hp_type)
}
func() {
defer func() {
if r := recover(); r != nil {
logus.Log.Debug("Recovered from grabbing ship IdsName. Error:\n", typelog.Any("recover", r))
}
}()
ship.IdsName.Get()
frelconfig.Ships = append(frelconfig.Ships, ship)
frelconfig.ShipsMap[ship.Nickname.Get()] = ship
}()
}
}
return frelconfig
}
func (frelconfig *Config) Write() []*file.File {
var files []*file.File
for _, file := range frelconfig.Files {
inifile := file.Render()
inifile.Write(inifile.File)
files = append(files, inifile.File)
}
return files
}