引入luban配表 需要命令行 npm install buffer
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "2bce8fa5-2ca5-44eb-89aa-d46f7e26d71b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { _decorator, resources, BufferAsset, Component } from "cc";
|
||||
import * as cfg from "../../schema/schema";
|
||||
import ByteBuf from "db://assets/Scripts/luban/ByteBuf";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@ccclass("ConfigManager")
|
||||
export default class ConfigManager extends Component {
|
||||
public static tables: cfg.Tables = null;
|
||||
private static dataMap = new Map<string, Uint8Array>();
|
||||
public static jsonFileNames: string[] = [];
|
||||
|
||||
onLoad() {
|
||||
this.loadAllConfig();
|
||||
}
|
||||
|
||||
public loadConfigName(): void {
|
||||
ConfigManager.jsonFileNames = cfg.Tables.getTableNames();
|
||||
}
|
||||
|
||||
public loadAllConfig() {
|
||||
this.loadConfigName();
|
||||
let promises: Promise<unknown>[] = [];
|
||||
for (let curFileName of ConfigManager.jsonFileNames) {
|
||||
let promise = new Promise((resolve, reject) => {
|
||||
resources.load("test/" + curFileName, BufferAsset, (err, data) => {
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
promise.then((data: BufferAsset) => {
|
||||
if (data) {
|
||||
ConfigManager.dataMap.set(
|
||||
curFileName,
|
||||
new Uint8Array(data.buffer().slice(0, data.buffer().byteLength))
|
||||
);
|
||||
} else {
|
||||
console.error("静态配置加载失败" + curFileName);
|
||||
}
|
||||
});
|
||||
promises.push(promise);
|
||||
}
|
||||
Promise.all(promises).then((values) => {
|
||||
console.log("静态配置加载完成");
|
||||
ConfigManager.tables = new cfg.Tables(this.getFileData);
|
||||
for (let item of ConfigManager.tables.Tbitem.getDataList()) {
|
||||
console.log(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
private getFileData(fileName: string): ByteBuf {
|
||||
if (ConfigManager.dataMap.has(fileName)) {
|
||||
return new ByteBuf(ConfigManager.dataMap.get(fileName));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "fbd435ab-238b-4ae8-a5ee-1823eec61491",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,18 +1,29 @@
|
||||
import { _decorator, Component, EditBox, Node,Label,Sprite,UITransform } from "cc";
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
EditBox,
|
||||
Node,
|
||||
Label,
|
||||
Sprite,
|
||||
UITransform,
|
||||
} from "cc";
|
||||
// 首先加载 polyfills 以确保兼容性
|
||||
import "../../utils/polyfills";
|
||||
import { DialogManager } from "../../manager/DialogManager";
|
||||
import { ChatAIService } from "../../core/ChatAIService";
|
||||
import li_BaseView from "db://assets/Scripts/Main/Common/li_BaseView";
|
||||
import Utils from "db://assets/Scripts/Main/Common/Utils";
|
||||
import {InnerMsgCode} from "db://assets/Scripts/Main/Config/InnerMsgCode";
|
||||
import {ChatContentsLayout} from "../components/ChatContentsLayout";
|
||||
import {ViewManager} from "db://assets/Scripts/Main/Manager/ViewManager";
|
||||
import { InnerMsgCode } from "db://assets/Scripts/Main/Config/InnerMsgCode";
|
||||
import { ChatContentsLayout } from "../components/ChatContentsLayout";
|
||||
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
|
||||
import GameRootUI from "db://assets/Scripts/Main/Common/GameRootUI";
|
||||
import {ImagePopup} from "../components/ImagePopup";
|
||||
import {girlDetailInfo, GirlsData} from "db://assets/Scripts/Main/Config/cfg/characters";
|
||||
import { ImagePopup } from "../components/ImagePopup";
|
||||
import {
|
||||
girlDetailInfo,
|
||||
GirlsData,
|
||||
} from "db://assets/Scripts/Main/Config/cfg/characters";
|
||||
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
||||
import {VideoRoleType} from "db://assets/Scripts/Main/Common/GlobalValue";
|
||||
import { VideoRoleType } from "db://assets/Scripts/Main/Common/GlobalValue";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("ChatPanel")
|
||||
@@ -34,44 +45,56 @@ export class ChatPanel extends li_BaseView {
|
||||
@property(ImagePopup)
|
||||
popUpImage: ImagePopup = null;
|
||||
|
||||
id:number
|
||||
id: number;
|
||||
private _nodeTab: any = {};
|
||||
|
||||
openUIDataCT(data)
|
||||
{
|
||||
openUIDataCT(data) {
|
||||
this.id = data;
|
||||
// 设置当前聊天的角色ID
|
||||
ChatAIService.Instance.setCurrentRole(this.id);
|
||||
}
|
||||
|
||||
onLoadCT()
|
||||
{
|
||||
Utils.parseNode(this.node,this._nodeTab);
|
||||
onLoadCT() {
|
||||
Utils.parseNode(this.node, this._nodeTab);
|
||||
|
||||
this.register();
|
||||
this.refresh(this.id);
|
||||
}
|
||||
register()
|
||||
{
|
||||
Utils.addInnerEL(InnerMsgCode.Chat_DialogRefresh,this,this.onDialogUpdate);
|
||||
register() {
|
||||
Utils.addInnerEL(
|
||||
InnerMsgCode.Chat_DialogRefresh,
|
||||
this,
|
||||
this.onDialogUpdate
|
||||
);
|
||||
}
|
||||
refresh(id:number) {
|
||||
refresh(id: number) {
|
||||
this.id = id;
|
||||
const data = girlDetailInfo.filter(value=>value.baseInfo.id == id)[0];
|
||||
if(!data) return;
|
||||
const data = girlDetailInfo.filter((value) => value.baseInfo.id == id)[0];
|
||||
if (!data) return;
|
||||
this.girlName.string = data.baseInfo.name;
|
||||
ResManager.I.changeBundleSpriteFrame(this.girlImg,data.baseInfo.pic.url,"Chat18x",()=>{
|
||||
let sizeTran = this.girlImg.node.parent.getComponent(UITransform);
|
||||
Utils.adjustBgPixelRatioToSize(sizeTran.contentSize,this.girlImg.node,2);
|
||||
ResManager.I.changeBundleSpriteFrame(
|
||||
this.girlImg,
|
||||
data.baseInfo.pic.url,
|
||||
"Chat18x",
|
||||
() => {
|
||||
let sizeTran = this.girlImg.node.parent.getComponent(UITransform);
|
||||
Utils.adjustBgPixelRatioToSize(
|
||||
sizeTran.contentSize,
|
||||
this.girlImg.node,
|
||||
2
|
||||
);
|
||||
}
|
||||
);
|
||||
let uiTransform: UITransform =
|
||||
this._nodeTab.BgFrame.getComponent(UITransform);
|
||||
|
||||
Utils.sendInnerMsg(InnerMsgCode.SimplePlayVide, {
|
||||
path: data.pics[0].url,
|
||||
size: uiTransform.contentSize,
|
||||
});
|
||||
let uiTransform:UITransform = this._nodeTab.BgFrame.getComponent(UITransform);
|
||||
|
||||
Utils.sendInnerMsg(InnerMsgCode.SimplePlayVide,{path:data.pics[0].url,size:uiTransform.contentSize} )
|
||||
|
||||
}
|
||||
onDialogUpdate()
|
||||
{
|
||||
this.layout.UpdateDialog(DialogManager.getInstance().getDialogs())
|
||||
onDialogUpdate() {
|
||||
this.layout.UpdateDialog(DialogManager.getInstance().getDialogs());
|
||||
}
|
||||
protected onEnable(): void {
|
||||
if (!this.manager) this.manager = DialogManager.getInstance();
|
||||
@@ -86,15 +109,11 @@ export class ChatPanel extends li_BaseView {
|
||||
|
||||
this.editBox.string = "";
|
||||
|
||||
DialogManager.getInstance().updateDialog(true, str,true);
|
||||
DialogManager.getInstance().updateDialog(true, str, true);
|
||||
|
||||
// 使用新的sendMessage方法,传入角色ID
|
||||
const ret = await ChatAIService.Instance.sendMessage(this.id, str);
|
||||
console.log(ret);
|
||||
|
||||
if (ret == null) {
|
||||
console.warn("rep null");
|
||||
}
|
||||
if (this.manager) {
|
||||
this.manager.updateDialog(false, ret);
|
||||
}
|
||||
@@ -104,11 +123,7 @@ export class ChatPanel extends li_BaseView {
|
||||
//this.popUpImage.refresh("Image/1/blur_naked_1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
returnBtn()
|
||||
{
|
||||
returnBtn() {
|
||||
this.onClose();
|
||||
GameRootUI.I.showDefaultView();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user