ConfigManager改全局单例

This commit is contained in:
2025-08-15 15:24:31 +08:00
parent 30e8effe86
commit 599c98f135
9 changed files with 361 additions and 376 deletions
Binary file not shown.
+2 -1
View File
@@ -5,6 +5,7 @@
"Temperature": 0.7, "Temperature": 0.7,
"MaxTokens": 2048, "MaxTokens": 2048,
"Timeout": 30000, "Timeout": 30000,
"FreeChatTimes": 20 "FreeChatTimes": 20,
"GameName": "AIGirlChat"
} }
] ]
+10 -70
View File
@@ -18,15 +18,12 @@
"_children": [ "_children": [
{ {
"__id__": 2 "__id__": 2
},
{
"__id__": 32
} }
], ],
"_active": true, "_active": true,
"_components": [], "_components": [],
"_prefab": { "_prefab": {
"__id__": 34 "__id__": 32
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@@ -57,7 +54,7 @@
}, },
"autoReleaseAssets": false, "autoReleaseAssets": false,
"_globals": { "_globals": {
"__id__": 35 "__id__": 33
}, },
"_id": "1a23cd3e-e487-4fd1-a415-346c2087464d" "_id": "1a23cd3e-e487-4fd1-a415-346c2087464d"
}, },
@@ -1018,63 +1015,6 @@
}, },
"_id": "98EWBIubZPlZT+LFQb4IYI" "_id": "98EWBIubZPlZT+LFQb4IYI"
}, },
{
"__type__": "cc.Node",
"_name": "ConfigManager",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 33
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "67ZXnZeExFXIu59phK6Xjz"
},
{
"__type__": "fbd43WrI4tK6KXuGCPuxhSR",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 32
},
"_enabled": true,
"__prefab": null,
"_id": "57vDjH7bVD4JDeqZChrdP3"
},
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",
"root": null, "root": null,
@@ -1086,28 +1026,28 @@
{ {
"__type__": "cc.SceneGlobals", "__type__": "cc.SceneGlobals",
"ambient": { "ambient": {
"__id__": 36 "__id__": 34
}, },
"shadows": { "shadows": {
"__id__": 37 "__id__": 35
}, },
"_skybox": { "_skybox": {
"__id__": 38 "__id__": 36
}, },
"fog": { "fog": {
"__id__": 39 "__id__": 37
}, },
"octree": { "octree": {
"__id__": 40 "__id__": 38
}, },
"skin": { "skin": {
"__id__": 41 "__id__": 39
}, },
"lightProbeInfo": { "lightProbeInfo": {
"__id__": 42 "__id__": 40
}, },
"postSettings": { "postSettings": {
"__id__": 43 "__id__": 41
}, },
"bakedWithStationaryMainLight": false, "bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false "bakedWithHighpLightmap": false
+318 -295
View File
@@ -1,328 +1,351 @@
import { _decorator, Color, isValid, Label, Node, RichText, Size, Sprite, UITransform, Vec3, view } from "cc"; import {
_decorator,
Color,
isValid,
Label,
Node,
RichText,
Size,
Sprite,
UITransform,
Vec3,
view,
} from "cc";
import li_EventManager from "./li_EventManager"; import li_EventManager from "./li_EventManager";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass @ccclass
export default class Utils { export default class Utils {
//log日志 //log日志
public static Log(msg: string | any, ...subst: any[]) { public static Log(msg: string | any, ...subst: any[]) {
let IsLocalCSChanel = true let IsLocalCSChanel = true;
if (IsLocalCSChanel) { if (IsLocalCSChanel) {
console.log(msg, subst) console.log(msg, subst);
}
} }
//警告日志 }
public static Warning(msg: string | any, ...subst: any[]) { //警告日志
let IsLocalCSChanel = true public static Warning(msg: string | any, ...subst: any[]) {
if (IsLocalCSChanel) { let IsLocalCSChanel = true;
console.warn(msg, subst) if (IsLocalCSChanel) {
} console.warn(msg, subst);
} }
//错误日志 }
public static Error(msg: string | any, ...subst: any[]) { //错误日志
let IsLocalCSChanel = true public static Error(msg: string | any, ...subst: any[]) {
if (IsLocalCSChanel) { let IsLocalCSChanel = true;
console.error(msg, subst) if (IsLocalCSChanel) {
} console.error(msg, subst);
} }
}
//解析节点
public static parseNode = function (node: Node, oriObj?: any) {
if (!node || !node.children) return;
oriObj = oriObj || node;
let chs = node.children;
for (let i = 0; i < chs.length; i++) {
let ch = chs[i];
let chName = ch.name;
if (chName && chName.length > 0) {
try {
oriObj[chName] = ch;
} catch (error) {
//hg_utils.hgLog("chName err:", chName);
}
}
Utils.parseNode(ch, oriObj);
}
};
//解析节点 //更换父节点,保留原有的坐标和旋转
public static parseNode = function (node: Node, oriObj?: any) { public static changeNodeParent(node: Node, parentNode: Node) {
if (!node || !node.children) return; let world_Q = node.getWorldRotation();
oriObj = oriObj || node; let world_pos = node.getWorldPosition(); //原来的世界坐标
let chs = node.children; node.setParent(parentNode);
for (let i = 0; i < chs.length; i++) { node.setRotation(world_Q);
let ch = chs[i]; node.setWorldPosition(world_pos);
let chName = ch.name; }
if (chName && chName.length > 0) {
try {
oriObj[chName] = ch;
} catch (error) {
//hg_utils.hgLog("chName err:", chName);
}
}
Utils.parseNode(ch, oriObj);
}
}
/**
//更换父节点,保留原有的坐标和旋转 * 封装setString方法
public static changeNodeParent(node:Node, parentNode:Node) { */
let world_Q = node.getWorldRotation() static setString(node: Node, str: string | number) {
let world_pos = node.getWorldPosition()//原来的世界坐标 if (!isValid(node)) return;
node.setParent(parentNode) let lb: any = node.getComponent(Label);
node.setRotation(world_Q); if (!lb) return;
node.setWorldPosition(world_pos) if (str == null) {
str = "";
} }
str += "";
lb.string = str;
}
/**
/** * 添加富文本
* 封装setString方法 * @param node
*/ * @param str
static setString(node: Node, str: string | number) { * @param outLine
if (!isValid(node)) return; * @param width
let lb:any = node.getComponent(Label); * @returns
if (!lb) return; */
if(str == null) {str = ""} static addRichText(
str += "" node: Node,
lb.string = str; str: string,
outLine: string | null = null,
width: number | null = 2,
max: number = 0
) {
if (!node) return;
let comp = node.getComponent(RichText);
if (!comp) return;
str = Utils.replaceAll(str, "</>", "</color>");
str = str.replace(/\<\/font\>/g, "</color>");
str = Utils.replaceAll(str, "'>", ">");
str = Utils.replaceAll(str, "<font", "<");
str = Utils.replaceAll(str, "color='", "color=");
str = Utils.replaceAll(str, "<br>", "\n");
if (outLine) {
str = `<outline color=${outLine} width=${width}>${str}</outline>`;
} }
comp.string = str;
// let csize:UITransform = comp.node.getComponent(UITransform)!
// comp.maxWidth = Math.min(csize.width,max) ;
}
static replaceAll(str: string, ch1: string, ch2: string) {
while (str.indexOf(ch1) >= 0) {
str = str.replace(ch1, ch2);
}
return str;
}
/**截取字符串,超过长度的用...代替
/** * @param str 要处理的字符串
* 添加富文本 * @param labelLimit 字符串长度限制
* @param node * @param repStr 超过长度后代替的字符串
* @param str */
* @param outLine static clampAiAnswer(
* @param width ansStr: string,
* @returns labelLimit: number,
*/ repStr: string = "..."
static addRichText(node: Node, str: string, outLine: string | null = null, width: number | null = 2,max: number = 0) { ) {
if (!node) return; // let labelLimit = 20 //字符串长度限制
let comp = node.getComponent(RichText); let tempStr: string = "";
if (!comp) return; let tempLen: number = 0;
str = Utils.replaceAll(str, "</>", "</color>"); for (let i = 0; i < ansStr.length; i++) {
str = str.replace(/\<\/font\>/g, '</color>'); tempLen += ansStr.charCodeAt(i) > 255 ? 2 : 1;
str = Utils.replaceAll(str, "'>", ">"); if (tempLen > labelLimit) {
str = Utils.replaceAll(str, "<font", "<"); return tempStr + repStr;
str = Utils.replaceAll(str, "color='", "color="); }
str = Utils.replaceAll(str, "<br>", "\n"); tempStr += ansStr.charAt(i);
if (outLine) {
str = `<outline color=${outLine} width=${width}>${str}</outline>`;
}
comp.string = str;
// let csize:UITransform = comp.node.getComponent(UITransform)!
// comp.maxWidth = Math.min(csize.width,max) ;
}
static replaceAll(str: string, ch1: string, ch2: string) {
while (str.indexOf(ch1) >= 0) {
str = str.replace(ch1, ch2);
}
return str;
} }
return ansStr;
}
/**设置节点置灰 */
/**截取字符串,超过长度的用...代替 static setNodeGray(node: Node, isGray: boolean, extra: any = {}) {
* @param str 要处理的字符串 if (!isValid(node)) return;
* @param labelLimit 字符串长度限制 //图片
* @param repStr 超过长度后代替的字符串 let sp: Sprite = node.getComponent(Sprite);
*/ if (sp) {
static clampAiAnswer(ansStr: string, labelLimit:number, repStr:string = "...") { sp.grayscale = isGray;
// let labelLimit = 20 //字符串长度限制
let tempStr: string = "";
let tempLen: number = 0;
for (let i = 0; i < ansStr.length; i++) {
tempLen += ansStr.charCodeAt(i) > 255 ? 2 : 1;
if (tempLen > labelLimit) {
return tempStr + repStr;
}
tempStr += ansStr.charAt(i);
}
return ansStr;
} }
// //文字
// let lb:Label = node.getComponent(Label);
// if (lb) {
// if (isGray) {
// lb.color = extra.labClrGray ? extra.labClrGray : Color.GRAY;
// } else {
// lb.color = extra.labClrWhite ? extra.labClrWhite : Color.WHITE;
// }
// }
//对子节点执行同样操作
let children = node.children;
for (let i = 0; i < children.length; i++) {
Utils.setNodeGray(children[i], isGray, extra);
}
}
/**适配背景图
/**设置节点置灰 */ * @method node 背景图节点
static setNodeGray(node: Node, isGray: boolean, extra: any={}) { * @param mod 适配模式 1=按高度适配 2=按宽度适配
if (!isValid(node)) return; */
//图片 public static adjustBgPixelRatioToSize(
let sp:Sprite = node.getComponent(Sprite); windowSize: Size,
if (sp) { node: Node,
sp.grayscale = isGray; mod: number = 1
} ) {
// //文字 //let windowSize = view.getVisibleSize();
// let lb:Label = node.getComponent(Label); let bgTf = node.getComponent(UITransform);
// if (lb) { if (bgTf) {
// if (isGray) { if (mod == 1 && bgTf.height <= windowSize.height) {
// lb.color = extra.labClrGray ? extra.labClrGray : Color.GRAY; let scale = windowSize.height / bgTf.height;
// } else { bgTf.height = bgTf.height * scale;
// lb.color = extra.labClrWhite ? extra.labClrWhite : Color.WHITE; bgTf.width = bgTf.width * scale;
// } } else if (mod == 2 && bgTf.width <= windowSize.width) {
// } let scale = windowSize.width / bgTf.width;
//对子节点执行同样操作 bgTf.height = bgTf.height * scale;
let children = node.children; bgTf.width = bgTf.width * scale;
for (let i = 0; i < children.length; i++) { }
Utils.setNodeGray(children[i], isGray, extra);
}
} }
}
/**适配背景图 /**适配背景图
* @method node 背景图节点 * @method node 背景图节点
* @param mod 适配模式 1=按高度适配 2=按宽度适配 * @param mod 适配模式 1=按高度适配 2=按宽度适配
*/ */
public static adjustBgPixelRatioToSize(windowSize:Size,node:Node, mod:number = 1) { public static adjustBgPixelRatio(node: Node, mod: number = 1) {
//let windowSize = view.getVisibleSize(); let windowSize = view.getVisibleSize();
let bgTf = node.getComponent(UITransform) let bgTf = node.getComponent(UITransform);
if (bgTf) { if (bgTf) {
if (mod == 1 && bgTf.height < windowSize.height) { if (mod == 3) {
let scale = windowSize.height / bgTf.height if (windowSize.height - bgTf.height < windowSize.width - bgTf.width) {
bgTf.height = bgTf.height * scale mod = 1;
bgTf.width = bgTf.width * scale
} else if (mod == 2 && bgTf.width < windowSize.width) {
let scale = windowSize.width / bgTf.width
bgTf.height = bgTf.height * scale
bgTf.width = bgTf.width * scale
}
}
}
/**适配背景图
* @method node 背景图节点
* @param mod 适配模式 1=按高度适配 2=按宽度适配
*/
public static adjustBgPixelRatio(node:Node, mod:number = 1) {
let windowSize = view.getVisibleSize();
let bgTf = node.getComponent(UITransform)
if (bgTf) {
if(mod == 3)
{
if(windowSize.height-bgTf.height < windowSize.width-bgTf.width )
{
mod = 1;
}else{
mod = 2;
}
}
if (mod == 1 && bgTf.height < windowSize.height) {
let scale = windowSize.height / bgTf.height
bgTf.height = bgTf.height * scale
bgTf.width = bgTf.width * scale
} else if (mod == 2 && bgTf.width < windowSize.width) {
let scale = windowSize.width / bgTf.width
bgTf.height = bgTf.height * scale
bgTf.width = bgTf.width * scale
}
}
}
/**适配背景图 按比例缩放 屏幕比设计分辨率小时缩小,反之则不缩放
* @param node 背景图节点
* @param mod 适配模式 1=按高度适配 2=按宽度适配
*/
public static adjustBgScaleRatio(node:Node, mod:number = 1) {
let windowSize = view.getVisibleSize();
let designSize = view.getDesignResolutionSize();
if (mod == 1 && windowSize.height < designSize.height) {
let scale = windowSize.height / designSize.height
node.scale = new Vec3(scale, scale, 1)
} else if (mod == 2 && windowSize.width < designSize.width) {
let scale = windowSize.width / designSize.width
node.scale = new Vec3(scale, scale, 1)
}
}
/**获取屏幕分辨率和设计分辨率的比例
* @method mod 适配模式 1=按高度适配 2=按宽度适配
*/
public static getScaleRatio(mod:number = 1) {
let windowSize = view.getVisibleSize();
let designSize = view.getDesignResolutionSize();
// console.log("游戏分辨率:", windowSize, designSize);
if (mod == 1) {
return windowSize.height / designSize.height
} else { } else {
return windowSize.width / designSize.width mod = 2;
} }
}
if (mod == 1 && bgTf.height < windowSize.height) {
let scale = windowSize.height / bgTf.height;
bgTf.height = bgTf.height * scale;
bgTf.width = bgTf.width * scale;
} else if (mod == 2 && bgTf.width < windowSize.width) {
let scale = windowSize.width / bgTf.width;
bgTf.height = bgTf.height * scale;
bgTf.width = bgTf.width * scale;
}
} }
}
/**适配背景图 按比例缩放 屏幕比设计分辨率小时缩小,反之则不缩放
* @param node 背景图节点
* @param mod 适配模式 1=按高度适配 2=按宽度适配
*/
public static adjustBgScaleRatio(node: Node, mod: number = 1) {
let windowSize = view.getVisibleSize();
let designSize = view.getDesignResolutionSize();
if (mod == 1 && windowSize.height < designSize.height) {
let scale = windowSize.height / designSize.height;
node.scale = new Vec3(scale, scale, 1);
} else if (mod == 2 && windowSize.width < designSize.width) {
let scale = windowSize.width / designSize.width;
node.scale = new Vec3(scale, scale, 1);
}
}
/**获取屏幕分辨率和设计分辨率的比例
* @method mod 适配模式 1=按高度适配 2=按宽度适配
*/
public static getScaleRatio(mod: number = 1) {
let windowSize = view.getVisibleSize();
let designSize = view.getDesignResolutionSize();
// console.log("游戏分辨率:", windowSize, designSize);
if (mod == 1) {
return windowSize.height / designSize.height;
} else {
return windowSize.width / designSize.width;
}
}
/**
/** * @method 浅复制一个对象
* @method 浅复制一个对象 * @param source 需要浅复制对象
* @param source 需要浅复制的对象 * 合并对象,如果excludes中没有指明需要排除的字段,target也含有相同的字段,则会被object同名字段值覆盖掉
* 合并对象,如果excludes中没有指明需要排除的字段,target也含有相同的字段,则会被object同名字段值覆盖掉 * @param object
* @param object * @param excludes 需要排除的字段
* @param excludes 需要排除的字段 */
*/ static applyIf(
static applyIf(object: any, target: any = {}, excludes: Array<string> = []): Object { object: any,
if (!target) target = {}; target: any = {},
for (let key in object) { excludes: Array<string> = []
if (object.hasOwnProperty(key)) { ): Object {
if (excludes.indexOf(key) < 0) { if (!target) target = {};
target[key] = object[key]; for (let key in object) {
} if (object.hasOwnProperty(key)) {
} if (excludes.indexOf(key) < 0) {
target[key] = object[key];
} }
return target; }
}
/**
* @method 浅复制一个对象
* @param source 需要浅复制的对象
* @return 返回一个新的对象
* @log 1. vincent,2018-12-18, func、date、reg 和 err 类型不能正常拷贝
*/
static easyCopy(source: Object): Object {
const newObject = [];
return Utils.applyIf(source);
}
/**复制一个数据表 */
static clone(data:any) {
return Utils.easyCopy(data);
} }
return target;
}
/**
* @method 浅复制一个对象
* @param source 需要浅复制的对象
* @return 返回一个新的对象
* @log 1. vincent,2018-12-18, func、date、reg 和 err 类型不能正常拷贝
*/
static easyCopy(source: Object): Object {
const newObject = [];
return Utils.applyIf(source);
}
/**复制一个数据表 */
static clone(data: any) {
return Utils.easyCopy(data);
}
/**发送内部事件 */
public static sendInnerMsg(innerId: number, param?: any) {
li_EventManager.I.onInnerEL(innerId, param);
}
/**注册内部事件 */
public static addInnerEL(innerId: number, i_target, i_callback: Function) {
li_EventManager.I.addInnerEL(innerId, i_callback, i_target);
}
/**移除内部事件 */
public static removeInnerEL(innerId: number, i_target, i_callback: Function) {
li_EventManager.I.removeInnerEL(innerId, i_callback, i_target);
}
/**发送内部事件 */ //获取随机数
public static sendInnerMsg(innerId: number, param?: any) { public static getRandomInt(i_start: number, i_end: number): number {
li_EventManager.I.onInnerEL(innerId, param); i_start = Math.ceil(i_start);
} i_end = Math.floor(i_end);
/**注册内部事件 */ return Math.floor(Math.random() * (i_end - i_start + 1)) + i_start;
public static addInnerEL(innerId: number, i_target, i_callback: Function,) { }
li_EventManager.I.addInnerEL(innerId, i_callback, i_target); //数字转字符串,指定位数,位数不足前面补0
} public static PrefixInt(num, length) {
/**移除内部事件 */ return (Array(length).join("0") + num).slice(-length);
public static removeInnerEL(innerId: number, i_target, i_callback: Function) { }
li_EventManager.I.removeInnerEL(innerId, i_callback, i_target) //数字保留几位小数
} public static DecimalPlaces(num: number, weishu: number) {
return num.toFixed(weishu);
}
/**获取屏幕分辨率 */
public static GetWinSize(): Size {
return view.getVisibleSize();
}
//获取随机数 /**获取当前日期,格式YYYY-MM-DD */
public static getRandomInt(i_start:number, i_end:number) : number { public static GetNowFormatDay(
i_start = Math.ceil(i_start); nowDate: Date | null = null,
i_end = Math.floor(i_end); char: string = "-"
return Math.floor(Math.random() * (i_end - i_start + 1)) + i_start; ) {
} if (nowDate == null) {
//数字转字符串,指定位数,位数不足前面补0 nowDate = new Date();
public static PrefixInt(num, length) {
return (Array(length).join('0') + num).slice(-length);
}
//数字保留几位小数
public static DecimalPlaces(num:number, weishu:number) {
return num.toFixed(weishu);
} }
let day = nowDate.getDate();
let month = nowDate.getMonth() + 1; //注意月份需要+1
let year = nowDate.getFullYear();
//补全0,并拼接
return (
year + char + Utils.completeDate(month) + char + Utils.completeDate(day)
);
}
//补全0
private static completeDate(value: number) {
return value < 10 ? "0" + value : value;
}
//打印消耗时间===================================================================================================
/**获取屏幕分辨率 */ private static _eplTime = 0;
public static GetWinSize():Size { /**记录当前时间 */
return view.getVisibleSize() public static ProfilerTimeRecord() {
} Utils._eplTime = new Date().getTime();
}
/**打印消耗时间 */
/**获取当前日期,格式YYYY-MM-DD */ public static ProfilerTimePrint(key: string = "") {
public static GetNowFormatDay(nowDate: Date | null = null, char: string = "-") { let time = new Date().getTime();
if (nowDate == null) { let timecha = time - Utils._eplTime;
nowDate = new Date(); console.log(`${key}消耗时间:${timecha}毫秒`);
} Utils._eplTime = time;
let day = nowDate.getDate(); }
let month = nowDate.getMonth() + 1;//注意月份需要+1 }
let year = nowDate.getFullYear();
//补全0,并拼接
return year + char + Utils.completeDate(month) + char + Utils.completeDate(day);
}
//补全0
private static completeDate(value: number) {
return value < 10 ? "0" + value : value;
}
//打印消耗时间===================================================================================================
private static _eplTime = 0;
/**记录当前时间 */
public static ProfilerTimeRecord() {
Utils._eplTime = new Date().getTime();
}
/**打印消耗时间 */
public static ProfilerTimePrint(key:string = "") {
let time = new Date().getTime();
let timecha = time - Utils._eplTime;
console.log(`${key}消耗时间:${timecha}毫秒`);
Utils._eplTime = time;
}
}
+5
View File
@@ -26,6 +26,7 @@ import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
import { promptItem } from "../Item/promptItem"; import { promptItem } from "../Item/promptItem";
import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils"; import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils";
import { DataManager } from "../../chat18x/data/DataManager"; import { DataManager } from "../../chat18x/data/DataManager";
import ConfigManager from "../../chat18x/manager/ConfigManager";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass("PreloadUI") @ccclass("PreloadUI")
@@ -239,6 +240,10 @@ export class PreloadUI extends Component {
// } else { // } else {
// //没登录成功,先进主界面,在主界面里进行登录 // //没登录成功,先进主界面,在主界面里进行登录
// } // }
ConfigManager.I.init();
//console.log(ConfigManager.tables.TbGlobalConfig.GameName);
ResManager.I.goMainScene(); //进入下一个场景 ResManager.I.goMainScene(); //进入下一个场景
// ResManager.I.goCustomScene("Test2DScene"); //进入自定义场景 // ResManager.I.goCustomScene("Test2DScene"); //进入自定义场景
} }
@@ -1,22 +1,28 @@
import { import {
_decorator,
resources, resources,
BufferAsset, BufferAsset,
Component,
assetManager, assetManager,
AssetManager, AssetManager,
} from "cc"; } from "cc";
import * as cfg from "../../schema/schema"; import * as cfg from "../../schema/schema";
import ByteBuf from "db://assets/Scripts/luban/ByteBuf"; import ByteBuf from "db://assets/Scripts/luban/ByteBuf";
const { ccclass, property } = _decorator; export default class ConfigManager {
@ccclass("ConfigManager") private static _instance: ConfigManager = null;
export default class ConfigManager extends Component { public static get I(): ConfigManager {
if (!this._instance) {
this._instance = new ConfigManager();
}
return this._instance;
}
public static tables: cfg.Tables = null; public static tables: cfg.Tables = null;
private static dataMap = new Map<string, Uint8Array>(); private static dataMap = new Map<string, Uint8Array>();
public static jsonFileNames: string[] = []; public static jsonFileNames: string[] = [];
onLoad() { private constructor() {}
public init() {
this.loadAllConfig(); this.loadAllConfig();
} }
@@ -65,7 +71,7 @@ export default class ConfigManager extends Component {
} }
Promise.all(promises).then((values) => { Promise.all(promises).then((values) => {
console.log("静态配置加载完成"); console.log("静态配置加载完成");
ConfigManager.tables = new cfg.Tables(this.getFileData); ConfigManager.tables = new cfg.Tables(ConfigManager.I.getFileData);
for (let item of ConfigManager.tables.TbGirls.getDataList()) { for (let item of ConfigManager.tables.TbGirls.getDataList()) {
console.log(item); console.log(item);
} }
@@ -71,14 +71,14 @@ export class ThemePanel extends li_BaseView {
this.cache.push(item); this.cache.push(item);
this.content.addChild(newNode); this.content.addChild(newNode);
} }
const rectInfo = cfgs[0]; const rectInfo = ConfigManager.tables.TbGirls.get(10001);
this.recId = rectInfo.id; this.recId = rectInfo.id;
this.rectNameKey = rectInfo.key; this.rectNameKey = rectInfo.nameKey;
//this.recName.string = LanguageUtils.getText(this.rectNameKey); //this.recName.string = LanguageUtils.getText(this.rectNameKey);
ResManager.I.changeBundleSpriteFrame( ResManager.I.changeBundleSpriteFrame(
this.recSprite, this.recSprite,
rectInfo.path, rectInfo.avatarPath,
"Chat18x", "Chat18x",
() => { () => {
let sizeTran = this.recSprite.node.parent.getComponent(UITransform); let sizeTran = this.recSprite.node.parent.getComponent(UITransform);
+10
View File
@@ -194,6 +194,7 @@ export class GlobalConfig {
this.MaxTokens = _buf_.readInt() this.MaxTokens = _buf_.readInt()
this.Timeout = _buf_.readInt() this.Timeout = _buf_.readInt()
this.FreeChatTimes = _buf_.readInt() this.FreeChatTimes = _buf_.readInt()
this.GameName = _buf_.readString()
} }
/** /**
@@ -217,6 +218,10 @@ export class GlobalConfig {
* 单个角色免费聊天次数 * 单个角色免费聊天次数
*/ */
readonly FreeChatTimes: number readonly FreeChatTimes: number
/**
* 游戏名
*/
readonly GameName: string
resolve(tables:Tables) { resolve(tables:Tables) {
@@ -225,6 +230,7 @@ export class GlobalConfig {
} }
} }
@@ -630,6 +636,10 @@ export class TbGlobalConfig {
* 单个角色免费聊天次数 * 单个角色免费聊天次数
*/ */
get FreeChatTimes(): number { return this._data.FreeChatTimes; } get FreeChatTimes(): number { return this._data.FreeChatTimes; }
/**
* 游戏名
*/
get GameName(): string { return this._data.GameName; }
resolve(tables:Tables) { resolve(tables:Tables) {
this._data.resolve(tables) this._data.resolve(tables)
Binary file not shown.