-
Notifications
You must be signed in to change notification settings - Fork 7
/
global.roomui.js
48 lines (40 loc) · 1.13 KB
/
global.roomui.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const uiCache = {
getOrAdd: function(roomName) {
this.ensureMap();
let result = this.uis[roomName];
if(!result) {
this.uis[roomName] = result = new RoomUI(roomName);
}
return result;
},
all: function() {
this.ensureMap();
return Object.values(this.uis);
},
ensureMap: function() {
if(!this.uis || Game.time !== this.currentTick) {
this.uis = {};
this.currentTick = Game.time;
}
}
}
module.exports = class RoomUI {
static forRoom(room) {
return uiCache.getOrAdd(room.name || room);
}
static get all() {
return uiCache.all();
}
constructor(roomName) {
this.visual = new RoomVisual(roomName);
this.captions = [];
}
addRoomCaption(caption, options) {
this.captions.push({ text: caption, options: options });
}
render() {
for(let row = 0; row < this.captions.length; row++) {
this.visual.text(this.captions[row].text, 0, row, { align: "left", color: "#fff", stroke: "#000", ...this.captions[row].options });
}
}
}