Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static inline var
- {
- }
- var coords
- {
- chat :
- {
- start : [1,1],
- width : 30,
- height : 30,
- history_length : 200
- },
- room :
- {
- start : [1,1],
- width : 30,
- height : 1
- },
- users :
- {
- start : [1,1],
- width : 20,
- height : 30
- },
- input :
- {
- start : [1,1],
- width : 30,
- height : 1
- },
- }
- var chat_lines = [];
- var users_lines = [];
- room(name)
- {
- clear_room();
- position(ROOM);
- write(name);
- position(INPUT);
- }
- chat(nick, text)
- {
- // Format width
- text = '<${nick}>:$text';
- var temp = '';
- if(text.length < coords.chat.width)
- {
- chat_lines.append(text);
- }
- else
- {
- for(i in 0...text.length)
- {
- temp += text.charAt(i);
- if(i % coords.chat.width == 0)
- {
- chat_lines.push(text);
- temp = '';
- }
- }
- }
- // Format history (to avoid overflow)
- while(chat_lines.length > coords.chat.history_length)
- chat_lines.shift(); // TODO: save into log
- var current_chat_lines = chat_lines;
- // Format height
- while(current_chat_lines.length > coords.chat.height)
- current_chat_lines.shift();
- // Draw lines
- clear_chat();
- for(i in 0...coords.chat.height)
- {
- position(CHAT(i));
- write(current_chat_lines(i));
- }
- position(INPUT);
- }
- // Add or delete user if exist
- user(nick)
- {
- // If user called and exist, delete it
- if(Lambda.exists(users_lines, nick))
- users_lines.remove(nick);
- else
- users_lines.push(nick);
- // Format height
- if(users_lines > coords.users.height)
- {
- while(users_lines.length > coords.users.height-1) // -1 to add ...
- users_lines.pop();
- users_line.push('...');
- }
- // Format width
- for(line in users_lines)
- {
- if(line.length > coords.users.width)
- {
- line = line.substring(0, coords.users.width-3);
- line += '...';
- }
- }
- // Draw lines
- clear_users();
- for(i in 0...coords.users.height)
- {
- position(USERS(i));
- write(users_line(i));
- }
- position(INPUT);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement