重构Api接口到Msg

This commit is contained in:
janing
2025-12-18 12:03:03 +08:00
parent 7301adbb43
commit c12e439add
15 changed files with 450 additions and 356 deletions

View File

@@ -0,0 +1,11 @@
/**
* 登录请求消息
*/
export interface MsgReqLogin {
/** 玩家ID用于识别玩家 */
playerId: string;
/** 玩家昵称(可选,新玩家时使用) */
playerName?: string;
}

View File

@@ -0,0 +1,10 @@
/**
* 移动请求消息
*/
export interface MsgReqMove {
/** X坐标 */
x: number;
/** Y坐标 */
y: number;
}

View File

@@ -0,0 +1,7 @@
/**
* 发送消息请求
*/
export interface MsgReqSend {
/** 消息内容 */
content: string;
}

View File

@@ -1,61 +1,50 @@
import { Position } from './base';
/**
*
*/
export interface ReqLogin {
/** 玩家ID(用于识别玩家) */
playerId: string;
/** 玩家昵称(可选,新玩家时使用) */
playerName?: string;
}
/**
*
*/
export interface PlayerInfo {
/** 玩家ID */
id: string;
/** 玩家昵称 */
name: string;
/** 当前位置 */
position: Position;
/** 出生点 */
spawnPoint: Position;
/** 当前生命值 */
hp: number;
/** 最大生命值 */
maxHp: number;
/** 是否存活 */
isAlive: boolean;
/** 创建时间 */
createdAt: number;
/** 最后登录时间 */
lastLoginAt: number;
}
/**
*
*/
export interface ResLogin {
/** 是否成功 */
success: boolean;
/** 消息 */
message: string;
/** 玩家信息 */
player?: PlayerInfo;
/** 是否新玩家 */
isNewPlayer?: boolean;
}
import { Position } from './base';
/**
*
*/
export interface PlayerInfo {
/** 玩家ID */
id: string;
/** 玩家昵称 */
name: string;
/** 当前位置 */
position: Position;
/** 出生点 */
spawnPoint: Position;
/** 当前生命值 */
hp: number;
/** 最大生命值 */
maxHp: number;
/** 是否存活 */
isAlive: boolean;
/** 创建时间 */
createdAt: number;
/** 最后登录时间 */
lastLoginAt: number;
}
/**
*
*/
export interface MsgResLogin {
/** 是否成功 */
success: boolean;
/** 消息 */
message: string;
/** 玩家信息 */
player?: PlayerInfo;
/** 是否新玩家 */
isNewPlayer?: boolean;
}

View File

@@ -0,0 +1,15 @@
import { Position } from './base';
/**
* 移动响应消息
*/
export interface MsgResMove {
/** 是否成功 */
success: boolean;
/** 消息 */
message: string;
/** 新位置(成功时返回) */
position?: Position;
}

View File

@@ -0,0 +1,7 @@
/**
* 发送消息响应
*/
export interface MsgResSend {
/** 发送时间 */
time: Date;
}

View File

@@ -1,26 +0,0 @@
import { Position } from './base';
/**
* 移动请求
*/
export interface ReqMove {
/** 目标位置 X 坐标 */
x: number;
/** 目标位置 Y 坐标 */
y: number;
}
/**
* 移动响应
*/
export interface ResMove {
/** 是否成功 */
success: boolean;
/** 消息 */
message?: string;
/** 实际移动后的位置 */
position?: Position;
}

View File

@@ -1,10 +0,0 @@
// This is a demo code file
// Feel free to delete it
export interface ReqSend {
content: string
}
export interface ResSend {
time: Date
}

View File

