package operate import ( "fmt" "joylink.club/ecs" "joylink.club/rtsssimulation/components" "joylink.club/rtsssimulation/system" ) const ( //道岔定位 SwitchNormalRate int8 = system.PercentageRateMin //道岔反位 SwitchReverseRate int8 = system.PercentageRateMax ) // 道岔定操 func FireSwitchDcj(w ecs.World, switchId string) error { return fireSwitchTurn(w, switchId, true) } // 道岔反操 func FireSwitchFcj(w ecs.World, switchId string) error { return fireSwitchTurn(w, switchId, false) } func fireSwitchTurn(w ecs.World, switchId string, turnNormal bool) error { var switchEntry *ecs.Entry = system.QueryEntityById(w, system.SwitchQuery, switchId) if switchEntry == nil { return fmt.Errorf("道岔[%s]的实体不存在", switchId) } relay := components.SwitchRelayStateComponent.Get(switchEntry) relay.DcJ = turnNormal relay.FcJ = !turnNormal // return nil }