diff --git a/jl-ecs-go b/jl-ecs-go index 200352e..4997760 160000 --- a/jl-ecs-go +++ b/jl-ecs-go @@ -1 +1 @@ -Subproject commit 200352eb58f1704a741d367e3c8afd02ae492b58 +Subproject commit 4997760ffb1284a7898ab84164671d5e21ec9248 diff --git a/repository/model.go b/repository/model.go index ea1fda6..4e0c6ed 100644 --- a/repository/model.go +++ b/repository/model.go @@ -44,8 +44,6 @@ type IRelayCRole interface { type IModelManager interface { //FindById 根据模型的复合id获取模型数据 FindById(id string) Identity - //FindByType 获取某类型设备的所有模型数据 - FindByType(deviceType proto.DeviceType) []Identity } // IPsdModel 仿真底层屏蔽门模型 diff --git a/repository/repository.go b/repository/repository.go index 9d049ec..8c9ff0c 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -39,6 +39,20 @@ func newRepository(id string, version string) *Repository { } } +// FindById 根据模型的复合id获取模型数据 +func (repo *Repository) FindById(id string) Identity { + if md, ok := repo.turnoutMap[id]; ok { + return md + } + if md, ok := repo.signalMap[id]; ok { + return md + } + if md, ok := repo.relayMap[id]; ok { + return md + } + return nil +} + func (repo *Repository) PhysicalSectionList() []*PhysicalSection { var list []*PhysicalSection for _, model := range repo.physicalSectionMap { diff --git a/repository/turnout.go b/repository/turnout.go index 64d21e1..1a5b222 100644 --- a/repository/turnout.go +++ b/repository/turnout.go @@ -3,7 +3,6 @@ package repository import ( "errors" "fmt" - "joylink.club/rtsssimulation/repository/model/proto" ) @@ -53,6 +52,39 @@ func NewTurnout(id string, km *proto.Kilometer, switchMachineType proto.Turnout_ } } +// FindCircuitRoleById 根据继电器id获取在具体电路中的电路角色 +// relayId-继电器id +// relayGroup-继电器组合类型 +// relayName-继电器在电路中的名称 +// find-true找到,false未找到 +func (t *Turnout) FindCircuitRoleById(relayId string) (relayGroup string, relayName string, find bool) { + if t.relayGroups != nil { + for _, rg := range t.relayGroups { + for _, relay := range rg.relays { + if relayId == relay.Id() { + return rg.code, relay.code, true + } + } + } + } + return "", "", false +} + +// FindRelayModelByCRole 根据继电器具体电路角色来获取继电器设备模型 +// relayGroup-继电器组合类型 +// relayName-继电器在电路中的名称 +func (t *Turnout) FindRelayModelByCRole(relayGroup string, relayName string) Identity { + if t.relayGroups != nil { + for _, rg := range t.relayGroups { + for _, relay := range rg.relays { + if rg.code == relayGroup && relay.code == relayName { + return relay + } + } + } + } + return nil +} func (t *Turnout) PortNum() int { return 3 } diff --git a/system/button_system.go b/system/button_system.go new file mode 100644 index 0000000..d8e0500 --- /dev/null +++ b/system/button_system.go @@ -0,0 +1,27 @@ +package system + +import "joylink.club/ecs" + +// ButtonState 广义按钮状态 +// 广义按钮在电路中作用为开关,至于是pressed接通电路还是released接通电路,要看具体电路 +type ButtonState struct { + //true-pressed,false-released + Pos bool +} + +// AutoReleaseState 广义按钮为自复位按钮时的自复位状态 +type AutoReleaseState struct { + //true-自复位按钮,false-非自复位按钮 + enable bool + //自复位剩余时间,ms + releaseTime int64 +} + +func NewButtonState() *ButtonState { + return &ButtonState{false} +} + +var ( + ButtonStateComponent = ecs.NewComponentType[ButtonState]() + AutoReleaseStateComponent = ecs.NewComponentType[AutoReleaseState]() +) diff --git a/system/spks_system.go b/system/spks_system.go new file mode 100644 index 0000000..5008a66 --- /dev/null +++ b/system/spks_system.go @@ -0,0 +1,6 @@ +package system + +//车站人员防护开关电路 + +type SpksCircuitState struct { +} diff --git a/system/system.go b/system/system.go index 7ff282d..95f9f1c 100644 --- a/system/system.go +++ b/system/system.go @@ -2,6 +2,7 @@ package system import ( "fmt" + "joylink.club/rtsssimulation/simulation" "github.com/yohamta/donburi/component" "github.com/yohamta/donburi/filter" @@ -38,10 +39,17 @@ func QueryEntityById(world ecs.World, q *ecs.Query, id string) *ecs.Entry { var modelStorageQuery = ecs.NewQuery(filter.Contains(ModelStorageComponent)) +// 测试用 +var xXDebug = false + // FindModelStorage 获取模型仓库 func FindModelStorage(world ecs.World) IModelManager { - e, _ := modelStorageQuery.First(world) - return ModelStorageComponent.Get(e).ModelManager + if xXDebug { + e, _ := modelStorageQuery.First(world) + return ModelStorageComponent.Get(e).ModelManager + } else { + return simulation.FindSimulation(world.Id()).GetRepo() + } } // 捕获panic并恢复执行