mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-01-18 22:36:27 +01:00
Working
This commit is contained in:
parent
9432c8b6d8
commit
475a83cb26
@ -1,5 +1,5 @@
|
||||
import { IMessageDataWrapper, IMessageParser } from '../../../../../core';
|
||||
import { GroupBadgePart } from './utils/GroupBadgePart';
|
||||
import { GroupDataBadgePart } from './utils/GroupDataBadgePart';
|
||||
|
||||
export class GroupSettingsParser implements IMessageParser
|
||||
{
|
||||
@ -12,7 +12,7 @@ export class GroupSettingsParser implements IMessageParser
|
||||
private _colorB: number;
|
||||
private _state: number;
|
||||
private _canMembersDecorate: boolean;
|
||||
private _badgeParts: Map<number, GroupBadgePart>;
|
||||
private _badgeParts: Map<number, GroupDataBadgePart>;
|
||||
private _badgeCode: string;
|
||||
private _membersCount: number;
|
||||
|
||||
@ -67,7 +67,7 @@ export class GroupSettingsParser implements IMessageParser
|
||||
|
||||
for(let i = 0; i < badgePartsCount; i++)
|
||||
{
|
||||
const part = new GroupBadgePart(i === 0);
|
||||
const part = new GroupDataBadgePart(i === 0);
|
||||
|
||||
part.key = wrapper.readInt();
|
||||
part.color = wrapper.readInt();
|
||||
@ -132,7 +132,7 @@ export class GroupSettingsParser implements IMessageParser
|
||||
return this._canMembersDecorate;
|
||||
}
|
||||
|
||||
public get badgeParts(): Map<number, GroupBadgePart>
|
||||
public get badgeParts(): Map<number, GroupDataBadgePart>
|
||||
{
|
||||
return this._badgeParts;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
export class GroupBadgePart
|
||||
export class GroupDataBadgePart
|
||||
{
|
||||
public isBase: boolean;
|
||||
public key: number;
|
@ -1,3 +1,3 @@
|
||||
export * from './GroupBadgePart';
|
||||
export * from './GroupDataBadgePart';
|
||||
export * from './GroupDataParser';
|
||||
export * from './GroupMemberParser';
|
||||
|
@ -1,108 +0,0 @@
|
||||
import { Resource, Texture } from '@pixi/core';
|
||||
import { IAssetManager } from '../../core/asset/IAssetManager';
|
||||
import { IEventDispatcher } from '../../core/events/IEventDispatcher';
|
||||
import { Nitro } from '../Nitro';
|
||||
import { BadgeInfo } from './BadgeInfo';
|
||||
import { BadgeImageReadyEvent } from './events/BadgeImageReadyEvent';
|
||||
|
||||
export class BadgeImageManager
|
||||
{
|
||||
public static GROUP_BADGE: string = 'group_badge';
|
||||
public static NORMAL_BADGE: string = 'normal_badge';
|
||||
|
||||
private _assets: IAssetManager;
|
||||
private _events: IEventDispatcher;
|
||||
private _requestedBadges: Map<string, boolean>;
|
||||
|
||||
constructor(assetManager: IAssetManager, eventDispatcher: IEventDispatcher)
|
||||
{
|
||||
this._assets = assetManager;
|
||||
this._events = eventDispatcher;
|
||||
this._requestedBadges = new Map();
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._assets = null;
|
||||
}
|
||||
|
||||
public getBadgeImage(badgeName: string, type: string = BadgeImageManager.NORMAL_BADGE, load: boolean = true): Texture<Resource>
|
||||
{
|
||||
let badge = this.getBadgeTexture(badgeName, type);
|
||||
|
||||
if(!badge && load) badge = this.getBadgePlaceholder();
|
||||
|
||||
return badge;
|
||||
}
|
||||
|
||||
public getBadgeInfo(k: string): BadgeInfo
|
||||
{
|
||||
const badge = this.getBadgeTexture(k);
|
||||
|
||||
return (badge) ? new BadgeInfo(badge, false) : new BadgeInfo(this.getBadgePlaceholder(), true);
|
||||
}
|
||||
|
||||
public loadBadgeImage(badgeName: string, type: string = BadgeImageManager.NORMAL_BADGE): string
|
||||
{
|
||||
if(this._assets.getTexture(this.getBadgeUrl(badgeName, type))) return badgeName;
|
||||
|
||||
this.getBadgeTexture(badgeName, type);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private getBadgeTexture(badgeName: string, type: string = BadgeImageManager.NORMAL_BADGE): Texture<Resource>
|
||||
{
|
||||
const url = this.getBadgeUrl(badgeName, type);
|
||||
|
||||
const existing = this._assets.getTexture(url);
|
||||
|
||||
if(existing) return existing.clone();
|
||||
|
||||
if(this._requestedBadges.get(badgeName)) return null;
|
||||
|
||||
if(url)
|
||||
{
|
||||
this._requestedBadges.set(badgeName, true);
|
||||
|
||||
this._assets.downloadAsset(url, (flag: boolean) =>
|
||||
{
|
||||
if(flag)
|
||||
{
|
||||
const texture = this._assets.getTexture(url);
|
||||
|
||||
if(texture && this._events) this._events.dispatchEvent(new BadgeImageReadyEvent(badgeName, texture.clone()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private getBadgePlaceholder(): Texture<Resource>
|
||||
{
|
||||
const url = (Nitro.instance.getConfiguration<string>('images.url') + '/loading_icon.png');
|
||||
const existing = this._assets.getTexture(url);
|
||||
|
||||
if(!existing) return null;
|
||||
|
||||
return existing.clone();
|
||||
}
|
||||
|
||||
public getBadgeUrl(badge: string, type: string = BadgeImageManager.NORMAL_BADGE): string
|
||||
{
|
||||
let url = null;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case BadgeImageManager.NORMAL_BADGE:
|
||||
url = (Nitro.instance.getConfiguration<string>('badge.asset.url')).replace('%badgename%', badge);
|
||||
break;
|
||||
case BadgeImageManager.GROUP_BADGE:
|
||||
url = (Nitro.instance.getConfiguration<string>('badge.asset.group.url')).replace('%badgedata%', badge);
|
||||
break;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ import { UserRespectComposer } from '../communication/messages/outgoing/user/Use
|
||||
import { NitroSettingsEvent } from '../events/NitroSettingsEvent';
|
||||
import { Nitro } from '../Nitro';
|
||||
import { HabboWebTools } from '../utils/HabboWebTools';
|
||||
import { BadgeImageManager } from './BadgeImageManager';
|
||||
import { BadgeImageManager } from './badge/BadgeImageManager';
|
||||
import { SecurityLevel } from './enum/SecurityLevel';
|
||||
import { MysteryBoxKeysUpdateEvent } from './events';
|
||||
import { SessionDataPreferencesEvent } from './events/SessionDataPreferencesEvent';
|
||||
@ -197,7 +197,8 @@ export class SessionDataManager extends NitroManager implements ISessionDataMana
|
||||
{
|
||||
if(this._badgeImageManager) return;
|
||||
|
||||
this._badgeImageManager = new BadgeImageManager(Nitro.instance.core.asset, this.events);
|
||||
this._badgeImageManager = new BadgeImageManager(Nitro.instance.core.asset, this);
|
||||
this._badgeImageManager.init();
|
||||
}
|
||||
|
||||
public hasProductData(listener: IProductDataListener): boolean
|
||||
|
@ -1,21 +1,22 @@
|
||||
import { Resource, Texture } from '@pixi/core';
|
||||
import { BadgeTypeEnum, GroupBadge } from '.';
|
||||
import { IAssetManager } from '../../../core/asset/IAssetManager';
|
||||
import { IMessageEvent } from '../../../core/communication/messages/IMessageEvent';
|
||||
import { NitroSprite } from '../../../core/utils/proxy/NitroSprite';
|
||||
import { GroupBadgePartsEvent } from '../../communication/messages/incoming/group/GroupBadgePartsEvent';
|
||||
import { GroupBadgePartsComposer } from '../../communication/messages/outgoing/group/GroupBadgePartsComposer';
|
||||
import { Nitro } from '../../Nitro';
|
||||
import { BadgeImageReadyEvent } from '../events/BadgeImageReadyEvent';
|
||||
import { ISessionDataManager } from '../ISessionDataManager';
|
||||
import { IDisposable } from './../../../core/common/disposable/IDisposable';
|
||||
import { TextureUtils } from './../../../room/utils/TextureUtils';
|
||||
import { SessionDataManager } from './../SessionDataManager';
|
||||
import { BadgeInfo } from './BadgeInfo';
|
||||
import { GroupBadge } from './GroupBadge';
|
||||
import { GroupBadgePart } from './GroupBadgePart';
|
||||
import { IBadgeImageManager } from './IBadgeImageManager';
|
||||
|
||||
export class BadgeImageManager implements IBadgeImageManager
|
||||
export class BadgeImageManager implements IDisposable
|
||||
{
|
||||
public static GROUP_BADGE: string = 'group_badge';
|
||||
public static NORMAL_BADGE: string = 'normal_badge';
|
||||
|
||||
private _assets: IAssetManager;
|
||||
private _sessionDataManager: SessionDataManager;
|
||||
private _messages: IMessageEvent[];
|
||||
@ -29,7 +30,7 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
|
||||
private _readyToGenerateGroupBadges: boolean;
|
||||
|
||||
constructor(assetManager: IAssetManager, sessionDataManager: ISessionDataManager)
|
||||
constructor(assetManager: IAssetManager, sessionDataManager: SessionDataManager)
|
||||
{
|
||||
this._assets = assetManager;
|
||||
this._sessionDataManager = sessionDataManager;
|
||||
@ -39,6 +40,7 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
this._groupPartColors = new Map();
|
||||
|
||||
this._requestedBadges = new Map();
|
||||
this._groupBadgesQueue = new Map();
|
||||
|
||||
this._readyToGenerateGroupBadges = false;
|
||||
}
|
||||
@ -53,7 +55,7 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
|
||||
for(const message of this._messages) this._sessionDataManager.communication.registerMessageEvent(message);
|
||||
|
||||
this._sessionDataManager.send(new GroupBadgePartsComposer());
|
||||
//this._sessionDataManager.send(new GroupBadgePartsComposer());
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +71,7 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
this._sessionDataManager = null;
|
||||
}
|
||||
|
||||
public getBadgeImage(badgeName: string, type: string = BadgeTypeEnum.NORMAL_BADGE, load: boolean = true): Texture<Resource>
|
||||
public getBadgeImage(badgeName: string, type: string = BadgeImageManager.NORMAL_BADGE, load: boolean = true): Texture<Resource>
|
||||
{
|
||||
let badge = this.getBadgeTexture(badgeName, type);
|
||||
|
||||
@ -85,7 +87,7 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
return (badge) ? new BadgeInfo(badge, false) : new BadgeInfo(this.getBadgePlaceholder(), true);
|
||||
}
|
||||
|
||||
public loadBadgeImage(badgeName: string, type: string = BadgeTypeEnum.NORMAL_BADGE): string
|
||||
public loadBadgeImage(badgeName: string, type: string = BadgeImageManager.NORMAL_BADGE): string
|
||||
{
|
||||
if(this._assets.getTexture(this.getBadgeUrl(badgeName, type))) return badgeName;
|
||||
|
||||
@ -94,7 +96,7 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
return null;
|
||||
}
|
||||
|
||||
private getBadgeTexture(badgeName: string, type: string = BadgeTypeEnum.NORMAL_BADGE): Texture<Resource>
|
||||
private getBadgeTexture(badgeName: string, type: string = BadgeImageManager.NORMAL_BADGE): Texture<Resource>
|
||||
{
|
||||
const url = this.getBadgeUrl(badgeName, type);
|
||||
|
||||
@ -108,7 +110,7 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
{
|
||||
this._requestedBadges.set(badgeName, true);
|
||||
|
||||
if(type === BadgeTypeEnum.NORMAL_BADGE)
|
||||
if(type === BadgeImageManager.NORMAL_BADGE)
|
||||
{
|
||||
this._assets.downloadAsset(url, (flag: boolean) =>
|
||||
{
|
||||
@ -126,7 +128,7 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
{
|
||||
if(!this._readyToGenerateGroupBadges)
|
||||
{
|
||||
if(this._groupBadgesQueue.get(badgeName)) this._groupBadgesQueue.set(badgeName, true);
|
||||
if(!this._groupBadgesQueue.get(badgeName)) this._groupBadgesQueue.set(badgeName, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -148,16 +150,16 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
return existing.clone();
|
||||
}
|
||||
|
||||
public getBadgeUrl(badge: string, type: string = BadgeTypeEnum.NORMAL_BADGE): string
|
||||
public getBadgeUrl(badge: string, type: string = BadgeImageManager.NORMAL_BADGE): string
|
||||
{
|
||||
let url = null;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case BadgeTypeEnum.NORMAL_BADGE:
|
||||
case BadgeImageManager.NORMAL_BADGE:
|
||||
url = (Nitro.instance.getConfiguration<string>('badge.asset.url')).replace('%badgename%', badge);
|
||||
break;
|
||||
case BadgeTypeEnum.GROUP_BADGE:
|
||||
case BadgeImageManager.GROUP_BADGE:
|
||||
//url = (Nitro.instance.getConfiguration<string>('badge.asset.group.url')).replace('%badgedata%', badge);
|
||||
url = badge;
|
||||
break;
|
||||
@ -190,6 +192,8 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
|
||||
const requiredAssets = isBase ? this._groupBases.get(partId) : this._groupSymbols.get(partId);
|
||||
|
||||
if(!requiredAssets) continue;
|
||||
|
||||
for(const requiredAsset of requiredAssets)
|
||||
{
|
||||
if(requiredAsset.length > 0)
|
||||
@ -214,6 +218,7 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
{
|
||||
for(const part of groupBadge.parts)
|
||||
{
|
||||
let isFirst = true;
|
||||
for(const partUrl of part.urls)
|
||||
{
|
||||
const texture = this._assets.getTexture(partUrl);
|
||||
@ -225,7 +230,10 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
const sprite = new NitroSprite(texture);
|
||||
sprite.x = pos.x;
|
||||
sprite.y = pos.y;
|
||||
sprite.tint = parseInt(this._groupPartColors.get(part.color), 16);
|
||||
|
||||
if(isFirst) sprite.tint = parseInt(this._groupPartColors.get(part.color), 16);
|
||||
|
||||
isFirst = false;
|
||||
|
||||
groupBadge.container.addChild(sprite);
|
||||
}
|
||||
@ -235,7 +243,6 @@ export class BadgeImageManager implements IBadgeImageManager
|
||||
this._groupBadgesQueue.delete(groupBadge.code);
|
||||
|
||||
const texture = TextureUtils.generateTexture(groupBadge.container);
|
||||
|
||||
this._assets.setTexture(groupBadge.code, texture);
|
||||
|
||||
if(this._sessionDataManager) this._sessionDataManager.events.dispatchEvent(new BadgeImageReadyEvent(groupBadge.code, texture));
|
||||
|
@ -1,2 +1,4 @@
|
||||
export * from './BadgeImageManager';
|
||||
export * from './BadgeInfo';
|
||||
export * from './GroupBadge';
|
||||
export * from './GroupBadgePart';
|
||||
|
@ -1,5 +1,4 @@
|
||||
export * from './BadgeImageManager';
|
||||
export * from './BadgeInfo';
|
||||
export * from './badge';
|
||||
export * from './enum';
|
||||
export * from './events';
|
||||
export * from './furniture';
|
||||
|
Loading…
Reference in New Issue
Block a user