Shared同步脚本

This commit is contained in:
janing
2025-12-14 22:38:09 +08:00
parent 7bd2c74e3d
commit 9989d60ee4
19 changed files with 738 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "d880422b-7474-4694-9f01-138e7df9414d",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "bfd5a75c-43bc-41e7-a05b-a4e75d7ff56b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

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

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "b478ded6-3b0f-4383-8369-02afbd456031",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,22 @@
import { Position } from './base';
/**
* 玩家加入游戏广播消息
* 当有新玩家登录或加入游戏时,广播给所有在线玩家
*/
export interface MsgPlayerJoin {
/** 加入的玩家ID */
playerId: string;
/** 玩家昵称 */
playerName: string;
/** 玩家位置 */
position: Position;
/** 是否新玩家 */
isNewPlayer: boolean;
/** 加入时间戳 */
timestamp: number;
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "bb38d10f-d355-4311-a606-6981836fe8bf",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,19 @@
import { Position } from './base';
/**
* 玩家移动广播消息
* 当有玩家移动时,广播给所有在线玩家
*/
export interface MsgPlayerMove {
/** 移动的玩家ID */
playerId: string;
/** 玩家昵称 */
playerName: string;
/** 移动后的位置 */
position: Position;
/** 移动时间戳 */
timestamp: number;
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "c1357c6f-8bdc-4760-964a-1796582de8db",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,61 @@
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;
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "db7f0511-7e71-4088-9822-186f68082db6",
"files": [],
"subMetas": {},
"userData": {}
}

View File

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

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "9fdf30ed-1223-4112-81f6-75339229fd1b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

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

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "4414c606-7995-4f83-b83c-30c9fe840a6b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,23 @@
export interface BaseRequest {
}
export interface BaseResponse {
}
export interface BaseConf {
}
export interface BaseMessage {
}
/**
* 位置坐标
*/
export interface Position {
x: number;
y: number;
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "2024ee2b-052f-472d-81c4-8aa59cd65029",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,378 @@
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';
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
}
}
export const serviceProto: ServiceProto<ServiceType> = {
"version": 3,
"services": [
{
"id": 0,
"name": "Chat",
"type": "msg"
},
{
"id": 3,
"name": "PlayerJoin",
"type": "msg"
},
{
"id": 4,
"name": "PlayerMove",
"type": "msg"
},
{
"id": 2,
"name": "Login",
"type": "api"
},
{
"id": 5,
"name": "Move",
"type": "api"
},
{
"id": 1,
"name": "Send",
"type": "api"
}
],
"types": {
"MsgChat/MsgChat": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "content",
"type": {
"type": "String"
}
},
{
"id": 1,
"name": "time",
"type": {
"type": "Date"
}
}
]
},
"MsgPlayerJoin/MsgPlayerJoin": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "playerId",
"type": {
"type": "String"
}
},
{
"id": 1,
"name": "playerName",
"type": {
"type": "String"
}
},
{
"id": 2,
"name": "position",
"type": {
"type": "Reference",
"target": "base/Position"
}
},
{
"id": 3,
"name": "isNewPlayer",
"type": {
"type": "Boolean"
}
},
{
"id": 4,
"name": "timestamp",
"type": {
"type": "Number"
}
}
]
},
"base/Position": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "x",
"type": {
"type": "Number"
}
},
{
"id": 1,
"name": "y",
"type": {
"type": "Number"
}
}
]
},
"MsgPlayerMove/MsgPlayerMove": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "playerId",
"type": {
"type": "String"
}
},
{
"id": 1,
"name": "playerName",
"type": {
"type": "String"
}
},
{
"id": 2,
"name": "position",
"type": {
"type": "Reference",
"target": "base/Position"
}
},
{
"id": 3,
"name": "timestamp",
"type": {
"type": "Number"
}
}
]
},
"PtlLogin/ReqLogin": {
"type": "Interface",
"properties": [
{
"id": 1,
"name": "playerId",
"type": {
"type": "String"
}
},
{
"id": 2,
"name": "playerName",
"type": {
"type": "String"
},
"optional": true
}
]
},
"PtlLogin/ResLogin": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "success",
"type": {
"type": "Boolean"
}
},
{
"id": 1,
"name": "message",
"type": {
"type": "String"
}
},
{
"id": 4,
"name": "player",
"type": {
"type": "Reference",
"target": "PtlLogin/PlayerInfo"
},
"optional": true
},
{
"id": 5,
"name": "isNewPlayer",
"type": {
"type": "Boolean"
},
"optional": true
}
]
},
"PtlLogin/PlayerInfo": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "id",
"type": {
"type": "String"
}
},
{
"id": 1,
"name": "name",
"type": {
"type": "String"
}
},
{
"id": 2,
"name": "position",
"type": {
"type": "Reference",
"target": "base/Position"
}
},
{
"id": 3,
"name": "spawnPoint",
"type": {
"type": "Reference",
"target": "base/Position"
}
},
{
"id": 4,
"name": "hp",
"type": {
"type": "Number"
}
},
{
"id": 5,
"name": "maxHp",
"type": {
"type": "Number"
}
},
{
"id": 6,
"name": "isAlive",
"type": {
"type": "Boolean"
}
},
{
"id": 7,
"name": "createdAt",
"type": {
"type": "Number"
}
},
{
"id": 8,
"name": "lastLoginAt",
"type": {
"type": "Number"
}
}
]
},
"PtlMove/ReqMove": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "x",
"type": {
"type": "Number"
}
},
{
"id": 1,
"name": "y",
"type": {
"type": "Number"
}
}
]
},
"PtlMove/ResMove": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "success",
"type": {
"type": "Boolean"
}
},
{
"id": 1,
"name": "message",
"type": {
"type": "String"
},
"optional": true
},
{
"id": 2,
"name": "position",
"type": {
"type": "Reference",
"target": "base/Position"
},
"optional": true
}
]
},
"PtlSend/ReqSend": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "content",
"type": {
"type": "String"
}
}
]
},
"PtlSend/ResSend": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "time",
"type": {
"type": "Date"
}
}
]
}
}
};

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "a67c105c-09d0-4f7e-acc7-4e2c94dc1360",
"files": [],
"subMetas": {},
"userData": {}
}

