package entities import ( "time" "joylink.club/ecs" "joylink.club/rtsssimulation/deprecated/simulation" "joylink.club/rtsssimulation/deprecated/system" "joylink.club/rtsssimulation/repository" ) type Position int type TurnoutState struct { Id string Normal bool Reverse bool Turning bool } const ( SK Position = iota //四开(不会起名字) D //定位 F //反位 ) // CreateSwitch2jzdj9Entity 双机zdj9 // 默认定位 func CreateSwitch2jzdj9Entity(w ecs.World, switchId string) *ecs.Entry { e := w.Create(system.EntityIdentityComponent, system.Switch2jZdj9StateComponent, system.PercentageDeviceState1Component, system.PercentageDeviceState2Component) system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: switchId}) //电路 system.Switch2jZdj9StateComponent.Set(e, system.NewSwitch2jZdj9State()) //J1 j1 := system.NewPercentageDeviceStateM() //定位 system.PercentageDeviceState1Component.Set(e, j1) //J2 j2 := system.NewPercentageDeviceStateM() //定位 system.PercentageDeviceState2Component.Set(e, j2) return e } func CreateTurnoutEntries(world ecs.World, turnouts []*repository.Turnout) []*ecs.Entry { var entries []*ecs.Entry for _, turnout := range turnouts { if len(turnout.RelayGroups()) == 0 { continue } entries = append(entries, CreateSwitch2jzdj9Entity(world, turnout.Id())) } return entries } func TurnToNormal(worldId ecs.WorldId, turnoutId string) { sim := simulation.FindSimulation(worldId) system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true) system.Switch2jZdj9DriveDc(sim.World(), turnoutId, true) go func() { <-time.After(5 * time.Second) system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false) system.Switch2jZdj9DriveDc(sim.World(), turnoutId, false) }() } func TurnToReverse(worldId ecs.WorldId, turnoutId string) { sim := simulation.FindSimulation(worldId) system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true) system.Switch2jZdj9DriveFc(sim.World(), turnoutId, true) go func() { <-time.After(5 * time.Second) system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false) system.Switch2jZdj9DriveFc(sim.World(), turnoutId, false) }() } func GetTurnoutState(worldId ecs.WorldId, turnoutId string) *TurnoutState { sim := simulation.FindSimulation(worldId) entry := sim.GetEntry(turnoutId) if entry == nil { return nil } state := system.Switch2jZdj9StateComponent.Get(entry) return &TurnoutState{Id: turnoutId, Normal: state.IsNormal(), Reverse: state.IsReverse(), Turning: state.IsTurning()} }