Skip to content

Improve the coding experience #148

Open
@wang-yichun

Description

@wang-yichun

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 {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions