日志控制

This commit is contained in:
chen wei bo
2025-09-21 20:25:42 +08:00
parent 8f90c1d7cf
commit e78f6b937e
13 changed files with 122 additions and 107 deletions
+23 -22
View File
@@ -9,6 +9,7 @@ import Utils from "../../Main/Common/Utils";
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
import { TipsPanel } from "../ui/panels/TipsPanel";
import LanguageUtils from "../../Main/Common/LanguageUtils";
import { logger } from "db://assets/Scripts/Main/Common/Logger";
/**
* 聊天控制器接口 - 定义Panel和Controller之间的通信协议
@@ -102,7 +103,7 @@ export class ChatController {
*/
public bindView(callback: IChatPanelCallback): void {
this.callback = callback;
console.log("ChatController: View bound successfully");
logger.log("ChatController: View bound successfully");
}
/**
@@ -110,7 +111,7 @@ export class ChatController {
*/
public unbindView(): void {
this.callback = null;
console.log("ChatController: View unbound");
logger.log("ChatController: View unbound");
}
/**
@@ -139,7 +140,7 @@ export class ChatController {
// 同步到DialogManager
//this.syncDialogData();
console.log(`ChatController initialized with role ${roleId}`);
logger.log(`ChatController initialized with role ${roleId}`);
} else {
const error = new Error(`Invalid roleId: ${roleId}`);
this.handleError(error);
@@ -153,7 +154,7 @@ export class ChatController {
*/
public switchRole(categoryId: string, roleId: number): boolean {
if (!this.chatModel.switchToRole(categoryId, roleId)) {
console.error(`Failed to switch to role ${roleId}`);
logger.error(`Failed to switch to role ${roleId}`);
return false;
}
@@ -166,7 +167,7 @@ export class ChatController {
// 同步对话数据到DialogManager
//this.syncDialogData();
console.log(`ChatController switched to role ${roleId}`);
logger.log(`ChatController switched to role ${roleId}`);
return true;
}
@@ -182,7 +183,7 @@ export class ChatController {
// 检查聊天次数限制
if (!this.canSendMessage()) {
console.warn("ChatController: Cannot send message - chat limit reached");
logger.warn("ChatController: Cannot send message - chat limit reached");
this.callback?.onChatLimitReached();
return false;
}
@@ -190,7 +191,7 @@ export class ChatController {
try {
const roleId = this.chatModel.getCurrentRoleId();
if (!roleId) {
console.error("Role ID is not available in ChatModel");
logger.error("Role ID is not available in ChatModel");
TipsPanel.show(LanguageUtils.getText("chat_error_code_1004"));
}
@@ -200,7 +201,7 @@ export class ChatController {
// 显示加载中的对话
//this.dialogManager?.addLoadingDialog();
console.log(`Sending message to role ${roleId}: ${message}`);
logger.log(`Sending message to role ${roleId}: ${message}`);
// 发送消息给AI服务
const response = await ChatAIService.Instance.sendMessage(
roleId,
@@ -225,7 +226,7 @@ export class ChatController {
// 注意:情绪状态将通过异步事件更新,不在这里同步获取
console.log(`Response received from role ${roleId}: ${response}`);
logger.log(`Response received from role ${roleId}: ${response}`);
return true;
} else {
return false;
@@ -259,7 +260,7 @@ export class ChatController {
public clearChatHistory(): void {
const roleId = this.chatModel.getCurrentRoleId();
if (!roleId) {
console.warn("Cannot clear history: roleId is null");
logger.warn("Cannot clear history: roleId is null");
return;
}
@@ -270,9 +271,9 @@ export class ChatController {
// 清除模型中的对话记录
this.chatModel.clearDialogs();
console.log(`Chat history cleared for role ${roleId}`);
logger.log(`Chat history cleared for role ${roleId}`);
} catch (error) {
console.error("Failed to clear chat history:", error);
logger.error("Failed to clear chat history:", error);
this.handleError(error as Error);
}
}
@@ -289,9 +290,9 @@ export class ChatController {
// 清除模型中的对话记录
this.chatModel.clearDialogs(roleId);
console.log(`Chat history cleared for role ${roleId}`);
logger.log(`Chat history cleared for role ${roleId}`);
} catch (error) {
console.error(`Failed to clear chat history for role ${roleId}:`, error);
logger.error(`Failed to clear chat history for role ${roleId}:`, error);
this.handleError(error as Error);
}
}
@@ -311,7 +312,7 @@ export class ChatController {
this.chatModel.reset();
this.callback = null;
this.dialogManager = null;
console.log("ChatController destroyed");
logger.log("ChatController destroyed");
}
/**
@@ -373,7 +374,7 @@ export class ChatController {
this.chatModel.addDialog(isPlayer, content, targetRoleId);
});
console.log(
logger.log(
`Loaded ${chatHistory.length} messages from ChatHistoryManager for role ${targetRoleId}`
);
}
@@ -384,7 +385,7 @@ export class ChatController {
*/
public syncDialogData(): void {
if (!this.dialogManager || !this.chatModel.validate()) {
console.warn(
logger.warn(
"Cannot sync dialog data: missing DialogManager or invalid ChatModel"
);
return;
@@ -392,7 +393,7 @@ export class ChatController {
const dialogs = this.chatModel.getDialogs();
this.dialogManager.syncFromChatModel(dialogs);
console.log(
logger.log(
`Synced ${dialogs.length} dialogs from ChatModel to DialogManager`
);
}
@@ -445,9 +446,9 @@ export class ChatController {
// 清除模型中的角色数据
this.chatModel.clearRoleData(roleId);
console.log(`All data cleared for role ${roleId}`);
logger.log(`All data cleared for role ${roleId}`);
} catch (error) {
console.error(`Failed to clear all data for role ${roleId}:`, error);
logger.error(`Failed to clear all data for role ${roleId}:`, error);
this.handleError(error as Error);
}
}
@@ -482,7 +483,7 @@ export class ChatController {
*/
private onEmotionUpdated(data: any): void {
if (!data || !data.roleId || data.emotion === undefined) {
console.warn("Invalid emotion update data:", data);
logger.warn("Invalid emotion update data:", data);
return;
}
@@ -490,7 +491,7 @@ export class ChatController {
// 只处理当前角色的情绪更新
if (roleId === this.chatModel.getCurrentRoleId()) {
console.log(
logger.log(
`ChatController: Emotion updated for role ${roleId}: ${VideoEmotion[emotion]}`
);