-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDebugInfo.js
170 lines (135 loc) · 4.26 KB
/
DebugInfo.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* # DebugInfo
* Copyright(c) 2019 Stefano Balietti
* MIT Licensed
*
* Display information about the state of a player
*
* www.nodegame.org
*/
(function(node) {
"use strict";
var Table = W.Table;
node.widgets.register('DebugInfo', DebugInfo);
// ## Meta-data
DebugInfo.version = '0.6.2';
DebugInfo.description = 'Display basic info a client\'s status.';
DebugInfo.title = 'Debug Info';
DebugInfo.className = 'debuginfo';
// ## Dependencies
DebugInfo.dependencies = {
Table: {}
};
/**
* ## DebugInfo constructor
*
* `DebugInfo` displays information about the state of a player
*/
function DebugInfo() {
/**
* ### DebugInfo.table
*
* The `Table` which holds the information
*
* @See nodegame-window/Table
*/
this.table = null;
/**
* ### DebugInfo.interval
*
* The interval checking node properties
*/
this.interval = null;
/**
* ### DebugInfo.intervalTime
*
* The frequency of update of the interval. Default: 1000
*/
this.intervalTime = 1000;
}
// ## DebugInfo methods
/**
* ### DebugInfo.init
*
* Appends widget to `this.bodyDiv` and calls `this.updateAll`
*
* @see DebugInfo.updateAll
*/
DebugInfo.prototype.init = function(options) {
var that;
if ('number' === typeof options.intervalTime) {
this.intervalTime = options.intervalTime;
}
that = this;
this.on('destroyed', function() {
clearInterval(that.interval);
that.interval = null;
node.silly('DebugInfo destroyed.');
});
};
/**
* ### DebugInfo.append
*
* Appends widget to `this.bodyDiv` and calls `this.updateAll`
*
* @see DebugInfo.updateAll
*/
DebugInfo.prototype.append = function() {
var that;
this.table = new Table();
this.bodyDiv.appendChild(this.table.table);
this.updateAll();
that = this;
this.interval = setInterval(function() {
that.updateAll();
}, this.intervalTime);
};
/**
* ### DebugInfo.updateAll
*
* Updates information in `this.table`
*/
DebugInfo.prototype.updateAll = function() {
var stage, stageNo, stageId, playerId;
var stageLevel, stateLevel, winLevel;
var errMsg, connected, treatment;
var tmp, miss;
if (!this.bodyDiv) {
node.err('DebugInfo.updateAll: bodyDiv not found.');
return;
}
miss = '-';
stageId = miss;
stageNo = miss;
stage = node.game.getCurrentGameStage();
if (stage) {
tmp = node.game.plot.getStep(stage);
stageId = tmp ? tmp.id : '-';
stageNo = stage.toString();
}
stageLevel = J.getKeyByValue(node.constants.stageLevels,
node.game.getStageLevel());
stateLevel = J.getKeyByValue(node.constants.stateLevels,
node.game.getStateLevel());
winLevel = J.getKeyByValue(node.constants.windowLevels,
W.getStateLevel());
playerId = node.player ? node.player.id : miss;
errMsg = node.errorManager.lastErr || miss;
treatment = node.game.settings && node.game.settings.treatmentName ?
node.game.settings.treatmentName : miss;
connected = node.socket.connected ? 'yes' : 'no';
this.table.clear(true);
this.table.addRow(['Treatment: ', treatment]);
this.table.addRow(['Connected: ', connected]);
this.table.addRow(['Player Id: ', playerId]);
this.table.addRow(['Stage No: ', stageNo]);
this.table.addRow(['Stage Id: ', stageId]);
this.table.addRow(['Stage Lvl: ', stageLevel]);
this.table.addRow(['State Lvl: ', stateLevel]);
this.table.addRow(['Players : ', node.game.pl.size()]);
this.table.addRow(['Win Lvl: ', winLevel]);
this.table.addRow(['Win Loads: ', W.areLoading]);
this.table.addRow(['Last Err: ', errMsg]);
this.table.parse();
};
})(node);