Commit 2b3c9c8f authored by limingzhe's avatar limingzhe

fix: 真实人名 头像

parent 3637a917
No preview for this file type
...@@ -472,7 +472,7 @@ cc.Class({ ...@@ -472,7 +472,7 @@ cc.Class({
this.initMatchingView(); await this.initMatchingView();
console.log('~~~~~~~ 4'); console.log('~~~~~~~ 4');
...@@ -524,8 +524,9 @@ cc.Class({ ...@@ -524,8 +524,9 @@ cc.Class({
const len = 8 - this.serverAllUser.length; const len = 8 - this.serverAllUser.length;
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
const aiId = id + i; const aiId = id + i;
const headUrl = this.playerInfoData[i].headUrl;
const data = { playerId: aiId.toString(), name: this.playerInfoData[i].name, headUrl, isAi: true }
const data = { playerId: aiId.toString(), name: this.playerInfoData[i].name }
this.sendServerEvent('add_ai', data); this.sendServerEvent('add_ai', data);
} }
...@@ -592,9 +593,7 @@ cc.Class({ ...@@ -592,9 +593,7 @@ cc.Class({
nh.on('playerJoin', (event) => { nh.on('playerJoin', (event) => {
// if (this.server) {
// this.server.onPlayerJoin(event);
// }
this.log("playerJoin", (event)); this.log("playerJoin", (event));
this.onPlayerJoin(event); this.onPlayerJoin(event);
...@@ -646,6 +645,10 @@ cc.Class({ ...@@ -646,6 +645,10 @@ cc.Class({
this.onAddAi(res.data); this.onAddAi(res.data);
return; return;
case 'add_player':
this.onAddPlayer(res.data);
break;
case 'refresh_player_list': case 'refresh_player_list':
console.log(' on refresh_player_list') console.log(' on refresh_player_list')
this.onRefreshPlayerList(res.data); this.onRefreshPlayerList(res.data);
...@@ -662,6 +665,34 @@ cc.Class({ ...@@ -662,6 +665,34 @@ cc.Class({
onPlayerJoin(data) { onPlayerJoin(data) {
const middleLayer = cc.find("middleLayer");
if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent("middleLayer");
if (middleLayerComponent.getUserInfo && middleLayerComponent.getHeadUrl) {
middleLayerComponent.getUserInfo().then((kidInfo) => {
const playerHeadUrl = middleLayerComponent.getHeadUrl(kidInfo.avatar_url || kidInfo.id);
// playerInfo.playerHeadUrl = playerHeadUrl;
// playerInfo.playerName = kidInfo.nick_name || '拼读达人';
data.name = kidInfo.nick_name || '拼读达人';
data.playerHeadUrl = playerHeadUrl
this.sendServerEvent('add_player', data);
return;
})
}
}
data.name = '拼读达人';
data.headUrl = 'http://staging-teach.cdn.ireadabc.com/2e3d7b4c386400974bf9d6a1bb8550a7.png';
this.sendServerEvent('add_player', data);
return;
console.log(" in onPlayerJoin : ", data); console.log(" in onPlayerJoin : ", data);
let user = { playerId: data.playerId }; let user = { playerId: data.playerId };
...@@ -679,18 +710,28 @@ cc.Class({ ...@@ -679,18 +710,28 @@ cc.Class({
} }
} }
console.log(' in onPlayerJoin 2 ', JSON.stringify(user)); console.log(' in onPlayerJoin 2 ', JSON.stringify(user));
this.addUser(user) this.addUser(user)
}, },
onAddPlayer(data) {
console.log('onAddPlayer data: ', data);
if (this.isTeacher) {
this.addUser({ playerId: data.playerId, name: data.name, headUrl: data.headUrl })
}
},
onAddAi(data) { onAddAi(data) {
console.log(' in onAddAi data: ', data); console.log(' in onAddAi data: ', data);
// if (this.isTeacher) {
this.addUser({ playerId: data.playerId, name: data.name, isAi: true }) this.addUser(data)
// }
}, },
onRefreshPlayerList(data) { onRefreshPlayerList(data) {
...@@ -1310,7 +1351,7 @@ cc.Class({ ...@@ -1310,7 +1351,7 @@ cc.Class({
playerInfoData: null, playerInfoData: null,
loadingScript: null, loadingScript: null,
initMatchingView() { async initMatchingView() {
// http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png // http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png
// http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png // http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png
...@@ -1376,24 +1417,40 @@ cc.Class({ ...@@ -1376,24 +1417,40 @@ cc.Class({
for (let i = 0; i < this.serverAllUser.length; i++) { for (let i = 0; i < this.serverAllUser.length; i++) {
const user = this.serverAllUser[i]; const user = this.serverAllUser[i];
const isSelf = user.playerId == this.playerId; const isSelf = user.playerId == this.playerId;
let headUrl = playerData[i].headUrl; let headUrl = user.headUrl || playerData[i].headUrl;
if (isSelf && false) { if (isSelf) {
user.name = user.nick_name
headUrl = user.playerInfo.avatar; user.name = '拼读达人';
console.log('avatar: ', user.playerInfo.avatar) // user.name = playerData[i].name;
} else {
// user.name = nameList[RandomInt(0, 6)]; const middleLayer = cc.find("middleLayer");
user.name = playerData[i].name if (middleLayer) {
} const middleLayerComponent = middleLayer.getComponent("middleLayer");
script.addPlayer(user.name, isSelf, playerData[i].headUrl); if (middleLayerComponent.getUserInfo && middleLayerComponent.getHeadUrl) {
const kidInfo = await middleLayerComponent.getUserInfo();
const playerHeadUrl = middleLayerComponent.getHeadUrl(kidInfo.avatar_url || kidInfo.id);
// playerInfo.playerHeadUrl = playerHeadUrl;
// playerInfo.playerName = kidInfo.nick_name || '拼读达人';
user.name = kidInfo.nick_name || '拼读达人';
headUrl = playerHeadUrl;
}
}
if (this.isTeacher) {
// setTimeout(() => {
// this.gameServer.addUser(user); // user.name = user.nick_name
// }, 1000); // headUrl = user.playerInfo.avatar;
script.addPlayer(user.name, isSelf, headUrl);
user.headUrl = headUrl;
console.log('this.serverAllUser : ' , JSON.stringify( this.serverAllUser ))
} else {
user.name = playerData[i].name;
this.serverAllUser = [];
return;
} }
// script.addPlayer(user.name, isSelf, headUrl);
} }
// this.checkAddAi(); // this.checkAddAi();
...@@ -1436,6 +1493,7 @@ cc.Class({ ...@@ -1436,6 +1493,7 @@ cc.Class({
for (let i = 0; i < this.serverAllUser.length; i++) { for (let i = 0; i < this.serverAllUser.length; i++) {
if (this.serverAllUser[i].playerId == user.playerId) { if (this.serverAllUser[i].playerId == user.playerId) {
console.log(' 该用户已经存在 无需再加入。') console.log(' 该用户已经存在 无需再加入。')
return; return;
} }
} }
...@@ -1446,17 +1504,21 @@ cc.Class({ ...@@ -1446,17 +1504,21 @@ cc.Class({
const isSelf = this.playerId == user.playerId; const isSelf = this.playerId == user.playerId;
this.loadingScript.addPlayer(user.name, isSelf, this.playerInfoData[len - 1].headUrl);
let headUrl = user.headUrl
this.loadingScript.addPlayer(user.name, isSelf, headUrl);
console.log('isSelf: ', isSelf); console.log('isSelf: ', isSelf);
console.log('this.isTeacher: ', this.isTeacher); console.log('this.isTeacher: ', this.isTeacher);
console.log('user.isAi: ', user.isAi); console.log('user.isAi: ', user.isAi);
if (this.isTeacher && !user.isAi) { if (this.isTeacher && !user.isAi) {
setTimeout(() => { setTimeout(() => {
this.sendServerEvent('refresh_player_list', this.serverAllUser); this.sendServerEvent('refresh_player_list', this.serverAllUser);
// this.gameServer.addUser(user);
}, 1); }, 1);
} }
}, },
......
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