59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package memory
|
|
|
|
import (
|
|
"fmt"
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
|
"joylink.club/bj-rtsts-server/sys_error"
|
|
appcomponent "joylink.club/bj-rtsts-server/ts/simulation/app_component"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"joylink.club/rtsssimulation/fi"
|
|
"unsafe"
|
|
)
|
|
|
|
func CkmOperation(simulation *VerifySimulation, req *request_proto.CkmOperationReq) *sys_error.BusinessError {
|
|
switch req.Operation {
|
|
case request_proto.Ckm_SetParams:
|
|
return setParam(simulation, req)
|
|
default:
|
|
panic(fmt.Sprintf("未知的屏蔽门操作:%s", req.Operation))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func CkmBoxOperation(sim *VerifySimulation, req *request_proto.CkmBoxOperationReq) *sys_error.BusinessError {
|
|
uid := QueryUidStructure[*StationUidStructure](req.MapId)
|
|
ckmBoxBtnUid := uid.CkmBoxIds[req.CkmBoxId].Uid
|
|
var err error
|
|
if req.Down {
|
|
err = fi.PressDownButton(sim.World, ckmBoxBtnUid+"_"+req.ButtonCode)
|
|
} else {
|
|
err = fi.PressUpButton(sim.World, ckmBoxBtnUid+"_"+req.ButtonCode)
|
|
}
|
|
if err != nil {
|
|
return sys_error.New("车库门控制盒操作失败", err)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func setParam(simulation *VerifySimulation, req *request_proto.CkmOperationReq) *sys_error.BusinessError {
|
|
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.GarageDoor{})
|
|
result := <-ecs.Request[ecs.EmptyType](simulation.World, func() ecs.Result[ecs.EmptyType] {
|
|
wd := entity.GetWorldData(simulation.World)
|
|
entry, ok := wd.EntityMap[uid]
|
|
if ok {
|
|
entry.AddComponent(appcomponent.CkmParamType, unsafe.Pointer(req.Param))
|
|
} else {
|
|
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的实体", uid))
|
|
}
|
|
return ecs.NewOkEmptyResult()
|
|
})
|
|
if result.Err != nil {
|
|
return sys_error.New("车库门设置参数失败", result.Err)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|