-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
102 lines (84 loc) 路 1.96 KB
/
index.ts
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
import { Context, IContextOptions } from '../context';
import { Hash } from '../player';
import { kSerializeData, pickProperties } from '../../utils';
import { CapeHash, CapeName, CapeType } from './types';
export interface ICapeContextOptions extends IContextOptions<CapeContext> {
/**
* Cape hash
*/
hash: Hash;
}
export class CapeContext extends Context<CapeContext> {
/**
* Cape hash
*/
readonly hash: Hash;
/**
* @hidden
*/
protected endpoint = this.options.getEndpoint();
/**
* @hidden
*/
constructor({ hash, ...options }: ICapeContextOptions) {
super(options);
this.hash = hash;
}
/**
* Get cape url
*/
get url(): string {
return `${this.endpoint}/texture/${this.hash}.png`;
}
/**
* Get cape type
*/
get type(): CapeType {
return Object.values(CapeHash).includes(this.hash as CapeHash) ?
CapeType.MINECRAFT
:
CapeType.OPTIFINE;
}
/**
* Get cape name
*/
get name(): CapeName {
const cape = new Map(
Object.entries(CapeHash)
.map((entry) => entry.reverse() as [string, string])
)
.get(this.hash);
if (cape) {
const capeName = new Map(
Object.entries(CapeName)
)
.get(cape);
return capeName as CapeName;
}
return CapeName.OPTIFINE;
}
/**
* Check is Minecraft cape
*/
get isMinecraft(): boolean {
return this.type === CapeType.MINECRAFT;
}
/**
* Check is Optifine cape
*/
get isOptifine(): boolean {
return this.type === CapeType.OPTIFINE;
}
/**
* @hidden
*/
[kSerializeData](): any {
return pickProperties(this, [
'hash',
'url',
'name',
'type'
]);
}
}
export * from './types';