2023-09-13 10:05:42 +08:00
|
|
|
package entities
|
|
|
|
|
|
|
|
import (
|
2023-09-21 16:28:13 +08:00
|
|
|
"github.com/yohamta/donburi/component"
|
2023-09-13 10:05:42 +08:00
|
|
|
"joylink.club/ecs"
|
2023-09-21 16:28:13 +08:00
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
2023-09-13 10:05:42 +08:00
|
|
|
"joylink.club/rtsssimulation/system"
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
|
|
func CreateTurnoutEntries(world ecs.World, turnouts []*repository.Turnout, systemTypeMap map[system.Type]bool) []*ecs.Entry {
|
|
|
|
var entries []*ecs.Entry
|
|
|
|
for _, turnout := range turnouts {
|
|
|
|
var components []component.IComponentType
|
|
|
|
components = append(components, system.EntityIdentityComponent)
|
|
|
|
loadZdj9Double := turnout.SwitchMachineType() == proto.Turnout_ZDJ9_Double && systemTypeMap[system.SWITCH_ZDJ9_2]
|
|
|
|
if loadZdj9Double {
|
|
|
|
components = append(components, system.Switch2jZdj9StateComponent)
|
|
|
|
}
|
|
|
|
entry := world.Create(components...)
|
|
|
|
entries = append(entries, entry)
|
|
|
|
system.EntityIdentityComponent.Set(entry, &system.EntityIdentity{Id: turnout.Id()})
|
|
|
|
if loadZdj9Double {
|
|
|
|
system.Switch2jZdj9StateComponent.Set(entry, system.NewSwitch2jZdj9State())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return entries
|
|
|
|
}
|