添加道岔位置根据转辙机位置更新的系统

This commit is contained in:
walker 2023-09-28 16:36:25 +08:00
parent 04b1e2b6d7
commit fb39939e3b
2 changed files with 39 additions and 1 deletions

View File

@ -24,7 +24,7 @@ func LoadTurnouts(w ecs.World) error {
case proto.Turnout_ZDJ9_Double:
err = LoadTurnoutZdj9Two(w, turnout, entry, data.EntityMap)
default:
fmt.Println("id=", turnout.Id(), "的道岔没有转辙机类型")
err = fmt.Errorf("id=%s的道岔没有转辙机型号", turnout.Id())
}
if err != nil {
return err

38
sys/device_sys/turnout.go Normal file
View File

@ -0,0 +1,38 @@
package device_sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
// 道岔位置更新系统
type TurnoutSys struct {
query *ecs.Query
}
func NewTurnoutSys() *TurnoutSys {
return &TurnoutSys{
query: ecs.NewQuery(filter.Contains(component.TurnoutPositionType, component.TurnoutZzjType)),
}
}
func (s *TurnoutSys) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
zzjs := component.TurnoutZzjType.Get(entry)
tp := component.TurnoutPositionType.Get(entry)
dw := true
fw := true
for _, zzj := range zzjs.ZzjList {
state := component.ZzjStateType.Get(zzj)
if !(!state.JD12 && !state.JD34) {
dw = false
}
if !(state.JD12 && state.JD34) {
fw = false
}
}
tp.Dw = dw
tp.Fw = fw
})
}