-
Notifications
You must be signed in to change notification settings - Fork 12
/
String.ts
41 lines (37 loc) · 1.04 KB
/
String.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
import { Font, Screen, Text } from '..';
import { Maths } from './Maths';
export abstract class String {
public static stringToArray(input: string): string[] {
let stringsNeeded = 1;
if (input.length > 99) {
stringsNeeded = Math.ceil(input.length / 99);
}
const outputString: string[] = new Array(stringsNeeded);
for (let i = 0; i < stringsNeeded; i++) {
outputString[i] = input.substring(
i * 99,
i * 99 + Maths.clamp(input.substring(i * 99).length, 0, 99),
);
}
return outputString;
}
public static measureStringWidthNoConvert(
input: string,
font = Font.ChaletLondon,
scale = 0,
): number {
SetTextEntryForWidth('STRING');
Text.addLongString(input);
SetTextFont(font);
SetTextScale(1, scale);
return GetTextScreenWidth(false);
}
public static measureString(
str: string,
font?: Font,
scale?: number,
screenWidth = Screen.ScaledWidth,
): number {
return this.measureStringWidthNoConvert(str, font, scale) * screenWidth;
}
}