-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathAsset.hx
106 lines (61 loc) · 1.76 KB
/
Asset.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
package project;
import haxe.io.Path;
import helpers.FileHelper;
import helpers.ObjectHelper;
import helpers.StringHelper;
class Asset {
public var data:Dynamic;
public var embed:Bool;
public var flatName:String;
public var format:String;
public var glyphs:String;
public var id:String;
//public var path:String;
//public var rename:String;
public var resourceName:String;
public var sourcePath:String;
public var targetPath:String;
public var type:AssetType;
public function new (path:String = "", rename:String = "", type:AssetType = null, embed:Bool = true) {
this.embed = embed;
sourcePath = path;
if (rename == "") {
targetPath = path;
} else {
targetPath = rename;
}
id = targetPath;
resourceName = targetPath;
flatName = StringHelper.getFlatName (targetPath);
format = Path.extension (path).toLowerCase ();
glyphs = "32-255";
if (type == null) {
var extension = Path.extension (path);
switch (extension.toLowerCase ()) {
case "jpg", "jpeg", "png", "gif":
this.type = AssetType.IMAGE;
case "otf", "ttf":
this.type = AssetType.FONT;
case "wav", "ogg":
this.type = AssetType.SOUND;
case "mp3", "mp2":
this.type = AssetType.MUSIC;
case "text", "txt", "json", "xml", "svg", "css":
this.type = AssetType.TEXT;
default:
if (path != "" && FileHelper.isText (path)) {
this.type = AssetType.TEXT;
} else {
this.type = AssetType.BINARY;
}
}
} else {
this.type = type;
}
}
public function clone ():Asset {
var asset = new Asset ();
ObjectHelper.copyFields (this, asset);
return asset;
}
}