From 26e625a85108e16763bef4b66931dcc3181c9303 Mon Sep 17 00:00:00 2001 From: skeletor Date: Mon, 28 Mar 2022 06:59:02 +0000 Subject: [PATCH] Revert "fix group badges for weird badge strings" This reverts commit 629bb9b11121c3c11d57ba0b112591429574f548 --- src/nitro/session/badge/BadgeImageManager.ts | 32 +++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/nitro/session/badge/BadgeImageManager.ts b/src/nitro/session/badge/BadgeImageManager.ts index c07d01a2..757c7a97 100644 --- a/src/nitro/session/badge/BadgeImageManager.ts +++ b/src/nitro/session/badge/BadgeImageManager.ts @@ -173,37 +173,19 @@ export class BadgeImageManager implements IDisposable for(const partMatch of partMatches) { const partCode = partMatch[0]; - const part = this.parsePartString(partCode); + const shortMethod = (partCode.length === 6); + const partType = partCode[0]; + const partId = parseInt(partCode.slice(1, shortMethod ? 3 : 4)); + const partColor = parseInt(partCode.slice(shortMethod ? 3 : 4, shortMethod ? 5 : 6)); + const partPosition = partCode.length < 6 ? 0 : parseInt(partCode.slice(shortMethod ? 5 : 6, shortMethod ? 6 : 7)); // sometimes position is ommitted + const part = new GroupBadgePart(partType, partId, partColor, partPosition); - if(part) groupBadge.parts.push(part); + groupBadge.parts.push(part); } this.renderGroupBadge(groupBadge); } - /** - * Returns a badge part based on the part string. - * This is ugly but it is not my fault. I blame emulators for - * different ways of implementing group badges wrong - * @param partCode (for example b08010) - * @returns badge part object - */ - private parsePartString(partCode: string) : GroupBadgePart - { - const arr = partCode.split(''); - - const partType = arr.splice(0, 1).join(''); - const isSymbol = partType !== 'b'; - - const partId = parseInt(arr.splice(0, (partCode.length == 7 || (!isSymbol && partCode.length == 6 && arr[0] == '0')) ? 3 : 2).join('')); - - const partColor = parseInt(arr.splice(0, 2).join('')); - - const partPosition = arr.length ? parseInt(arr[0]) : 0; // sometimes position is ommitted - - return new GroupBadgePart(partType, partId, partColor, partPosition); - } - private renderGroupBadge(groupBadge: GroupBadge): void { const container = new NitroContainer();