mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
|
import Singleton from "../../../extensions/ngame/assets/ngame/util/Singleton";
|
||
|
import { app } from "../App";
|
||
|
import { GAction } from "../consts/GAction";
|
||
|
import { GActionType, GUIChatMessage } from "../consts/GActionType";
|
||
|
import BaseData from "./BaseData";
|
||
|
|
||
|
//聊天数据
|
||
|
export default class ChatData extends BaseData{
|
||
|
|
||
|
//世界消息列表
|
||
|
datas:string[] = [];
|
||
|
|
||
|
//接受消息事件
|
||
|
receives:Function[] = [];
|
||
|
|
||
|
onInit() {
|
||
|
//监听聊天消息
|
||
|
app.socket.on(GAction.CHAT_RECEIVE_MESSAGE,this.onChatReceiveMessage,this,GActionType.GUIChatMessage);
|
||
|
}
|
||
|
|
||
|
|
||
|
//接受聊天消息
|
||
|
onChatReceiveMessage(info:GUIChatMessage){
|
||
|
console.log(`ChatData - onChatReceiveMessage`,info.message);
|
||
|
this.datas.push(info.message);
|
||
|
this.receives.forEach(fun => fun(info))
|
||
|
}
|
||
|
|
||
|
//发送消息
|
||
|
onSend(message:GUIChatMessage){
|
||
|
app.socket.Send(GAction.CHAT_MESSAGE,message,GActionType.GUIChatMessage);
|
||
|
}
|
||
|
|
||
|
//监听接受消息
|
||
|
on(receive:Function){
|
||
|
this.receives.push(receive);
|
||
|
}
|
||
|
//取消
|
||
|
off(receive:Function){
|
||
|
let index = this.receives.indexOf(receive);
|
||
|
if(index != -1)
|
||
|
this.receives.splice(index,1);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|