-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBase.ts
More file actions
62 lines (50 loc) · 1.05 KB
/
Base.ts
File metadata and controls
62 lines (50 loc) · 1.05 KB
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
// Import Internal Dependencies
import { parse } from "../../utils/path.ts";
export type AssetTypeName =
| "unknown"
| "model"
| "font"
| "tilemap"
| (string & {});
export class Asset {
id = globalThis.crypto.randomUUID();
name: string;
ext: string;
path: string;
type: AssetTypeName;
constructor(
path: string,
type?: AssetTypeName
) {
const { dir, name, ext } = parse(path);
this.name = name;
this.path = dir;
this.ext = ext;
this.type = type ?? "unknown";
}
get basename() {
return this.name + this.ext;
}
get longExt() {
const basename = this.basename;
const firstDotIndex = basename.indexOf(".");
return firstDotIndex === -1 ?
"" :
basename.slice(firstDotIndex);
}
toString() {
return this.path + this.basename;
}
static from(
assetOrPath: Asset | string
): Asset {
if (assetOrPath instanceof Asset) {
return assetOrPath;
}
return new Asset(assetOrPath);
}
}
export interface LazyAsset<T = unknown> {
asset: Asset;
get: () => T;
}