Skip to content

Commit 332be7e

Browse files
committed
cleanup Resource
1 parent 8b53878 commit 332be7e

1 file changed

Lines changed: 15 additions & 29 deletions

File tree

src/om/Resource.hx

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,31 @@ abstract Resource(haxe.Resource) {
1111
return std.haxe.Resource.getString(name);
1212

1313
public static inline function exists(name:String):Bool
14-
return list().indexOf(name) >= 0;
14+
return names().indexOf(name) >= 0;
1515

16-
public static inline function list():Array<String> {
16+
public static inline function names():Array<String> {
1717
return std.haxe.Resource.listNames();
1818
}
1919

2020
macro public static function all():ExprOf<Map<String, haxe.io.Bytes>> {
21-
var m = Context.getResources();
22-
return macro $a{
23-
list().map(f -> {
24-
var n = f;
25-
var v = macro $v{m.get(f)};
26-
return macro $v{n} => $v;
27-
})
28-
};
21+
var map:Array<Expr> = [];
22+
for (name in Context.getResources().keys()) {
23+
var k = macro $v{name};
24+
var v = macro haxe.Resource.getBytes($v{name});
25+
map.push(macro $k => $v);
26+
}
27+
return macro $a{map};
2928
}
3029

3130
macro public static function set(name:String, str:String) {
3231
Context.addResource(name, haxe.io.Bytes.ofString(str));
3332
return macro null;
3433
}
35-
/*
36-
macro public static function embed( path : String, id : String ) {
37-
trace( path, id );
38-
Context.addResource( id, File.getBytes( path ) );
39-
return macro null;
40-
}
4134

42-
macro public static function embedInline( path : String, id : String ) {
43-
trace( path, id );
44-
return macro null;
45-
}
46-
*/
47-
/*
48-
#if php
49-
@:access(haxe.Resource.getPath)
50-
public static inline function getPath( name : String ) : String {
51-
return std.haxe.Resource.getPath( name );
52-
}
53-
#end
54-
*/
35+
macro public static function embed(path:String, ?name:String) {
36+
if (name == null)
37+
name = path;
38+
Context.addResource(name, sys.io.File.getBytes(path));
39+
return macro null;
40+
}
5541
}

0 commit comments

Comments
 (0)