49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package system
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"github.com/yohamta/donburi/filter"
|
||
"joylink.club/ecs"
|
||
"joylink.club/rtsssimulation/components"
|
||
"joylink.club/rtsssimulation/cstate"
|
||
)
|
||
|
||
type SignalSystem struct {
|
||
}
|
||
|
||
// 信号机显示状态查询
|
||
var signalQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SignalStateComponent))
|
||
|
||
// world 执行
|
||
func (me *SignalSystem) Update(world ecs.World) {
|
||
|
||
}
|
||
func NewSignalSystem() *SignalSystem {
|
||
return &SignalSystem{}
|
||
}
|
||
|
||
// 设置某个信号机的显示
|
||
// 返回值:true-设置成功,false-设置失败
|
||
func SetSignalDisplay(w ecs.World, signalId string, display cstate.SignalAspect) error {
|
||
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) {
|
||
var signalEntry *ecs.Entry = queryEntityById(w, signalQuery, signalId)
|
||
if signalEntry != nil {
|
||
return signalEntry, nil
|
||
} else {
|
||
return nil, fmt.Errorf("信号机[%s]的实体不存在", signalId)
|
||
}
|
||
}
|