import { NetManager } from "../../libs/tw/manager/NetManager";
import Loading from "../loading/Loading";
import { DataManager } from "../../libs/tw/manager/DataManager";
import { NetName } from "../../libs/tw/enum/NetName";

/**
 * 加入游戏
 */
export const JoinGame = function() {
    Loading.instace.show();
    return new Promise((resolve, reject) => {
        NetManager.ins.doJoin((success, res) => {
            if(!success) {
                Loading.instace.hide();
                reject(res);
                return;
            }
            resolve(res);
        });
    });
};


/**
 * 游戏结束提交
 */
export const Submit = function() {
    Loading.instace.show();
    return new Promise((resolve, reject) => {
        NetManager.ins.getOrderStatus((success, res) => {	// 轮询查询订单状态
            Loading.instace.hide();
            if(!success) {  // 返回true
                reject(res);
                return
            }
            resolve(res);   // 返回false
        }, DataManager.ins.getData(NetName.DO_JOIN_DATA).data, (res) => {
            return res.code != "0000000000";
        }, 10);
    })
};
