2022-03-24 21:23:42 +08:00
|
|
|
var callbacks = {};
|
|
|
|
|
|
|
|
callbacks["NetworkDelayTest"] = function(jsonData) {
|
2022-03-27 14:49:41 +08:00
|
|
|
ClientInstance.notifyServer("Setup", JSON.stringify([
|
2022-03-24 21:23:42 +08:00
|
|
|
config.screenName,
|
|
|
|
config.password
|
|
|
|
]));
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
|
|
|
callbacks["ErrorMsg"] = function(jsonData) {
|
2022-04-01 20:51:01 +08:00
|
|
|
console.log("ERROR: " + jsonData);
|
2022-03-27 14:49:41 +08:00
|
|
|
toast.show(jsonData, 5000);
|
2022-03-23 19:40:28 +08:00
|
|
|
mainWindow.busy = false;
|
|
|
|
}
|
|
|
|
|
2022-03-27 14:49:41 +08:00
|
|
|
callbacks["BackToStart"] = function(jsonData) {
|
|
|
|
while (mainStack.depth > 1) {
|
|
|
|
mainStack.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 19:40:28 +08:00
|
|
|
callbacks["EnterLobby"] = function(jsonData) {
|
|
|
|
// depth == 1 means the lobby page is not present in mainStack
|
|
|
|
if (mainStack.depth === 1) {
|
|
|
|
mainStack.push(lobby);
|
2022-03-24 21:23:42 +08:00
|
|
|
} else {
|
|
|
|
mainStack.pop();
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
mainWindow.busy = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["EnterRoom"] = function(jsonData) {
|
2022-03-30 14:14:40 +08:00
|
|
|
// jsonData: int capacity, int timeout
|
|
|
|
let data = JSON.parse(jsonData);
|
|
|
|
config.roomCapacity = data[0];
|
|
|
|
config.roomTimeout = data[1];
|
2022-03-23 19:40:28 +08:00
|
|
|
mainStack.push(room);
|
|
|
|
mainWindow.busy = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks["UpdateRoomList"] = function(jsonData) {
|
|
|
|
let current = mainStack.currentItem; // should be lobby
|
|
|
|
current.roomModel.clear();
|
|
|
|
JSON.parse(jsonData).forEach(function(room) {
|
|
|
|
current.roomModel.append({
|
|
|
|
roomId: room[0],
|
|
|
|
roomName: room[1],
|
|
|
|
gameMode: room[2],
|
|
|
|
playerNum: room[3],
|
|
|
|
capacity: room[4],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|