Commit fc887792 authored by liujiangnan's avatar liujiangnan

feat

parent 762ae1c9
......@@ -93,8 +93,8 @@ cc.Class({
this.uid = res.uid;
// 测试数据
this.role = 'audience';
this.uid = 'student';
this.role = 'anchor';
this.uid = 'teacher';
const nickObj = await drawOpenNickName(res.nickName);
......
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import { getRoomId, asyncCallNetworkApiGet } from "../../douyin_xiaoxiaole/script/supportToolsDy";
import { asyncDelay } from "../../douyin_xiaoxiaole/script/hw_elimination_letter_util";
const { ccclass, property } = cc._decorator;
......@@ -12,6 +13,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Node)
rankTemplate: cc.Node = null;
@property(cc.Node)
rankpage: cc.Node = null;
addPreloadImage() {
}
......@@ -34,41 +38,39 @@ export default class SceneComponent extends MyCocosSceneComponent {
async initView() {
const startFlag = await this.isGameStart();
if (startFlag) {
// 直接显示排行榜
cc.find(`Canvas/rankpage`).active = true;
this.runRankList();
} else {
await this.loadData();
this.drawPage();
}
// 直接显示排行榜
this.runRankList();
await this.loadData();
this.drawPage();
}
async runRankList() {
let rows = await asyncCallNetworkApiGet('/api/douyin/v1/rank', {roomid: this.roomId});
// let rows = await asyncCallNetworkApiGet('/api/douyin/v1/rank', {roomid: "7248252618835790603"});
rows = JSON.parse(rows);
this.rankContent.removeAllChildren();
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const itemClone = cc.instantiate(this.rankTemplate);
itemClone.parent = this.rankContent;
itemClone.active = true;
itemClone.attr({user_id: row.user_id});
cc.find(`ready`,itemClone).active = false;
cc.find(`score`,itemClone).active = true;
cc.find(`score`,itemClone).getComponent(cc.Label).string = row.score;
const nickObj = JSON.parse(row.nick_name);
await this.drawNickName(itemClone, nickObj);
const startFlag = await this.isGameStart();
if (startFlag) {
this.rankpage.active = true;
let rows = await asyncCallNetworkApiGet('/api/douyin/v1/rank', {roomid: this.roomId});
// let rows = await asyncCallNetworkApiGet('/api/douyin/v1/rank', {roomid: "7248252618835790603"});
rows = JSON.parse(rows);
this.rankContent.removeAllChildren();
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const itemClone = cc.instantiate(this.rankTemplate);
itemClone.parent = this.rankContent;
itemClone.active = true;
itemClone.attr({user_id: row.user_id});
cc.find(`ready`,itemClone).active = false;
cc.find(`score`,itemClone).active = true;
cc.find(`score`,itemClone).getComponent(cc.Label).string = row.score;
const nickObj = JSON.parse(row.nick_name);
await this.drawNickName(itemClone, nickObj);
}
} else {
this.rankpage.active = false;
}
this.scheduleOnce( async () => {
const startFlag = await this.isGameStart();
if (startFlag) {
await this.runRankList();
}
await this.runRankList();
}, 1);
}
......@@ -251,10 +253,35 @@ export default class SceneComponent extends MyCocosSceneComponent {
roomid: this.roomId,
data: keys.join(","),
});
this.rankpage.active = true;
this.canTouch = true;
}
// 显示排行榜
cc.find(`Canvas/rankpage`).active = true;
this.runRankList();
async restart() {
if (!this.canTouch) {
return;
}
this.canTouch = false;
cc.find(`Canvas/loading`).active = true;
await asyncCallNetworkApiGet("/api/douyin/v1/stopgame", {
roomid: this.roomId
});
await asyncDelay(5);
await asyncCallNetworkApiGet("/api/douyin/v1/startgame", {
roomid: this.roomId
});
cc.find(`Canvas/loading`).active = false;
this.canTouch = true;
}
async reset() {
if (!this.canTouch) {
return;
}
this.canTouch = false;
await asyncCallNetworkApiGet("/api/douyin/v1/stopgame", {
roomid: this.roomId
});
this.rankpage.active = false;
this.canTouch = true;
}
......
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