Add legacy color code support in NameFormatService and implement unit tests for colored name parsing.
This commit is contained in:
@@ -12,6 +12,25 @@ export class NameFormatService {
|
||||
return this.parseColoredName(this.getNameFromType(channel));
|
||||
}
|
||||
|
||||
private readonly LEGACY_COLOR_MAP: Record<string, string> = {
|
||||
'4': '#AA0000',
|
||||
'c': '#FF5555',
|
||||
'6': '#FFAA00',
|
||||
'e': '#FFFF55',
|
||||
'2': '#00AA00',
|
||||
'a': '#55FF55',
|
||||
'b': '#55FFFF',
|
||||
'3': '#00AAAA',
|
||||
'1': '#0000AA',
|
||||
'9': '#5555FF',
|
||||
'd': '#FF55FF',
|
||||
'5': '#AA00AA',
|
||||
'f': '#FFFFFF',
|
||||
'7': '#AAAAAA',
|
||||
'8': '#555555',
|
||||
'0': '#000000'
|
||||
};
|
||||
|
||||
private getNameFromType(channel: ChatChannel): string {
|
||||
if (channel.type === 'PARTY') {
|
||||
return this.chatService.partieMap().get(channel.name) ?? channel.name;
|
||||
@@ -23,7 +42,7 @@ export class NameFormatService {
|
||||
}
|
||||
|
||||
private parseColoredName(name: string): ColoredNameSegment[] {
|
||||
const markerRegex = /\{#([0-9a-fA-F]{6})(<>|[<>]?)}/g;
|
||||
const markerRegex = /\{#([0-9a-fA-F]{6})(<>|[<>]?)\}|&([0-9a-fA-F])/g;
|
||||
const segments: ColoredNameSegment[] = [];
|
||||
let currentColor: string | undefined;
|
||||
let gradientStartColor: string | undefined;
|
||||
@@ -34,8 +53,9 @@ export class NameFormatService {
|
||||
while ((match = markerRegex.exec(name)) !== null) {
|
||||
this.addColoredTextSegment(segments, name.slice(lastIndex, match.index), currentColor);
|
||||
|
||||
const markerColor = `#${match[1]}`;
|
||||
const markerType = match[2];
|
||||
const isLegacy = !!match[3];
|
||||
const markerColor = isLegacy ? this.LEGACY_COLOR_MAP[match[3]] : `#${match[1]}`;
|
||||
const markerType = isLegacy ? undefined : match[2];
|
||||
|
||||
if (markerType === '>') {
|
||||
currentColor = markerColor;
|
||||
|
||||
Reference in New Issue
Block a user