121 lines
3.1 KiB
Go
121 lines
3.1 KiB
Go
package system
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
)
|
|
|
|
//站台紧急停车按钮
|
|
|
|
type EmpsCircuitState struct {
|
|
//ture-按钮开关接通常开点
|
|
XEMPFA bool
|
|
//ture-按钮开关接通常开点
|
|
SEMPFA bool
|
|
//ture-灯亮
|
|
XEMPD bool
|
|
//ture-灯亮
|
|
SEMPD bool
|
|
//ture-按钮开关接通常开点
|
|
SDA bool
|
|
//true-蜂鸣器响
|
|
FMQ bool
|
|
//ture-按钮开关接通常开点
|
|
QBA bool
|
|
//ture-继电器吸起,接通常开点
|
|
XEMPJ bool
|
|
//ture-继电器吸起,接通常开点
|
|
SEMPJ bool
|
|
//EMP-X ture-按钮开关接通常开点
|
|
XEMPA bool
|
|
//EMP-S ture-按钮开关接通常开点
|
|
SEMPA bool
|
|
//EMP1 ture-按钮开关接通常开点
|
|
EMP1A bool
|
|
//EMP2 ture-按钮开关接通常开点
|
|
EMP2A bool
|
|
//EMP3 ture-按钮开关接通常开点
|
|
EMP3A bool
|
|
//EMP4 ture-按钮开关接通常开点
|
|
EMP4A bool
|
|
//EMP5 ture-按钮开关接通常开点
|
|
EMP5A bool
|
|
//EMP6 ture-按钮开关接通常开点
|
|
EMP6A bool
|
|
}
|
|
type EmpsCircuitSystem struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewEmpsCircuitSystem() *EmpsCircuitSystem {
|
|
return &EmpsCircuitSystem{query: ecs.NewQuery(filter.Contains(EmpsCircuitStateComponent))}
|
|
}
|
|
func NewEmpsCircuitState() *EmpsCircuitState {
|
|
return &EmpsCircuitState{
|
|
//ture-按钮开关接通常开点
|
|
XEMPFA: false,
|
|
//ture-按钮开关接通常开点
|
|
SEMPFA: false,
|
|
//ture-灯亮
|
|
XEMPD: false,
|
|
//ture-灯亮
|
|
SEMPD: false,
|
|
//ture-按钮开关接通常开点
|
|
SDA: false,
|
|
//true-蜂鸣器响
|
|
FMQ: false,
|
|
//ture-按钮开关接通常开点
|
|
QBA: false,
|
|
//ture-继电器吸起,接通常开点
|
|
XEMPJ: true,
|
|
//ture-继电器吸起,接通常开点
|
|
SEMPJ: true,
|
|
//EMP-X ture-按钮开关接通常开点
|
|
XEMPA: true,
|
|
//EMP-S ture-按钮开关接通常开点
|
|
SEMPA: true,
|
|
//EMP1 ture-按钮开关接通常开点
|
|
EMP1A: true,
|
|
//EMP2 ture-按钮开关接通常开点
|
|
EMP2A: true,
|
|
//EMP3 ture-按钮开关接通常开点
|
|
EMP3A: true,
|
|
//EMP4 ture-按钮开关接通常开点
|
|
EMP4A: true,
|
|
//EMP5 ture-按钮开关接通常开点
|
|
EMP5A: true,
|
|
//EMP6 ture-按钮开关接通常开点
|
|
EMP6A: true,
|
|
}
|
|
}
|
|
|
|
var (
|
|
EmpsCircuitStateComponent = ecs.NewComponentType[EmpsCircuitState]()
|
|
)
|
|
|
|
// Update world 执行
|
|
func (me *EmpsCircuitSystem) Update(w ecs.World) {
|
|
me.query.Each(w, func(e *ecs.Entry) {
|
|
state := EmpsCircuitStateComponent.Get(e)
|
|
me.calculateXEMPJ(state)
|
|
me.calculateSEMPJ(state)
|
|
me.calculateEMPD(state)
|
|
me.calculateFMQ(state)
|
|
})
|
|
}
|
|
func (me *EmpsCircuitSystem) calculateXEMPJ(state *EmpsCircuitState) {
|
|
state.XEMPJ = state.XEMPFA || state.XEMPJ && state.XEMPA && state.EMP5A && state.EMP3A && state.EMP1A
|
|
}
|
|
func (me *EmpsCircuitSystem) calculateSEMPJ(state *EmpsCircuitState) {
|
|
state.SEMPJ = state.SEMPFA || state.SEMPJ && state.SEMPA && state.EMP6A && state.EMP4A && state.EMP2A
|
|
}
|
|
func (me *EmpsCircuitSystem) calculateEMPD(state *EmpsCircuitState) {
|
|
state.XEMPD = state.SDA || !state.XEMPJ
|
|
state.SEMPD = state.SDA || !state.SEMPJ
|
|
}
|
|
|
|
// 蜂鸣器运算
|
|
func (me *EmpsCircuitSystem) calculateFMQ(state *EmpsCircuitState) {
|
|
state.FMQ = state.QBA && state.XEMPJ && state.SEMPJ || !state.QBA && (!state.XEMPJ || !state.SEMPJ)
|
|
}
|