-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.ts
More file actions
73 lines (62 loc) · 2.04 KB
/
Copy pathutils.ts
File metadata and controls
73 lines (62 loc) · 2.04 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
import Chart from './chart';
import Player from './player';
export const selectionModeDescriptions: { [index: number]: string } = {
0: 'By chartkey',
1: 'By title, subtitle, artist, difficulty meter and filehash',
2: 'By title, subtitle, artist and filehash'
};
export const selectionModes: { [index: number]: (ch: Chart) => object } = {
0: (ch: Chart) => ({ chartkey: ch.chartkey }),
1: (ch: Chart) => ({
title: ch.title,
subtitle: ch.subtitle,
artist: ch.artist,
difficulty: ch.difficulty,
meter: ch.meter,
filehash: ch.filehash
}),
2: (ch: Chart) => ({
title: ch.title,
subtitle: ch.subtitle,
artist: ch.artist,
filehash: ch.filehash
})
};
export function removeMultiColor(s: string) {
return s.replace(/(\|c[0-9A-Fa-f]{7}(\s*))*(\|c[0-9A-Fa-f]{7})/g, '$2$3');
}
export function color(c: string) {
return `|c0${c}`;
}
export const systemPrepend = `${color('BBBBFF')}System:${color('FFFFFF')} `;
export const ownerColor = 'BBFFBB';
export const playerColor = 'AAFFFF';
export const opColor = 'FFBBBB';
export function unauthorizedChat(player: Player, operator: boolean = false) {
if (!player.room) {
// TODO
// The player is not in a room, but managed to instance a room command - idk how you
// would want to deal with this.
} else if (operator) {
player.sendChat(1, `${systemPrepend}You are not room owner or operator.`, player.room.name);
} else {
player.sendChat(1, `${systemPrepend}You are not room owner`, player.room.name);
}
}
export const stringToColour = function(str: string) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
// eslint-disable-next-line no-bitwise
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
let colour = '';
for (let i = 0; i < 3; i++) {
// eslint-disable-next-line no-bitwise
const value = (hash >> (i * 8)) & 0xFF;
colour += `00${value.toString(16)}`.substr(-2);
}
return colour;
};
export function colorize(string: string, colour = stringToColour(string)) {
return color(colour) + string + color('FFFFFF');
}