refactor(chess): 重构象棋程序基础结构,使用Nullable重构核心代码
- 更新了多个文件的代码结构和类型定义,提高了代码的健壮性和可维护性 - 优化了事件处理、棋子管理和移动逻辑,为后续功能扩展打下坚实基础 - 修复了一些潜在的空指针异常问题,提高了程序的稳定性 - 修复部分bug
This commit is contained in:
@ -9,12 +9,14 @@ public static class RPHelper
|
||||
return message.ToDictionary();
|
||||
}
|
||||
|
||||
public static RPMessage DeserializeRPMessage(Dictionary data)
|
||||
public static RPMessage? DeserializeRPMessage(Dictionary data)
|
||||
{
|
||||
return new RPMessage
|
||||
{
|
||||
Type = data.ContainsKey("type") ? (string)data["type"] : null,
|
||||
Cmd = data.ContainsKey("cmd") ? (string)data["cmd"] : null,
|
||||
if (!data.ContainsKey("type") || !data.ContainsKey("cmd")) {
|
||||
return null;
|
||||
}
|
||||
return new RPMessage {
|
||||
Type = (string)data["type"],
|
||||
Cmd = (string)data["cmd"],
|
||||
Code = data.ContainsKey("code") ? (string)data["code"] : null,
|
||||
Uid = data.ContainsKey("uid") ? (string)data["uid"] : null,
|
||||
Token = data.ContainsKey("token") ? (string)data["token"] : null,
|
||||
@ -28,7 +30,7 @@ public static class RPHelper
|
||||
ws.SendJsonEx(RPHelper.SerializeRPMessage(message));
|
||||
}
|
||||
|
||||
public static RPMessage HandleIncomingMessage(string jsonMessage)
|
||||
public static RPMessage? HandleIncomingMessage(string jsonMessage)
|
||||
{
|
||||
var dataDict = Json.ParseString(jsonMessage).AsGodotDictionary();
|
||||
if (dataDict != null)
|
||||
|
Reference in New Issue
Block a user