Commit 61961e74 authored by 范雪寒's avatar 范雪寒

fix: bugs

parent 1e642681
...@@ -417,6 +417,9 @@ cc.Class({ ...@@ -417,6 +417,9 @@ cc.Class({
this.networkHelper.on("frameEvent", (event) => { this.networkHelper.on("frameEvent", (event) => {
event.data.frame.items.forEach((item) => { event.data.frame.items.forEach((item) => {
if (this.server) {
this.server.onFrameEvent(item.data);
}
if (item.data.type == "all_player_info") { if (item.data.type == "all_player_info") {
item.data.playerData.forEach((player) => { item.data.playerData.forEach((player) => {
if (!this.allPlayerList) { if (!this.allPlayerList) {
...@@ -467,10 +470,6 @@ cc.Class({ ...@@ -467,10 +470,6 @@ cc.Class({
duration: this._gameDuration duration: this._gameDuration
}); });
} }
} else if (item.data.type == "complete") {
if (this.server) {
this.server.onPlayerComplete(item.data.uuid, item.data.duration);
}
} }
}); });
}); });
...@@ -494,6 +493,27 @@ cc.Class({ ...@@ -494,6 +493,27 @@ cc.Class({
} catch (e) { } catch (e) {
this.log(e.toString()); this.log(e.toString());
} }
await this.initHeadImgAndName();
},
async initHeadImgAndName() {
const playerInfo = {
playerHeadUrl: "http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png",
playerName: "test",
};
const middleLayer = cc.find("middleLayer");
if (middleLayer) {
const kidInfo = await middleLayer.getComponent('middleLayer').getUserInfo();
const playerHeadUrl = middleLayer.getComponent('middleLayer').getHeadUrl(kidInfo.avatar_url || kidInfo.id);
playerInfo.playerHeadUrl = playerHeadUrl;
playerInfo.playerName = kidInfo.nick_name;
}
this.networkHelper.sendFrame({
type: "playerInfo",
playerId: this.playerId,
playerName: playerInfo.playerName,
playerHeadUrl: playerInfo.playerHeadUrl,
});
}, },
//TODO:copy---start //TODO:copy---start
......
...@@ -40,6 +40,7 @@ export class GameServer { ...@@ -40,6 +40,7 @@ export class GameServer {
duration: null duration: null
}); });
if (player.isAI) {
if (this.playerList.length == this.playerMaxNumber) { if (this.playerList.length == this.playerMaxNumber) {
this.networkHelper.closeRoom(); this.networkHelper.closeRoom();
this.startAIDuration(); this.startAIDuration();
...@@ -50,6 +51,25 @@ export class GameServer { ...@@ -50,6 +51,25 @@ export class GameServer {
playerData: this.playerList playerData: this.playerList
}); });
} }
}
onFrameEvent(event) {
if (event.type == "complete") {
this.onPlayerComplete(event.uuid, event.duration);
} else if (event.type == "playerInfo") {
const player = this.playerList.find(p => p.uuid == event.playerId);
player.name = event.playerName;
player.headUrl = event.playerHeadUrl;
if (this.playerList.length == this.playerMaxNumber) {
this.networkHelper.closeRoom();
this.startAIDuration();
}
this.networkHelper.sendFrame({
type: 'all_player_info',
playerData: this.playerList
});
}
}
onPlayerComplete(uuid: string, duration: number) { onPlayerComplete(uuid: string, duration: number) {
const player = this.playerList.find(player => player.uuid == uuid); const player = this.playerList.find(player => player.uuid == uuid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment