Enhance debugging utilities for developers

This commit is contained in:
Ryan McGrath 2011-07-11 08:29:39 -04:00
parent 372cd854b1
commit 319bdaf885
4 changed files with 215 additions and 53 deletions

View file

@ -9,6 +9,19 @@
*/
Wii.util = {
/**
* A placeholder for the original Error function, since we pretty much overwrite it to actually
* be useful to us. See "Wii.installListeners()" for more information on this.
*/
originalErrFunction: null,
/**
* Upon first call to Wii.util.debug(), this becomes a div that we keep
* a reference to. It's primarily used for logging information to the screen
* on the Wii itself.
*/
msgNode: null,
/**
* Wii.util.debug(err);
*
@ -18,37 +31,46 @@ Wii.util = {
* try { ... } catch(e) { Wii.util.debug(e); }
*/
debug: function(err) {
if(Wii.debuggerDiv === null) {
Wii.debuggerDiv = document.createElement('div');
if(Wii.util.msgNode === null) {
Wii.util.msgNode = document.createElement('div');
Wii.debuggerDiv.style.cssText = [
'width: 90%;',
'height: 90%;',
Wii.util.msgNode.style.cssText = [
'min-width: 756px;',
'padding: 10px;',
'font-size: 26px;',
'font-size: 28px;',
'line-height: 32px;',
'font-family: monospace;',
'overflow: scroll',
'position: absolute;',
'top: 10px;',
'left: 10px;',
'color: #f9f9f9;',
'background-color: #010101;'
'background-color: rgba(44, 44, 44, .7);',
'border: 2px solid #42a2cc;'
].join('');
document.body.appendChild(Wii.debuggerDiv);
Wii.util.msgNode.addEventListener('click', Wii.util.hideDebugger, false);
document.body.appendChild(Wii.util.msgNode);
}
if(typeof err === 'string') {
Wii.debuggerDiv.innerHTML = err;
} else {
var msg = '';
for(var e in err) { msg += e + '=' + err[e] + '<br>'; }
for(var e in err) { msg += '<span style="color: #42a2cc; font-weight: bold;">' + e + '</span>=' + err[e] + '<br>'; }
Wii.debuggerDiv.innerHTML = msg;
}
Wii.debuggerDiv.style.display = 'block';
},
/**
* Wii.util.hideDebugger()
*
* Keep this around so we've got an easy reference to use for proper unloading
* of event handlers once someone leaves this page.
*/
hideDebugger: function() { this.style.display = 'none'; },
/**
* Wiimote.util.bind(bindReference, fn)
*