[add] set ESlint

This commit is contained in:
建喵 2023-09-10 15:29:58 +08:00
parent 3e8d8ad058
commit 3dfff7ea54
9 changed files with 23 additions and 20 deletions

2
.eslintignore Normal file
View File

@ -0,0 +1,2 @@
src/utils
src/Engine

View File

@ -342,7 +342,7 @@
"memberVariableDeclaration": true,
"parameter": true,
"propertyDeclaration": true,
"variableDeclaration": false,
"variableDeclaration": true,
"variableDeclarationIgnoreFunction": true
}
]

View File

@ -19,10 +19,10 @@ export module NumberEx {
if (others.length > 0) {
return times(times(num1, num2), others[0], ...others.slice(1));
}
const num1Changed = num1.Float2Fixed();
const num2Changed = num2.Float2Fixed();
const baseNum = num1.DigitLength() + num2.DigitLength();
const leftValue = num1Changed * num2Changed;
const num1Changed: number = num1.Float2Fixed();
const num2Changed: number = num2.Float2Fixed();
const baseNum: number = num1.DigitLength() + num2.DigitLength();
const leftValue: number = num1Changed * num2Changed;
checkBoundary(leftValue);
@ -36,7 +36,7 @@ export module NumberEx {
if (others.length > 0) {
return plus(plus(num1, num2), others[0], ...others.slice(1));
}
const baseNum = Math.pow(10, Math.max(num1.DigitLength(), num2.DigitLength()));
const baseNum: number = Math.pow(10, Math.max(num1.DigitLength(), num2.DigitLength()));
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
}
@ -47,7 +47,7 @@ export module NumberEx {
if (others.length > 0) {
return minus(minus(num1, num2), others[0], ...others.slice(1));
}
const baseNum = Math.pow(10, Math.max(num1.DigitLength(), num2.DigitLength()));
const baseNum: number = Math.pow(10, Math.max(num1.DigitLength(), num2.DigitLength()));
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
}
@ -58,8 +58,8 @@ export module NumberEx {
if (others.length > 0) {
return divide(divide(num1, num2), others[0], ...others.slice(1));
}
const num1Changed = num1.Float2Fixed();
const num2Changed = num2.Float2Fixed();
const num1Changed: number = num1.Float2Fixed();
const num2Changed: number = num2.Float2Fixed();
checkBoundary(num1Changed);
checkBoundary(num2Changed);
return times((num1Changed / num2Changed), Math.pow(10, num2.DigitLength() - num1.DigitLength()));
@ -69,11 +69,11 @@ export module NumberEx {
*
*/
export function round(num: number, ratio: number): number {
const base = Math.pow(10, ratio);
const base: number = Math.pow(10, ratio);
return divide(Math.round(times(num, base)), base);
}
let _boundaryCheckingState = false;
let _boundaryCheckingState: boolean = false;
/**
*
* @param flag true false

View File

@ -5,7 +5,7 @@ import { ServiceType } from "../../shared/protocols/serviceProto";
export default async function (call: ApiCall<ReqCreate, ResCreate>) {
const conn: BaseConnection<ServiceType> = call.conn;
const room = new Room();
const room: Room = new Room();
room.Join(conn);
conn.Room = room;
call.succ(room.RoomId);

View File

@ -6,7 +6,7 @@ import { ServiceType } from "../../shared/protocols/serviceProto";
export default async function (call: ApiCall<ReqJoin, ResJoin>) {
const { roomId } = call.req;
const conn: BaseConnection<ServiceType> = call.conn;
const room = Room.GetRoom(roomId);
const room: Room = Room.GetRoom(roomId);
if (room) {
if (room.ConnCount() >= 2) {
call.error("房間已滿");

View File

@ -1,11 +1,12 @@
import { ApiCall } from "tsrpc";
import Lobby from "../../component/Lobby/Lobby";
import Room from "../../component/Room/Room";
import { ReqList, ResList } from "../../shared/protocols/room/PtlList";
export default async function (call: ApiCall<ReqList, ResList>) {
const data: any[] = [];
for (let i = 0; i < Lobby.Room.length; i++) {
const room = Lobby.Room[i];
for (let i: number = 0; i < Lobby.Room.length; i++) {
const room: Room = Lobby.Room[i];
data.push(room.RoomId);
}
call.succ(data);

View File

@ -28,7 +28,7 @@ export default class Lobby {
/** DelConns */
public static DelConns(conn: BaseConnection): void {
for (let i = 0; i < this.conns.length; i++) {
for (let i: number = 0; i < this.conns.length; i++) {
if (this.conns[i] === conn) {
this.conns.splice(i, 1);
break;

View File

@ -1,5 +1,6 @@
import { BaseConnection, WsConnection } from "tsrpc";
import { server } from "../..";
import { RandomEx } from "../../Engine/Utils/Number/RandomEx";
import { ServiceType } from "../../shared/protocols/serviceProto";
@ -38,6 +39,8 @@ export default class Room {
// 给每个新房间生成一个唯一的 ID
this.RoomId = ++Room.maxRoomId;
Room.rooms[this.RoomId] = this;
const now: number = RandomEx.GetInt(0, 2);
}
//#endregion

View File

@ -17,7 +17,7 @@ dotenv.config();
// Create the Server
const port: number = +process.env.PORT || 3000;
export const server = new WsServer(serviceProto, {
export const server: WsServer<ServiceType> = new WsServer(serviceProto, {
port: port,
// Remove this to use binary mode (remove from the client too)
json: true
@ -28,9 +28,6 @@ async function init() {
await server.autoImplementApi(path.resolve(__dirname, "api"));
// Prepare something... (e.g. connect the db)
// server.flows.postConnectFlow.push((conn) => {
// Lobby.AddConns(conn);
// });
server.flows.postConnectFlow.push((conn: BaseConnection<ServiceType>) => {
Lobby.AddConns(conn);
console.log(`${conn.ip} is connected`);