48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package entities
|
|
|
|
import (
|
|
"github.com/yohamta/donburi/component"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/repository"
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
"joylink.club/rtsssimulation/system"
|
|
)
|
|
|
|
// 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, 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
|
|
}
|