[add] Room OK
This commit is contained in:
parent
93f66106fc
commit
011667a064
@ -5,15 +5,18 @@
|
|||||||
"version": "1.0.0"
|
"version": "1.0.0"
|
||||||
},
|
},
|
||||||
"paths": {
|
"paths": {
|
||||||
"/Send": {
|
"/account/Login": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "Send",
|
"tags": [
|
||||||
|
"account"
|
||||||
|
],
|
||||||
|
"operationId": "account/Login",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"description": "Req<Send>",
|
"description": "Req<Login>",
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/PtlSend_ReqSend"
|
"$ref": "#/components/schemas/account_PtlLogin_ReqLogin"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -25,7 +28,7 @@
|
|||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "ApiReturn<ResSend>",
|
"description": "ApiReturn<ResLogin>",
|
||||||
"properties": {
|
"properties": {
|
||||||
"isSucc": {
|
"isSucc": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -35,7 +38,242 @@
|
|||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
"res": {
|
"res": {
|
||||||
"$ref": "#/components/schemas/PtlSend_ResSend"
|
"$ref": "#/components/schemas/account_PtlLogin_ResLogin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "Error",
|
||||||
|
"$ref": "#/components/responses/error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/room/ChangeState": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"room"
|
||||||
|
],
|
||||||
|
"operationId": "room/ChangeState",
|
||||||
|
"requestBody": {
|
||||||
|
"description": "Req<ChangeState>",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlChangeState_ReqChangeState"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Success",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "ApiReturn<ResChangeState>",
|
||||||
|
"properties": {
|
||||||
|
"isSucc": {
|
||||||
|
"type": "boolean",
|
||||||
|
"enum": [
|
||||||
|
true
|
||||||
|
],
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"res": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlChangeState_ResChangeState"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "Error",
|
||||||
|
"$ref": "#/components/responses/error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/room/Create": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"room"
|
||||||
|
],
|
||||||
|
"operationId": "room/Create",
|
||||||
|
"requestBody": {
|
||||||
|
"description": "Req<Create>",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlCreate_ReqCreate"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Success",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "ApiReturn<ResCreate>",
|
||||||
|
"properties": {
|
||||||
|
"isSucc": {
|
||||||
|
"type": "boolean",
|
||||||
|
"enum": [
|
||||||
|
true
|
||||||
|
],
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"res": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlCreate_ResCreate"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "Error",
|
||||||
|
"$ref": "#/components/responses/error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/room/Exit": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"room"
|
||||||
|
],
|
||||||
|
"operationId": "room/Exit",
|
||||||
|
"requestBody": {
|
||||||
|
"description": "Req<Exit>",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlExit_ReqExit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Success",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "ApiReturn<ResExit>",
|
||||||
|
"properties": {
|
||||||
|
"isSucc": {
|
||||||
|
"type": "boolean",
|
||||||
|
"enum": [
|
||||||
|
true
|
||||||
|
],
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"res": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlExit_ResExit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "Error",
|
||||||
|
"$ref": "#/components/responses/error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/room/Join": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"room"
|
||||||
|
],
|
||||||
|
"operationId": "room/Join",
|
||||||
|
"requestBody": {
|
||||||
|
"description": "Req<Join>",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlJoin_ReqJoin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Success",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "ApiReturn<ResJoin>",
|
||||||
|
"properties": {
|
||||||
|
"isSucc": {
|
||||||
|
"type": "boolean",
|
||||||
|
"enum": [
|
||||||
|
true
|
||||||
|
],
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"res": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlJoin_ResJoin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "Error",
|
||||||
|
"$ref": "#/components/responses/error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/room/List": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"room"
|
||||||
|
],
|
||||||
|
"operationId": "room/List",
|
||||||
|
"requestBody": {
|
||||||
|
"description": "Req<List>",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlList_ReqList"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Success",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "ApiReturn<ResList>",
|
||||||
|
"properties": {
|
||||||
|
"isSucc": {
|
||||||
|
"type": "boolean",
|
||||||
|
"enum": [
|
||||||
|
true
|
||||||
|
],
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"res": {
|
||||||
|
"$ref": "#/components/schemas/room_PtlList_ResList"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,6 +290,20 @@
|
|||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"schemas": {
|
"schemas": {
|
||||||
|
"account_PtlLogin_ReqLogin": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"name"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"account_PtlLogin_ResLogin": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
"MsgChat_MsgChat": {
|
"MsgChat_MsgChat": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -68,29 +320,88 @@
|
|||||||
"time"
|
"time"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"PtlSend_ReqSend": {
|
"room_MsgChangeState_MsgChangeState": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"room_MsgExit_MsgExit": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"room_MsgGoToGame_MsgGoToGame": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"room_PtlChangeState_ReqChangeState": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"content": {
|
"state": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"state"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"room_PtlChangeState_ResChangeState": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"room_PtlCreate_ReqCreate": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"null": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"content"
|
"null"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"PtlSend_ResSend": {
|
"room_PtlCreate_ResCreate": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"room_PtlExit_ReqExit": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"time": {
|
"null": {
|
||||||
"type": "string",
|
"type": "string"
|
||||||
"format": "date-time"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"time"
|
"null"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"room_PtlExit_ResExit": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"room_PtlJoin_ReqJoin": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"roomId": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"roomId"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"room_PtlJoin_ResJoin": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"room_PtlList_ReqList": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"null": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"null"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"room_PtlList_ResList": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
"?bson_ObjectID": {
|
"?bson_ObjectID": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
118
docs/tsapi.md
118
docs/tsapi.md
@ -9,26 +9,130 @@
|
|||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
|
|
||||||
- [Send](#/Send)
|
- account
|
||||||
|
- [Login](#/account/Login)
|
||||||
|
- room
|
||||||
|
- [ChangeState](#/room/ChangeState)
|
||||||
|
- [Create](#/room/Create)
|
||||||
|
- [Exit](#/room/Exit)
|
||||||
|
- [Join](#/room/Join)
|
||||||
|
- [List](#/room/List)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Send <a id="/Send"></a>
|
## account
|
||||||
|
|
||||||
|
### Login <a id="/account/Login"></a>
|
||||||
|
|
||||||
**路径**
|
**路径**
|
||||||
- POST `/Send`
|
- POST `/account/Login`
|
||||||
|
|
||||||
**请求**
|
**请求**
|
||||||
```ts
|
```ts
|
||||||
interface ReqSend {
|
interface ReqLogin {
|
||||||
content: string
|
name: string
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**响应**
|
**响应**
|
||||||
```ts
|
```ts
|
||||||
interface ResSend {
|
type ResLogin = number
|
||||||
time: /*datetime*/ string
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## room
|
||||||
|
|
||||||
|
### ChangeState <a id="/room/ChangeState"></a>
|
||||||
|
|
||||||
|
**路径**
|
||||||
|
- POST `/room/ChangeState`
|
||||||
|
|
||||||
|
**请求**
|
||||||
|
```ts
|
||||||
|
interface ReqChangeState {
|
||||||
|
state: number
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**响应**
|
||||||
|
```ts
|
||||||
|
type ResChangeState = number
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Create <a id="/room/Create"></a>
|
||||||
|
|
||||||
|
**路径**
|
||||||
|
- POST `/room/Create`
|
||||||
|
|
||||||
|
**请求**
|
||||||
|
```ts
|
||||||
|
interface ReqCreate {
|
||||||
|
null: string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应**
|
||||||
|
```ts
|
||||||
|
type ResCreate = number
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Exit <a id="/room/Exit"></a>
|
||||||
|
|
||||||
|
**路径**
|
||||||
|
- POST `/room/Exit`
|
||||||
|
|
||||||
|
**请求**
|
||||||
|
```ts
|
||||||
|
interface ReqExit {
|
||||||
|
null: string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应**
|
||||||
|
```ts
|
||||||
|
type ResExit = number
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Join <a id="/room/Join"></a>
|
||||||
|
|
||||||
|
**路径**
|
||||||
|
- POST `/room/Join`
|
||||||
|
|
||||||
|
**请求**
|
||||||
|
```ts
|
||||||
|
interface ReqJoin {
|
||||||
|
roomId: number
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应**
|
||||||
|
```ts
|
||||||
|
type ResJoin = number
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### List <a id="/room/List"></a>
|
||||||
|
|
||||||
|
**路径**
|
||||||
|
- POST `/room/List`
|
||||||
|
|
||||||
|
**请求**
|
||||||
|
```ts
|
||||||
|
interface ReqList {
|
||||||
|
null: string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**响应**
|
||||||
|
```ts
|
||||||
|
type ResList = any[]
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { server } from "../..";
|
|||||||
import { RandomEx } from "../../Engine/Utils/Number/RandomEx";
|
import { RandomEx } from "../../Engine/Utils/Number/RandomEx";
|
||||||
import { EGameState } from "../../shared/protocols/define/enum";
|
import { EGameState } from "../../shared/protocols/define/enum";
|
||||||
import { ServiceType } from "../../shared/protocols/serviceProto";
|
import { ServiceType } from "../../shared/protocols/serviceProto";
|
||||||
|
import { RoomConnData } from "./RoomUtils";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +28,7 @@ export default class Room {
|
|||||||
|
|
||||||
private conns: BaseConnection[] = [];
|
private conns: BaseConnection[] = [];
|
||||||
|
|
||||||
private ready: boolean[] = [];
|
private connData = new Map<BaseConnection, RoomConnData>();
|
||||||
|
|
||||||
private nowPlayer: [conn: BaseConnection, state: number] = undefined;
|
private nowPlayer: [conn: BaseConnection, state: number] = undefined;
|
||||||
|
|
||||||
@ -69,14 +70,14 @@ export default class Room {
|
|||||||
|
|
||||||
/** ChangeState */
|
/** ChangeState */
|
||||||
public ChangeState(conn: BaseConnection, state: EGameState): void {
|
public ChangeState(conn: BaseConnection, state: EGameState): void {
|
||||||
if (state === EGameState.Loading) {
|
if (state === EGameState.Ready) {
|
||||||
this.SetReady(conn);
|
this.SetReady(conn);
|
||||||
}
|
}
|
||||||
const index: number = this.conns.indexOf(conn);
|
this.connData.forEach((connData: RoomConnData, key: BaseConnection) => {
|
||||||
const nowPlayer: WsConnection<ServiceType>[] = <WsConnection<ServiceType>[]>this.conns.filter((conn, i) => i === index);
|
const player: WsConnection<ServiceType>[] = <WsConnection<ServiceType>[]>this.conns.filter((conn) => conn === key);
|
||||||
const othersPlayer: WsConnection<ServiceType>[] = <WsConnection<ServiceType>[]>this.conns.filter((conn, i) => i !== index);
|
const apiNum: number = conn === key ? 100 : 200;
|
||||||
server.broadcastMsg("room/ChangeState", state + 100, nowPlayer);
|
server.broadcastMsg("room/ChangeState", [connData.state + apiNum], player);
|
||||||
server.broadcastMsg("room/ChangeState", state + 200, othersPlayer);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
@ -86,20 +87,41 @@ export default class Room {
|
|||||||
/** Join */
|
/** Join */
|
||||||
public Join(conn: BaseConnection): void {
|
public Join(conn: BaseConnection): void {
|
||||||
this.conns.push(conn);
|
this.conns.push(conn);
|
||||||
this.ready.push(false);
|
const data: RoomConnData = {
|
||||||
|
state: undefined,
|
||||||
|
card: undefined,
|
||||||
|
};
|
||||||
|
this.connData.set(conn, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SetReady */
|
/** SetReady */
|
||||||
public SetReady(conn: BaseConnection): void {
|
public SetReady(conn: BaseConnection): void {
|
||||||
const index: number = this.conns.indexOf(conn);
|
const self: this = this;
|
||||||
this.ready[index] = true;
|
const cardCount: number = 24;
|
||||||
if (!this.ready.includes(false)) {
|
const data: RoomConnData = this.connData.get(conn);
|
||||||
|
data.state = EGameState.Ready;
|
||||||
|
this.connData.set(conn, data);
|
||||||
|
let canStart: boolean = true;
|
||||||
|
this.connData.forEach((connData: RoomConnData) => {
|
||||||
|
if (connData.state === undefined || connData.state !== EGameState.Ready) {
|
||||||
|
canStart = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (canStart) {
|
||||||
const now: number = RandomEx.GetInt(0, 2);
|
const now: number = RandomEx.GetInt(0, 2);
|
||||||
this.nowPlayer = [this.conns[now], EGameState.TurnCards];
|
this.connData.forEach((connData: RoomConnData, key: BaseConnection) => {
|
||||||
this.ChangeState(...this.nowPlayer);
|
const card: number = RandomEx.GetInt(0, cardCount);
|
||||||
|
connData.state = key === self.conns[now] ? EGameState.TurnCards : EGameState.Wait;
|
||||||
|
connData.card = card;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** RestartGame */
|
||||||
|
public RestartGame(): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** ConnCount */
|
/** ConnCount */
|
||||||
public ConnCount(): number {
|
public ConnCount(): number {
|
||||||
return this.conns.length;
|
return this.conns.length;
|
||||||
|
8
src/component/Room/RoomUtils.ts
Normal file
8
src/component/Room/RoomUtils.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// #region Interface
|
||||||
|
|
||||||
|
export interface RoomConnData {
|
||||||
|
state: number
|
||||||
|
card?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
// #endregion
|
Loading…
x
Reference in New Issue
Block a user