聊天记录展示
This commit is contained in:
@@ -4,12 +4,11 @@ export interface Dialog {
|
||||
}
|
||||
|
||||
export class DiaLogData {
|
||||
public playerDialog: Dialog = null;
|
||||
public aiDialogs: Dialog[] = [];
|
||||
// 统一的对话数组,保存所有历史对话
|
||||
private dialogs: Dialog[] = [];
|
||||
|
||||
public cleanDialog() {
|
||||
this.playerDialog = null;
|
||||
this.aiDialogs = [];
|
||||
this.dialogs = [];
|
||||
}
|
||||
|
||||
public pushDialog(
|
||||
@@ -17,17 +16,42 @@ export class DiaLogData {
|
||||
str: string,
|
||||
isLoading: boolean = false
|
||||
) {
|
||||
if (isPlayer) {
|
||||
this.playerDialog = { isPlayer: true, content: str };
|
||||
} else {
|
||||
this.aiDialogs.push({ isPlayer: false, content: str });
|
||||
}
|
||||
// 追加新对话到数组末尾
|
||||
this.dialogs.push({ isPlayer, content: str });
|
||||
}
|
||||
|
||||
public GetPlayerDialog() {
|
||||
return this.playerDialog;
|
||||
/**
|
||||
* 获取最后一条玩家对话(兼容旧接口)
|
||||
*/
|
||||
public GetPlayerDialog(): Dialog | null {
|
||||
// 从后往前查找最后一条玩家消息
|
||||
for (let i = this.dialogs.length - 1; i >= 0; i--) {
|
||||
if (this.dialogs[i].isPlayer) {
|
||||
return this.dialogs[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public GetAIDialog() {
|
||||
return this.aiDialogs;
|
||||
|
||||
/**
|
||||
* 获取所有AI对话(兼容旧接口)
|
||||
*/
|
||||
public GetAIDialog(): Dialog[] {
|
||||
// 返回所有AI消息
|
||||
return this.dialogs.filter(dialog => !dialog.isPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有对话记录
|
||||
*/
|
||||
public getAllDialogs(): Dialog[] {
|
||||
return [...this.dialogs];
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量设置对话记录(用于加载历史)
|
||||
*/
|
||||
public setDialogs(dialogs: Dialog[]): void {
|
||||
this.dialogs = [...dialogs];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user