package system import ( "joylink.club/ecs" "joylink.club/ecs/filter" ) // SpksCircuitState 车站人员防护开关电路 type SpksCircuitState struct { //ture-按钮开关接通常开点 SPKSX1JA bool //ture-按钮开关接通常开点 SPKSX3JA bool //ture-按钮开关接通常开点 SPKSS2JA bool //ture-按钮开关接通常开点 SPKSS4JA bool //ture-按钮开关接通常开点 SPKSXPLA bool //ture-按钮开关接通常开点 SPKSSPLA bool //true-灯亮 SPKSX1D bool //true-灯亮 SPKSX3D bool //true-灯亮 SPKSS2D bool //true-灯亮 SPKSS4D bool //true-灯亮 SPKSXPLAD bool //true-灯亮 SPKSSPLAD bool //ture-按钮开关接通常开点 SDA bool //ture-继电器吸起,接通常开点 SPKSX1J bool //ture-继电器吸起,接通常开点 SPKSX3J bool //ture-继电器吸起,接通常开点 SPKSS2J bool //ture-继电器吸起,接通常开点 SPKSS4J bool //ture-继电器吸起,接通常开点 SPKSXPLAJ bool //ture-继电器吸起,接通常开点 SPKSSPLAJ bool } type SpksCircuitSystem struct { query *ecs.Query } var ( SpksCircuitStateComponent = ecs.NewComponentType[SpksCircuitState]() ) func NewSpksCircuitSystem() *SpksCircuitSystem { return &SpksCircuitSystem{query: ecs.NewQuery(filter.Contains(SpksCircuitStateComponent))} } 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 { //继电器状态需要改变 } }