102
client/sync-shared.js Normal file
View File

@@ -0,0 +1,102 @@
#!/usr/bin/env node
/**
* 同步服务端 shared 目录到客户端
* 用法: node sync-shared.js
*/
const fs = require('fs-extra');
const path = require('path');
// 路径配置
const SERVER_SHARED_PATH = path.resolve(__dirname, '../server/src/shared');
const CLIENT_SHARED_PATH = path.resolve(__dirname, 'assets/scripts/Shared');
/**
* 同步目录
*/
async function syncShared() {
console.log('==========================================');
console.log('开始同步 Shared 协议目录');
console.log('==========================================');
console.log('源目录:', SERVER_SHARED_PATH);
console.log('目标目录:', CLIENT_SHARED_PATH);
console.log('');
try {
// 检查源目录是否存在
if (!fs.existsSync(SERVER_SHARED_PATH)) {
console.error('❌ 错误: 服务端 shared 目录不存在!');
console.error(' 路径:', SERVER_SHARED_PATH);
console.error(' 请确保服务端项目在正确的位置');
process.exit(1);
}
// 确保目标目录存在
await fs.ensureDir(CLIENT_SHARED_PATH);
// 复制目录
console.log('📦 正在复制文件...');
await fs.copy(SERVER_SHARED_PATH, CLIENT_SHARED_PATH, {
overwrite: true,
errorOnExist: false,
filter: (src) => {
// 过滤掉不需要的文件
const basename = path.basename(src);
if (basename === 'node_modules' || basename === '.git') {
return false;
}
return true;
}
});
console.log('✅ 同步完成!');
console.log('');
// 列出同步的文件
const files = await getFileList(CLIENT_SHARED_PATH);
console.log(`共同步 ${files.length} 个文件:`);
files.forEach(file => {
const relativePath = path.relative(CLIENT_SHARED_PATH, file);
console.log(' -', relativePath);
});
console.log('');
console.log('==========================================');
} catch (error) {
console.error('❌ 同步失败:', error.message);
process.exit(1);
}
}
/**
* 递归获取目录下所有文件
*/
async function getFileList(dir) {
const files = [];
async function walk(currentPath) {
const items = await fs.readdir(currentPath);
for (const item of items) {
const itemPath = path.join(currentPath, item);
const stat = await fs.stat(itemPath);
if (stat.isDirectory()) {
await walk(itemPath);
} else {
files.push(itemPath);
}
}
}
await walk(dir);
return files;
}
// 执行同步
syncShared().catch(error => {
console.error('未知错误:', error);
process.exit(1);
});