This repository has been archived on 2026-10-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

94 lines
2.5 KiB
Go

package catalogs
import (
"encoding/json"
"os"
"path/filepath"
"sync"
)
var _ = json.RawMessage{}
var _ = sync.Mutex{}
var _ = os.ReadFile
var _ = filepath.Join
//
// 改装店改装件的落盘(save/vehicles/<pid>.json)。
// <para>为什么需要:donor 最初把购买结果只放在 WorldEntryState 的内存字典里,
// 服务端一重启买过的件全没了(donor backlog #2 的原话)。买一次就要写一次盘 —— 没有可靠的
// session-end 钩子,所以走「每次购买后立刻写」。</para>
// <para>开关 gameplay.repairShop.persistTuning(默认 false = 与 donor 默认一致):
// 关掉时本类只读不写,行为完全等同 donor 未接 store 时的样子。</para>
// <para>写盘用 tmp + move 的原子替换,避免写一半崩掉留下截断的 json。</para>
//
var (
VehicleTuningStore_cacheLock sync.RWMutex
VehicleTuningStore_cached = false
VehicleTuningStore_entries []any
)
// LoadVehicleTuningStore loads catalog records from client config directory
func LoadVehicleTuningStore(configDir string) ([]any, error) {
VehicleTuningStore_cacheLock.RLock()
if VehicleTuningStore_cached {
defer VehicleTuningStore_cacheLock.RUnlock()
return VehicleTuningStore_entries, nil
}
VehicleTuningStore_cacheLock.RUnlock()
VehicleTuningStore_cacheLock.Lock()
defer VehicleTuningStore_cacheLock.Unlock()
if VehicleTuningStore_cached { return VehicleTuningStore_entries, nil }
filePath := filepath.Join(configDir, "VehicleTuningStore.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)
}
}
VehicleTuningStore_entries = result
VehicleTuningStore_cached = true
return result, nil
}
func VehicleTuningStore_PathFor(pid uint64) string {
// Catalog helper VehicleTuningStore_PathFor
return ""
}
// 把当前会话的改装状态写盘。开关关闭或 world 为空时直接返回。
func VehicleTuningStore_Save(pid uint64, world *any) {
// Catalog helper VehicleTuningStore_Save
}
type SaveFile struct {
Vehicles []VehicleDto `json:"vehicles"`
}
type VehicleDto struct {
ConfigId uint32 `json:"configId"`
SuitId uint32 `json:"suitId"`
Parts []PartDto `json:"parts"`
}
type PartDto struct {
Type uint32 `json:"type"`
ConfigId uint32 `json:"configId"`
}