nitro-renderer/packages/localization/src/BadgeBaseAndLevel.ts

54 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-03-17 03:02:09 +01:00
export class BadgeBaseAndLevel
{
2022-03-03 01:21:30 +01:00
private _badgeId: string = '';
private _level: number = 1;
private _base: string = '';
2021-03-17 03:02:09 +01:00
constructor(badgeId: string)
{
this._badgeId = badgeId;
this.parseText();
}
private parseText():void
{
let length = (this._badgeId.length - 1);
while(length > 0 && this.isNumber(this._badgeId.charAt(length))) length--;
this._base = this._badgeId.substr(0, (length + 1));
const level = this._badgeId.substr((length + 1), this._badgeId.length);
if(level && (level !== '')) this._level = Number.parseInt(level);
}
private isNumber(text: string): boolean
{
const char = text.charCodeAt(0);
return (char >= 48 && char <= 57);
}
public get level(): number
{
return this._level;
}
2021-08-26 06:08:46 +02:00
public set level(k : number)
2021-03-17 03:02:09 +01:00
{
this._level = Math.max(1, k);
}
public get getBadgeId(): string
{
return this._base + this._level;
}
public get base(): string
{
return this._base;
}
}