From 98eab7ed81098c16686d7ec268d8be7f754f3945 Mon Sep 17 00:00:00 2001 From: moyin Date: Mon, 8 Dec 2025 16:49:24 +0800 Subject: [PATCH] =?UTF-8?q?init=EF=BC=9A=E5=88=9B=E5=BB=BA=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E9=A1=B9=E7=9B=AE=E6=A1=86=E6=9E=B6=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E7=8E=AF=E5=A2=83=E7=9A=84=E5=9F=BA=E6=9C=AC=E8=BF=90?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 39 +++++++++++++++++++++++ README.md | 72 +++++++++++++++++++++++++++++++++++++++++++ nest-cli.json | 8 +++++ package.json | 31 +++++++++++++++++++ src/api/.gitkeep | 0 src/app.controller.ts | 12 ++++++++ src/app.module.ts | 10 ++++++ src/app.service.ts | 8 +++++ src/config/.gitkeep | 0 src/data/.gitkeep | 0 src/main.ts | 10 ++++++ src/model/.gitkeep | 0 src/service/.gitkeep | 0 src/utils/.gitkeep | 0 test/api/.gitkeep | 0 test/service/.gitkeep | 0 tsconfig.json | 24 +++++++++++++++ 17 files changed, 214 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 nest-cli.json create mode 100644 package.json create mode 100644 src/api/.gitkeep create mode 100644 src/app.controller.ts create mode 100644 src/app.module.ts create mode 100644 src/app.service.ts create mode 100644 src/config/.gitkeep create mode 100644 src/data/.gitkeep create mode 100644 src/main.ts create mode 100644 src/model/.gitkeep create mode 100644 src/service/.gitkeep create mode 100644 src/utils/.gitkeep create mode 100644 test/api/.gitkeep create mode 100644 test/service/.gitkeep create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7f4dc1d --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# 依赖 +node_modules/ +yarn.lock +package-lock.json + +# 构建输出 +dist/ +build/ +*.tsbuildinfo + +# 环境变量 +.env +.env.local +.env.*.local + +# 日志 +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# 操作系统 +.DS_Store +Thumbs.db + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# 测试覆盖率 +coverage/ +.nyc_output/ + +# 临时文件 +*.tmp +.cache/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..1412666 --- /dev/null +++ b/README.md @@ -0,0 +1,72 @@ +# Pixel Game Server + +一个基于 NestJS 的 2D 像素风游戏后端服务 + +## 技术栈 + +- **NestJS** - 渐进式 Node.js 框架 +- **TypeScript** - 类型安全 +- **WebSocket** - 实时通信支持 + +## 前置要求 + +如果还没有安装 Yarn,请先安装: + +```bash +npm install -g yarn +``` + +## 安装依赖 + +```bash +yarn install +``` + +## 开发 + +启动开发服务器(支持热重载): + +```bash +yarn dev +``` + +服务器将运行在 `http://localhost:3000` + +## 构建 + +```bash +yarn build +``` + +## 生产环境运行 + +```bash +yarn start:prod +``` + +## 项目结构 + +``` +src/ +├── api/ # API 接口层(控制器、网关) +├── config/ # 配置文件 +├── data/ # 数据访问层(数据库、缓存) +├── model/ # 数据模型、实体、DTO +├── service/ # 业务逻辑层 +├── utils/ # 工具函数 +├── main.ts # 应用入口 +├── app.module.ts # 根模块 +├── app.controller.ts # 根控制器 +└── app.service.ts # 根服务 +test/ +├── api/ # API 测试 +└── service/ # 服务测试 +``` + +## 下一步 + +- 在 `src/api/` 目录下创建游戏相关的控制器和网关 +- 在 `src/model/` 目录下定义游戏数据模型 +- 在 `src/service/` 目录下实现游戏业务逻辑 +- 使用 NestJS CLI 快速生成模块:`nest g module game` +- 添加 WebSocket 网关实现实时游戏逻辑 diff --git a/nest-cli.json b/nest-cli.json new file mode 100644 index 0000000..f9aa683 --- /dev/null +++ b/nest-cli.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src", + "compilerOptions": { + "deleteOutDir": true + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..1dd6731 --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "pixel-game-server", + "version": "1.0.0", + "description": "A 2D pixel art game server built with NestJS", + "main": "dist/main.js", + "scripts": { + "dev": "nest start --watch", + "build": "nest build", + "start": "node dist/main.js", + "start:prod": "node dist/main.js" + }, + "keywords": ["game", "pixel", "2d", "server", "nestjs"], + "author": "", + "license": "MIT", + "dependencies": { + "@nestjs/common": "^10.0.0", + "@nestjs/core": "^10.0.0", + "@nestjs/platform-express": "^10.0.0", + "@nestjs/websockets": "^10.0.0", + "@nestjs/platform-socket.io": "^10.0.0", + "reflect-metadata": "^0.1.13", + "rxjs": "^7.8.1" + }, + "devDependencies": { + "@nestjs/cli": "^10.0.0", + "@nestjs/schematics": "^10.0.0", + "@types/node": "^20.0.0", + "ts-node": "^10.9.0", + "typescript": "^5.3.0" + } +} diff --git a/src/api/.gitkeep b/src/api/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/app.controller.ts b/src/app.controller.ts new file mode 100644 index 0000000..1d102bb --- /dev/null +++ b/src/app.controller.ts @@ -0,0 +1,12 @@ +import { Controller, Get } from '@nestjs/common'; +import { AppService } from './app.service'; + +@Controller() +export class AppController { + constructor(private readonly appService: AppService) {} + + @Get() + getStatus(): string { + return this.appService.getStatus(); + } +} diff --git a/src/app.module.ts b/src/app.module.ts new file mode 100644 index 0000000..8662803 --- /dev/null +++ b/src/app.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { AppController } from './app.controller'; +import { AppService } from './app.service'; + +@Module({ + imports: [], + controllers: [AppController], + providers: [AppService], +}) +export class AppModule {} diff --git a/src/app.service.ts b/src/app.service.ts new file mode 100644 index 0000000..c93fae9 --- /dev/null +++ b/src/app.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class AppService { + getStatus(): string { + return 'Pixel Game Server is running!'; + } +} diff --git a/src/config/.gitkeep b/src/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/data/.gitkeep b/src/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..cd3ba5e --- /dev/null +++ b/src/main.ts @@ -0,0 +1,10 @@ +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; + +async function bootstrap() { + const app = await NestFactory.create(AppModule); + await app.listen(3000); + console.log('Pixel Game Server is running on http://localhost:3000'); +} + +bootstrap(); diff --git a/src/model/.gitkeep b/src/model/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/service/.gitkeep b/src/service/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/utils/.gitkeep b/src/utils/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/api/.gitkeep b/test/api/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/service/.gitkeep b/test/service/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..83112bf --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "CommonJS", + "lib": ["ES2020"], + "moduleResolution": "node", + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "strictNullChecks": false + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +}