forked from Bitcoindefi/OpenAO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextStyles.ts
More file actions
94 lines (77 loc) · 2.32 KB
/
Copy pathtextStyles.ts
File metadata and controls
94 lines (77 loc) · 2.32 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
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
import { Text, TextStyle } from "pixi.js";
export const CLAN_TAG_HIGHLIGHT_COLOR = 0xe0b84f;
const characterClanTextStyleCache = new Map<string, TextStyle>();
const hudStatusTextStyleCache = new Map<string, TextStyle>();
const getTextStyleCacheKey = (color: string | number) =>
`${typeof color}:${String(color)}`;
export const createCharacterNameTextStyle = (color: string | number) =>
new TextStyle({
fontFamily: "Verdana",
align: "center",
fontSize: 12,
lineHeight: 13,
fontWeight: "700",
fill: color,
dropShadow: {
alpha: 1,
angle: Math.PI / 5,
blur: 0,
color: 0x000000,
distance: 1,
},
});
export const createCharacterClanTextStyle = (color: string | number) => {
const cacheKey = getTextStyleCacheKey(color);
const cachedStyle = characterClanTextStyleCache.get(cacheKey);
if (cachedStyle) {
return cachedStyle;
}
const style = new TextStyle({
fontFamily: "Verdana",
align: "center",
fontSize: 12,
lineHeight: 13,
fontWeight: "700",
fill: color,
dropShadow: {
alpha: 1,
angle: Math.PI / 5,
blur: 0,
color: 0x000000,
distance: 1,
},
});
characterClanTextStyleCache.set(cacheKey, style);
return style;
};
export const getHudStatusTextStyle = (color: number) => {
const cacheKey = getTextStyleCacheKey(color);
const cachedStyle = hudStatusTextStyleCache.get(cacheKey);
if (cachedStyle) {
return cachedStyle;
}
const style = new TextStyle({
fontFamily: "Arial",
fontSize: 11,
fontWeight: "bold",
fill: color,
stroke: { color: 0x000000, width: 1.5 },
});
hudStatusTextStyleCache.set(cacheKey, style);
return style;
};
export const setTextIfChanged = (label: Text, nextText: string) => {
if (label.text !== nextText) {
label.text = nextText;
}
};
export const setVisibilityIfChanged = (label: Text, nextVisible: boolean) => {
if (label.visible !== nextVisible) {
label.visible = nextVisible;
}
};
export const setStyleIfChanged = (label: Text, nextStyle: TextStyle) => {
if (label.style !== nextStyle) {
label.style = nextStyle;
}
};