rts-sim-module/deprecated/entities/switch_entity.go
walker 0bba8f0934 删除donburi包引用
修改filter导入为从ecs项目导入
整理包结构,将弃用的包放入deprecated文件中
2023-10-09 11:17:25 +08:00

88 lines
2.5 KiB
Go

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()}
}