dev: 更新代码,并准备LuaMod
This commit is contained in:
@ -1,31 +1,22 @@
|
||||
#nullable disable
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using ChineseChess;
|
||||
|
||||
public partial class ChessGame : Node2D {
|
||||
ChessBoard board;
|
||||
GlobalManager global = GlobalManager.Instance;
|
||||
ConfirmationDialog dialog;
|
||||
readonly Logging.Logger logger = Logging.GetLogger("ChessGame");
|
||||
ChessBoard board = null!;
|
||||
ConfirmationDialog dialog = null!;
|
||||
ChessCore Game = null!;
|
||||
private bool isSession = false;
|
||||
ChessCore Game;
|
||||
ChessCore.TurnsSideType sideSelf;
|
||||
ChessCore.TurnsSideType sideOpposite;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready() {
|
||||
// Init.Call();
|
||||
board = GetNode<ChessBoard>("Chessboard");
|
||||
// ChessGameAPI api = new();
|
||||
// api.BindToLua(global.ModManager.lua);
|
||||
|
||||
// isSession = global.RPClient.IsOnline();
|
||||
|
||||
GetNode<LineEdit>("Control/VBoxContainer/MarginContainer3/HFlowContainer/LineEdit")
|
||||
.Text = global.GlobalData["player_color"].AsString();
|
||||
LineEdit turnSideEdit = GetNode<LineEdit>("Control/VBoxContainer/MarginContainer3/HFlowContainer/LineEdit2");
|
||||
board = GetNode<ChessBoard>("%Chessboard");
|
||||
GetNode<LineEdit>("%LineEdit_YouAre").Text = global.GlobalData["player_color"].AsString();
|
||||
LineEdit turnSideEdit = GetNode<LineEdit>("%LineEdit_TurnSide");
|
||||
turnSideEdit.Text = "red";
|
||||
// GD.Print("ChessGame uid:", global.RPClient.GetUserId(), " color:",global.GlobalData["player_color"]);
|
||||
|
||||
dialog = new ConfirmationDialog {
|
||||
DialogAutowrap = true,
|
||||
@ -52,107 +43,32 @@ public partial class ChessGame : Node2D {
|
||||
int posX = (int)pos.X;
|
||||
int posY = (int)pos.Y;
|
||||
Vector.Vector2I vector = new(posX, posY);
|
||||
if (isSession) {
|
||||
Game.OnPosClicked(vector, ChessCore.PlayerSideType.Self);
|
||||
// var res = global.RPClient.SendSessionToAll(global.sessionId, new Dictionary {
|
||||
// {"type", "mouseClicked"},
|
||||
// {"X", pos.X},
|
||||
// {"Y", pos.Y},
|
||||
// {"id", global.RPClient.GetUserId()}
|
||||
// });
|
||||
} else {
|
||||
Game.OnPosClicked(vector);
|
||||
}
|
||||
Game.OnPosClicked(vector);
|
||||
};
|
||||
|
||||
if (isSession) {
|
||||
GD.Print("ws is connected");
|
||||
|
||||
// global.RPClient.OnPRCSessionExit += (cmd, code) => {
|
||||
// GoHome();
|
||||
// };
|
||||
|
||||
// global.RPClient.OnPRCSessionRecv += (msg) => {
|
||||
// SessionMsgHandle(msg["msg"].AsGodotDictionary());
|
||||
// };
|
||||
}
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta) {
|
||||
}
|
||||
|
||||
// private void SessionMsgHandle(Dictionary msg) {
|
||||
// GD.PrintErr($"session msg: {msg}");
|
||||
// switch (msg["type"].AsString()) {
|
||||
// case "over":
|
||||
// if (global.RPClient.GetUserId() == msg["id"].AsString()) {
|
||||
// break;
|
||||
// }
|
||||
// dialog.Title = "Opponent Finished";
|
||||
// dialog.DialogText = "Turn On You\n";
|
||||
// dialog.Visible = true;
|
||||
// break;
|
||||
// case "mouseClicked":
|
||||
// if (msg["id"].ToString() == global.RPClient.GetUserId()) {
|
||||
// break;
|
||||
// }
|
||||
// Vector2 mouseClicked = new(GD.StrToVar(msg["X"].ToString()).AsInt32(),
|
||||
// GD.StrToVar(msg["Y"].ToString()).AsInt32());
|
||||
// Vector.Vector2I vector = new((int)mouseClicked.X, (int)mouseClicked.Y);
|
||||
// Game.OnPosClicked(vector, ChessCore.PlayerSideType.Opponent);
|
||||
// break;
|
||||
// case "undo":
|
||||
// Game.Undo();
|
||||
// break;
|
||||
// case "reInit":
|
||||
// Game.ReInit();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
private void BtnOver() {
|
||||
GD.Print($"BtnOver {isSession}");
|
||||
if (isSession == false) {
|
||||
return;
|
||||
}
|
||||
// global.RPClient.SendSessionToAll(global.sessionId, new Dictionary{
|
||||
// {"type", "over"},
|
||||
// {"id", global.RPClient.GetUserId()},
|
||||
// });
|
||||
logger.Info($"BtnOver");
|
||||
}
|
||||
|
||||
public void GoHome() {
|
||||
// if (global.RPClient.IsOnline()) {
|
||||
// global.RPClient.ExitServer();
|
||||
// }
|
||||
// TODO ClearServer();
|
||||
global.GotoScene("res://Main.tscn");
|
||||
}
|
||||
|
||||
public void Undo() {
|
||||
GD.Print($"Undo {isSession}");
|
||||
|
||||
if (isSession) {
|
||||
// global.RPClient.SendSessionToAll(global.sessionId, new Dictionary{
|
||||
// {"type", "undo"},
|
||||
// {"id", global.RPClient.GetUserId()},
|
||||
// });
|
||||
} else {
|
||||
if (Game.board.Steps == 0) board.Clear();
|
||||
Game.Undo();
|
||||
}
|
||||
logger.Info($"Undo");
|
||||
if (Game.board.Steps == 0) board.Clear();
|
||||
Game.Undo();
|
||||
}
|
||||
|
||||
public void ReInit() {
|
||||
GD.PrintErr($"ReInit {isSession}");
|
||||
|
||||
if (isSession) {
|
||||
// global.RPClient.SendSessionToAll(global.sessionId, new Dictionary{
|
||||
// {"type", "reInit"},
|
||||
// });
|
||||
} else {
|
||||
Game.ReInit();
|
||||
board.Clear();
|
||||
}
|
||||
// TODO using dialog to confirm
|
||||
logger.Info($"ReInit");
|
||||
Game.ReInit();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user