54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
|
package entity
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"joylink.club/ecs"
|
||
|
"joylink.club/rtsssimulation/component"
|
||
|
"joylink.club/rtsssimulation/repository"
|
||
|
"joylink.club/rtsssimulation/repository/model/proto"
|
||
|
)
|
||
|
|
||
|
// 加载道岔实体
|
||
|
func LoadTurnouts(w ecs.World) error {
|
||
|
data := GetWorldData(w)
|
||
|
turnouts := data.Repo.TurnoutList()
|
||
|
for _, turnout := range turnouts {
|
||
|
entry := NewTurnoutEntity(w, turnout.Id(), data)
|
||
|
var err error
|
||
|
switch turnout.SwitchMachineType() {
|
||
|
case proto.Turnout_ZDJ9_Single:
|
||
|
err = LoadTurnoutZdj9One(w, turnout, entry)
|
||
|
case proto.Turnout_ZDJ9_Double:
|
||
|
err = LoadTurnoutZdj9Two(w, turnout, entry)
|
||
|
default:
|
||
|
fmt.Println("id=", turnout.Id(), "的道岔没有转辙机类型")
|
||
|
}
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// 加载道岔ZDJ9单机转辙机
|
||
|
func LoadTurnoutZdj9One(w ecs.World, turnout *repository.Turnout, entry *ecs.Entry) error {
|
||
|
panic("unimplemented")
|
||
|
}
|
||
|
|
||
|
// 加载道岔ZDJ9双机转辙机
|
||
|
func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Entry) error {
|
||
|
panic("unimplemented")
|
||
|
}
|
||
|
|
||
|
// 新建道岔实体
|
||
|
func NewTurnoutEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
|
||
|
entry, ok := worldData.EntityMap[uid]
|
||
|
if !ok {
|
||
|
entry = w.Create(component.TurnoutTag, component.UidType, component.TurnoutPositionType)
|
||
|
component.UidType.Set(entry, &component.Uid{Id: uid})
|
||
|
worldData.EntityMap[uid] = entry
|
||
|
}
|
||
|
return entry
|
||
|
}
|