rts-sim-module/system/signal_system.go

49 lines
1.2 KiB
Go
Raw Normal View History

2023-08-15 18:12:30 +08:00
package system
import (
2023-08-18 16:45:05 +08:00
"fmt"
2023-08-15 18:12:30 +08:00
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
2023-08-23 15:13:06 +08:00
"joylink.club/rtsssimulation/components/cstate"
2023-08-15 18:12:30 +08:00
)
type SignalSystem struct {
}
// 信号机显示状态查询
2023-08-18 10:06:17 +08:00
var signalQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SignalStateComponent))
2023-08-15 18:12:30 +08:00
// world 执行
func (me *SignalSystem) Update(world ecs.World) {
}
2023-08-16 15:00:24 +08:00
func NewSignalSystem() *SignalSystem {
return &SignalSystem{}
}
2023-08-15 18:12:30 +08:00
// 设置某个信号机的显示
// 返回值true-设置成功false-设置失败
2023-08-22 11:00:14 +08:00
func SetSignalDisplay(w ecs.World, signalId string, display cstate.SignalAspect) error {
2023-08-18 16:45:05 +08:00
signalEntry, err := findSignalEntry(w, signalId)
if err != nil {
return err
}
//
signalState := components.SignalStateComponent.Get(signalEntry)
signalState.Display = display
//
return nil
}
// 获取信号机实体
func findSignalEntry(w ecs.World, signalId string) (*ecs.Entry, error) {
2023-08-22 15:04:46 +08:00
var signalEntry *ecs.Entry = queryEntityById(w, signalQuery, signalId)
2023-08-18 16:45:05 +08:00
if signalEntry != nil {
return signalEntry, nil
} else {
return nil, fmt.Errorf("信号机[%s]的实体不存在", signalId)
2023-08-15 18:12:30 +08:00
}
}