@@ -2,34 +2,32 @@ import { ServiceProto } from 'tsrpc-proto';
import { MsgChat } from './MsgChat';
import { MsgPlayerJoin } from './MsgPlayerJoin';
import { MsgPlayerMove } from './MsgPlayerMove';
import { ReqLogin, ResLogin } from './PtlLogin';
import { ReqMove, ResMove } from './PtlMove';
import { ReqSend, ResSend } from './PtlSend';
import { MsgReqLogin } from './MsgReqLogin';
import { MsgReqMove } from './MsgReqMove';
import { MsgReqSend } from './MsgReqSend';
import { MsgResLogin } from './MsgResLogin';
import { MsgResMove } from './MsgResMove';
import { MsgResSend } from './MsgResSend';
export interface ServiceType {
api: {
"Login": {
req: ReqLogin,
res: ResLogin
},
"Move": {
req: ReqMove,
res: ResMove
},
"Send": {
req: ReqSend,
res: ResSend
}
},
msg: {
"Chat": MsgChat,
"PlayerJoin": MsgPlayerJoin,
"PlayerMove": MsgPlayerMove
"PlayerMove": MsgPlayerMove,
"ReqLogin": MsgReqLogin,
"ReqMove": MsgReqMove,
"ReqSend": MsgReqSend,
"ResLogin": MsgResLogin,
"ResMove": MsgResMove,
"ResSend": MsgResSend
}
}
export const serviceProto: ServiceProto<ServiceType> = {
"version": 3,
"version": 5,
"services": [
{
"id": 0,
@@ -47,19 +45,34 @@ export const serviceProto: ServiceProto<ServiceType> = {
"type": "msg"
},
{
"id": 2,
"name": "Login",
"type": "api"
"id": 6,
"name": "ReqLogin",
"type": "msg"
},
{
"id": 5,
"name": "Move",
"type": "api"
"id": 7,
"name": "ReqMove",
"type": "msg"
},
{
"id": 1,
"name": "Send",
"type": "api"
"id": 8,
"name": "ReqSend",
"type": "msg"
},
{
"id": 9,
"name": "ResLogin",
"type": "msg"
},
{
"id": 10,
"name": "ResMove",
"type": "msg"
},
{
"id": 11,
"name": "ResSend",
"type": "msg"
}
],
"types": {
@@ -176,18 +189,18 @@ export const serviceProto: ServiceProto<ServiceType> = {
}
]
},
"PtlLogin/ReqLogin": {
"MsgReqLogin/MsgReqLogin": {
"type": "Interface",
"properties": [
{
"id": 1,
"id": 0,
"name": "playerId",
"type": {
"type": "String"
}
},
{
"id": 2,
"id": 1,
"name": "playerName",
"type": {
"type": "String"
@@ -196,7 +209,38 @@ export const serviceProto: ServiceProto<ServiceType> = {
}
]
},
"PtlLogin/ResLogin": {
"MsgReqMove/MsgReqMove": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "x",
"type": {
"type": "Number"
}
},
{
"id": 1,
"name": "y",
"type": {
"type": "Number"
}
}
]
},
"MsgReqSend/MsgReqSend": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "content",
"type": {
"type": "String"
}
}
]
},
"MsgResLogin/MsgResLogin": {
"type": "Interface",
"properties": [
{
@@ -214,16 +258,16 @@ export const serviceProto: ServiceProto<ServiceType> = {
}
},
{
"id": 4,
"id": 2,
"name": "player",
"type": {
"type": "Reference",
"target": "PtlLogin/PlayerInfo"
"target": "MsgResLogin/PlayerInfo"
},
"optional": true
},
{
"id": 5,
"id": 3,
"name": "isNewPlayer",
"type": {
"type": "Boolean"
@@ -232,7 +276,7 @@ export const serviceProto: ServiceProto<ServiceType> = {
}
]
},
"PtlLogin/PlayerInfo": {
"MsgResLogin/PlayerInfo": {
"type": "Interface",
"properties": [
{
@@ -302,26 +346,7 @@ export const serviceProto: ServiceProto<ServiceType> = {
}
]
},
"PtlMove/ReqMove": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "x",
"type": {
"type": "Number"
}
},
{
"id": 1,
"name": "y",
"type": {
"type": "Number"
}
}
]
},
"PtlMove/ResMove": {
"MsgResMove/MsgResMove": {
"type": "Interface",
"properties": [
{
@@ -336,8 +361,7 @@ export const serviceProto: ServiceProto<ServiceType> = {
"name": "message",
"type": {
"type": "String"
},
"optional": true
}
},
{
"id": 2,
@@ -350,19 +374,7 @@ export const serviceProto: ServiceProto<ServiceType> = {
}
]
},
"PtlSend/ReqSend": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "content",
"type": {
"type": "String"
}
}
]
},
"PtlSend/ResSend": {
"MsgResSend/MsgResSend": {
"type": "Interface",
"properties": [
{