2023-09-13 10:05:42 +08:00
|
|
|
package entities
|
|
|
|
|
|
|
|
import (
|
2023-09-26 15:27:12 +08:00
|
|
|
"time"
|
|
|
|
|
2023-09-13 10:05:42 +08:00
|
|
|
"joylink.club/ecs"
|
2023-10-09 11:17:25 +08:00
|
|
|
"joylink.club/rtsssimulation/deprecated/simulation"
|
|
|
|
"joylink.club/rtsssimulation/deprecated/system"
|
2023-09-21 16:28:13 +08:00
|
|
|
"joylink.club/rtsssimulation/repository"
|
2023-09-13 10:05:42 +08:00
|
|
|
)
|
|
|
|
|
2023-09-26 13:45:00 +08:00
|
|
|
type Position int
|
|
|
|
|
2023-09-27 10:28:55 +08:00
|
|
|
type TurnoutState struct {
|
2023-09-27 14:11:53 +08:00
|
|
|
Id string
|
2023-09-27 10:28:55 +08:00
|
|
|
Normal bool
|
|
|
|
Reverse bool
|
|
|
|
Turning bool
|
|
|
|
}
|
|
|
|
|
2023-09-26 13:45:00 +08:00
|
|
|
const (
|
|
|
|
SK Position = iota //四开(不会起名字)
|
|
|
|
D //定位
|
|
|
|
F //反位
|
|
|
|
)
|
|
|
|
|
2023-09-15 13:50:15 +08:00
|
|
|
// CreateSwitch2jzdj9Entity 双机zdj9
|
2023-09-14 13:52:36 +08:00
|
|
|
// 默认定位
|
2023-09-13 10:05:42 +08:00
|
|
|
func CreateSwitch2jzdj9Entity(w ecs.World, switchId string) *ecs.Entry {
|
2023-09-15 15:07:41 +08:00
|
|
|
e := w.Create(system.EntityIdentityComponent,
|
|
|
|
system.Switch2jZdj9StateComponent,
|
2023-09-21 15:22:22 +08:00
|
|
|
system.PercentageDeviceState1Component,
|
|
|
|
system.PercentageDeviceState2Component)
|
2023-09-13 10:05:42 +08:00
|
|
|
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: switchId})
|
2023-09-13 18:03:55 +08:00
|
|
|
//电路
|
|
|
|
system.Switch2jZdj9StateComponent.Set(e, system.NewSwitch2jZdj9State())
|
|
|
|
//J1
|
2023-09-21 15:22:22 +08:00
|
|
|
j1 := system.NewPercentageDeviceStateM() //定位
|
|
|
|
system.PercentageDeviceState1Component.Set(e, j1)
|
2023-09-13 18:03:55 +08:00
|
|
|
//J2
|
2023-09-21 15:22:22 +08:00
|
|
|
j2 := system.NewPercentageDeviceStateM() //定位
|
|
|
|
system.PercentageDeviceState2Component.Set(e, j2)
|
2023-09-13 10:05:42 +08:00
|
|
|
return e
|
|
|
|
}
|
2023-09-21 16:28:13 +08:00
|
|
|
|
2023-09-26 10:25:00 +08:00
|
|
|
func CreateTurnoutEntries(world ecs.World, turnouts []*repository.Turnout) []*ecs.Entry {
|
2023-09-21 16:28:13 +08:00
|
|
|
var entries []*ecs.Entry
|
|
|
|
for _, turnout := range turnouts {
|
2023-09-26 10:25:00 +08:00
|
|
|
if len(turnout.RelayGroups()) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2023-09-27 10:05:59 +08:00
|
|
|
entries = append(entries, CreateSwitch2jzdj9Entity(world, turnout.Id()))
|
2023-09-21 16:28:13 +08:00
|
|
|
}
|
|
|
|
return entries
|
|
|
|
}
|
2023-09-26 10:25:00 +08:00
|
|
|
|
|
|
|
func TurnToNormal(worldId ecs.WorldId, turnoutId string) {
|
|
|
|
sim := simulation.FindSimulation(worldId)
|
2023-09-26 14:53:37 +08:00
|
|
|
system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true)
|
2023-09-27 10:05:59 +08:00
|
|
|
system.Switch2jZdj9DriveDc(sim.World(), turnoutId, true)
|
2023-09-26 14:53:37 +08:00
|
|
|
go func() {
|
2023-09-27 10:05:59 +08:00
|
|
|
<-time.After(5 * time.Second)
|
2023-09-26 14:53:37 +08:00
|
|
|
system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false)
|
2023-09-27 10:05:59 +08:00
|
|
|
system.Switch2jZdj9DriveDc(sim.World(), turnoutId, false)
|
2023-09-26 14:53:37 +08:00
|
|
|
}()
|
2023-09-26 10:25:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TurnToReverse(worldId ecs.WorldId, turnoutId string) {
|
|
|
|
sim := simulation.FindSimulation(worldId)
|
2023-09-26 14:53:37 +08:00
|
|
|
system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true)
|
2023-09-27 10:05:59 +08:00
|
|
|
system.Switch2jZdj9DriveFc(sim.World(), turnoutId, true)
|
2023-09-26 14:53:37 +08:00
|
|
|
go func() {
|
2023-09-27 10:05:59 +08:00
|
|
|
<-time.After(5 * time.Second)
|
2023-09-26 14:53:37 +08:00
|
|
|
system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false)
|
2023-09-27 10:05:59 +08:00
|
|
|
system.Switch2jZdj9DriveFc(sim.World(), turnoutId, false)
|
2023-09-26 14:53:37 +08:00
|
|
|
}()
|
2023-09-26 10:25:00 +08:00
|
|
|
}
|
2023-09-26 13:45:00 +08:00
|
|
|
|
2023-09-27 17:12:15 +08:00
|
|
|
func GetTurnoutState(worldId ecs.WorldId, turnoutId string) *TurnoutState {
|
2023-09-26 13:45:00 +08:00
|
|
|
sim := simulation.FindSimulation(worldId)
|
2023-09-27 14:11:53 +08:00
|
|
|
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()}
|
2023-09-26 13:45:00 +08:00
|
|
|
}
|