You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
442 lines
16 KiB
442 lines
16 KiB
|
|
|
|
import { JsonAsset, sys } from "cc";
|
|
import { MINIGAME, PREVIEW } from "cc/env";
|
|
import { EResUrls } from "../ResUrl/EResUrls";
|
|
import ResLoad from "../ResUrl/ResLoad";
|
|
import { EBundleName } from "../const/GameEnum";
|
|
import CSVTools from "./CSVTools";
|
|
import { FIAgent, FIBuilds, FIConfidante, FIConfidanteArr, FIDiscretization, FIEnemy, FIGongFa, FIItems, FIItemTypes, FILevel, FIMutate, FIProp, FIPropArr, FIShopItems, FISignin, FISuitEffect, FISuitEffectType, FITalenArr, FITask, FIWuGong, FIWuGongType, IBaseRes, IHotvs, INoticeData, IRedemptionData } from "./CsvEnum";
|
|
import { CSVHttpValue, CsvList } from "./CsvList";
|
|
import { Utils } from "../ExUtils/Utils";
|
|
import PlatformData from "../Platform/Data/PlatformData";
|
|
import { MainConfig } from "../../Launch/_MainConfig";
|
|
|
|
export default class CsvMgr {
|
|
/**基础资源 */
|
|
public static base_res_csv: { [key: number]: IBaseRes } = {};
|
|
/**离散表 */
|
|
public static cnf_discretization_csv: FIDiscretization = {};
|
|
/**多语言配置 */
|
|
public static language_csv = {};
|
|
/**敌人 */
|
|
public static Enemy_csv: FIEnemy = {};
|
|
/**功法 */
|
|
public static GongFa_csv: FIGongFa = {};
|
|
/**物品 */
|
|
public static Items_csv: FIItems = {};
|
|
/**物品 */
|
|
public static Items_type_csv: FIItemTypes = {};
|
|
/**套装物品 */
|
|
public static Items_suit_csv: FIItemTypes = {};
|
|
/**关卡 */
|
|
public static Level_csv: FILevel = {};
|
|
/**NPC */
|
|
public static Agent_csv: FIAgent = {};
|
|
/**签到 */
|
|
public static signin_csv: FISignin = [];
|
|
/**任务 */
|
|
public static tasks_csv: FITask = {};
|
|
/**道具 */
|
|
public static Props_csv: FIProp = {};
|
|
/**珍宝数组 */
|
|
public static Props_array_csv: FIPropArr = [];
|
|
/**天赋数组 */
|
|
public static Talen_array_csv: FITalenArr = [];
|
|
/**武功 */
|
|
public static WuGong_csv: FIWuGong = {};
|
|
/**武功类型表 */
|
|
public static WuGong_type_csv:FIWuGongType = {};
|
|
/**投资表 */
|
|
public static Builds_csv:FIBuilds = {};
|
|
/**经脉 */
|
|
public static Confidante_csv: FIConfidante = {};
|
|
/**异兽 */
|
|
public static Mutate_csv: FIMutate = {};
|
|
/**其他商店商品 */
|
|
public static ShopItems_csv: FIShopItems = {};
|
|
/**套装效果 */
|
|
public static Suit_eff_csv: FISuitEffect = {};
|
|
/**套装效果 */
|
|
public static Suit_eff_type_csv: FISuitEffectType = {};
|
|
// public static Confidante_array_csv: FIConfidanteArr = [];
|
|
|
|
|
|
private static mPlatData:PlatformData;
|
|
private static HotVs:IHotvs = null;
|
|
|
|
private static NextVs:IHotvs = null;
|
|
|
|
private static RedemCodeVs:IRedemptionData = null;
|
|
private static NoticeVs:INoticeData = null;
|
|
|
|
// public static initCsv(CSVLoadBack: Function = null, Progress: Function = null) {
|
|
// if (false) {
|
|
// this.LoadLocalCSV(CSVLoadBack, Progress)
|
|
// } else {
|
|
// !MINIGAME ? this.GetHttpCsvList(CSVLoadBack, Progress) : this.LoadLocalCSV(CSVLoadBack, Progress);
|
|
// }
|
|
// }
|
|
|
|
private static LoadHotHttp(CSVLoadBack: Function = null, Progress: Function = null) {
|
|
let MaxLoadCount = Object.keys(CsvList).length;
|
|
let CurLoadCount = MaxLoadCount;
|
|
let logList: string[] = [];
|
|
for (const key in CsvList) {
|
|
/**CSV配置 */
|
|
const tConfig = CsvList[key];
|
|
let url = `${this.hotHttps}/${tConfig.name + `.csv`}?${this.HotVs.vs}`;
|
|
Utils.XMLHttp.Request(url, (text: any) => {
|
|
if (text.length > 0) {
|
|
let object = CSVTools.parse(text, tConfig);
|
|
this[key] = object;
|
|
} else {
|
|
ConsoleEx.Error("未加载到目标数据", tConfig);
|
|
}
|
|
CurLoadCount--;
|
|
Progress && Progress(CurLoadCount, MaxLoadCount, tConfig);
|
|
PREVIEW && logList.push(EResUrls.ConfigCsv(tConfig.name));
|
|
/** 进入游戏 */
|
|
if (CurLoadCount <= 0) {
|
|
CSVLoadBack && CSVLoadBack();
|
|
PREVIEW && ConsoleEx.Log("加载CSV完成:", logList)
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
static readonly OpenHot: boolean = true;
|
|
static readonly hotHttpsBase = "https://material.lvzhouyouxi.com/WuXia"
|
|
|
|
private static get hotHttps() {
|
|
const Data = this.mPlatData;
|
|
if(window['ks']){
|
|
return `${this.hotHttpsBase}/ks/${Data.appId}`
|
|
}
|
|
switch (sys.platform) {
|
|
case sys.Platform.WECHAT_GAME:
|
|
return `${this.hotHttpsBase}/wx/${Data.appId}`
|
|
break;
|
|
case sys.Platform.BYTEDANCE_MINI_GAME:
|
|
return `${this.hotHttpsBase}/tt/${Data.appId}`
|
|
break;
|
|
default:
|
|
return `${this.hotHttpsBase}/debug`
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 公告url
|
|
private static get hotNoticeHttps() {
|
|
if(window['ks']){
|
|
return `${this.hotHttpsBase}/ks/notice`
|
|
}
|
|
switch (sys.platform) {
|
|
case sys.Platform.WECHAT_GAME:
|
|
return `${this.hotHttpsBase}/wx/notice`
|
|
case sys.Platform.BYTEDANCE_MINI_GAME:
|
|
return `${this.hotHttpsBase}/tt/notice`
|
|
default:
|
|
return `${this.hotHttpsBase}/debug/notice`
|
|
}
|
|
}
|
|
|
|
private static get HotJsonUrl() {
|
|
return `${this.hotHttps}/hot-vs.json`
|
|
}
|
|
private static loadHotVs(CSVLoadBack: Function = null, Progress: Function = null){
|
|
//let lastTime = LocalStorage.getItem(`LastJsonUrlTime`);
|
|
|
|
Utils.XMLHttp.Request(`${this.HotJsonUrl}?${Date.now()}`, (Text) => {
|
|
if (Text) {
|
|
let hotData = JSON.parse(Text);
|
|
CSVLoadBack && CSVLoadBack(hotData);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
private static get HotConfigJsonUrl() {
|
|
return `${this.hotHttpsBase}/config/csv_${MainConfig.DisplayVersions}.json`//"https://material.lvzhouyouxi.com/WuXia/config/csv_1_0_3.json"
|
|
}
|
|
private static loadHotConfigVs(CSVLoadBack: Function = null, Progress: Function = null){
|
|
Utils.XMLHttp.Request(`${this.HotConfigJsonUrl}?${Date.now()}`, (Text) => {
|
|
if (Text) {
|
|
let configData = JSON.parse(Text);
|
|
for (const key in CsvList) {
|
|
this[key] = configData[key]
|
|
}
|
|
CSVLoadBack && CSVLoadBack();
|
|
}else{
|
|
this.TryLoadCsvZip(CSVLoadBack, Progress);
|
|
}
|
|
});
|
|
}
|
|
|
|
public static CheckWlist(uid:string){
|
|
if(this.HotVs && this.HotVs.wlist && this.HotVs.wlist.includes(uid)){
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static GetHotVs(platData:PlatformData,CSVHotBack: Function = null){
|
|
ConsoleEx.Com("开始获取热更新数据")
|
|
this.mPlatData = platData;
|
|
if (this.OpenHot && MINIGAME){
|
|
this.loadHotVs((data: IHotvs) => {
|
|
// ConsoleEx.Log("HotVs:",data);
|
|
this.HotVs = data;
|
|
CSVHotBack && CSVHotBack();
|
|
});
|
|
}else{
|
|
CSVHotBack && CSVHotBack();
|
|
}
|
|
this.GetRedemConfigVs();
|
|
this.GetNoticeConfigVs();
|
|
}
|
|
|
|
/**获取兑换码版本 */
|
|
private static get RedemJsonUrl() {
|
|
return `${this.hotHttps}/redemcode-vs.json`//"https://material.lvzhouyouxi.com/WuXia/code/redemcode-vs.json"
|
|
}
|
|
|
|
private static loadRedemCodeVs(CSVLoadBack: Function = null){
|
|
Utils.XMLHttp.Request(`${this.RedemJsonUrl}?${Date.now()}`, (Text) => {
|
|
if (Text) {
|
|
let redemData = JSON.parse(Text);
|
|
CSVLoadBack && CSVLoadBack(redemData);
|
|
}
|
|
});
|
|
}
|
|
|
|
public static GetRedemConfigVs(CSVBack: Function = null){
|
|
ConsoleEx.Com("开始获取兑换码数据")
|
|
this.loadRedemCodeVs((data: IRedemptionData) => {
|
|
this.RedemCodeVs = data;
|
|
CSVBack && CSVBack();
|
|
});
|
|
}
|
|
|
|
public static GetRedemData(){
|
|
return this.RedemCodeVs ? this.RedemCodeVs.data : [];
|
|
}
|
|
|
|
/** 公告数据 */
|
|
private static get NoticeJsonUrl() {
|
|
return `${this.hotNoticeHttps}/${MainConfig.DisplayVersions}.json`
|
|
}
|
|
private static loadNoticeCodeVs(CSVLoadBack: Function = null){
|
|
Utils.XMLHttp.Request(`${this.NoticeJsonUrl}?${Date.now()}`, (Text) => {
|
|
if (Text) {
|
|
let noticeData = JSON.parse(Text);
|
|
CSVLoadBack && CSVLoadBack(noticeData);
|
|
}else{
|
|
this.TryLoadLocalNoticeData(CSVLoadBack);
|
|
// CSVLoadBack && CSVLoadBack(null);
|
|
}
|
|
});
|
|
}
|
|
private static GetNoticeConfigVs(CSVBack: Function = null){
|
|
ConsoleEx.Com("开始获取公告数据")
|
|
this.loadNoticeCodeVs((data: INoticeData) => {
|
|
this.NoticeVs = null;
|
|
if(data){
|
|
const today = Utils.TimeUtils.GetFormatDayNumber();
|
|
if(data.showdays < 0 || today - data.timenum < data.showdays){
|
|
ConsoleEx.Com("今日公告获取公告数据成功:", data)
|
|
this.NoticeVs = data;
|
|
}
|
|
}
|
|
CSVBack && CSVBack();
|
|
});
|
|
}
|
|
|
|
private static TryLoadLocalNoticeData(CSVLoadBack: Function = null){
|
|
ResLoad.Ins.Load(EResUrls.ConfigJsonURL("notice"), EBundleName.Presets, JsonAsset, (err, res: JsonAsset) => {
|
|
if (err || !res) {
|
|
CSVLoadBack && CSVLoadBack(null);
|
|
return;
|
|
}
|
|
CSVLoadBack && CSVLoadBack(res.json);
|
|
});
|
|
}
|
|
|
|
public static GetNoticeData():INoticeData{
|
|
return this.NoticeVs ? this.NoticeVs : null;
|
|
}
|
|
|
|
|
|
public static initCsv(platData:PlatformData,CSVLoadBack: Function = null, Progress: Function = null) {
|
|
this.mPlatData = platData;
|
|
if (false) {
|
|
this.TryLoadCsvZip(CSVLoadBack, Progress)
|
|
} else {
|
|
if (MINIGAME) {
|
|
if (this.OpenHot) {
|
|
this.loadHotConfigVs(CSVLoadBack, Progress);
|
|
// this.loadHotVs((data: IHotvs) => {
|
|
// this.HotVs = data;
|
|
// });
|
|
}else{
|
|
this.TryLoadCsvZip(CSVLoadBack, Progress);
|
|
}
|
|
} else {
|
|
this.TryLoadCsvZip(CSVLoadBack, Progress);
|
|
// this.GetHttpCsvList(CSVLoadBack, Progress);
|
|
// this.loadHotConfigVs(CSVLoadBack, Progress);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static isReviewVer(){
|
|
return this.HotVs && this.HotVs.isReviewVer;
|
|
}
|
|
public static openInterstitalAd(){
|
|
return this.HotVs && this.HotVs.openInterstitalAd;
|
|
}
|
|
public static openSideBar(){
|
|
return this.HotVs && this.HotVs.openSideBar;
|
|
}
|
|
public static openSubscribe(){
|
|
return this.HotVs && this.HotVs.openSubscribe;
|
|
}
|
|
|
|
/**返回太极源掉落概率,没开启掉落时返回0 */
|
|
public static getDropTJRate(){
|
|
return (this.HotVs && this.HotVs.drop_tj_open)? this.HotVs.drop_tj_rate : 0;
|
|
}
|
|
|
|
/**返回分享配置 */
|
|
public static getShareId(){
|
|
return (this.HotVs && this.HotVs.shareId)? this.HotVs.shareId : [];
|
|
}
|
|
|
|
/**返回激励视频广告id */
|
|
public static getRewardVideoId(){
|
|
return (this.HotVs && this.HotVs.rewardVideoId)? this.HotVs.rewardVideoId : "";
|
|
}
|
|
|
|
/**返回插屏广告id */
|
|
public static getInterstitialId(){
|
|
return (this.HotVs && this.HotVs.interstitialId)? this.HotVs.interstitialId : [];
|
|
}
|
|
|
|
|
|
/**尝试加载CSV压缩包 */
|
|
private static TryLoadCsvZip(CSVLoadBack: Function = null, Progress: Function = null) {
|
|
let csvLoadTime = performance.now();
|
|
ResLoad.Ins.Load(EResUrls.ConfigJsonURL("csv"), EBundleName.Presets, JsonAsset, (err, res: JsonAsset) => {
|
|
if (err || !res) {
|
|
this.LoadLocalCSV(CSVLoadBack, Progress);
|
|
return;
|
|
}
|
|
ConsoleEx.Log("开始加载本地CSV.json")
|
|
for (const key in CsvList) {
|
|
this[key] = res.json[key]
|
|
}
|
|
CSVLoadBack && CSVLoadBack();
|
|
});
|
|
}
|
|
|
|
private static LoadLocalCSV(CSVLoadBack: Function = null, Progress: Function = null) {
|
|
let MaxLoadCount = Object.keys(CsvList).length;
|
|
let CurLoadCount = MaxLoadCount;
|
|
let logList: string[] = [];
|
|
ConsoleEx.Log("开始加载本地CSV")
|
|
for (const key in CsvList) {
|
|
const element = CsvList[key];
|
|
CSVTools.LoadCsv(EResUrls.ConfigCsv(element.name), (object, name) => {
|
|
this[key] = object;
|
|
CurLoadCount--;
|
|
Progress && Progress(CurLoadCount, MaxLoadCount, element);
|
|
PREVIEW && logList.push(EResUrls.ConfigCsv(element.name));
|
|
if (CurLoadCount <= 0) {
|
|
CSVLoadBack && CSVLoadBack();
|
|
PREVIEW && ConsoleEx.Log("加载CSV完成:", logList)
|
|
}
|
|
}, element);
|
|
}
|
|
}
|
|
|
|
private static GetHttpCsvList(CSVLoadBack: Function = null, Progress: Function = null) {
|
|
ConsoleEx.Log("开始拉取网络配置");
|
|
Utils.XMLHttp.Request(this.DownLoadListCsv, (Text) => {
|
|
if (Text) {
|
|
let list = JSON.parse(Text);
|
|
for (let i = 0; i < list.length; i++) {
|
|
const data: {
|
|
sheet_id: string,
|
|
title: string,
|
|
path?: string,
|
|
version?: number,
|
|
} = list[i];
|
|
for (const key in CsvList) {
|
|
let csvCnf = CsvList[key];
|
|
if (data.sheet_id == csvCnf.name) {
|
|
csvCnf.name = data.path;
|
|
}
|
|
}
|
|
}
|
|
this.LoadHttp(CSVLoadBack, Progress);
|
|
}
|
|
});
|
|
}
|
|
|
|
private static LoadHttp(CSVLoadBack: Function = null, Progress: Function = null) {
|
|
let MaxLoadCount = Object.keys(CsvList).length;
|
|
let CurLoadCount = MaxLoadCount;
|
|
let logList: string[] = [];
|
|
for (const key in CsvList) {
|
|
/**CSV配置 */
|
|
const tConfig = CsvList[key];
|
|
let data: AcceptMessage = {
|
|
CacheKey: CSVHttpValue.mCacheKey,
|
|
token: CSVHttpValue.mTokenID,
|
|
sub_id: tConfig.name + `.csv`,
|
|
}
|
|
let url = `${this.DownLoadCsv}${JSON.stringify(data)}`;
|
|
Utils.XMLHttp.Request(url, (text: any) => {
|
|
if (text.length > 0) {
|
|
let object = CSVTools.parse(text, tConfig);
|
|
this[key] = object;
|
|
} else {
|
|
ConsoleEx.Error("未加载到目标数据", tConfig);
|
|
}
|
|
CurLoadCount--;
|
|
Progress && Progress(CurLoadCount, MaxLoadCount, tConfig);
|
|
PREVIEW && logList.push(EResUrls.ConfigCsv(tConfig.name));
|
|
/** 进入游戏 */
|
|
if (CurLoadCount <= 0) {
|
|
CSVLoadBack && CSVLoadBack();
|
|
PREVIEW && ConsoleEx.Log("加载CSV完成:", logList)
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private static get DownLoadCsv(): string {
|
|
return `${CSVHttpValue.DownLoadHttp}getCsvByData/`;
|
|
}
|
|
|
|
private static get DownLoadListCsv(): string {
|
|
let data: AcceptMessage = {
|
|
CacheKey: CSVHttpValue.mCacheKey,
|
|
token: CSVHttpValue.mTokenID
|
|
}
|
|
return `${CSVHttpValue.DownLoadHttp}getcsvlist/${JSON.stringify(data)}`
|
|
}
|
|
|
|
}
|
|
|
|
export interface AcceptMessage {
|
|
CacheKey: string;
|
|
token: string;
|
|
sub_id?: string;
|
|
}
|
|
|
|
if (PREVIEW) {
|
|
window['CsvMgr'] = CsvMgr;
|
|
}
|