From f3dc3ef7ba17981136f6681c545e9d83eacc7b41 Mon Sep 17 00:00:00 2001 From: sli97 <775303361@qq.com> Date: Sat, 3 Dec 2022 20:06:57 +0800 Subject: [PATCH] update --- apps/client/assets/Scenes/Hall.scene | 4 +- apps/client/assets/Scenes/Room.scene | 4 +- .../{Entity/Player.meta => Common.meta} | 2 +- .../Room.meta => Scripts/Entity/Actor.meta} | 2 +- .../ActorManager.ts} | 26 +- .../Actor/ActorManager.ts.meta} | 2 +- .../ActorStateMachine.ts} | 3 +- .../Actor/ActorStateMachine.ts.meta} | 2 +- .../{Player => Actor}/PlayerManager.ts.meta | 0 .../PlayerStateMachine.ts.meta | 0 .../Scripts/Entity/Bullet/BulletManager.ts | 7 +- .../Entity/Bullet/BulletStateMachine.ts | 3 +- .../Entity/Explosion/ExplosionManager.ts | 4 +- .../Entity/Explosion/ExplosionStateMachine.ts | 3 +- .../Scripts/Entity/Weapon/WeaponManager.ts | 12 +- .../Entity/Weapon/WeaponStateMachine.ts | 3 +- apps/client/assets/Scripts/Enum/index.ts | 31 +- .../assets/Scripts/Global/DataManager.ts | 56 +- .../assets/Scripts/Global/NetworkManager.ts | 74 +- .../Scripts/Global/ObjectPoolManager.ts | 2 +- .../assets/Scripts/Scene/BattleManager.ts | 15 +- .../assets/Scripts/Scene/HallManager.ts | 35 +- .../assets/Scripts/Scene/LoginManager.ts | 8 +- .../assets/Scripts/Scene/RoomManager.ts | 38 +- ...{PlayerItemManager.ts => PlayerManager.ts} | 4 +- .../assets/Scripts/UI/PlayerManager.ts.meta | 9 + .../UI/{RoomItemManager.ts => RoomManager.ts} | 4 +- .../assets/Scripts/UI/RoomManager.ts.meta | 9 + .../assets/resources/prefab/Actor.prefab | 690 ++++++++++++++++++ ...ayerItem.prefab.meta => Actor.prefab.meta} | 4 +- apps/client/assets/resources/prefab/Hall.meta | 12 - .../resources/prefab/Hall/PlayerItem.prefab | 200 ----- .../assets/resources/prefab/Player.prefab | 602 ++------------- .../resources/prefab/Player.prefab.meta | 2 +- .../{Hall/RoomItem.prefab => Room.prefab} | 46 +- .../RoomItem.prefab.meta => Room.prefab.meta} | 2 +- .../texture/{player.meta => actor.meta} | 0 .../player1.meta => actor/actor1.meta} | 0 .../player1 => actor/actor1}/idle.meta | 0 .../actor1}/idle/idle (1).png | Bin .../actor1}/idle/idle (1).png.meta | 0 .../actor1}/idle/idle (2).png | Bin .../actor1}/idle/idle (2).png.meta | 0 .../actor1}/idle/idle (3).png | Bin .../actor1}/idle/idle (3).png.meta | 0 .../actor1}/idle/idle (4).png | Bin .../actor1}/idle/idle (4).png.meta | 0 .../actor1}/idle/idle (5).png | Bin .../actor1}/idle/idle (5).png.meta | 0 .../actor1}/idle/idle (6).png | Bin .../actor1}/idle/idle (6).png.meta | 0 .../{player/player1 => actor/actor1}/run.meta | 0 .../player1 => actor/actor1}/run/run (1).png | Bin .../actor1}/run/run (1).png.meta | 0 .../player1 => actor/actor1}/run/run (2).png | Bin .../actor1}/run/run (2).png.meta | 0 .../player1 => actor/actor1}/run/run (3).png | Bin .../actor1}/run/run (3).png.meta | 0 .../player1 => actor/actor1}/run/run (4).png | Bin .../actor1}/run/run (4).png.meta | 0 .../player1 => actor/actor1}/run/run (5).png | Bin .../actor1}/run/run (5).png.meta | 0 .../player1 => actor/actor1}/run/run (6).png | Bin .../actor1}/run/run (6).png.meta | 0 .../player2.meta => actor/actor2.meta} | 0 .../player2 => actor/actor2}/idle.meta | 0 .../actor2}/idle/idle (1).png | Bin .../actor2}/idle/idle (1).png.meta | 0 .../actor2}/idle/idle (2).png | Bin .../actor2}/idle/idle (2).png.meta | 0 .../actor2}/idle/idle (3).png | Bin .../actor2}/idle/idle (3).png.meta | 0 .../actor2}/idle/idle (4).png | Bin .../actor2}/idle/idle (4).png.meta | 0 .../actor2}/idle/idle (5).png | Bin .../actor2}/idle/idle (5).png.meta | 0 .../actor2}/idle/idle (6).png | Bin .../actor2}/idle/idle (6).png.meta | 0 .../{player/player2 => actor/actor2}/run.meta | 0 .../player2 => actor/actor2}/run/run (1).png | Bin .../actor2}/run/run (1).png.meta | 0 .../player2 => actor/actor2}/run/run (2).png | Bin .../actor2}/run/run (2).png.meta | 0 .../player2 => actor/actor2}/run/run (3).png | Bin .../actor2}/run/run (3).png.meta | 0 .../player2 => actor/actor2}/run/run (4).png | Bin .../actor2}/run/run (4).png.meta | 0 .../player2 => actor/actor2}/run/run (5).png | Bin .../actor2}/run/run (5).png.meta | 0 .../player2 => actor/actor2}/run/run (6).png | Bin .../actor2}/run/run (6).png.meta | 0 apps/server/src/Common/Api.ts | 49 ++ apps/server/src/Common/Api.ts.meta | 9 + apps/server/src/Common/Enum.ts | 34 + apps/server/src/Common/Enum.ts.meta | 9 + apps/server/src/Common/Model.ts | 9 + apps/server/src/Common/Model.ts.meta | 9 + apps/server/src/Common/Msg.ts | 23 + apps/server/src/Common/Msg.ts.meta | 9 + apps/server/src/Common/State.ts | 56 ++ apps/server/src/Common/State.ts.meta | 9 + apps/server/src/Common/index.ts.meta | 9 + apps/server/src/biz/Player.ts | 6 +- apps/server/src/biz/PlayerManager.ts | 8 +- apps/server/src/biz/Room.ts | 45 +- apps/server/src/biz/RoomManager.ts | 12 +- apps/server/src/common/index.ts | 52 +- apps/server/src/core/Connection.ts | 5 +- apps/server/src/index.ts | 75 +- apps/server/src/utils/index.ts | 27 +- 110 files changed, 1347 insertions(+), 1028 deletions(-) rename apps/client/assets/Scripts/{Entity/Player.meta => Common.meta} (77%) rename apps/client/assets/{resources/prefab/Room.meta => Scripts/Entity/Actor.meta} (77%) rename apps/client/assets/Scripts/Entity/{Player/PlayerManager.ts => Actor/ActorManager.ts} (81%) rename apps/client/assets/Scripts/{UI/PlayerItemManager.ts.meta => Entity/Actor/ActorManager.ts.meta} (70%) rename apps/client/assets/Scripts/Entity/{Player/PlayerStateMachine.ts => Actor/ActorStateMachine.ts} (93%) rename apps/client/assets/Scripts/{UI/RoomItemManager.ts.meta => Entity/Actor/ActorStateMachine.ts.meta} (70%) rename apps/client/assets/Scripts/Entity/{Player => Actor}/PlayerManager.ts.meta (100%) rename apps/client/assets/Scripts/Entity/{Player => Actor}/PlayerStateMachine.ts.meta (100%) rename apps/client/assets/Scripts/UI/{PlayerItemManager.ts => PlayerManager.ts} (87%) create mode 100644 apps/client/assets/Scripts/UI/PlayerManager.ts.meta rename apps/client/assets/Scripts/UI/{RoomItemManager.ts => RoomManager.ts} (87%) create mode 100644 apps/client/assets/Scripts/UI/RoomManager.ts.meta create mode 100644 apps/client/assets/resources/prefab/Actor.prefab rename apps/client/assets/resources/prefab/{Hall/PlayerItem.prefab.meta => Actor.prefab.meta} (61%) delete mode 100644 apps/client/assets/resources/prefab/Hall.meta delete mode 100644 apps/client/assets/resources/prefab/Hall/PlayerItem.prefab rename apps/client/assets/resources/prefab/{Hall/RoomItem.prefab => Room.prefab} (95%) rename apps/client/assets/resources/prefab/{Hall/RoomItem.prefab.meta => Room.prefab.meta} (85%) rename apps/client/assets/resources/texture/{player.meta => actor.meta} (100%) rename apps/client/assets/resources/texture/{player/player1.meta => actor/actor1.meta} (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (1).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (1).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (2).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (2).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (3).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (3).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (4).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (4).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (5).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (5).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (6).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/idle/idle (6).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (1).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (1).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (2).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (2).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (3).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (3).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (4).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (4).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (5).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (5).png.meta (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (6).png (100%) rename apps/client/assets/resources/texture/{player/player1 => actor/actor1}/run/run (6).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2.meta => actor/actor2.meta} (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (1).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (1).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (2).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (2).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (3).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (3).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (4).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (4).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (5).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (5).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (6).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/idle/idle (6).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (1).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (1).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (2).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (2).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (3).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (3).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (4).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (4).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (5).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (5).png.meta (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (6).png (100%) rename apps/client/assets/resources/texture/{player/player2 => actor/actor2}/run/run (6).png.meta (100%) create mode 100644 apps/server/src/Common/Api.ts create mode 100644 apps/server/src/Common/Api.ts.meta create mode 100644 apps/server/src/Common/Enum.ts create mode 100644 apps/server/src/Common/Enum.ts.meta create mode 100644 apps/server/src/Common/Model.ts create mode 100644 apps/server/src/Common/Model.ts.meta create mode 100644 apps/server/src/Common/Msg.ts create mode 100644 apps/server/src/Common/Msg.ts.meta create mode 100644 apps/server/src/Common/State.ts create mode 100644 apps/server/src/Common/State.ts.meta create mode 100644 apps/server/src/Common/index.ts.meta diff --git a/apps/client/assets/Scenes/Hall.scene b/apps/client/assets/Scenes/Hall.scene index 712de6f..ab4c938 100644 --- a/apps/client/assets/Scenes/Hall.scene +++ b/apps/client/assets/Scenes/Hall.scene @@ -1996,14 +1996,14 @@ "playerContainer": { "__id__": 23 }, - "playerItem": { + "playerPrefab": { "__uuid__": "7b0c739f-cf46-48f7-8c15-c97ab34268fe", "__expectedType__": "cc.Prefab" }, "roomContainer": { "__id__": 36 }, - "roomItem": { + "roomPrefab": { "__uuid__": "b91571d9-7804-4e62-b9d4-eef2f8f0cadd", "__expectedType__": "cc.Prefab" }, diff --git a/apps/client/assets/Scenes/Room.scene b/apps/client/assets/Scenes/Room.scene index cd03035..0c462f3 100644 --- a/apps/client/assets/Scenes/Room.scene +++ b/apps/client/assets/Scenes/Room.scene @@ -1314,7 +1314,7 @@ }, "component": "", "_componentId": "8ee1b1zWztIraCgWh1qCNp9", - "handler": "handleGameStart", + "handler": "handleStart", "customEventData": "" }, { @@ -1688,7 +1688,7 @@ "playerContainer": { "__id__": 19 }, - "playerItem": { + "playerPrefab": { "__uuid__": "7b0c739f-cf46-48f7-8c15-c97ab34268fe", "__expectedType__": "cc.Prefab" }, diff --git a/apps/client/assets/Scripts/Entity/Player.meta b/apps/client/assets/Scripts/Common.meta similarity index 77% rename from apps/client/assets/Scripts/Entity/Player.meta rename to apps/client/assets/Scripts/Common.meta index 9007398..083b650 100644 --- a/apps/client/assets/Scripts/Entity/Player.meta +++ b/apps/client/assets/Scripts/Common.meta @@ -2,7 +2,7 @@ "ver": "1.1.0", "importer": "directory", "imported": true, - "uuid": "5802fd2f-7823-4294-91c8-d71adca41319", + "uuid": "b5fb8ade-69bf-469c-9685-0d14804b00ac", "files": [], "subMetas": {}, "userData": { diff --git a/apps/client/assets/resources/prefab/Room.meta b/apps/client/assets/Scripts/Entity/Actor.meta similarity index 77% rename from apps/client/assets/resources/prefab/Room.meta rename to apps/client/assets/Scripts/Entity/Actor.meta index 04487e1..111b098 100644 --- a/apps/client/assets/resources/prefab/Room.meta +++ b/apps/client/assets/Scripts/Entity/Actor.meta @@ -2,7 +2,7 @@ "ver": "1.1.0", "importer": "directory", "imported": true, - "uuid": "d4aded25-46cd-4911-b695-170d2eb72fd6", + "uuid": "b207a15b-0f84-4e83-93de-cb6186e22772", "files": [], "subMetas": {}, "userData": { diff --git a/apps/client/assets/Scripts/Entity/Player/PlayerManager.ts b/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts similarity index 81% rename from apps/client/assets/Scripts/Entity/Player/PlayerManager.ts rename to apps/client/assets/Scripts/Entity/Actor/ActorManager.ts index 0852c80..f4789ce 100644 --- a/apps/client/assets/Scripts/Entity/Player/PlayerManager.ts +++ b/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts @@ -1,14 +1,16 @@ import { _decorator, instantiate, ProgressBar, Label } from 'cc'; import { EntityManager } from '../../Base/EntityManager'; -import { EntityTypeEnum, EntityStateEnum, InputType } from '../../Enum'; -import DataManager, { IPlayer, IVec2 } from '../../Global/DataManager'; +import { ApiMsgEnum, EntityTypeEnum, IActor, InputTypeEnum, IVec2 } from '../../Common'; +import { EntityStateEnum } from '../../Enum'; +import DataManager from '../../Global/DataManager'; +import NetworkManager from '../../Global/NetworkManager'; import { rad2Angle } from '../../Utils'; import { WeaponManager } from '../Weapon/WeaponManager'; -import { PlayerStateMachine } from './PlayerStateMachine'; +import { PlayerStateMachine } from './ActorStateMachine'; const { ccclass } = _decorator; -@ccclass('PlayerManager') -export class PlayerManager extends EntityManager { +@ccclass('ActorManager') +export class ActorManager extends EntityManager implements IActor { //静态数据 id: number nickname: string @@ -29,7 +31,7 @@ export class PlayerManager extends EntityManager { return DataManager.Instance.myPlayerId === this.id } - init(data: IPlayer) { + init(data: IActor) { const { id, nickname, type, weaponType, bulletType } = data this.id = id this.nickname = nickname @@ -58,8 +60,8 @@ export class PlayerManager extends EntityManager { } const { x, y } = DataManager.Instance.jm.input - DataManager.Instance.applyInput({ - type: InputType.PlayerMove, + NetworkManager.Instance.sendMsg(ApiMsgEnum.MsgClientSync, { + type: InputTypeEnum.ActorMove, id: this.id, direction: { x, @@ -69,21 +71,21 @@ export class PlayerManager extends EntityManager { }) } - render(data: IPlayer) { + render(data: IActor) { this.renderHP(data) this.renderPosition(data) this.renderDirection(data) } - renderHP(data: IPlayer) { + renderHP(data: IActor) { this.hpBar.progress = data.hp / this.hpBar.totalLength } - renderPosition(data: IPlayer) { + renderPosition(data: IActor) { this.node.setPosition(data.position.x, data.position.y) } - renderDirection(data: IPlayer) { + renderDirection(data: IActor) { if (data.direction.x === 0 && data.direction.y === 0) { this.state = EntityStateEnum.Idle return diff --git a/apps/client/assets/Scripts/UI/PlayerItemManager.ts.meta b/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts.meta similarity index 70% rename from apps/client/assets/Scripts/UI/PlayerItemManager.ts.meta rename to apps/client/assets/Scripts/Entity/Actor/ActorManager.ts.meta index 4547002..4fb4518 100644 --- a/apps/client/assets/Scripts/UI/PlayerItemManager.ts.meta +++ b/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts.meta @@ -2,7 +2,7 @@ "ver": "4.0.23", "importer": "typescript", "imported": true, - "uuid": "0b36580d-5fc7-40c1-9ac0-0fb78a685fd1", + "uuid": "aaa694fa-4476-44b2-9213-4b4978a57d66", "files": [], "subMetas": {}, "userData": {} diff --git a/apps/client/assets/Scripts/Entity/Player/PlayerStateMachine.ts b/apps/client/assets/Scripts/Entity/Actor/ActorStateMachine.ts similarity index 93% rename from apps/client/assets/Scripts/Entity/Player/PlayerStateMachine.ts rename to apps/client/assets/Scripts/Entity/Actor/ActorStateMachine.ts index f8b950f..f35ba25 100644 --- a/apps/client/assets/Scripts/Entity/Player/PlayerStateMachine.ts +++ b/apps/client/assets/Scripts/Entity/Actor/ActorStateMachine.ts @@ -1,7 +1,8 @@ import { _decorator, Animation, AnimationClip } from 'cc' import State from '../../Base/State' import StateMachine, { getInitParamsTrigger } from '../../Base/StateMachine' -import { EntityTypeEnum, EntityStateEnum, ParamsNameEnum } from '../../Enum' +import { EntityTypeEnum } from '../../Common' +import { EntityStateEnum, ParamsNameEnum } from '../../Enum' const { ccclass } = _decorator @ccclass('PlayerStateMachine') diff --git a/apps/client/assets/Scripts/UI/RoomItemManager.ts.meta b/apps/client/assets/Scripts/Entity/Actor/ActorStateMachine.ts.meta similarity index 70% rename from apps/client/assets/Scripts/UI/RoomItemManager.ts.meta rename to apps/client/assets/Scripts/Entity/Actor/ActorStateMachine.ts.meta index b1bb727..2357d90 100644 --- a/apps/client/assets/Scripts/UI/RoomItemManager.ts.meta +++ b/apps/client/assets/Scripts/Entity/Actor/ActorStateMachine.ts.meta @@ -2,7 +2,7 @@ "ver": "4.0.23", "importer": "typescript", "imported": true, - "uuid": "26da1a71-eb0d-463d-b2d6-fbc64bf0ab89", + "uuid": "67239e69-9cbb-42c8-ae8f-27f8bae24103", "files": [], "subMetas": {}, "userData": {} diff --git a/apps/client/assets/Scripts/Entity/Player/PlayerManager.ts.meta b/apps/client/assets/Scripts/Entity/Actor/PlayerManager.ts.meta similarity index 100% rename from apps/client/assets/Scripts/Entity/Player/PlayerManager.ts.meta rename to apps/client/assets/Scripts/Entity/Actor/PlayerManager.ts.meta diff --git a/apps/client/assets/Scripts/Entity/Player/PlayerStateMachine.ts.meta b/apps/client/assets/Scripts/Entity/Actor/PlayerStateMachine.ts.meta similarity index 100% rename from apps/client/assets/Scripts/Entity/Player/PlayerStateMachine.ts.meta rename to apps/client/assets/Scripts/Entity/Actor/PlayerStateMachine.ts.meta diff --git a/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts b/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts index 6f1759c..79dc292 100644 --- a/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts +++ b/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts @@ -1,7 +1,8 @@ import { _decorator } from 'cc' import { EntityManager } from '../../Base/EntityManager' -import { EntityTypeEnum, EntityStateEnum, EventEnum } from '../../Enum' -import DataManager, { IBullet, IVec2 } from '../../Global/DataManager' +import { EntityTypeEnum, IBullet, IVec2 } from '../../Common' +import { EntityStateEnum, EventEnum } from '../../Enum' +import DataManager from '../../Global/DataManager' import EventManager from '../../Global/EventManager' import ObjectPoolManager from '../../Global/ObjectPoolManager' import { rad2Angle } from '../../Utils' @@ -10,7 +11,7 @@ import { BulletStateMachine } from './BulletStateMachine' const { ccclass } = _decorator @ccclass('BulletManager') -export class BulletManager extends EntityManager { +export class BulletManager extends EntityManager implements IBullet { //静态数据 id: number owner: number diff --git a/apps/client/assets/Scripts/Entity/Bullet/BulletStateMachine.ts b/apps/client/assets/Scripts/Entity/Bullet/BulletStateMachine.ts index 33bd08c..389c6a4 100644 --- a/apps/client/assets/Scripts/Entity/Bullet/BulletStateMachine.ts +++ b/apps/client/assets/Scripts/Entity/Bullet/BulletStateMachine.ts @@ -1,7 +1,8 @@ import { _decorator, Animation } from 'cc' import State from '../../Base/State' import StateMachine, { getInitParamsTrigger } from '../../Base/StateMachine' -import { EntityTypeEnum, EntityStateEnum, ParamsNameEnum } from '../../Enum' +import { EntityTypeEnum } from '../../Common' +import { EntityStateEnum, ParamsNameEnum } from '../../Enum' const { ccclass } = _decorator @ccclass('BulletStateMachine') diff --git a/apps/client/assets/Scripts/Entity/Explosion/ExplosionManager.ts b/apps/client/assets/Scripts/Entity/Explosion/ExplosionManager.ts index 8ecf726..54a95ba 100644 --- a/apps/client/assets/Scripts/Entity/Explosion/ExplosionManager.ts +++ b/apps/client/assets/Scripts/Entity/Explosion/ExplosionManager.ts @@ -1,7 +1,7 @@ import { _decorator } from 'cc' import { EntityManager } from '../../Base/EntityManager' -import { EntityTypeEnum, EntityStateEnum } from '../../Enum' -import { IVec2 } from '../../Global/DataManager' +import { EntityTypeEnum, IVec2 } from '../../Common' +import { EntityStateEnum } from '../../Enum' import { ExplosionStateMachine } from './ExplosionStateMachine' const { ccclass, property } = _decorator diff --git a/apps/client/assets/Scripts/Entity/Explosion/ExplosionStateMachine.ts b/apps/client/assets/Scripts/Entity/Explosion/ExplosionStateMachine.ts index 71edb61..ec4d32f 100644 --- a/apps/client/assets/Scripts/Entity/Explosion/ExplosionStateMachine.ts +++ b/apps/client/assets/Scripts/Entity/Explosion/ExplosionStateMachine.ts @@ -1,7 +1,8 @@ import { _decorator, Animation } from 'cc' import State from '../../Base/State' import StateMachine, { getInitParamsTrigger } from '../../Base/StateMachine' -import { EntityTypeEnum, EntityStateEnum, ParamsNameEnum } from '../../Enum' +import { EntityTypeEnum } from '../../Common' +import { EntityStateEnum, ParamsNameEnum } from '../../Enum' import ObjectPoolManager from '../../Global/ObjectPoolManager' const { ccclass, property } = _decorator diff --git a/apps/client/assets/Scripts/Entity/Weapon/WeaponManager.ts b/apps/client/assets/Scripts/Entity/Weapon/WeaponManager.ts index b6151a6..6ff4779 100644 --- a/apps/client/assets/Scripts/Entity/Weapon/WeaponManager.ts +++ b/apps/client/assets/Scripts/Entity/Weapon/WeaponManager.ts @@ -1,8 +1,10 @@ import { _decorator, Node, Vec2, UITransform } from 'cc' import { EntityManager } from '../../Base/EntityManager' -import { EntityTypeEnum, EntityStateEnum, EventEnum, InputType } from '../../Enum' -import DataManager, { IPlayer } from '../../Global/DataManager' +import { ApiMsgEnum, EntityTypeEnum, InputTypeEnum } from '../../Common' +import { EntityStateEnum, EventEnum } from '../../Enum' +import DataManager from '../../Global/DataManager' import EventManager from '../../Global/EventManager' +import NetworkManager from '../../Global/NetworkManager' import { WeaponStateMachine } from './WeaponStateMachine' const { ccclass } = _decorator @@ -19,7 +21,7 @@ export class WeaponManager extends EntityManager { return DataManager.Instance.myPlayerId === this.owner } - init({ id, weaponType }: IPlayer) { + init({ id, weaponType }: { id: number, weaponType: EntityTypeEnum }) { this.owner = id this.type = weaponType @@ -58,8 +60,8 @@ export class WeaponManager extends EntityManager { const anchorWorldPos = this.anchor.getWorldPosition() const directionVec2 = new Vec2(pointWorldPos.x - anchorWorldPos.x, pointWorldPos.y - anchorWorldPos.y).normalize() - DataManager.Instance.applyInput({ - type: InputType.WeaponShoot, + NetworkManager.Instance.sendMsg(ApiMsgEnum.MsgClientSync, { + type: InputTypeEnum.WeaponShoot, owner: this.owner, position: { x: pointStagePos.x, diff --git a/apps/client/assets/Scripts/Entity/Weapon/WeaponStateMachine.ts b/apps/client/assets/Scripts/Entity/Weapon/WeaponStateMachine.ts index be897cc..1fb342b 100644 --- a/apps/client/assets/Scripts/Entity/Weapon/WeaponStateMachine.ts +++ b/apps/client/assets/Scripts/Entity/Weapon/WeaponStateMachine.ts @@ -1,7 +1,8 @@ import { _decorator, Animation, AnimationClip } from 'cc' import State from '../../Base/State' import StateMachine, { getInitParamsTrigger } from '../../Base/StateMachine' -import { EntityStateEnum, EntityTypeEnum, ParamsNameEnum } from '../../Enum' +import { EntityTypeEnum } from '../../Common' +import { EntityStateEnum, ParamsNameEnum } from '../../Enum' import { WeaponManager } from './WeaponManager' const { ccclass } = _decorator diff --git a/apps/client/assets/Scripts/Enum/index.ts b/apps/client/assets/Scripts/Enum/index.ts index c052bad..a6decc0 100644 --- a/apps/client/assets/Scripts/Enum/index.ts +++ b/apps/client/assets/Scripts/Enum/index.ts @@ -23,23 +23,10 @@ export enum EventEnum { GameStart = 'GameStart', } -export enum EntityTypeEnum { - Map1 = 'Map1', - Player1 = 'Player1', - Player2 = 'Player2', - Weapon1 = 'Weapon1', - Weapon2 = 'Weapon2', - Bullet1 = 'Bullet1', - Bullet2 = 'Bullet2', - Explosion = 'Explosion', - JoyStick = 'JoyStick', - Shoot = 'Shoot', -} - export enum PrefabPathEnum { Map1 = 'prefab/Map1', - Player1 = 'prefab/Player', - Player2 = 'prefab/Player', + Actor1 = 'prefab/Actor', + Actor2 = 'prefab/Actor', Weapon1 = 'prefab/Weapon1', Weapon2 = 'prefab/Weapon2', Bullet1 = 'prefab/Bullet', @@ -50,10 +37,10 @@ export enum PrefabPathEnum { } export enum TexturePathEnum { - Player1Idle = 'texture/player/player1/idle', - Player1Run = 'texture/player/player1/run', - Player2Idle = 'texture/player/player2/idle', - Player2Run = 'texture/player/player2/run', + Actor1Idle = 'texture/actor/actor1/idle', + Actor1Run = 'texture/actor/actor1/run', + Actor2Idle = 'texture/actor/actor2/idle', + Actor2Run = 'texture/actor/actor2/run', Weapon1Idle = 'texture/weapon/weapon1/idle', Weapon1Attack = 'texture/weapon/weapon1/attack', Weapon2Idle = 'texture/weapon/weapon2/idle', @@ -63,12 +50,6 @@ export enum TexturePathEnum { ExplosionIdle = 'texture/explosion', } -export enum InputType { - PlayerMove = 'PlayerMove', - WeaponShoot = 'WeaponShoot', - TimePast = 'TimePast', -} - export enum SceneEnum { Login = 'Login', Hall = 'Hall', diff --git a/apps/client/assets/Scripts/Global/DataManager.ts b/apps/client/assets/Scripts/Global/DataManager.ts index 3e6f32e..512196c 100644 --- a/apps/client/assets/Scripts/Global/DataManager.ts +++ b/apps/client/assets/Scripts/Global/DataManager.ts @@ -1,14 +1,12 @@ import { Node, Prefab, SpriteFrame } from 'cc' import Singleton from '../Base/Singleton' +import { EntityTypeEnum, IBullet, IClientInput, InputTypeEnum, IRoom, IState } from '../Common' +import { ActorManager } from '../Entity/Actor/ActorManager' import { BulletManager } from '../Entity/Bullet/BulletManager' -import { PlayerManager } from '../Entity/Player/PlayerManager' -import { EntityTypeEnum, EventEnum, InputType } from '../Enum' +import { EventEnum } from '../Enum' import { JoyStickManager } from '../UI/JoyStickManager' import EventManager from './EventManager' -import { IData } from './NetworkManager' -export type IPlayer = Pick -export type IBullet = Pick const PLAYER_SPEED = 100 const BULLET_SPEED = 600 @@ -18,36 +16,6 @@ const WEAPON_DAMAGE = 5 const PLAYER_RADIUS = 50 const BULLET_RADIUS = 10 -export interface IVec2 { - x: number; - y: number -} - -interface IState { - players: IPlayer[], - bullets: IBullet[], - nextBulletId: number -} - -interface IPlayerMove { - type: InputType.PlayerMove - id: number; - direction: IVec2; - dt: number; -} - -interface IWeaponShoot { - type: InputType.WeaponShoot - owner: number; - position: IVec2; - direction: IVec2; -} - -interface ITimePast { - type: InputType.TimePast; - dt: number -} - export default class DataManager extends Singleton { static get Instance() { return super.GetInstance() @@ -59,11 +27,11 @@ export default class DataManager extends Singleton { prefabMap: Map = new Map() textureMap: Map = new Map() - playerMap: Map = new Map() + actorMap: Map = new Map() bulletMap: Map = new Map() myPlayerId = 1 - roomInfo: IData + roomInfo: IRoom mapSize = { x: 960, y: 640, @@ -82,7 +50,7 @@ export default class DataManager extends Singleton { y: 0 }, hp: 100, - type: EntityTypeEnum.Player1, + type: EntityTypeEnum.Actor1, weaponType: EntityTypeEnum.Weapon1, bulletType: EntityTypeEnum.Bullet1, }, { @@ -97,7 +65,7 @@ export default class DataManager extends Singleton { y: -1 }, hp: 100, - type: EntityTypeEnum.Player2, + type: EntityTypeEnum.Actor2, weaponType: EntityTypeEnum.Weapon2, bulletType: EntityTypeEnum.Bullet2, }], @@ -105,9 +73,9 @@ export default class DataManager extends Singleton { nextBulletId: 1 } - applyInput(input: IPlayerMove | IWeaponShoot | ITimePast) { + applyInput(input: IClientInput) { switch (input.type) { - case InputType.PlayerMove: { + case InputTypeEnum.ActorMove: { const { direction: { x, y }, dt, id } = input const player = this.state.players.find(e => e.id === id) if (!player) { @@ -120,21 +88,21 @@ export default class DataManager extends Singleton { break } - case InputType.WeaponShoot: { + case InputTypeEnum.WeaponShoot: { const { owner, position, direction } = input const bullet: IBullet = { id: this.state.nextBulletId++, owner, position, direction, - type: this.playerMap.get(owner).bulletType + type: this.actorMap.get(owner).bulletType } this.state.bullets.push(bullet) EventManager.Instance.emit(EventEnum.BulletBorn, owner) break } - case InputType.TimePast: { + case InputTypeEnum.TimePast: { const { dt } = input const { bullets, players } = this.state diff --git a/apps/client/assets/Scripts/Global/NetworkManager.ts b/apps/client/assets/Scripts/Global/NetworkManager.ts index 9c758e9..a5c558b 100644 --- a/apps/client/assets/Scripts/Global/NetworkManager.ts +++ b/apps/client/assets/Scripts/Global/NetworkManager.ts @@ -1,27 +1,15 @@ import Singleton from '../Base/Singleton' +import { IModel } from '../Common'; const TIMEOUT = 5000 -export type IData = Record - -export interface ICallApiRet { +export interface ICallApiRet { success: boolean; error?: Error; - res?: IData -} - -export enum ApiMsgEnum { - ApiPlayerList = 'ApiPlayerList', - ApiPlayerJoin = 'ApiPlayerJoin', - ApiRoomList = 'ApiRoomList', - ApiRoomCreate = 'ApiRoomCreate', - ApiRoomJoin = 'ApiRoomJoin', - ApiRoomLeave = 'ApiRoomLeave', - MsgPlayerList = 'MsgPlayerList', - MsgRoomList = 'MsgRoomList', - MsgRoom = 'MsgRoom', + res?: T } +type aaa = keyof IModel export default class NetworkManager extends Singleton { static get Instance() { return super.GetInstance() @@ -71,11 +59,36 @@ export default class NetworkManager extends Singleton { }) } - sendMsg(name: string, data: IData) { + callApi(name: T, data: IModel['api'][T]['req']): Promise> { + return new Promise((resolve) => { + try { + // 超时处理 + const timer = setTimeout(() => { + resolve({ success: false, error: new Error('timeout') }) + this.unlistenMsg(name, cb) + }, TIMEOUT) + + // 回调处理 + const cb = (res) => { + resolve(res) + clearTimeout(timer) + this.unlistenMsg(name, cb) + } + this.listenMsg(name as any, cb) + + this.ws.send(JSON.stringify({ name, data })) + } catch (error) { + console.log(error) + resolve({ success: false, error: error as Error }) + } + }) + } + + sendMsg(name: T, data: IModel['msg'][T]) { this.ws.send(JSON.stringify({ name, data })) } - listenMsg(name: string, cb: Function) { + listenMsg(name: T, cb: (args: IModel['msg'][T]) => void) { if (this.cbs.has(name)) { this.cbs.get(name).push(cb) } else { @@ -89,29 +102,4 @@ export default class NetworkManager extends Singleton { index > -1 && this.cbs.get(name).splice(index, 1) } } - - callApi(name: string, data: IData) { - return new Promise((resolve) => { - try { - // 超时处理 - const timer = setTimeout(() => { - resolve({ success: false, error: new Error('timeout') }) - this.unlistenMsg(name, cb) - }, TIMEOUT) - - // 回调处理 - const cb = (res: ICallApiRet) => { - resolve(res) - clearTimeout(timer) - this.unlistenMsg(name, cb) - } - this.listenMsg(name, cb) - - this.ws.send(JSON.stringify({ name, data })) - } catch (error) { - console.log(error) - resolve({ success: false, error: error as Error }) - } - }) - } } diff --git a/apps/client/assets/Scripts/Global/ObjectPoolManager.ts b/apps/client/assets/Scripts/Global/ObjectPoolManager.ts index 4e35294..41c332a 100644 --- a/apps/client/assets/Scripts/Global/ObjectPoolManager.ts +++ b/apps/client/assets/Scripts/Global/ObjectPoolManager.ts @@ -1,7 +1,7 @@ import Singleton from '../Base/Singleton' import { instantiate, Node } from 'cc' -import { EntityTypeEnum } from '../Enum' import DataManager from './DataManager' +import { EntityTypeEnum } from '../Common' export default class ObjectPoolManager extends Singleton { static get Instance() { diff --git a/apps/client/assets/Scripts/Scene/BattleManager.ts b/apps/client/assets/Scripts/Scene/BattleManager.ts index 819f5bc..e45b509 100644 --- a/apps/client/assets/Scripts/Scene/BattleManager.ts +++ b/apps/client/assets/Scripts/Scene/BattleManager.ts @@ -1,12 +1,13 @@ import { _decorator, Component, Node, Prefab, instantiate, SpriteFrame } from 'cc'; -import { PlayerManager } from '../Entity/Player/PlayerManager'; +import { ActorManager } from '../Entity/Actor/ActorManager'; import DataManager from '../Global/DataManager'; import { JoyStickManager } from '../UI/JoyStickManager'; import { ResourceManager } from '../Global/ResourceManager'; -import { EntityTypeEnum, InputType, PrefabPathEnum, TexturePathEnum } from '../Enum'; +import { PrefabPathEnum, TexturePathEnum } from '../Enum'; import NetworkManager from '../Global/NetworkManager'; import ObjectPoolManager from '../Global/ObjectPoolManager'; import { BulletManager } from '../Entity/Bullet/BulletManager'; +import { EntityTypeEnum, InputTypeEnum } from '../Common'; const { ccclass } = _decorator; @@ -98,7 +99,7 @@ export class BattleManager extends Component { tickPlayer(dt: number) { for (const p of DataManager.Instance.state.players) { - const playerManager = DataManager.Instance.playerMap.get(p.id) + const playerManager = DataManager.Instance.actorMap.get(p.id) if (!playerManager) { return } @@ -108,7 +109,7 @@ export class BattleManager extends Component { tickGlobal(dt: number) { DataManager.Instance.applyInput({ - type: InputType.TimePast, + type: InputTypeEnum.TimePast, dt }) } @@ -120,13 +121,13 @@ export class BattleManager extends Component { renderPlayer() { for (const p of DataManager.Instance.state.players) { - let playerManager = DataManager.Instance.playerMap.get(p.id) + let playerManager = DataManager.Instance.actorMap.get(p.id) if (!playerManager) { const playerPrefab = DataManager.Instance.prefabMap.get(p.type) const player = instantiate(playerPrefab) player.setParent(this.stage) - playerManager = player.addComponent(PlayerManager) - DataManager.Instance.playerMap.set(p.id, playerManager) + playerManager = player.addComponent(ActorManager) + DataManager.Instance.actorMap.set(p.id, playerManager) playerManager.init(p) } else { playerManager.render(p) diff --git a/apps/client/assets/Scripts/Scene/HallManager.ts b/apps/client/assets/Scripts/Scene/HallManager.ts index bb5bc53..2c30918 100644 --- a/apps/client/assets/Scripts/Scene/HallManager.ts +++ b/apps/client/assets/Scripts/Scene/HallManager.ts @@ -1,10 +1,11 @@ import { _decorator, Component, Node, Prefab, director, instantiate } from 'cc'; +import { ApiMsgEnum, IApiPlayerListRes, IApiRoomListRes, IMsgPlayerList, IMsgRoomList } from '../Common'; import { EventEnum, SceneEnum } from '../Enum'; import DataManager from '../Global/DataManager'; import EventManager from '../Global/EventManager'; -import NetworkManager, { ApiMsgEnum, IData } from '../Global/NetworkManager'; -import { PlayerItemManager } from '../UI/PlayerItemManager'; -import { RoomItemManager } from '../UI/RoomItemManager'; +import NetworkManager from '../Global/NetworkManager'; +import { PlayerManager } from '../UI/PlayerManager'; +import { RoomManager } from '../UI/RoomManager'; const { ccclass, property } = _decorator; @ccclass('HallManager') @@ -13,24 +14,24 @@ export class HallManager extends Component { playerContainer: Node = null; @property(Prefab) - playerItem: Prefab = null; + playerPrefab: Prefab = null; @property(Node) roomContainer: Node = null; @property(Prefab) - roomItem: Prefab = null; + roomPrefab: Prefab = null; onLoad() { director.preloadScene(SceneEnum.Room); EventManager.Instance.on(EventEnum.RoomJoin, this.joinRoom, this) - NetworkManager.Instance.listenMsg(ApiMsgEnum.MsgPlayerList, this.renderPlayer); + NetworkManager.Instance.listenMsg(ApiMsgEnum.MsgPlayerList, this.renderPlayers); NetworkManager.Instance.listenMsg(ApiMsgEnum.MsgRoomList, this.renderRooms); } onDestroy() { EventManager.Instance.off(EventEnum.RoomJoin, this.joinRoom, this) - NetworkManager.Instance.unlistenMsg(ApiMsgEnum.MsgPlayerList, this.renderPlayer); + NetworkManager.Instance.unlistenMsg(ApiMsgEnum.MsgPlayerList, this.renderPlayers); NetworkManager.Instance.unlistenMsg(ApiMsgEnum.MsgRoomList, this.renderRooms); } @@ -46,15 +47,15 @@ export class HallManager extends Component { return; } - this.renderPlayer(res) + this.renderPlayers(res) } - renderPlayer = ({ list }: IData) => { + renderPlayers = ({ list }: IApiPlayerListRes | IMsgPlayerList) => { for (const item of this.playerContainer.children) { item.active = false } while (this.playerContainer.children.length < list.length) { - const playerItem = instantiate(this.playerItem); + const playerItem = instantiate(this.playerPrefab); playerItem.active = false playerItem.setParent(this.playerContainer) } @@ -62,7 +63,7 @@ export class HallManager extends Component { for (let i = 0; i < list.length; i++) { const data = list[i]; const node = this.playerContainer.children[i] - const playerItemManager = node.getComponent(PlayerItemManager) + const playerItemManager = node.getComponent(PlayerManager) playerItemManager.init(data) } } @@ -77,12 +78,12 @@ export class HallManager extends Component { this.renderRooms(res) } - renderRooms = ({ list }: IData) => { + renderRooms = ({ list }: IApiRoomListRes | IMsgRoomList) => { for (const item of this.roomContainer.children) { item.active = false } while (this.roomContainer.children.length < list.length) { - const roomItem = instantiate(this.roomItem); + const roomItem = instantiate(this.roomPrefab); roomItem.active = false roomItem.setParent(this.roomContainer) } @@ -90,7 +91,7 @@ export class HallManager extends Component { for (let i = 0; i < list.length; i++) { const data = list[i]; const node = this.roomContainer.children[i] - const roomItemManager = node.getComponent(RoomItemManager) + const roomItemManager = node.getComponent(RoomManager) roomItemManager.init(data) } } @@ -102,8 +103,7 @@ export class HallManager extends Component { return; } - DataManager.Instance.roomInfo = { ...res } - + DataManager.Instance.roomInfo = res.room director.loadScene(SceneEnum.Room); } @@ -114,8 +114,7 @@ export class HallManager extends Component { return; } - DataManager.Instance.roomInfo = { ...res } - + DataManager.Instance.roomInfo = res.room director.loadScene(SceneEnum.Room); } } diff --git a/apps/client/assets/Scripts/Scene/LoginManager.ts b/apps/client/assets/Scripts/Scene/LoginManager.ts index ae90435..76742ec 100644 --- a/apps/client/assets/Scripts/Scene/LoginManager.ts +++ b/apps/client/assets/Scripts/Scene/LoginManager.ts @@ -1,7 +1,8 @@ -import { _decorator, Component, Node, EditBox, Button, director } from 'cc'; +import { _decorator, Component, EditBox, director } from 'cc'; +import { ApiMsgEnum } from '../Common'; import { SceneEnum } from '../Enum'; import DataManager from '../Global/DataManager'; -import NetworkManager, { ApiMsgEnum } from '../Global/NetworkManager'; +import NetworkManager from '../Global/NetworkManager'; const { ccclass, property } = _decorator; @ccclass('LoginManager') @@ -16,7 +17,6 @@ export class LoginManager extends Component { async start() { await NetworkManager.Instance.connect(); console.log("服务连接成功!"); - } async handleClick() { @@ -38,7 +38,7 @@ export class LoginManager extends Component { return; } - DataManager.Instance.myPlayerId = res.id; + DataManager.Instance.myPlayerId = res.player.id; director.loadScene(SceneEnum.Hall); } } diff --git a/apps/client/assets/Scripts/Scene/RoomManager.ts b/apps/client/assets/Scripts/Scene/RoomManager.ts index adbc5cf..e8cead8 100644 --- a/apps/client/assets/Scripts/Scene/RoomManager.ts +++ b/apps/client/assets/Scripts/Scene/RoomManager.ts @@ -1,9 +1,10 @@ import { _decorator, Component, Node, Prefab, director, instantiate } from 'cc'; +import { ApiMsgEnum, IMsgGameStart, IMsgRoom } from '../Common'; import { EventEnum, SceneEnum } from '../Enum'; import DataManager from '../Global/DataManager'; import EventManager from '../Global/EventManager'; -import NetworkManager, { ApiMsgEnum, IData } from '../Global/NetworkManager'; -import { PlayerItemManager } from '../UI/PlayerItemManager'; +import NetworkManager from '../Global/NetworkManager'; +import { PlayerManager } from '../UI/PlayerManager'; const { ccclass, property } = _decorator; @ccclass('RoomManager') @@ -12,27 +13,31 @@ export class RoomManager extends Component { playerContainer: Node = null; @property(Prefab) - playerItem: Prefab = null; + playerPrefab: Prefab = null; onLoad() { director.preloadScene(SceneEnum.Battle); - NetworkManager.Instance.listenMsg(ApiMsgEnum.MsgRoom, this.renderPlayer); + NetworkManager.Instance.listenMsg(ApiMsgEnum.MsgRoom, this.renderPlayers); + NetworkManager.Instance.listenMsg(ApiMsgEnum.MsgGameStart, this.startGame); } onDestroy() { - NetworkManager.Instance.unlistenMsg(ApiMsgEnum.MsgRoom, this.renderPlayer); + NetworkManager.Instance.unlistenMsg(ApiMsgEnum.MsgRoom, this.renderPlayers); + NetworkManager.Instance.unlistenMsg(ApiMsgEnum.MsgGameStart, this.startGame); } async start() { - this.renderPlayer(DataManager.Instance.roomInfo) + this.renderPlayers({ + room: DataManager.Instance.roomInfo + }) } - renderPlayer = ({ players: list }: any) => { + renderPlayers = ({ room: { players: list } }: IMsgRoom) => { for (const item of this.playerContainer.children) { item.active = false } while (this.playerContainer.children.length < list.length) { - const playerItem = instantiate(this.playerItem); + const playerItem = instantiate(this.playerPrefab); playerItem.active = false playerItem.setParent(this.playerContainer) } @@ -40,7 +45,7 @@ export class RoomManager extends Component { for (let i = 0; i < list.length; i++) { const data = list[i]; const node = this.playerContainer.children[i] - const playerItemManager = node.getComponent(PlayerItemManager) + const playerItemManager = node.getComponent(PlayerManager) playerItemManager.init(data) } } @@ -56,9 +61,20 @@ export class RoomManager extends Component { director.loadScene(SceneEnum.Hall); } - handleGameStart() { - console.log("handleGameStart"); + async handleStart() { + const { success, res, error } = await NetworkManager.Instance.callApi(ApiMsgEnum.ApiGameStart, { rid: DataManager.Instance.roomInfo.id }); + if (!success) { + console.log(error) + return; + } + // director.loadScene(SceneEnum.Battle); + } + + startGame = ({ state }: IMsgGameStart) => { + DataManager.Instance.state = state + + director.loadScene(SceneEnum.Battle); } } diff --git a/apps/client/assets/Scripts/UI/PlayerItemManager.ts b/apps/client/assets/Scripts/UI/PlayerManager.ts similarity index 87% rename from apps/client/assets/Scripts/UI/PlayerItemManager.ts rename to apps/client/assets/Scripts/UI/PlayerManager.ts index e48dfb8..018492d 100644 --- a/apps/client/assets/Scripts/UI/PlayerItemManager.ts +++ b/apps/client/assets/Scripts/UI/PlayerManager.ts @@ -4,8 +4,8 @@ import DataManager from '../Global/DataManager'; import EventManager from '../Global/EventManager'; const { ccclass, property } = _decorator; -@ccclass('PlayerItemManager') -export class PlayerItemManager extends Component { +@ccclass('PlayerManager') +export class PlayerManager extends Component { init({ id, nickname, rid }: { id: number, nickname: string, rid: number }) { const label = this.getComponent(Label) let str = nickname diff --git a/apps/client/assets/Scripts/UI/PlayerManager.ts.meta b/apps/client/assets/Scripts/UI/PlayerManager.ts.meta new file mode 100644 index 0000000..727a31e --- /dev/null +++ b/apps/client/assets/Scripts/UI/PlayerManager.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "741a7f88-76ef-4669-95a8-ce39c63a1c41", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/apps/client/assets/Scripts/UI/RoomItemManager.ts b/apps/client/assets/Scripts/UI/RoomManager.ts similarity index 87% rename from apps/client/assets/Scripts/UI/RoomItemManager.ts rename to apps/client/assets/Scripts/UI/RoomManager.ts index e33d5a0..b2ae3bd 100644 --- a/apps/client/assets/Scripts/UI/RoomItemManager.ts +++ b/apps/client/assets/Scripts/UI/RoomManager.ts @@ -3,8 +3,8 @@ import { EventEnum } from '../Enum'; import EventManager from '../Global/EventManager'; const { ccclass, property } = _decorator; -@ccclass('RoomItemManager') -export class RoomItemManager extends Component { +@ccclass('RoomManager') +export class RoomManager extends Component { id: number init({ id, players }: { id: number, players: Array<{ id: number, nickname: string }> }) { this.id = id diff --git a/apps/client/assets/Scripts/UI/RoomManager.ts.meta b/apps/client/assets/Scripts/UI/RoomManager.ts.meta new file mode 100644 index 0000000..5a6d56b --- /dev/null +++ b/apps/client/assets/Scripts/UI/RoomManager.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "23e17e0e-7637-4c8c-9af7-91dc0f41301b", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/apps/client/assets/resources/prefab/Actor.prefab b/apps/client/assets/resources/prefab/Actor.prefab new file mode 100644 index 0000000..89258da --- /dev/null +++ b/apps/client/assets/resources/prefab/Actor.prefab @@ -0,0 +1,690 @@ +[ + { + "__type__": "cc.Prefab", + "_name": "Actor", + "_objFlags": 0, + "_native": "", + "data": { + "__id__": 1 + }, + "optimizationPolicy": 0, + "persistent": false, + "asyncLoadAssets": false + }, + { + "__type__": "cc.Node", + "_name": "Actor", + "_objFlags": 0, + "__editorExtras__": {}, + "_parent": null, + "_children": [ + { + "__id__": 2 + }, + { + "__id__": 18 + }, + { + "__id__": 22 + } + ], + "_active": true, + "_components": [ + { + "__id__": 28 + }, + { + "__id__": 30 + } + ], + "_prefab": { + "__id__": 32 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_layer": 33554432, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "HP", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [ + { + "__id__": 3 + } + ], + "_active": true, + "_components": [ + { + "__id__": 11 + }, + { + "__id__": 13 + }, + { + "__id__": 15 + } + ], + "_prefab": { + "__id__": 17 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 70, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_layer": 33554432, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "Bar", + "_objFlags": 0, + "_parent": { + "__id__": 2 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 4 + }, + { + "__id__": 6 + }, + { + "__id__": 8 + } + ], + "_prefab": { + "__id__": 10 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": -50, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_layer": 33554432, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 3 + }, + "_enabled": true, + "__prefab": { + "__id__": 5 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 100, + "height": 15 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "6eSfVOfMxPjb1oQVZ1z5hY" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 3 + }, + "_enabled": true, + "__prefab": { + "__id__": 7 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 0, + "b": 0, + "a": 255 + }, + "_spriteFrame": { + "__uuid__": "24a704da-2867-446d-8d1a-5e920c75e09d@f9941", + "__expectedType__": "cc.SpriteFrame" + }, + "_type": 1, + "_fillType": 0, + "_sizeMode": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_useGrayscale": false, + "_atlas": null, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "267GXyiYJB6qxCg6pLEfLQ" + }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 3 + }, + "_enabled": true, + "__prefab": { + "__id__": 9 + }, + "_alignFlags": 8, + "_target": null, + "_left": 0, + "_right": 0, + "_top": 0, + "_bottom": 0, + "_horizontalCenter": 0, + "_verticalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 0, + "_originalHeight": 0, + "_alignMode": 2, + "_lockFlags": 0, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "160ZgDPIFBEZ5Msv1mYMvN" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "35OAlXyaBOBpLPAOKsDZHk" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "__prefab": { + "__id__": 12 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 100, + "height": 15 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "ca65l+rt9Iz5il0zQDlfgE" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "__prefab": { + "__id__": 14 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 0, + "g": 0, + "b": 0, + "a": 255 + }, + "_spriteFrame": { + "__uuid__": "9fd900dd-221b-4f89-8f2c-fba34243c835@f9941", + "__expectedType__": "cc.SpriteFrame" + }, + "_type": 1, + "_fillType": 0, + "_sizeMode": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_useGrayscale": false, + "_atlas": null, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "796J69Ia1LgrmmxsVBavZU" + }, + { + "__type__": "cc.ProgressBar", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "__prefab": { + "__id__": 16 + }, + "_barSprite": { + "__id__": 6 + }, + "_mode": 0, + "_totalLength": 100, + "_progress": 1, + "_reverse": false, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "d2mnLSm7RHF7V3bD57PvC5" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "29DaYGvxpFo5cOAmvhl1Uj" + }, + { + "__type__": "cc.Node", + "_name": "Nickname", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 19 + } + ], + "_prefab": { + "__id__": 21 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_layer": 33554432, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 18 + }, + "_enabled": true, + "__prefab": { + "__id__": 20 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 100, + "height": 100 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "8blUJZ4nJKpKsLO2YpEChI" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "5adoggTLFPToeEZEIA7Yh3" + }, + { + "__type__": "cc.Node", + "_name": "Label", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 23 + }, + { + "__id__": 25 + } + ], + "_prefab": { + "__id__": 27 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 98.845, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_layer": 33554432, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 22 + }, + "_enabled": true, + "__prefab": { + "__id__": 24 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 110.72, + "height": 50.4 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "2a/IDEWZRPcb6AKU5/XAlD" + }, + { + "__type__": "cc.Label", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 22 + }, + "_enabled": true, + "__prefab": { + "__id__": 26 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_string": "nickname", + "_horizontalAlign": 1, + "_verticalAlign": 1, + "_actualFontSize": 24, + "_fontSize": 24, + "_fontFamily": "Arial", + "_lineHeight": 40, + "_overflow": 0, + "_enableWrapText": true, + "_font": null, + "_isSystemFontUsed": true, + "_spacingX": 0, + "_isItalic": false, + "_isBold": true, + "_isUnderline": false, + "_underlineHeight": 2, + "_cacheMode": 0, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "71ZjYMvjBES7FqZGSo1L00" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "03OAmogbVI5qDqTUJvplOC" + }, + { + "__type__": "cc.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 29 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 100, + "height": 100 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "43sIN2Al5OsJRxFqY+HJTV" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 31 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_spriteFrame": { + "__uuid__": "f0f5e564-2d98-4de1-bb92-794eeb1acffc@f9941", + "__expectedType__": "cc.SpriteFrame" + }, + "_type": 0, + "_fillType": 0, + "_sizeMode": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_useGrayscale": false, + "_atlas": null, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "48V6DZW5BPxIbiTPVjSL37" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "60xKi1fHZAl6spWUrSZzlZ" + } +] \ No newline at end of file diff --git a/apps/client/assets/resources/prefab/Hall/PlayerItem.prefab.meta b/apps/client/assets/resources/prefab/Actor.prefab.meta similarity index 61% rename from apps/client/assets/resources/prefab/Hall/PlayerItem.prefab.meta rename to apps/client/assets/resources/prefab/Actor.prefab.meta index 73e984a..60d658e 100644 --- a/apps/client/assets/resources/prefab/Hall/PlayerItem.prefab.meta +++ b/apps/client/assets/resources/prefab/Actor.prefab.meta @@ -2,12 +2,12 @@ "ver": "1.1.39", "importer": "prefab", "imported": true, - "uuid": "7b0c739f-cf46-48f7-8c15-c97ab34268fe", + "uuid": "d565d84f-56c4-4aa3-831c-99db0a0d2390", "files": [ ".json" ], "subMetas": {}, "userData": { - "syncNodeName": "PlayerItem" + "syncNodeName": "Actor" } } diff --git a/apps/client/assets/resources/prefab/Hall.meta b/apps/client/assets/resources/prefab/Hall.meta deleted file mode 100644 index 91b8c57..0000000 --- a/apps/client/assets/resources/prefab/Hall.meta +++ /dev/null @@ -1,12 +0,0 @@ -{ - "ver": "1.1.0", - "importer": "directory", - "imported": true, - "uuid": "9348a0ae-1f83-44fe-ae79-892e1db86d1a", - "files": [], - "subMetas": {}, - "userData": { - "compressionType": {}, - "isRemoteBundle": {} - } -} diff --git a/apps/client/assets/resources/prefab/Hall/PlayerItem.prefab b/apps/client/assets/resources/prefab/Hall/PlayerItem.prefab deleted file mode 100644 index af47a71..0000000 --- a/apps/client/assets/resources/prefab/Hall/PlayerItem.prefab +++ /dev/null @@ -1,200 +0,0 @@ -[ - { - "__type__": "cc.Prefab", - "_name": "PlayerItem", - "_objFlags": 0, - "_native": "", - "data": { - "__id__": 1 - }, - "optimizationPolicy": 0, - "persistent": false, - "asyncLoadAssets": false - }, - { - "__type__": "cc.Node", - "_name": "PlayerItem", - "_objFlags": 0, - "__editorExtras__": {}, - "_parent": null, - "_children": [], - "_active": true, - "_components": [ - { - "__id__": 2 - }, - { - "__id__": 4 - }, - { - "__id__": 6 - }, - { - "__id__": 8 - } - ], - "_prefab": { - "__id__": 10 - }, - "_lpos": { - "__type__": "cc.Vec3", - "x": -460, - "y": -20, - "z": 0 - }, - "_lrot": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 - }, - "_lscale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 - }, - "_layer": 33554432, - "_euler": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_id": "" - }, - { - "__type__": "cc.UITransform", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 3 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 240, - "height": 50.4 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0, - "y": 1 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "69g2Ps4UpEQIdkibaU0mB+" - }, - { - "__type__": "cc.Label", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 5 - }, - "_customMaterial": null, - "_srcBlendFactor": 2, - "_dstBlendFactor": 4, - "_color": { - "__type__": "cc.Color", - "r": 255, - "g": 255, - "b": 255, - "a": 255 - }, - "_string": "这是一个昵称", - "_horizontalAlign": 0, - "_verticalAlign": 0, - "_actualFontSize": 40, - "_fontSize": 40, - "_fontFamily": "Arial", - "_lineHeight": 40, - "_overflow": 0, - "_enableWrapText": true, - "_font": null, - "_isSystemFontUsed": true, - "_spacingX": 0, - "_isItalic": false, - "_isBold": false, - "_isUnderline": false, - "_underlineHeight": 2, - "_cacheMode": 0, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "1fVVQb7LdIUZ7E43CVIsuV" - }, - { - "__type__": "cc.Widget", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 7 - }, - "_alignFlags": 8, - "_target": null, - "_left": 20, - "_right": 0, - "_top": 0, - "_bottom": 0, - "_horizontalCenter": 0, - "_verticalCenter": 0, - "_isAbsLeft": true, - "_isAbsRight": true, - "_isAbsTop": true, - "_isAbsBottom": true, - "_isAbsHorizontalCenter": true, - "_isAbsVerticalCenter": true, - "_originalWidth": 0, - "_originalHeight": 0, - "_alignMode": 2, - "_lockFlags": 0, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "1dyUPgippJNLS6AWV5oz7O" - }, - { - "__type__": "0b365gNX8dAwZrAD7eKaF/R", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 9 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "35yNVdeqZKy6dIzoq3eYwD" - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 1 - }, - "asset": { - "__id__": 0 - }, - "fileId": "fcj/6WYKJAnbG8wIajLBQ9" - } -] \ No newline at end of file diff --git a/apps/client/assets/resources/prefab/Player.prefab b/apps/client/assets/resources/prefab/Player.prefab index dce2fd4..315f793 100644 --- a/apps/client/assets/resources/prefab/Player.prefab +++ b/apps/client/assets/resources/prefab/Player.prefab @@ -17,122 +17,12 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": null, - "_children": [ - { - "__id__": 2 - }, - { - "__id__": 18 - }, - { - "__id__": 22 - } - ], - "_active": true, - "_components": [ - { - "__id__": 28 - }, - { - "__id__": 30 - } - ], - "_prefab": { - "__id__": 32 - }, - "_lpos": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_lrot": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 - }, - "_lscale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 - }, - "_layer": 33554432, - "_euler": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_id": "" - }, - { - "__type__": "cc.Node", - "_name": "HP", - "_objFlags": 0, - "_parent": { - "__id__": 1 - }, - "_children": [ - { - "__id__": 3 - } - ], - "_active": true, - "_components": [ - { - "__id__": 11 - }, - { - "__id__": 13 - }, - { - "__id__": 15 - } - ], - "_prefab": { - "__id__": 17 - }, - "_lpos": { - "__type__": "cc.Vec3", - "x": 0, - "y": 70, - "z": 0 - }, - "_lrot": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 - }, - "_lscale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 - }, - "_layer": 33554432, - "_euler": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_id": "" - }, - { - "__type__": "cc.Node", - "_name": "Bar", - "_objFlags": 0, - "_parent": { - "__id__": 2 - }, "_children": [], "_active": true, "_components": [ + { + "__id__": 2 + }, { "__id__": 4 }, @@ -148,8 +38,8 @@ }, "_lpos": { "__type__": "cc.Vec3", - "x": -50, - "y": 0, + "x": -460, + "y": -20, "z": 0 }, "_lrot": { @@ -179,38 +69,38 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 3 + "__id__": 1 }, "_enabled": true, "__prefab": { - "__id__": 5 + "__id__": 3 }, "_contentSize": { "__type__": "cc.Size", - "width": 100, - "height": 15 + "width": 240, + "height": 50.4 }, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0, - "y": 0.5 + "y": 1 }, "_id": "" }, { "__type__": "cc.CompPrefabInfo", - "fileId": "6eSfVOfMxPjb1oQVZ1z5hY" + "fileId": "69g2Ps4UpEQIdkibaU0mB+" }, { - "__type__": "cc.Sprite", + "__type__": "cc.Label", "_name": "", "_objFlags": 0, "node": { - "__id__": 3 + "__id__": 1 }, "_enabled": true, "__prefab": { - "__id__": 7 + "__id__": 5 }, "_customMaterial": null, "_srcBlendFactor": 2, @@ -218,47 +108,47 @@ "_color": { "__type__": "cc.Color", "r": 255, - "g": 0, - "b": 0, + "g": 255, + "b": 255, "a": 255 }, - "_spriteFrame": { - "__uuid__": "24a704da-2867-446d-8d1a-5e920c75e09d@f9941", - "__expectedType__": "cc.SpriteFrame" - }, - "_type": 1, - "_fillType": 0, - "_sizeMode": 0, - "_fillCenter": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_fillStart": 0, - "_fillRange": 0, - "_isTrimmedMode": true, - "_useGrayscale": false, - "_atlas": null, + "_string": "这是一个昵称", + "_horizontalAlign": 0, + "_verticalAlign": 0, + "_actualFontSize": 40, + "_fontSize": 40, + "_fontFamily": "Arial", + "_lineHeight": 40, + "_overflow": 0, + "_enableWrapText": true, + "_font": null, + "_isSystemFontUsed": true, + "_spacingX": 0, + "_isItalic": false, + "_isBold": false, + "_isUnderline": false, + "_underlineHeight": 2, + "_cacheMode": 0, "_id": "" }, { "__type__": "cc.CompPrefabInfo", - "fileId": "267GXyiYJB6qxCg6pLEfLQ" + "fileId": "1fVVQb7LdIUZ7E43CVIsuV" }, { "__type__": "cc.Widget", "_name": "", "_objFlags": 0, "node": { - "__id__": 3 + "__id__": 1 }, "_enabled": true, "__prefab": { - "__id__": 9 + "__id__": 7 }, "_alignFlags": 8, "_target": null, - "_left": 0, + "_left": 20, "_right": 0, "_top": 0, "_bottom": 0, @@ -278,7 +168,24 @@ }, { "__type__": "cc.CompPrefabInfo", - "fileId": "160ZgDPIFBEZ5Msv1mYMvN" + "fileId": "1dyUPgippJNLS6AWV5oz7O" + }, + { + "__type__": "741a7+Idu9GaZWozjnGOhxB", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 9 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "3a+8FHvk1IJKQVn3a/W2Mb" }, { "__type__": "cc.PrefabInfo", @@ -288,403 +195,6 @@ "asset": { "__id__": 0 }, - "fileId": "35OAlXyaBOBpLPAOKsDZHk" - }, - { - "__type__": "cc.UITransform", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 2 - }, - "_enabled": true, - "__prefab": { - "__id__": 12 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 100, - "height": 15 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "ca65l+rt9Iz5il0zQDlfgE" - }, - { - "__type__": "cc.Sprite", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 2 - }, - "_enabled": true, - "__prefab": { - "__id__": 14 - }, - "_customMaterial": null, - "_srcBlendFactor": 2, - "_dstBlendFactor": 4, - "_color": { - "__type__": "cc.Color", - "r": 0, - "g": 0, - "b": 0, - "a": 255 - }, - "_spriteFrame": { - "__uuid__": "9fd900dd-221b-4f89-8f2c-fba34243c835@f9941", - "__expectedType__": "cc.SpriteFrame" - }, - "_type": 1, - "_fillType": 0, - "_sizeMode": 0, - "_fillCenter": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_fillStart": 0, - "_fillRange": 0, - "_isTrimmedMode": true, - "_useGrayscale": false, - "_atlas": null, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "796J69Ia1LgrmmxsVBavZU" - }, - { - "__type__": "cc.ProgressBar", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 2 - }, - "_enabled": true, - "__prefab": { - "__id__": 16 - }, - "_barSprite": { - "__id__": 6 - }, - "_mode": 0, - "_totalLength": 100, - "_progress": 1, - "_reverse": false, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "d2mnLSm7RHF7V3bD57PvC5" - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 1 - }, - "asset": { - "__id__": 0 - }, - "fileId": "29DaYGvxpFo5cOAmvhl1Uj" - }, - { - "__type__": "cc.Node", - "_name": "Nickname", - "_objFlags": 0, - "_parent": { - "__id__": 1 - }, - "_children": [], - "_active": true, - "_components": [ - { - "__id__": 19 - } - ], - "_prefab": { - "__id__": 21 - }, - "_lpos": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_lrot": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 - }, - "_lscale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 - }, - "_layer": 33554432, - "_euler": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_id": "" - }, - { - "__type__": "cc.UITransform", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 18 - }, - "_enabled": true, - "__prefab": { - "__id__": 20 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 100, - "height": 100 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "8blUJZ4nJKpKsLO2YpEChI" - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 1 - }, - "asset": { - "__id__": 0 - }, - "fileId": "5adoggTLFPToeEZEIA7Yh3" - }, - { - "__type__": "cc.Node", - "_name": "Label", - "_objFlags": 0, - "_parent": { - "__id__": 1 - }, - "_children": [], - "_active": true, - "_components": [ - { - "__id__": 23 - }, - { - "__id__": 25 - } - ], - "_prefab": { - "__id__": 27 - }, - "_lpos": { - "__type__": "cc.Vec3", - "x": 0, - "y": 98.845, - "z": 0 - }, - "_lrot": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 - }, - "_lscale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 - }, - "_layer": 33554432, - "_euler": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_id": "" - }, - { - "__type__": "cc.UITransform", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 22 - }, - "_enabled": true, - "__prefab": { - "__id__": 24 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 110.72, - "height": 50.4 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "2a/IDEWZRPcb6AKU5/XAlD" - }, - { - "__type__": "cc.Label", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 22 - }, - "_enabled": true, - "__prefab": { - "__id__": 26 - }, - "_customMaterial": null, - "_srcBlendFactor": 2, - "_dstBlendFactor": 4, - "_color": { - "__type__": "cc.Color", - "r": 255, - "g": 255, - "b": 255, - "a": 255 - }, - "_string": "nickname", - "_horizontalAlign": 1, - "_verticalAlign": 1, - "_actualFontSize": 24, - "_fontSize": 24, - "_fontFamily": "Arial", - "_lineHeight": 40, - "_overflow": 0, - "_enableWrapText": true, - "_font": null, - "_isSystemFontUsed": true, - "_spacingX": 0, - "_isItalic": false, - "_isBold": true, - "_isUnderline": false, - "_underlineHeight": 2, - "_cacheMode": 0, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "71ZjYMvjBES7FqZGSo1L00" - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 1 - }, - "asset": { - "__id__": 0 - }, - "fileId": "03OAmogbVI5qDqTUJvplOC" - }, - { - "__type__": "cc.UITransform", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 29 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 100, - "height": 100 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "43sIN2Al5OsJRxFqY+HJTV" - }, - { - "__type__": "cc.Sprite", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 31 - }, - "_customMaterial": null, - "_srcBlendFactor": 2, - "_dstBlendFactor": 4, - "_color": { - "__type__": "cc.Color", - "r": 255, - "g": 255, - "b": 255, - "a": 255 - }, - "_spriteFrame": { - "__uuid__": "f0f5e564-2d98-4de1-bb92-794eeb1acffc@f9941", - "__expectedType__": "cc.SpriteFrame" - }, - "_type": 0, - "_fillType": 0, - "_sizeMode": 0, - "_fillCenter": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_fillStart": 0, - "_fillRange": 0, - "_isTrimmedMode": true, - "_useGrayscale": false, - "_atlas": null, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "48V6DZW5BPxIbiTPVjSL37" - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 1 - }, - "asset": { - "__id__": 0 - }, - "fileId": "60xKi1fHZAl6spWUrSZzlZ" + "fileId": "fcj/6WYKJAnbG8wIajLBQ9" } ] \ No newline at end of file diff --git a/apps/client/assets/resources/prefab/Player.prefab.meta b/apps/client/assets/resources/prefab/Player.prefab.meta index 841cff6..0a300e5 100644 --- a/apps/client/assets/resources/prefab/Player.prefab.meta +++ b/apps/client/assets/resources/prefab/Player.prefab.meta @@ -2,7 +2,7 @@ "ver": "1.1.39", "importer": "prefab", "imported": true, - "uuid": "d565d84f-56c4-4aa3-831c-99db0a0d2390", + "uuid": "7b0c739f-cf46-48f7-8c15-c97ab34268fe", "files": [ ".json" ], diff --git a/apps/client/assets/resources/prefab/Hall/RoomItem.prefab b/apps/client/assets/resources/prefab/Room.prefab similarity index 95% rename from apps/client/assets/resources/prefab/Hall/RoomItem.prefab rename to apps/client/assets/resources/prefab/Room.prefab index ef83062..42d5a76 100644 --- a/apps/client/assets/resources/prefab/Hall/RoomItem.prefab +++ b/apps/client/assets/resources/prefab/Room.prefab @@ -1,7 +1,7 @@ [ { "__type__": "cc.Prefab", - "_name": "RoomItem", + "_name": "Room", "_objFlags": 0, "_native": "", "data": { @@ -13,7 +13,7 @@ }, { "__type__": "cc.Node", - "_name": "RoomItem", + "_name": "Room", "_objFlags": 0, "__editorExtras__": {}, "_parent": null, @@ -33,7 +33,7 @@ "__id__": 8 }, { - "__id__": 10 + "__id__": 11 } ], "_prefab": { @@ -174,7 +174,7 @@ "fileId": "04BVJ/YxxGgJB9RdmtoR81" }, { - "__type__": "26da1px6w1GPbLW+8ZL8KuJ", + "__type__": "cc.Button", "_name": "", "_objFlags": 0, "node": { @@ -184,26 +184,9 @@ "__prefab": { "__id__": 9 }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "fcJVJHKllGEpVqSAW4IqSW" - }, - { - "__type__": "cc.Button", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 11 - }, "clickEvents": [ { - "__id__": 12 + "__id__": 10 } ], "_interactable": true, @@ -255,10 +238,27 @@ "__id__": 1 }, "component": "", - "_componentId": "26da1px6w1GPbLW+8ZL8KuJ", + "_componentId": "23e174OdjdMjJr3kdwPQTAb", "handler": "handleClick", "customEventData": "" }, + { + "__type__": "23e174OdjdMjJr3kdwPQTAb", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 12 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "2fkxfXB3NCsI8C8viDWANS" + }, { "__type__": "cc.PrefabInfo", "root": { diff --git a/apps/client/assets/resources/prefab/Hall/RoomItem.prefab.meta b/apps/client/assets/resources/prefab/Room.prefab.meta similarity index 85% rename from apps/client/assets/resources/prefab/Hall/RoomItem.prefab.meta rename to apps/client/assets/resources/prefab/Room.prefab.meta index 0917a55..d6927a3 100644 --- a/apps/client/assets/resources/prefab/Hall/RoomItem.prefab.meta +++ b/apps/client/assets/resources/prefab/Room.prefab.meta @@ -8,6 +8,6 @@ ], "subMetas": {}, "userData": { - "syncNodeName": "RoomItem" + "syncNodeName": "Room" } } diff --git a/apps/client/assets/resources/texture/player.meta b/apps/client/assets/resources/texture/actor.meta similarity index 100% rename from apps/client/assets/resources/texture/player.meta rename to apps/client/assets/resources/texture/actor.meta diff --git a/apps/client/assets/resources/texture/player/player1.meta b/apps/client/assets/resources/texture/actor/actor1.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1.meta rename to apps/client/assets/resources/texture/actor/actor1.meta diff --git a/apps/client/assets/resources/texture/player/player1/idle.meta b/apps/client/assets/resources/texture/actor/actor1/idle.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle.meta rename to apps/client/assets/resources/texture/actor/actor1/idle.meta diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (1).png b/apps/client/assets/resources/texture/actor/actor1/idle/idle (1).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (1).png rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (1).png diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (1).png.meta b/apps/client/assets/resources/texture/actor/actor1/idle/idle (1).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (1).png.meta rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (1).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (2).png b/apps/client/assets/resources/texture/actor/actor1/idle/idle (2).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (2).png rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (2).png diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (2).png.meta b/apps/client/assets/resources/texture/actor/actor1/idle/idle (2).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (2).png.meta rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (2).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (3).png b/apps/client/assets/resources/texture/actor/actor1/idle/idle (3).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (3).png rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (3).png diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (3).png.meta b/apps/client/assets/resources/texture/actor/actor1/idle/idle (3).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (3).png.meta rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (3).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (4).png b/apps/client/assets/resources/texture/actor/actor1/idle/idle (4).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (4).png rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (4).png diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (4).png.meta b/apps/client/assets/resources/texture/actor/actor1/idle/idle (4).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (4).png.meta rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (4).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (5).png b/apps/client/assets/resources/texture/actor/actor1/idle/idle (5).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (5).png rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (5).png diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (5).png.meta b/apps/client/assets/resources/texture/actor/actor1/idle/idle (5).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (5).png.meta rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (5).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (6).png b/apps/client/assets/resources/texture/actor/actor1/idle/idle (6).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (6).png rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (6).png diff --git a/apps/client/assets/resources/texture/player/player1/idle/idle (6).png.meta b/apps/client/assets/resources/texture/actor/actor1/idle/idle (6).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/idle/idle (6).png.meta rename to apps/client/assets/resources/texture/actor/actor1/idle/idle (6).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/run.meta b/apps/client/assets/resources/texture/actor/actor1/run.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run.meta rename to apps/client/assets/resources/texture/actor/actor1/run.meta diff --git a/apps/client/assets/resources/texture/player/player1/run/run (1).png b/apps/client/assets/resources/texture/actor/actor1/run/run (1).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (1).png rename to apps/client/assets/resources/texture/actor/actor1/run/run (1).png diff --git a/apps/client/assets/resources/texture/player/player1/run/run (1).png.meta b/apps/client/assets/resources/texture/actor/actor1/run/run (1).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (1).png.meta rename to apps/client/assets/resources/texture/actor/actor1/run/run (1).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/run/run (2).png b/apps/client/assets/resources/texture/actor/actor1/run/run (2).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (2).png rename to apps/client/assets/resources/texture/actor/actor1/run/run (2).png diff --git a/apps/client/assets/resources/texture/player/player1/run/run (2).png.meta b/apps/client/assets/resources/texture/actor/actor1/run/run (2).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (2).png.meta rename to apps/client/assets/resources/texture/actor/actor1/run/run (2).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/run/run (3).png b/apps/client/assets/resources/texture/actor/actor1/run/run (3).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (3).png rename to apps/client/assets/resources/texture/actor/actor1/run/run (3).png diff --git a/apps/client/assets/resources/texture/player/player1/run/run (3).png.meta b/apps/client/assets/resources/texture/actor/actor1/run/run (3).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (3).png.meta rename to apps/client/assets/resources/texture/actor/actor1/run/run (3).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/run/run (4).png b/apps/client/assets/resources/texture/actor/actor1/run/run (4).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (4).png rename to apps/client/assets/resources/texture/actor/actor1/run/run (4).png diff --git a/apps/client/assets/resources/texture/player/player1/run/run (4).png.meta b/apps/client/assets/resources/texture/actor/actor1/run/run (4).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (4).png.meta rename to apps/client/assets/resources/texture/actor/actor1/run/run (4).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/run/run (5).png b/apps/client/assets/resources/texture/actor/actor1/run/run (5).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (5).png rename to apps/client/assets/resources/texture/actor/actor1/run/run (5).png diff --git a/apps/client/assets/resources/texture/player/player1/run/run (5).png.meta b/apps/client/assets/resources/texture/actor/actor1/run/run (5).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (5).png.meta rename to apps/client/assets/resources/texture/actor/actor1/run/run (5).png.meta diff --git a/apps/client/assets/resources/texture/player/player1/run/run (6).png b/apps/client/assets/resources/texture/actor/actor1/run/run (6).png similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (6).png rename to apps/client/assets/resources/texture/actor/actor1/run/run (6).png diff --git a/apps/client/assets/resources/texture/player/player1/run/run (6).png.meta b/apps/client/assets/resources/texture/actor/actor1/run/run (6).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player1/run/run (6).png.meta rename to apps/client/assets/resources/texture/actor/actor1/run/run (6).png.meta diff --git a/apps/client/assets/resources/texture/player/player2.meta b/apps/client/assets/resources/texture/actor/actor2.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2.meta rename to apps/client/assets/resources/texture/actor/actor2.meta diff --git a/apps/client/assets/resources/texture/player/player2/idle.meta b/apps/client/assets/resources/texture/actor/actor2/idle.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle.meta rename to apps/client/assets/resources/texture/actor/actor2/idle.meta diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (1).png b/apps/client/assets/resources/texture/actor/actor2/idle/idle (1).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (1).png rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (1).png diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (1).png.meta b/apps/client/assets/resources/texture/actor/actor2/idle/idle (1).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (1).png.meta rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (1).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (2).png b/apps/client/assets/resources/texture/actor/actor2/idle/idle (2).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (2).png rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (2).png diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (2).png.meta b/apps/client/assets/resources/texture/actor/actor2/idle/idle (2).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (2).png.meta rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (2).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (3).png b/apps/client/assets/resources/texture/actor/actor2/idle/idle (3).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (3).png rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (3).png diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (3).png.meta b/apps/client/assets/resources/texture/actor/actor2/idle/idle (3).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (3).png.meta rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (3).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (4).png b/apps/client/assets/resources/texture/actor/actor2/idle/idle (4).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (4).png rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (4).png diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (4).png.meta b/apps/client/assets/resources/texture/actor/actor2/idle/idle (4).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (4).png.meta rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (4).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (5).png b/apps/client/assets/resources/texture/actor/actor2/idle/idle (5).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (5).png rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (5).png diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (5).png.meta b/apps/client/assets/resources/texture/actor/actor2/idle/idle (5).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (5).png.meta rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (5).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (6).png b/apps/client/assets/resources/texture/actor/actor2/idle/idle (6).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (6).png rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (6).png diff --git a/apps/client/assets/resources/texture/player/player2/idle/idle (6).png.meta b/apps/client/assets/resources/texture/actor/actor2/idle/idle (6).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/idle/idle (6).png.meta rename to apps/client/assets/resources/texture/actor/actor2/idle/idle (6).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/run.meta b/apps/client/assets/resources/texture/actor/actor2/run.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run.meta rename to apps/client/assets/resources/texture/actor/actor2/run.meta diff --git a/apps/client/assets/resources/texture/player/player2/run/run (1).png b/apps/client/assets/resources/texture/actor/actor2/run/run (1).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (1).png rename to apps/client/assets/resources/texture/actor/actor2/run/run (1).png diff --git a/apps/client/assets/resources/texture/player/player2/run/run (1).png.meta b/apps/client/assets/resources/texture/actor/actor2/run/run (1).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (1).png.meta rename to apps/client/assets/resources/texture/actor/actor2/run/run (1).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/run/run (2).png b/apps/client/assets/resources/texture/actor/actor2/run/run (2).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (2).png rename to apps/client/assets/resources/texture/actor/actor2/run/run (2).png diff --git a/apps/client/assets/resources/texture/player/player2/run/run (2).png.meta b/apps/client/assets/resources/texture/actor/actor2/run/run (2).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (2).png.meta rename to apps/client/assets/resources/texture/actor/actor2/run/run (2).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/run/run (3).png b/apps/client/assets/resources/texture/actor/actor2/run/run (3).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (3).png rename to apps/client/assets/resources/texture/actor/actor2/run/run (3).png diff --git a/apps/client/assets/resources/texture/player/player2/run/run (3).png.meta b/apps/client/assets/resources/texture/actor/actor2/run/run (3).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (3).png.meta rename to apps/client/assets/resources/texture/actor/actor2/run/run (3).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/run/run (4).png b/apps/client/assets/resources/texture/actor/actor2/run/run (4).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (4).png rename to apps/client/assets/resources/texture/actor/actor2/run/run (4).png diff --git a/apps/client/assets/resources/texture/player/player2/run/run (4).png.meta b/apps/client/assets/resources/texture/actor/actor2/run/run (4).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (4).png.meta rename to apps/client/assets/resources/texture/actor/actor2/run/run (4).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/run/run (5).png b/apps/client/assets/resources/texture/actor/actor2/run/run (5).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (5).png rename to apps/client/assets/resources/texture/actor/actor2/run/run (5).png diff --git a/apps/client/assets/resources/texture/player/player2/run/run (5).png.meta b/apps/client/assets/resources/texture/actor/actor2/run/run (5).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (5).png.meta rename to apps/client/assets/resources/texture/actor/actor2/run/run (5).png.meta diff --git a/apps/client/assets/resources/texture/player/player2/run/run (6).png b/apps/client/assets/resources/texture/actor/actor2/run/run (6).png similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (6).png rename to apps/client/assets/resources/texture/actor/actor2/run/run (6).png diff --git a/apps/client/assets/resources/texture/player/player2/run/run (6).png.meta b/apps/client/assets/resources/texture/actor/actor2/run/run (6).png.meta similarity index 100% rename from apps/client/assets/resources/texture/player/player2/run/run (6).png.meta rename to apps/client/assets/resources/texture/actor/actor2/run/run (6).png.meta diff --git a/apps/server/src/Common/Api.ts b/apps/server/src/Common/Api.ts new file mode 100644 index 0000000..908a54b --- /dev/null +++ b/apps/server/src/Common/Api.ts @@ -0,0 +1,49 @@ +import { IPlayer, IRoom } from "./Model" + +export interface IApiPlayerListReq { +} + +export interface IApiPlayerListRes { + list: Array +} + +export interface IApiPlayerJoinReq { + nickname: string +} + +export interface IApiPlayerJoinRes { + player: IPlayer +} + +export interface IApiRoomListReq { +} + +export interface IApiRoomListRes { + list: Array +} + +export interface IApiRoomCreateReq { +} + +export interface IApiRoomCreateRes { + room: IRoom +} + +export interface IApiRoomJoinReq { + rid: number +} + +export interface IApiRoomJoinRes { + room: IRoom +} + +export interface IApiRoomLeaveReq { +} + +export interface IApiRoomLeaveRes { } + +export interface IApiGameStartReq { + rid: number +} + +export interface IApiGameStartRes { } \ No newline at end of file diff --git a/apps/server/src/Common/Api.ts.meta b/apps/server/src/Common/Api.ts.meta new file mode 100644 index 0000000..263efb0 --- /dev/null +++ b/apps/server/src/Common/Api.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "7b9c95da-edaa-4c0c-8e41-b135b9802b86", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/apps/server/src/Common/Enum.ts b/apps/server/src/Common/Enum.ts new file mode 100644 index 0000000..1f41c0c --- /dev/null +++ b/apps/server/src/Common/Enum.ts @@ -0,0 +1,34 @@ +export enum ApiMsgEnum { + ApiPlayerList = 'ApiPlayerList', + ApiPlayerJoin = 'ApiPlayerJoin', + ApiRoomList = 'ApiRoomList', + ApiRoomCreate = 'ApiRoomCreate', + ApiRoomJoin = 'ApiRoomJoin', + ApiRoomLeave = 'ApiRoomLeave', + ApiGameStart = 'ApiGameStart', + MsgPlayerList = 'MsgPlayerList', + MsgRoomList = 'MsgRoomList', + MsgRoom = 'MsgRoom', + MsgGameStart = 'MsgGameStart', + MsgClientSync = 'MsgClientSync', + MsgServerSync = 'MsgServerSync', +} + +export enum InputTypeEnum { + ActorMove = 'ActorMove', + WeaponShoot = 'WeaponShoot', + TimePast = 'TimePast', +} + +export enum EntityTypeEnum { + Map1 = 'Map1', + Actor1 = 'Actor1', + Actor2 = 'Actor2', + Weapon1 = 'Weapon1', + Weapon2 = 'Weapon2', + Bullet1 = 'Bullet1', + Bullet2 = 'Bullet2', + Explosion = 'Explosion', + JoyStick = 'JoyStick', + Shoot = 'Shoot', +} \ No newline at end of file diff --git a/apps/server/src/Common/Enum.ts.meta b/apps/server/src/Common/Enum.ts.meta new file mode 100644 index 0000000..e6f88e2 --- /dev/null +++ b/apps/server/src/Common/Enum.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "2ba2bf1e-f8be-4a48-b759-666d5e757029", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/apps/server/src/Common/Model.ts b/apps/server/src/Common/Model.ts new file mode 100644 index 0000000..7dbc0d8 --- /dev/null +++ b/apps/server/src/Common/Model.ts @@ -0,0 +1,9 @@ + +export interface IPlayer { + id: number, nickname: string, rid: number +} + +export interface IRoom { + id: number, players: Array +} + diff --git a/apps/server/src/Common/Model.ts.meta b/apps/server/src/Common/Model.ts.meta new file mode 100644 index 0000000..b71e96c --- /dev/null +++ b/apps/server/src/Common/Model.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "87dc45aa-8878-48f4-9084-b4fd293a6414", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/apps/server/src/Common/Msg.ts b/apps/server/src/Common/Msg.ts new file mode 100644 index 0000000..25911cc --- /dev/null +++ b/apps/server/src/Common/Msg.ts @@ -0,0 +1,23 @@ +import { IPlayer, IRoom } from "./Model" +import { IState } from "./State" + +export interface IMsgPlayerList { + list: Array +} + +export interface IMsgRoomList { + list: Array +} + +export interface IMsgRoom { + room: IRoom +} + +export interface IMsgGameStart { + state: IState +} + + +export interface IMsgGameStart { + state: IState +} \ No newline at end of file diff --git a/apps/server/src/Common/Msg.ts.meta b/apps/server/src/Common/Msg.ts.meta new file mode 100644 index 0000000..064ad0f --- /dev/null +++ b/apps/server/src/Common/Msg.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "70de0494-112b-4a60-a266-3eadc82c20a4", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/apps/server/src/Common/State.ts b/apps/server/src/Common/State.ts new file mode 100644 index 0000000..11114c3 --- /dev/null +++ b/apps/server/src/Common/State.ts @@ -0,0 +1,56 @@ +import { EntityTypeEnum, InputTypeEnum } from "./Enum" + +export interface IActor { + id: number + nickname: string + type: EntityTypeEnum + weaponType: EntityTypeEnum + bulletType: EntityTypeEnum + + //动态数据 + hp: number + position: IVec2 + direction: IVec2 +} + +export interface IBullet { + id: number + owner: number + type: EntityTypeEnum + + //动态数据 + position: IVec2 + direction: IVec2 +} + +export interface IVec2 { + x: number; + y: number +} + +export interface IState { + players: IActor[], + bullets: IBullet[], + nextBulletId: number +} + +export type IClientInput = IActorMove | IWeaponShoot | ITimePast + +export interface IActorMove { + type: InputTypeEnum.ActorMove + id: number; + direction: IVec2; + dt: number; +} + +export interface IWeaponShoot { + type: InputTypeEnum.WeaponShoot + owner: number; + position: IVec2; + direction: IVec2; +} + +export interface ITimePast { + type: InputTypeEnum.TimePast; + dt: number +} \ No newline at end of file diff --git a/apps/server/src/Common/State.ts.meta b/apps/server/src/Common/State.ts.meta new file mode 100644 index 0000000..dc54f54 --- /dev/null +++ b/apps/server/src/Common/State.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "5d81c809-0c6d-402c-a029-c92d96ced679", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/apps/server/src/Common/index.ts.meta b/apps/server/src/Common/index.ts.meta new file mode 100644 index 0000000..02baf87 --- /dev/null +++ b/apps/server/src/Common/index.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "dfbf9e38-3546-4d54-9a00-515d6639c002", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/apps/server/src/biz/Player.ts b/apps/server/src/biz/Player.ts index cd71637..b6ad1ea 100644 --- a/apps/server/src/biz/Player.ts +++ b/apps/server/src/biz/Player.ts @@ -1,6 +1,4 @@ -import Connection from '../core/Connection' - -export type IPlayer = Pick +import Connection from '../Core/Connection' export default class Player { id: number @@ -8,7 +6,7 @@ export default class Player { connection: Connection rid: number - constructor({ id, nickname, connection }: IPlayer) { + constructor({ id, nickname, connection }: Pick) { this.id = id this.nickname = nickname this.connection = connection diff --git a/apps/server/src/biz/PlayerManager.ts b/apps/server/src/biz/PlayerManager.ts index 68949fd..9c9e09a 100644 --- a/apps/server/src/biz/PlayerManager.ts +++ b/apps/server/src/biz/PlayerManager.ts @@ -1,8 +1,8 @@ -import { ApiMsgEnum } from '..' -import Singleton from '../base/Singleton' -import type { IPlayer } from './Player' +import Singleton from '../Base/Singleton' +import { ApiMsgEnum, IApiPlayerJoinReq } from '../Common' import Player from './Player' import RoomManager from './RoomManager' +import Connection from '../Core/Connection' export default class PlayerManager extends Singleton { static get Instance() { @@ -13,7 +13,7 @@ export default class PlayerManager extends Singleton { players: Set = new Set() idMapPlayer: Map = new Map() - createPlayer({ connection, nickname }: Omit) { + createPlayer({ connection, nickname }: IApiPlayerJoinReq & { connection: Connection }) { const player = new Player({ id: this.playerId++, connection, nickname }) this.players.add(player) this.idMapPlayer.set(player.id, player) diff --git a/apps/server/src/biz/Room.ts b/apps/server/src/biz/Room.ts index cf1bb1e..68ec089 100644 --- a/apps/server/src/biz/Room.ts +++ b/apps/server/src/biz/Room.ts @@ -1,4 +1,4 @@ -import { ApiMsgEnum } from '..' +import { ApiMsgEnum, EntityTypeEnum, IState } from '../Common' import type Player from './Player' import PlayerManager from './PlayerManager' import RoomManager from './RoomManager' @@ -11,6 +11,8 @@ export default class Room { this.id = rid } + private inputs = [] + join(uid: number) { const player = PlayerManager.Instance.getPlayerById(uid) if (player) { @@ -33,7 +35,46 @@ export default class Room { sync() { for (const player of this.players) { - player.connection.sendMsg(ApiMsgEnum.MsgRoom, RoomManager.Instance.getRoomView(this)) + player.connection.sendMsg(ApiMsgEnum.MsgRoom, { + room: RoomManager.Instance.getRoomView(this) + }) + } + } + + start() { + const state: IState = { + players: [...this.players].map((player, index) => ({ + id: player.id, + nickname: player.nickname, + position: { + x: -150 + index * 300, + y: -150 + index * 300, + }, + direction: { + x: 1, + y: 0 + }, + hp: 100, + type: EntityTypeEnum.Actor1, + weaponType: EntityTypeEnum.Weapon1, + bulletType: EntityTypeEnum.Bullet1, + })), + bullets: [], + nextBulletId: 1 + } + + for (const player of this.players) { + player.connection.sendMsg(ApiMsgEnum.MsgGameStart, { + state + }) + } + this.listenPlayer() + } + + listenPlayer() { + for (const player of this.players) { + player.connection.listenMsg(ApiMsgEnum.MsgClientSync, () => { } + ) } } } diff --git a/apps/server/src/biz/RoomManager.ts b/apps/server/src/biz/RoomManager.ts index 3057112..03104c9 100644 --- a/apps/server/src/biz/RoomManager.ts +++ b/apps/server/src/biz/RoomManager.ts @@ -1,6 +1,5 @@ -import { ApiMsgEnum } from '..' -import Singleton from '../base/Singleton' -import Player from './Player' +import Singleton from '../Base/Singleton' +import { ApiMsgEnum } from '../Common' import PlayerManager from './PlayerManager' import Room from './Room' @@ -43,6 +42,13 @@ export default class RoomManager extends Singleton { } } + startRoom(rid: number) { + const room = this.getRoomById(rid) + if (room) { + room.start() + } + } + getRoomById(id: number) { return this.idMapRoom.get(id) } diff --git a/apps/server/src/common/index.ts b/apps/server/src/common/index.ts index ecbe74e..2dbb671 100644 --- a/apps/server/src/common/index.ts +++ b/apps/server/src/common/index.ts @@ -1 +1,51 @@ -console.log(112221); +import { IApiGameStartReq, IApiGameStartRes, IApiPlayerJoinReq, IApiPlayerJoinRes, IApiPlayerListReq, IApiPlayerListRes, IApiRoomCreateReq, IApiRoomCreateRes, IApiRoomJoinReq, IApiRoomJoinRes, IApiRoomLeaveReq, IApiRoomLeaveRes, IApiRoomListReq, IApiRoomListRes } from './Api' +import { ApiMsgEnum } from './Enum' +import { IMsgGameStart, IMsgPlayerList, IMsgRoom, IMsgRoomList } from './Msg' +import { IClientInput } from './State' +export * from './Api' +export * from './Msg' +export * from './Enum' +export * from './Model' +export * from './State' + +export interface IModel { + api: { + [ApiMsgEnum.ApiPlayerJoin]: { + req: IApiPlayerJoinReq, + res: IApiPlayerJoinRes, + } + [ApiMsgEnum.ApiPlayerList]: { + req: IApiPlayerListReq, + res: IApiPlayerListRes, + } + [ApiMsgEnum.ApiRoomList]: { + req: IApiRoomListReq, + res: IApiRoomListRes, + } + [ApiMsgEnum.ApiRoomCreate]: { + req: IApiRoomCreateReq, + res: IApiRoomCreateRes, + } + [ApiMsgEnum.ApiRoomJoin]: { + req: IApiRoomJoinReq, + res: IApiRoomJoinRes, + } + [ApiMsgEnum.ApiRoomLeave]: { + req: IApiRoomLeaveReq, + res: IApiRoomLeaveRes, + } + [ApiMsgEnum.ApiGameStart]: { + req: IApiGameStartReq, + res: IApiGameStartRes, + } + }, + msg: { + [ApiMsgEnum.MsgPlayerList]: IMsgPlayerList + [ApiMsgEnum.MsgRoomList]: IMsgRoomList, + [ApiMsgEnum.MsgRoom]: IMsgRoom, + [ApiMsgEnum.MsgGameStart]: IMsgGameStart, + [ApiMsgEnum.MsgClientSync]: IClientInput, + [ApiMsgEnum.MsgServerSync]: IMsgGameStart, + } +} + diff --git a/apps/server/src/core/Connection.ts b/apps/server/src/core/Connection.ts index b6aed13..b8a2b01 100644 --- a/apps/server/src/core/Connection.ts +++ b/apps/server/src/core/Connection.ts @@ -1,7 +1,8 @@ import WebSocket from 'ws'; import { EventEmitter } from 'stream'; import MyServer, { IData } from '.'; -import { getTime } from '../utils'; +import { getTime } from '../Utils'; +import { IModel } from '../Common'; export enum ConnectionEventEnum { Close = 'Close', @@ -68,7 +69,7 @@ export default class Connection extends EventEmitter { } } - sendMsg(name: string, data: IData) { + sendMsg(name: T, data: IModel['msg'][T]) { const msg = JSON.stringify({ name, data diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts index 436294a..093fc84 100644 --- a/apps/server/src/index.ts +++ b/apps/server/src/index.ts @@ -1,23 +1,9 @@ -import MyServer, { IData, MyServerEventEnum } from './core'; -import Player from './biz/Player'; -import PlayerManager from './biz/PlayerManager'; -import RoomManager from './biz/RoomManager'; -import Connection from './core/Connection'; -import { copyCommon, getTime } from './utils'; - -export enum ApiMsgEnum { - ApiPlayerList = 'ApiPlayerList', - ApiPlayerJoin = 'ApiPlayerJoin', - ApiRoomList = 'ApiRoomList', - ApiRoomCreate = 'ApiRoomCreate', - ApiRoomJoin = 'ApiRoomJoin', - ApiRoomLeave = 'ApiRoomLeave', - MsgPlayerList = 'MsgPlayerList', - MsgRoomList = 'MsgRoomList', - MsgRoom = 'MsgRoom', -} - -copyCommon() +import MyServer, { MyServerEventEnum } from './Core'; +import PlayerManager from './Biz/PlayerManager'; +import RoomManager from './Biz/RoomManager'; +import Connection from './Core/Connection'; +import { getTime, symlinkCommon } from './Utils'; +import { ApiMsgEnum, IApiGameStartReq, IApiGameStartRes, IApiPlayerJoinReq, IApiPlayerJoinRes, IApiPlayerListReq, IApiPlayerListRes, IApiRoomCreateReq, IApiRoomCreateRes, IApiRoomJoinReq, IApiRoomJoinRes, IApiRoomLeaveReq, IApiRoomLeaveRes, IApiRoomListReq, IApiRoomListRes, IModel } from './Common'; const server = new MyServer({ port: 8888 }) @@ -34,28 +20,32 @@ server.on(MyServerEventEnum.DisConnect, (connection: Connection) => { }) // api -server.setApi(ApiMsgEnum.ApiPlayerList, (connection: Connection, data: IData) => { +server.setApi(ApiMsgEnum.ApiPlayerList, (connection: Connection, data: IApiPlayerListReq): IApiPlayerListRes => { return { list: PlayerManager.Instance.getPlayersView() } }) -server.setApi(ApiMsgEnum.ApiPlayerJoin, (connection: Connection, data: IData) => { - const nickname = data.nickname +server.setApi(ApiMsgEnum.ApiPlayerJoin, (connection: Connection, { nickname }: IApiPlayerJoinReq): IApiPlayerJoinRes => { const player = PlayerManager.Instance.createPlayer({ connection, nickname }) PlayerManager.Instance.syncPlayers() - return PlayerManager.Instance.getPlayerView(player) + return { + player: PlayerManager.Instance.getPlayerView(player) + } }) -server.setApi(ApiMsgEnum.ApiRoomList, (connection: Connection, data: IData) => { + +server.setApi(ApiMsgEnum.ApiRoomList, (connection: Connection, data: IApiRoomListReq): IApiRoomListRes => { return { list: RoomManager.Instance.getRoomsView() } }) -server.setApi(ApiMsgEnum.ApiRoomCreate, (connection: Connection, data: IData) => { +server.setApi(ApiMsgEnum.ApiRoomCreate, (connection: Connection, data: IApiRoomCreateReq): IApiRoomCreateRes => { if (connection.playerId) { const room = RoomManager.Instance.joinRoom(RoomManager.Instance.createRoom().id, connection.playerId) if (room) { RoomManager.Instance.syncRooms() PlayerManager.Instance.syncPlayers() - return RoomManager.Instance.getRoomView(room) + return { + room: RoomManager.Instance.getRoomView(room) + } } else { throw new Error("ApiRoomCreate room不存在") } @@ -64,14 +54,16 @@ server.setApi(ApiMsgEnum.ApiRoomCreate, (connection: Connection, data: IData) => } }) -server.setApi(ApiMsgEnum.ApiRoomJoin, (connection: Connection, data: IData) => { +server.setApi(ApiMsgEnum.ApiRoomJoin, (connection: Connection, data: IApiRoomJoinReq): IApiRoomJoinRes => { if (connection.playerId) { const room = RoomManager.Instance.joinRoom(data.rid, connection.playerId) if (room) { RoomManager.Instance.syncRooms() PlayerManager.Instance.syncPlayers() RoomManager.Instance.syncRoom(room.id) - return RoomManager.Instance.getRoomView(room) + return { + room: RoomManager.Instance.getRoomView(room) + } } else { throw new Error("ApiRoomJoin room不存在") } @@ -80,7 +72,7 @@ server.setApi(ApiMsgEnum.ApiRoomJoin, (connection: Connection, data: IData) => { } }) -server.setApi(ApiMsgEnum.ApiRoomLeave, (connection: Connection, data: IData) => { +server.setApi(ApiMsgEnum.ApiRoomLeave, (connection: Connection, data: IApiRoomLeaveReq): IApiRoomLeaveRes => { if (connection.playerId) { const player = PlayerManager.Instance.getPlayerById(connection.playerId) if (player) { @@ -90,6 +82,28 @@ server.setApi(ApiMsgEnum.ApiRoomLeave, (connection: Connection, data: IData) => PlayerManager.Instance.syncPlayers() RoomManager.Instance.syncRooms() RoomManager.Instance.syncRoom(rid) + return {} + } else { + throw new Error("ApiRoomLeave 玩家不在房间") + } + } else { + throw new Error("ApiRoomLeave 玩家不存在") + } + } else { + throw new Error("ApiRoomLeave 玩家未登录") + } +}) + +server.setApi(ApiMsgEnum.ApiGameStart, (connection: Connection, data: IApiGameStartReq): IApiGameStartRes => { + if (connection.playerId) { + const player = PlayerManager.Instance.getPlayerById(connection.playerId) + if (player) { + const rid = player.rid + if (rid) { + RoomManager.Instance.startRoom(rid) + // PlayerManager.Instance.syncPlayers() + // RoomManager.Instance.syncRooms() + return {} } else { throw new Error("ApiRoomLeave 玩家不在房间") } @@ -103,6 +117,7 @@ server.setApi(ApiMsgEnum.ApiRoomLeave, (connection: Connection, data: IData) => // start!! server.start().then(() => { + symlinkCommon() console.log("服务启动!") }).catch((e) => { console.log("服务异常", e) diff --git a/apps/server/src/utils/index.ts b/apps/server/src/utils/index.ts index 0266ee2..69dbb06 100644 --- a/apps/server/src/utils/index.ts +++ b/apps/server/src/utils/index.ts @@ -3,10 +3,26 @@ import path from 'path' export const getTime = () => new Date().toLocaleString().split("├")[0] -export async function copyCommon() { - const src = path.resolve('./common') - const dst = path.resolve('../client/assets/Scripts/common') +//symlink同步 +export const symlinkCommon = async () => { + const src = path.resolve(__dirname, '../Common') + const dst = path.resolve(__dirname, '../../../client/assets/Scripts/Common') + if (await fs.lstat(dst).then(v => v.isSymbolicLink()).catch(() => false) && await fs.readlink(dst) === src) { + console.log('同步成功!') + } else { + fs.symlink(src, dst).then(() => { + console.log('同步成功!') + }).catch((e) => { + console.log('同步失败!', e) + }) + } +} + +//copy同步 +export const copyCommon = async () => { + const src = path.resolve(__dirname, '../Common') + const dst = path.resolve(__dirname, '../../../client/assets/Scripts/Common') console.log(src, dst); // clean @@ -17,6 +33,5 @@ export async function copyCommon() { // copy await fs.copy(src, dst) - console.log('同步成功') -} - + console.log('同步成功!') +} \ No newline at end of file