[add] set ESlint
This commit is contained in:
parent
3e8d8ad058
commit
3dfff7ea54
2
.eslintignore
Normal file
2
.eslintignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
src/utils
|
||||||
|
src/Engine
|
@ -342,7 +342,7 @@
|
|||||||
"memberVariableDeclaration": true,
|
"memberVariableDeclaration": true,
|
||||||
"parameter": true,
|
"parameter": true,
|
||||||
"propertyDeclaration": true,
|
"propertyDeclaration": true,
|
||||||
"variableDeclaration": false,
|
"variableDeclaration": true,
|
||||||
"variableDeclarationIgnoreFunction": true
|
"variableDeclarationIgnoreFunction": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -19,10 +19,10 @@ export module NumberEx {
|
|||||||
if (others.length > 0) {
|
if (others.length > 0) {
|
||||||
return times(times(num1, num2), others[0], ...others.slice(1));
|
return times(times(num1, num2), others[0], ...others.slice(1));
|
||||||
}
|
}
|
||||||
const num1Changed = num1.Float2Fixed();
|
const num1Changed: number = num1.Float2Fixed();
|
||||||
const num2Changed = num2.Float2Fixed();
|
const num2Changed: number = num2.Float2Fixed();
|
||||||
const baseNum = num1.DigitLength() + num2.DigitLength();
|
const baseNum: number = num1.DigitLength() + num2.DigitLength();
|
||||||
const leftValue = num1Changed * num2Changed;
|
const leftValue: number = num1Changed * num2Changed;
|
||||||
|
|
||||||
checkBoundary(leftValue);
|
checkBoundary(leftValue);
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ export module NumberEx {
|
|||||||
if (others.length > 0) {
|
if (others.length > 0) {
|
||||||
return plus(plus(num1, num2), others[0], ...others.slice(1));
|
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;
|
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ export module NumberEx {
|
|||||||
if (others.length > 0) {
|
if (others.length > 0) {
|
||||||
return minus(minus(num1, num2), others[0], ...others.slice(1));
|
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;
|
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +58,8 @@ export module NumberEx {
|
|||||||
if (others.length > 0) {
|
if (others.length > 0) {
|
||||||
return divide(divide(num1, num2), others[0], ...others.slice(1));
|
return divide(divide(num1, num2), others[0], ...others.slice(1));
|
||||||
}
|
}
|
||||||
const num1Changed = num1.Float2Fixed();
|
const num1Changed: number = num1.Float2Fixed();
|
||||||
const num2Changed = num2.Float2Fixed();
|
const num2Changed: number = num2.Float2Fixed();
|
||||||
checkBoundary(num1Changed);
|
checkBoundary(num1Changed);
|
||||||
checkBoundary(num2Changed);
|
checkBoundary(num2Changed);
|
||||||
return times((num1Changed / num2Changed), Math.pow(10, num2.DigitLength() - num1.DigitLength()));
|
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 {
|
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);
|
return divide(Math.round(times(num, base)), base);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _boundaryCheckingState = false;
|
let _boundaryCheckingState: boolean = false;
|
||||||
/**
|
/**
|
||||||
* 是否进行边界检查
|
* 是否进行边界检查
|
||||||
* @param flag 标记开关,true 为开启,false 为关闭
|
* @param flag 标记开关,true 为开启,false 为关闭
|
||||||
|
@ -5,7 +5,7 @@ import { ServiceType } from "../../shared/protocols/serviceProto";
|
|||||||
|
|
||||||
export default async function (call: ApiCall<ReqCreate, ResCreate>) {
|
export default async function (call: ApiCall<ReqCreate, ResCreate>) {
|
||||||
const conn: BaseConnection<ServiceType> = call.conn;
|
const conn: BaseConnection<ServiceType> = call.conn;
|
||||||
const room = new Room();
|
const room: Room = new Room();
|
||||||
room.Join(conn);
|
room.Join(conn);
|
||||||
conn.Room = room;
|
conn.Room = room;
|
||||||
call.succ(room.RoomId);
|
call.succ(room.RoomId);
|
||||||
|
@ -6,7 +6,7 @@ import { ServiceType } from "../../shared/protocols/serviceProto";
|
|||||||
export default async function (call: ApiCall<ReqJoin, ResJoin>) {
|
export default async function (call: ApiCall<ReqJoin, ResJoin>) {
|
||||||
const { roomId } = call.req;
|
const { roomId } = call.req;
|
||||||
const conn: BaseConnection<ServiceType> = call.conn;
|
const conn: BaseConnection<ServiceType> = call.conn;
|
||||||
const room = Room.GetRoom(roomId);
|
const room: Room = Room.GetRoom(roomId);
|
||||||
if (room) {
|
if (room) {
|
||||||
if (room.ConnCount() >= 2) {
|
if (room.ConnCount() >= 2) {
|
||||||
call.error("房間已滿");
|
call.error("房間已滿");
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { ApiCall } from "tsrpc";
|
import { ApiCall } from "tsrpc";
|
||||||
import Lobby from "../../component/Lobby/Lobby";
|
import Lobby from "../../component/Lobby/Lobby";
|
||||||
|
import Room from "../../component/Room/Room";
|
||||||
import { ReqList, ResList } from "../../shared/protocols/room/PtlList";
|
import { ReqList, ResList } from "../../shared/protocols/room/PtlList";
|
||||||
|
|
||||||
export default async function (call: ApiCall<ReqList, ResList>) {
|
export default async function (call: ApiCall<ReqList, ResList>) {
|
||||||
const data: any[] = [];
|
const data: any[] = [];
|
||||||
for (let i = 0; i < Lobby.Room.length; i++) {
|
for (let i: number = 0; i < Lobby.Room.length; i++) {
|
||||||
const room = Lobby.Room[i];
|
const room: Room = Lobby.Room[i];
|
||||||
data.push(room.RoomId);
|
data.push(room.RoomId);
|
||||||
}
|
}
|
||||||
call.succ(data);
|
call.succ(data);
|
||||||
|
@ -28,7 +28,7 @@ export default class Lobby {
|
|||||||
|
|
||||||
/** DelConns */
|
/** DelConns */
|
||||||
public static DelConns(conn: BaseConnection): void {
|
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) {
|
if (this.conns[i] === conn) {
|
||||||
this.conns.splice(i, 1);
|
this.conns.splice(i, 1);
|
||||||
break;
|
break;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { BaseConnection, WsConnection } from "tsrpc";
|
import { BaseConnection, WsConnection } from "tsrpc";
|
||||||
import { server } from "../..";
|
import { server } from "../..";
|
||||||
|
import { RandomEx } from "../../Engine/Utils/Number/RandomEx";
|
||||||
import { ServiceType } from "../../shared/protocols/serviceProto";
|
import { ServiceType } from "../../shared/protocols/serviceProto";
|
||||||
|
|
||||||
|
|
||||||
@ -38,6 +39,8 @@ export default class Room {
|
|||||||
// 给每个新房间生成一个唯一的 ID
|
// 给每个新房间生成一个唯一的 ID
|
||||||
this.RoomId = ++Room.maxRoomId;
|
this.RoomId = ++Room.maxRoomId;
|
||||||
Room.rooms[this.RoomId] = this;
|
Room.rooms[this.RoomId] = this;
|
||||||
|
|
||||||
|
const now: number = RandomEx.GetInt(0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
@ -17,7 +17,7 @@ dotenv.config();
|
|||||||
|
|
||||||
// Create the Server
|
// Create the Server
|
||||||
const port: number = +process.env.PORT || 3000;
|
const port: number = +process.env.PORT || 3000;
|
||||||
export const server = new WsServer(serviceProto, {
|
export const server: WsServer<ServiceType> = new WsServer(serviceProto, {
|
||||||
port: port,
|
port: port,
|
||||||
// Remove this to use binary mode (remove from the client too)
|
// Remove this to use binary mode (remove from the client too)
|
||||||
json: true
|
json: true
|
||||||
@ -28,9 +28,6 @@ async function init() {
|
|||||||
await server.autoImplementApi(path.resolve(__dirname, "api"));
|
await server.autoImplementApi(path.resolve(__dirname, "api"));
|
||||||
|
|
||||||
// Prepare something... (e.g. connect the db)
|
// Prepare something... (e.g. connect the db)
|
||||||
// server.flows.postConnectFlow.push((conn) => {
|
|
||||||
// Lobby.AddConns(conn);
|
|
||||||
// });
|
|
||||||
server.flows.postConnectFlow.push((conn: BaseConnection<ServiceType>) => {
|
server.flows.postConnectFlow.push((conn: BaseConnection<ServiceType>) => {
|
||||||
Lobby.AddConns(conn);
|
Lobby.AddConns(conn);
|
||||||
console.log(`${conn.ip} is connected`);
|
console.log(`${conn.ip} is connected`);
|
||||||
|
Loading…
Reference in New Issue
Block a user