JS修改+距离计算修改 (#179)

- 替换大多数let为const
- 将一些双等号替换为三等号
- 距离计算追加“玩家自己与距离为0”设定,副作用是不显示自身距离
This commit is contained in:
YoumuKon 2023-06-09 01:16:23 +08:00 committed by GitHub
parent 713bbca17a
commit a6ad71c19f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 293 additions and 286 deletions

View File

@ -17,7 +17,7 @@ function createClientPages() {
var callbacks = {}; var callbacks = {};
let sheduled_download = ""; let sheduled_download = "";
callbacks["NetworkDelayTest"] = function(jsonData) { callbacks["NetworkDelayTest"] = (jsonData) => {
// jsonData: RSA pub key // jsonData: RSA pub key
let cipherText; let cipherText;
let aeskey; let aeskey;
@ -37,10 +37,10 @@ callbacks["NetworkDelayTest"] = function(jsonData) {
Backend.replyDelayTest(config.screenName, cipherText); Backend.replyDelayTest(config.screenName, cipherText);
} }
callbacks["ErrorMsg"] = function(jsonData) { callbacks["ErrorMsg"] = (jsonData) => {
let log; let log;
try { try {
let a = JSON.parse(jsonData); const a = JSON.parse(jsonData);
log = qsTr(a[0]).arg(a[1]); log = qsTr(a[0]).arg(a[1]);
} catch (e) { } catch (e) {
log = qsTr(jsonData); log = qsTr(jsonData);
@ -58,22 +58,22 @@ callbacks["ErrorMsg"] = function(jsonData) {
callbacks["UpdatePackage"] = (jsonData) => sheduled_download = jsonData; callbacks["UpdatePackage"] = (jsonData) => sheduled_download = jsonData;
callbacks["UpdateBusyText"] = function(jsonData) { callbacks["UpdateBusyText"] = (jsonData) => {
mainWindow.busyText = jsonData; mainWindow.busyText = jsonData;
} }
callbacks["DownloadComplete"] = function() { callbacks["DownloadComplete"] = () => {
mainWindow.busy = false; mainWindow.busy = false;
mainStack.currentItem.downloadComplete(); // should be pacman page mainStack.currentItem.downloadComplete(); // should be pacman page
} }
callbacks["BackToStart"] = function(jsonData) { callbacks["BackToStart"] = (jsonData) => {
while (mainStack.depth > 1) { while (mainStack.depth > 1) {
mainStack.pop(); mainStack.pop();
} }
} }
callbacks["EnterLobby"] = function(jsonData) { callbacks["EnterLobby"] = (jsonData) => {
// depth == 1 means the lobby page is not present in mainStack // depth == 1 means the lobby page is not present in mainStack
createClientPages(); createClientPages();
if (mainStack.depth === 1) { if (mainStack.depth === 1) {
@ -92,21 +92,22 @@ callbacks["EnterLobby"] = function(jsonData) {
mainWindow.busy = false; mainWindow.busy = false;
} }
callbacks["EnterRoom"] = function(jsonData) { callbacks["EnterRoom"] = (jsonData) => {
// jsonData: int capacity, int timeout // jsonData: int capacity, int timeout
let data = JSON.parse(jsonData); const data = JSON.parse(jsonData);
config.roomCapacity = data[0]; config.roomCapacity = data[0];
config.roomTimeout = data[1] - 1; config.roomTimeout = data[1] - 1;
let roomSettings = data[2]; const roomSettings = data[2];
config.enableFreeAssign = roomSettings.enableFreeAssign; config.enableFreeAssign = roomSettings.enableFreeAssign;
mainStack.push(room); mainStack.push(room);
mainWindow.busy = false; mainWindow.busy = false;
} }
callbacks["UpdateRoomList"] = function(jsonData) { callbacks["UpdateRoomList"] = (jsonData) => {
let current = mainStack.currentItem; // should be lobby const current = mainStack.currentItem; // should be lobby
if (mainStack.currentItem === lobby) {
current.roomModel.clear(); current.roomModel.clear();
JSON.parse(jsonData).forEach(function(room) { JSON.parse(jsonData).forEach(function (room) {
current.roomModel.append({ current.roomModel.append({
roomId: room[0], roomId: room[0],
roomName: room[1], roomName: room[1],
@ -116,26 +117,29 @@ callbacks["UpdateRoomList"] = function(jsonData) {
hasPassword: room[5] ? true : false, hasPassword: room[5] ? true : false,
}); });
}); });
}
} }
callbacks["UpdatePlayerNum"] = (j) => { callbacks["UpdatePlayerNum"] = (j) => {
let current = mainStack.currentItem; // should be lobby const current = mainStack.currentItem; // should be lobby
let data = JSON.parse(j); if (mainStack.currentItem === lobby) {
let l = data[0]; const data = JSON.parse(j);
let s = data[1]; const l = data[0];
const s = data[1];
current.lobbyPlayerNum = l; current.lobbyPlayerNum = l;
current.serverPlayerNum = s; current.serverPlayerNum = s;
}
} }
callbacks["Chat"] = function(jsonData) { callbacks["Chat"] = (jsonData) => {
// jsonData: { string userName, string general, string time, string msg } // jsonData: { string userName, string general, string time, string msg }
let current = mainStack.currentItem; // lobby or room const current = mainStack.currentItem; // lobby or room
let data = JSON.parse(jsonData); const data = JSON.parse(jsonData);
let pid = data.sender; const pid = data.sender;
let userName = data.userName; const userName = data.userName;
let general = Backend.translate(data.general); const general = Backend.translate(data.general);
let time = data.time; const time = data.time;
let msg = data.msg; const msg = data.msg;
if (general === "") if (general === "")
current.addToChat(pid, data, `[${time}] ${userName}: ${msg}`); current.addToChat(pid, data, `[${time}] ${userName}: ${msg}`);
@ -143,8 +147,8 @@ callbacks["Chat"] = function(jsonData) {
current.addToChat(pid, data, `[${time}] ${userName}(${general}): ${msg}`); current.addToChat(pid, data, `[${time}] ${userName}(${general}): ${msg}`);
} }
callbacks["ServerMessage"] = function(jsonData) { callbacks["ServerMessage"] = (jsonData) => {
let current = mainStack.currentItem; // lobby or room const current = mainStack.currentItem; // lobby or room
current.sendDanmaku('<font color="gold"><b>[Server] </b></font>' + jsonData); current.sendDanmaku('<font color="gold"><b>[Server] </b></font>' + jsonData);
} }

View File

@ -1,12 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
callbacks["UpdateAvatar"] = function(jsonData) { callbacks["UpdateAvatar"] = (jsonData) => {
mainWindow.busy = false; mainWindow.busy = false;
Self.avatar = jsonData; Self.avatar = jsonData;
toast.show("Update avatar done."); toast.show("Update avatar done.");
} }
callbacks["UpdatePassword"] = function(jsonData) { callbacks["UpdatePassword"] = (jsonData) => {
mainWindow.busy = false; mainWindow.busy = false;
if (jsonData === "1") if (jsonData === "1")
toast.show("Update password done."); toast.show("Update password done.");

File diff suppressed because it is too large Load Diff

View File

@ -397,7 +397,8 @@ end
--- 通过 二者位次+距离技能之和 与 两者间固定距离 进行对比,更大的为实际距离。 --- 通过 二者位次+距离技能之和 与 两者间固定距离 进行对比,更大的为实际距离。
---@param other Player @ 其他玩家 ---@param other Player @ 其他玩家
function Player:distanceTo(other) function Player:distanceTo(other)
assert(other:isInstanceOf(Player)) -- assert(other:isInstanceOf(Player))
if other == self then return 0 end
local right = 0 local right = 0
local temp = self local temp = self
while temp ~= other do while temp ~= other do