Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the coding experience #148

Open
wang-yichun opened this issue Nov 8, 2024 · 2 comments
Open

Improve the coding experience #148

wang-yichun opened this issue Nov 8, 2024 · 2 comments

Comments

@wang-yichun
Copy link

The client uses TypeScript with Cocos Creator. It would be great if a unified schema definition file could also be used on the client side. This way, I can have a consistent code suggestion experience.
// server: part of GameRoomState.ts class
export class GameRoomState extends Schema {

@type({ map: PlayerState }) // 所有玩家的状态
players = new MapSchema<PlayerState>();

@type('number') // 使用数字表示游戏状态
gameState: GameState = GameState.READY; // 初始状态为准备

}
// cocos client: fake type define
export type GameRoomState = Schema & {
players: MapSchema;
gameState: GameState; // 初始状态为准备
} // ugly code, and no use...

This idea came up while coding an AI bot for a game. I tried to import the Colyseus client code on the server side (using npm install --save colyseus.js), logging in and entering the room in the same way as the client, and simulating all the normal client operation logic. The development experience was excellent, and I was even able to use the same GameRoomState file during development, which provided complete code suggestion functionality. So I was thinking about how to achieve a similar process in Cocos Creator, allowing for direct usage of definitions like export class GameRoomState extends Schema {}

@wang-yichun
Copy link
Author

The colyseus.d.ts file may not be effective in Cocos Creator.

@endel
Copy link
Member

endel commented Nov 8, 2024

HI @wang-yichun, I believe you can import only the type directly from the backend into your Cocos Creator project by using import type, please let me know if that works for you:

// In Cocos Creator
import type { GameRoomState } from "../../location-of-your-backend-project/GameRoomState";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants