mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-01-19 06:46:28 +01:00
fix group badges for weird badge strings
This commit is contained in:
parent
c494d1c602
commit
629bb9b111
@ -173,19 +173,37 @@ export class BadgeImageManager implements IDisposable
|
|||||||
for(const partMatch of partMatches)
|
for(const partMatch of partMatches)
|
||||||
{
|
{
|
||||||
const partCode = partMatch[0];
|
const partCode = partMatch[0];
|
||||||
const shortMethod = (partCode.length === 6);
|
const part = this.parsePartString(partCode);
|
||||||
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);
|
|
||||||
|
|
||||||
groupBadge.parts.push(part);
|
if(part) groupBadge.parts.push(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderGroupBadge(groupBadge);
|
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
|
private renderGroupBadge(groupBadge: GroupBadge): void
|
||||||
{
|
{
|
||||||
const container = new NitroContainer();
|
const container = new NitroContainer();
|
||||||
|
Loading…
Reference in New Issue
Block a user