11import { EntityManager } from '../../../../../shared/system/EntityManager.js'
22import { MessageListComponent } from '../../../../../shared/component/MessageComponent.js'
33import { Entity } from '../../../../../shared/entity/Entity.js'
4- import { MessageEvent } from '../../component/events/MessageEvent.js'
4+ import { MessageEvent } from '../../component/events/MessageEvent.js'
55import { ChatComponent } from '../../component/tag/TagChatComponent.js'
66import { EventSystem } from '../../../../../shared/system/EventSystem.js'
77import { SerializedMessageType } from '../../../../../shared/network/server/serialized.js'
@@ -28,8 +28,8 @@ export class MessageEventSystem {
2828 }
2929
3030 for ( const chatMessageEvent of chatMessageEvents ) {
31- const chatListComponent = chatEntity . getComponent ( MessageListComponent )
32- if ( chatListComponent ) {
31+ const messageListComponent = chatEntity . getComponent ( MessageListComponent )
32+ if ( messageListComponent ) {
3333 let content = chatMessageEvent . content
3434 const sender = chatMessageEvent . sender
3535 const messageType = chatMessageEvent . messageType
@@ -40,42 +40,45 @@ export class MessageEventSystem {
4040 content = content . substring ( 0 , this . MAX_CONTENT_LENGTH )
4141 }
4242
43+ // Limit message history (bandwidth)
44+ if ( messageListComponent . list . length >= this . MAX_MESSAGES ) {
45+ messageListComponent . list . shift ( )
46+ }
47+
4348 // Handle different message types
49+ /**
50+ * Those messages are broadcasted to everybody, and front end handles the targeting.
51+ */
4452 switch ( messageType ) {
4553 case SerializedMessageType . GLOBAL_NOTIFICATION :
4654 // Add global notification
47- chatListComponent . addMessage ( sender , content , SerializedMessageType . GLOBAL_NOTIFICATION )
48- break ;
49-
55+ messageListComponent . addMessage (
56+ sender ,
57+ content ,
58+ SerializedMessageType . GLOBAL_NOTIFICATION
59+ )
60+ break
61+
5062 case SerializedMessageType . TARGETED_NOTIFICATION :
5163 case SerializedMessageType . TARGETED_CHAT :
5264 // Check if we have valid target player IDs
5365 if ( targetPlayerIds && targetPlayerIds . length > 0 ) {
5466 // Add targeted message with appropriate message type
55- chatListComponent . addMessage ( sender , content , messageType , targetPlayerIds )
67+ messageListComponent . addMessage ( sender , content , messageType , targetPlayerIds )
5668 } else {
5769 console . warn ( `ChatEventSystem: ${ messageType } without target player IDs` )
5870 // Fall back to regular chat message
59- this . addGlobalChatMessage ( chatListComponent , sender , content )
71+ messageListComponent . addMessage ( sender , content , SerializedMessageType . GLOBAL_CHAT )
6072 }
61- break ;
62-
73+ break
74+
6375 case SerializedMessageType . GLOBAL_CHAT :
6476 default :
6577 // Regular chat message
66- this . addGlobalChatMessage ( chatListComponent , sender , content )
67- break ;
78+ messageListComponent . addMessage ( sender , content , SerializedMessageType . GLOBAL_CHAT )
79+ break
6880 }
6981 }
7082 }
7183 }
72-
73- private addGlobalChatMessage ( chatListComponent : MessageListComponent , sender : string , content : string ) {
74- // Limit history to maxMessages
75- if ( chatListComponent . list . length >= this . MAX_MESSAGES ) {
76- chatListComponent . list . shift ( )
77- }
78-
79- chatListComponent . addMessage ( sender , content , SerializedMessageType . GLOBAL_CHAT )
80- }
8184}
0 commit comments