rts-sim-module/deprecated/test1/tstorages/storage_manager.go

75 lines
1.8 KiB
Go
Raw Normal View History

2023-08-24 10:27:50 +08:00
package tstorages
import (
"fmt"
"joylink.club/rtsssimulation/deprecated/system"
2023-09-21 16:23:03 +08:00
"joylink.club/rtsssimulation/repository/model/proto"
2023-08-24 10:27:50 +08:00
)
// 共享仓库映射
var ShareStoragesMapper *ModelStoragesMapper = &ModelStoragesMapper{storages: make(map[string]*ModelStorage)}
////////////////////////////////////////////////
type StorageKey struct {
LineId string
Version string
}
func (me *StorageKey) Key() string {
return fmt.Sprintf("%s||%s", me.LineId, me.Version)
}
////////////////////////////////////
type ModelStoragesMapper struct {
//共享模型仓库
//key-StorageKey
storages map[string]*ModelStorage
}
func (me *ModelStoragesMapper) FindShareModelStorage(skey StorageKey) *ModelStorage {
return me.storages[skey.Key()]
}
func (me *ModelStoragesMapper) AddShareModelStorage(skey StorageKey, storage *ModelStorage) {
me.storages[skey.Key()] = storage
}
// 通过共享模型仓库创建world模型仓库
func (me *ModelStoragesMapper) CreateWorldStorageWithShare(skey StorageKey, links *ModelStorage) *WorldModelStorage {
return &WorldModelStorage{Share: me.storages[skey.Key()], Links: links}
}
///////////////////////////////////
// 仿真world的模型仓库
type WorldModelStorage struct {
// 对公共模型的指针
Share *ModelStorage
// 该world独享的轨道模型
Links *ModelStorage
}
// 根据模型的复合id获取模型数据
2023-09-22 10:53:51 +08:00
func (me *WorldModelStorage) FindById(id string) system.IDeviceModel {
2023-08-24 10:27:50 +08:00
md := me.Links.FindModelById(id)
2023-08-28 16:33:00 +08:00
if md != nil {
2023-08-24 10:27:50 +08:00
return md
}
md = me.Share.FindModelById(id)
2023-08-28 16:33:00 +08:00
if md != nil {
2023-08-24 10:27:50 +08:00
return md
}
return nil
}
// 获取某类型设备的所有模型数据
2023-09-22 10:53:51 +08:00
func (me *WorldModelStorage) FindByType(deviceType system.DeviceType) []system.IDeviceModel {
2023-09-21 16:23:03 +08:00
if proto.DeviceType_DeviceType_Link == deviceType {
2023-08-24 10:27:50 +08:00
return me.Links.FindModelsByType(deviceType)
} else {
return me.Share.FindModelsByType(deviceType)
}
}