Implement KeepUpdated. Switch to Logrus logger. Relocate score-related functions.
This commit is contained in:
@@ -5,14 +5,15 @@ import (
|
||||
"InfantrySkillCalculator/utils"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var gameMetrics models.GameMetrics
|
||||
|
||||
func LoadMetrics() {
|
||||
f, err := os.Open("./config/metrics.json")
|
||||
if err != nil {
|
||||
log.Fatal("Failed to open metrics.json: ", err)
|
||||
utils.Logger.Fatal("Failed to open metrics.json: ", err)
|
||||
}
|
||||
defer func(f *os.File) {
|
||||
_ = f.Close()
|
||||
@@ -20,13 +21,31 @@ func LoadMetrics() {
|
||||
|
||||
data, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to read metrics.json: ", err)
|
||||
utils.Logger.Fatal("Failed to read metrics.json: ", err)
|
||||
}
|
||||
|
||||
var metrics models.GameMetrics
|
||||
if err := json.Unmarshal(data, &metrics); err != nil {
|
||||
log.Fatal("Failed to deserialize metrics.json: ", err)
|
||||
utils.Logger.Fatal("Failed to deserialize metrics.json: ", err)
|
||||
}
|
||||
|
||||
utils.GameMetrics = metrics
|
||||
gameMetrics = metrics
|
||||
}
|
||||
|
||||
func GetGameMetric(gameTag string) *models.GameMetric {
|
||||
for _, metric := range gameMetrics.GameMetrics {
|
||||
if metric.GameName == gameTag {
|
||||
return &metric
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FindWeaponMetric(weaponMetrics []models.WeaponMetric, weaponCategory string) *models.WeaponMetric {
|
||||
for _, metric := range weaponMetrics {
|
||||
if metric.WeaponCategory == weaponCategory {
|
||||
return &metric
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user