-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug.as
97 lines (86 loc) · 2.84 KB
/
Debug.as
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
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
//import microthread.MicroThread;
public class Debug {
public static const historyLength:uint = 29;
private static var parent:DisplayObjectContainer = null;
private static var contain:Sprite = null;
private static var commandLine:TextField;
private static var textFields:DisplayObjectContainer;
public static function attachTo(_parent:DisplayObjectContainer):void {
if (contain != null) { return; }
if (Config.BUILD_TYPE != Config.BUILD_DEBUG) { return; }
contain = new Sprite();
contain.graphics.beginFill(0x000000);
contain.graphics.drawRect(0, 0, Config.WIDTH, Config.HEIGHT);
contain.graphics.endFill();
contain.alpha = 0.6;
commandLine = new TextField();
commandLine.width = Config.WIDTH;
commandLine.height = 18;
commandLine.multiline = true;
commandLine.textColor = 0xFFFFFF;
commandLine.type = TextFieldType.INPUT;
var format:TextFormat = commandLine.defaultTextFormat;
format.font = "_typewriter";
commandLine.defaultTextFormat = format;
//commandLine.addEventListener(Event.CHANGE, onCommand);
contain.addChild(commandLine);
textFields = new Sprite();
textFields.y = 20;
contain.addChild(textFields);
parent = _parent;
parent.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey);
log("Debug created and attached to", parent);
}
public static function log(... args):void {
if (Config.BUILD_TYPE != Config.BUILD_DEBUG) { return; }
var textField:TextField = new TextField();
if (textFields.numChildren > 0) {
textField.y = textFields.getChildAt(textFields.numChildren - 1).y + 20;
}
textField.width = Config.WIDTH;
textField.height = 18;
textField.htmlText = '<font color="#FFFFFF" face="_typewriter">' +
args.join(" ").replace(/&/g, "&").replace(/</g, "<") + "</font>";
textFields.addChild(textField);
while (textFields.numChildren > historyLength) {
textFields.removeChildAt(0);
textFields.y -= 20;
}
}
/*private static function onCommand(e:Event):void {
var text:String = commandLine.text;
if (text.length > 0 && text.charCodeAt(text.length - 1) == 0x0D) {
var tokens:Array = text.split(/\s+/);
for (var i:uint = 0; i < tokens.length; i++) {
if (tokens[i].length == 0) {
tokens.splice(i, 1);
i--;
}
else if (tokens[i].match(/^-?\d/)) {
tokens[i] = Number(tokens[i]);
}
else if (tokens[i] == "true" || tokens[i] == "false") {
tokens[i] = (tokens[i] == "true");
}
else if (tokens[i] == "null") {
tokens[i] = null;
}
}
new MicroThread(tokens, "Debug-" + Math.random());
commandLine.text = "";
}
}*/
private static function onKey(e:KeyboardEvent):void {
if (e.keyCode != 0x30 || e.target == commandLine) { return; }
if (!parent.contains(contain)) {
parent.addChild(contain);
}
else {
parent.removeChild(contain);
}
}
}}