mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交聊天
This commit is contained in:
46
JisolGameCocos/assets/script/data/ChatData.ts
Normal file
46
JisolGameCocos/assets/script/data/ChatData.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
9
JisolGameCocos/assets/script/data/ChatData.ts.meta
Normal file
9
JisolGameCocos/assets/script/data/ChatData.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "37e2c6bd-5072-431f-a9c4-ec7fda53b41f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user