78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package catalogs
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"sync"
|
|
)
|
|
|
|
var _ = json.RawMessage{}
|
|
var _ = sync.Mutex{}
|
|
var _ = os.ReadFile
|
|
var _ = filepath.Join
|
|
|
|
type VehicleCatalogEntry4229938 struct {
|
|
Id uint32 `json:"id"`
|
|
Name string `json:"name"`
|
|
Model string `json:"model"`
|
|
SeatCount int32 `json:"seatCount"`
|
|
SpoonName string `json:"spoonName"`
|
|
VehicleType int32 `json:"vehicleType"`
|
|
}
|
|
|
|
//
|
|
// Build-4229938 vehicle catalog, read from VehicleConfig.json in the configured
|
|
// client-data directory (field names verified against ConfigDump_v3 + lua writers).
|
|
//
|
|
var (
|
|
VehicleCatalog4229938_cacheLock sync.RWMutex
|
|
VehicleCatalog4229938_cached = false
|
|
VehicleCatalog4229938_entries []any
|
|
)
|
|
|
|
// LoadVehicleCatalog4229938 loads catalog records from client config directory
|
|
func LoadVehicleCatalog4229938(configDir string) ([]any, error) {
|
|
VehicleCatalog4229938_cacheLock.RLock()
|
|
if VehicleCatalog4229938_cached {
|
|
defer VehicleCatalog4229938_cacheLock.RUnlock()
|
|
return VehicleCatalog4229938_entries, nil
|
|
}
|
|
VehicleCatalog4229938_cacheLock.RUnlock()
|
|
|
|
VehicleCatalog4229938_cacheLock.Lock()
|
|
defer VehicleCatalog4229938_cacheLock.Unlock()
|
|
if VehicleCatalog4229938_cached { return VehicleCatalog4229938_entries, nil }
|
|
|
|
filePath := filepath.Join(configDir, "VehicleCatalog.json.json")
|
|
data, err := os.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var raw struct {
|
|
Records []json.RawMessage `json:"records"`
|
|
}
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var result []any
|
|
for _, item := range raw.Records {
|
|
var m map[string]any
|
|
if err := json.Unmarshal(item, &m); err == nil {
|
|
result = append(result, m)
|
|
}
|
|
}
|
|
|
|
VehicleCatalog4229938_entries = result
|
|
VehicleCatalog4229938_cached = true
|
|
return result, nil
|
|
}
|
|
|
|
func VehicleCatalog4229938_TryGet(id uint32, entry VehicleCatalogEntry4229938) bool {
|
|
// Catalog helper VehicleCatalog4229938_TryGet
|
|
return false
|
|
}
|
|
|