【处理IBP不存在的按钮实体】

This commit is contained in:
weizhihong 2023-12-07 10:43:20 +08:00
parent 7545bd2ca6
commit 83f49b80c9

View File

@ -2,6 +2,7 @@ package message_server
import ( import (
"fmt" "fmt"
"log/slog"
"time" "time"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -96,7 +97,8 @@ func (ms *IbpMs) collectIBPButtonState(stationUid string, uidsMap *memory.IBPUid
uid := stationUid + "_" + uidsMap.IbpButtonIds[data.Common.Id].Uid uid := stationUid + "_" + uidsMap.IbpButtonIds[data.Common.Id].Uid
entry, ok := entity.GetEntityByUid(ms.vs.World, uid) entry, ok := entity.GetEntityByUid(ms.vs.World, uid)
if !ok { if !ok {
return nil, fmt.Errorf("ibp按钮实体不存在: World id=%d, uid=%s", ms.vs.World.Id(), uid) slog.Warn("ibp按钮实体不存在: World id=%d, uid=%s", ms.vs.World.Id(), uid)
continue
} }
if entry.HasComponent(component.ButtonTag) { if entry.HasComponent(component.ButtonTag) {
states = append(states, getIBPButtonState(data.Common.Id, entry)) states = append(states, getIBPButtonState(data.Common.Id, entry))
@ -125,7 +127,8 @@ func (ms *IbpMs) collectIBPAlarmState(stationUid string, uidsMap *memory.IBPUidS
uid := stationUid + "_" + uidsMap.IbpAlarmIds[data.Common.Id].Uid uid := stationUid + "_" + uidsMap.IbpAlarmIds[data.Common.Id].Uid
entry, ok := entity.GetEntityByUid(ms.vs.World, uid) entry, ok := entity.GetEntityByUid(ms.vs.World, uid)
if !ok { if !ok {
return nil, fmt.Errorf("ibp报警器实体不存在: World id=%d, uid=%s", ms.vs.World.Id(), uid) slog.Warn("ibp报警器实体不存在: World id=%d, uid=%s", ms.vs.World.Id(), uid)
continue
} }
if entry.HasComponent(component.AlarmTag) { if entry.HasComponent(component.AlarmTag) {
states = append(states, &state.AlarmState{Id: data.Common.Id, Active: component.BitStateType.Get(entry).Val}) states = append(states, &state.AlarmState{Id: data.Common.Id, Active: component.BitStateType.Get(entry).Val})
@ -141,7 +144,8 @@ func (ms *IbpMs) collectIBPLightState(stationUid string, uidsMap *memory.IBPUidS
uid := stationUid + "_" + uidsMap.IbpLightIds[data.Common.Id].Uid uid := stationUid + "_" + uidsMap.IbpLightIds[data.Common.Id].Uid
entry, ok := entity.GetEntityByUid(ms.vs.World, uid) entry, ok := entity.GetEntityByUid(ms.vs.World, uid)
if !ok { if !ok {
return nil, fmt.Errorf("ibp指示灯实体不存在: World id=%d, uid=%s", ms.vs.World.Id(), uid) slog.Warn("ibp指示灯实体不存在: World id=%d, uid=%s", ms.vs.World.Id(), uid)
continue
} }
if entry.HasComponent(component.LightTag) { if entry.HasComponent(component.LightTag) {
states = append(states, &state.LightState{Id: data.Common.Id, Active: component.BitStateType.Get(entry).Val}) states = append(states, &state.LightState{Id: data.Common.Id, Active: component.BitStateType.Get(entry).Val})
@ -157,7 +161,8 @@ func (ms *IbpMs) collectIBPKeyState(stationUid string, uidsMap *memory.IBPUidStr
uid := stationUid + "_" + uidsMap.IbpKeyIds[data.Common.Id].Uid uid := stationUid + "_" + uidsMap.IbpKeyIds[data.Common.Id].Uid
entry, ok := entity.GetEntityByUid(ms.vs.World, uid) entry, ok := entity.GetEntityByUid(ms.vs.World, uid)
if !ok { if !ok {
return nil, fmt.Errorf("ibp钥匙实体不存在: World id=%d, uid=%s", ms.vs.World.Id(), uid) slog.Warn("ibp钥匙实体不存在: World id=%d, uid=%s", ms.vs.World.Id(), uid)
continue
} }
if entry.HasComponent(component.KeyTag) { if entry.HasComponent(component.KeyTag) {
states = append(states, &state.KeyState{Id: data.Common.Id, Gear: component.GearStateType.Get(entry).Val}) states = append(states, &state.KeyState{Id: data.Common.Id, Gear: component.GearStateType.Get(entry).Val})