-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmessageBlock.js
More file actions
31 lines (29 loc) · 824 Bytes
/
messageBlock.js
File metadata and controls
31 lines (29 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 😉 Credits: Anuken
// 👨💻 Converted from https://github.com/Anuken/Mindustry/blob/master/core/src/mindustry/world/blocks/logic/MessageBlock.java
class MessageBlock {
constructor(){
this.message = "";
this.maxTextLength = 220;
this.maxNewLines = 24;
}
config(text){
if (text.length > this.maxTextLength){
return; //no. -Anuken
}
this.message = "";
text = text.trim();
let count = 0;
for(let i = 0; i < text.length; i++){
let c = text.charAt(i);
if(c == '\n'){
if(count++ <= this.maxNewLines){
this.message += '\n';
}
}
else{
this.message += c;
}
}
}
}
export {MessageBlock};