spks电路

This commit is contained in:
xzb 2023-09-26 14:00:40 +08:00
parent ff6910ed7b
commit 0dfade56ad

View File

@ -13,6 +13,10 @@ type SpksCircuitState struct {
SPKSS2JA bool
//ture-按钮开关接通常开点
SPKSS4JA bool
//ture-按钮开关接通常开点
SPKSXPLA bool
//ture-按钮开关接通常开点
SPKSSPLA bool
//true-灯亮
SPKSX1D bool
//true-灯亮
@ -41,13 +45,77 @@ type SpksCircuitState struct {
SPKSSPLAJ bool
}
type SpksCircuitSystem struct {
query *ecs.Query
}
var (
SpksCircuitStateComponent = ecs.NewComponentType[SpksCircuitState]()
)
func NewSpksCircuitState() *SpksCircuitState {
return &SpksCircuitState{
SPKSX1JA: true,
SPKSX3JA: true,
SPKSS2JA: true,
SPKSS4JA: true,
SPKSXPLA: false,
SPKSSPLA: false,
SPKSX1D: false,
SPKSX3D: false,
SPKSS2D: false,
SPKSS4D: false,
SPKSXPLAD: false,
SPKSSPLAD: false,
SDA: false,
SPKSX1J: true,
SPKSX3J: true,
SPKSS2J: true,
SPKSS4J: true,
SPKSXPLAJ: false,
SPKSSPLAJ: false,
}
}
// Update world 执行
func (me *SpksCircuitSystem) Update(w ecs.World) {
me.query.Each(w, func(e *ecs.Entry) {
state := SpksCircuitStateComponent.Get(e)
_state := &(*state)
//
me.calculateSpksD(state)
me.calculateSPKSXJ(state)
me.calculateSPKSSJ(state)
me.calculateSPKSPLAJ(state)
me.calculateChange(state, _state)
})
}
// 亮灯运算
func (me *SpksCircuitSystem) calculateSpksD(state *SpksCircuitState) {
state.SPKSX1D = state.SDA || !state.SPKSX1J
state.SPKSX3D = state.SDA || !state.SPKSX3J
state.SPKSS2D = state.SDA || !state.SPKSS2J
state.SPKSS4D = state.SDA || !state.SPKSS4J
state.SPKSXPLAD = state.SDA || state.SPKSXPLAJ
state.SPKSSPLAD = state.SDA || state.SPKSSPLAJ
}
func (me *SpksCircuitSystem) calculateSPKSXJ(state *SpksCircuitState) {
state.SPKSX1J = state.SPKSX1JA || state.SPKSXPLAJ
state.SPKSX3J = state.SPKSX3JA || state.SPKSXPLAJ
}
func (me *SpksCircuitSystem) calculateSPKSSJ(state *SpksCircuitState) {
state.SPKSS2J = state.SPKSS2JA || state.SPKSSPLAJ
state.SPKSS4J = state.SPKSS4JA || state.SPKSSPLAJ
}
func (me *SpksCircuitSystem) calculateSPKSPLAJ(state *SpksCircuitState) {
state.SPKSXPLAJ = state.SPKSXPLA
state.SPKSSPLAJ = state.SPKSSPLA
}
// 状态改变运算,通过pre与cur比较如果某个状态改变则发送对应事件
func (me *SpksCircuitSystem) calculateChange(curState *SpksCircuitState, preState *SpksCircuitState) {
if curState.SPKSX1J != preState.SPKSX1J {
//继电器状态需要改变
}
}