-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtraUtils.hx
142 lines (135 loc) · 3.84 KB
/
ExtraUtils.hx
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
import com.stencyl.Engine;
import com.stencyl.models.Actor;
import com.stencyl.models.actor.Group;
import com.stencyl.models.actor.ActorType;
import com.stencyl.models.Font;
import com.stencyl.models.Region;
import com.stencyl.models.Scene;
import com.stencyl.models.Sound;
import nme.display.BitmapData;
import nme.display.Bitmap;
import box2D.dynamics.joints.B2Joint;
// import com.stencyl.behavior.Attribute;
// import com.stencyl.behavior.SceneScript;
class ExtraUtils {
public static function sanitizeGameName(name:String):String {
var replacements:Map<String, String> = [
"$" => "$$",
"\n" => "$0A",
"\r" => "$0D",
" " => "$20",
"\"" => "$22",
"#" => "$23",
"%" => "$25",
"&" => "$26",
"'" => "$27",
"," => "$2C",
":" => "$3A",
";" => "$3B",
"<" => "$3C",
">" => "$3E",
"?" => "$3F",
"\\" => "$5C",
"~" => "$7E"
];
for (key in replacements.keys()) {
name = StringTools.replace(name, key, replacements[key]);
}
return name;
}
public static function equalsOr(thing:Dynamic, thing1:Dynamic, thing2:Dynamic):Bool {
return thing == thing1 || thing == thing2;
}
public static function is(thing:Dynamic, type:String):Bool {
if (type == "String") {
return Std.is(thing, String);
} else if (type == "Bool") {
return Std.is(thing, Bool);
} else if (type == "Int") {
return Std.is(thing, Int);
} else if (type == "Float") {
return Std.is(thing, Float);
} else if (type == "Actor") {
return Std.is(thing, Actor);
} else if (type == "Group") {
return Std.is(thing, Group);
} else if (type == "Type") {
return Std.is(thing, Type);
} else if (type == "Font") {
return Std.is(thing, Font);
} else if (type == "BitmapData") {
return Std.is(thing, BitmapData);
} else if (type == "Bitmap") {
return Std.is(thing, Bitmap);
} else if (type == "Joint") {
return Std.is(thing, B2Joint);
} else if (type == "Region") {
return Std.is(thing, Region);
} else if (type == "Scene") {
return Std.is(thing, Scene);
} else if (type == "Sound") {
return Std.is(thing, Sound);
} else if (type == "Array") {
switch (Type.typeof(thing)) {
case TClass(Array):
return true;
default:
return false;
}
} else if (type == "Map") {
// switch (Type.typeof(thing)) {
// case TClass(Map):
// return true;
// default:
return false;
// }
} else {
trace("ERROR: Type (" + type + ") is not a valid type!");
return false;
}
}
/* public static function getSceneBehaviorNames():Array<Dynamic> {
var behaviorNames:Array<Dynamic> = new Array<Dynamic>();
for (i in Engine.engine.behaviors.behaviors) {
behaviorNames.push(i.name);
}
return behaviorNames;
}
public static function getActorBehaviorNames(actor:Actor):Array<Dynamic> {
var behaviorNames:Array<Dynamic> = new Array<Dynamic>();
for (i in actor.behaviors.behaviors) {
behaviorNames.push(i.name);
}
return behaviorNames;
}
public static function getSceneBehaviorAttrs(name:String):Map<String,Dynamic> {
var behavior:Dynamic = null;
for (i in Engine.engine.behaviors.behaviors) {
if (i.name == name) {
behavior = i;
}
}
if (behavior == null) { return null; }
var attrs:Map<String,Attribute> = behavior.attributes;
var behaviorAttrs:Map<String,Dynamic> = new Map<String,Dynamic>();
for (i in attrs) {
behaviorAttrs.set(i.fullName, i.getRealValue());
}
return behaviorAttrs;
}
public static function getActorBehaviorAttrs(actor:Actor, name:String):Map<String,Dynamic> {
var behavior:Dynamic = null;
for (i in actor.behaviors.behaviors) {
if (i.name == name) {
behavior = i;
}
}
if (behavior == null) { return null; }
var attrs:Map<String,Attribute> = behavior.attributes;
var behaviorAttrs:Map<String,Dynamic> = new Map<String,Dynamic>();
for (i in attrs) {
behaviorAttrs.set(i.fullName, i.getRealValue());
}
return behaviorAttrs;
} */
}