mirror of
https://github.com/duckietm/Nitro-Cool-UI-Renderer.git
synced 2025-06-21 15:06:58 +00:00
🆙 More Updates
This commit is contained in:
parent
4cae55befc
commit
791309ff73
@ -12,7 +12,6 @@ export interface IAssetManager
|
||||
getAsset(name: string): IGraphicAsset;
|
||||
getCollection(name: string): IGraphicAssetCollection;
|
||||
createCollection(data: IAssetData, spritesheet: Spritesheet): IGraphicAssetCollection;
|
||||
loadTextureFromUrl(url: string, name?: string): Promise<Texture>
|
||||
downloadAssets(urls: string[]): Promise<boolean>;
|
||||
downloadAsset(url: string): Promise<boolean>;
|
||||
readonly collections: Map<string, IGraphicAssetCollection>;
|
||||
|
@ -14,8 +14,8 @@
|
||||
"dependencies": {
|
||||
"@nitrots/api": "1.0.0",
|
||||
"@nitrots/utils": "1.0.0",
|
||||
"pixi.js": "^8.2.5",
|
||||
"@pixi/gif": "^3.0.0"
|
||||
"@pixi/gif": "^3.0.1",
|
||||
"pixi.js": "^8.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "~5.5.4"
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { IAssetData, IAssetManager, IGraphicAsset, IGraphicAssetCollection } from '@nitrots/api';
|
||||
import { NitroBundle, NitroLogger } from '@nitrots/utils';
|
||||
import { AnimatedGIF } from '@pixi/gif';
|
||||
import { Assets, Spritesheet, SpritesheetData, Texture } from 'pixi.js';
|
||||
import { GraphicAssetCollection } from './GraphicAssetCollection';
|
||||
|
||||
@ -73,33 +74,6 @@ export class AssetManager implements IAssetManager
|
||||
return collection;
|
||||
}
|
||||
|
||||
public async loadTextureFromUrl(url: string, name: string = null): Promise<Texture>
|
||||
{
|
||||
if(!url || !url.length) return null;
|
||||
|
||||
let texture = this.getTexture(name);
|
||||
|
||||
if(!texture) texture = this.getTexture(url);
|
||||
|
||||
if(texture) return texture;
|
||||
|
||||
try
|
||||
{
|
||||
texture = await Assets.load<Texture>(url);
|
||||
|
||||
if(!texture) return null;
|
||||
|
||||
this.setTexture(name ?? url, texture);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
catch (err)
|
||||
{
|
||||
NitroLogger.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
public async downloadAssets(urls: string[]): Promise<boolean>
|
||||
{
|
||||
if(!urls || !urls.length) return Promise.resolve(true);
|
||||
@ -125,23 +99,37 @@ export class AssetManager implements IAssetManager
|
||||
{
|
||||
if(!url || !url.length) return false;
|
||||
|
||||
if(url.endsWith('.png') || url.endsWith('.jpg') || url.endsWith('.jpeg') || url.endsWith('.gif'))
|
||||
{
|
||||
const texture = await Assets.load<Texture>(url);
|
||||
|
||||
this.setTexture(url, texture);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const response = await fetch(url);
|
||||
|
||||
if(response.status !== 200 || !response.headers.has('Content-Type') || response.headers.get('Content-Type') !== 'application/octet-stream') return false;
|
||||
if(!response || response.status !== 200) return false;
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
const nitroBundle = await NitroBundle.from(buffer);
|
||||
const contentType = response.headers.get('Content-Type');
|
||||
|
||||
await this.processAsset(nitroBundle.texture, nitroBundle.jsonFile as IAssetData);
|
||||
switch(contentType)
|
||||
{
|
||||
case 'application/octet-stream': {
|
||||
const buffer = await response.arrayBuffer();
|
||||
const nitroBundle = await NitroBundle.from(buffer);
|
||||
|
||||
await this.processAsset(nitroBundle.texture, nitroBundle.jsonFile as IAssetData);
|
||||
break;
|
||||
}
|
||||
case 'image/png':
|
||||
case 'image/jpeg': {
|
||||
const texture = await Assets.load<Texture>(url);
|
||||
|
||||
if(texture) this.setTexture(url, texture);
|
||||
break;
|
||||
}
|
||||
case 'image/gif': {
|
||||
const buffer = await response.arrayBuffer();
|
||||
const animatedGif = AnimatedGIF.fromBuffer(buffer);
|
||||
const texture = animatedGif.texture;
|
||||
|
||||
if(texture) this.setTexture(url, texture);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -174,4 +162,4 @@ export class AssetManager implements IAssetManager
|
||||
{
|
||||
return this._collections;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
import { Assets } from 'pixi.js';
|
||||
import { AssetManager } from './AssetManager';
|
||||
|
||||
Assets.init();
|
||||
|
||||
const assetManager = new AssetManager();
|
||||
|
||||
export const GetAssetManager = () => assetManager;
|
||||
export const GetAssetManager = () => assetManager;
|
4
packages/room/src/GetRoomPreviewerInstance.ts
Normal file
4
packages/room/src/GetRoomPreviewerInstance.ts
Normal file
@ -0,0 +1,4 @@
|
||||
1import { GetRoomEngine } from './GetRoomEngine';
|
||||
import { RoomPreviewer } from './RoomPreviewer';
|
||||
|
||||
export const GetRoomPreviewerInstance = () => new RoomPreviewer(GetRoomEngine(), ++RoomPreviewer.PREVIEW_COUNTER);
|
@ -2,7 +2,7 @@ import { GetAssetManager } from '@nitrots/assets';
|
||||
import { GetCommunication, GroupBadgePartsEvent } from '@nitrots/communication';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { BadgeImageReadyEvent, GetEventDispatcher } from '@nitrots/events';
|
||||
import { TextureUtils } from '@nitrots/utils';
|
||||
import { NitroLogger, TextureUtils } from '@nitrots/utils';
|
||||
import { Container, Sprite, Texture } from 'pixi.js';
|
||||
import { BadgeInfo } from './BadgeInfo';
|
||||
import { GroupBadge } from './GroupBadge';
|
||||
@ -20,7 +20,7 @@ export class BadgeImageManager
|
||||
private _groupBadgesQueue: Map<string, boolean> = new Map();
|
||||
private _readyToGenerateGroupBadges: boolean = false;
|
||||
|
||||
public init(): void
|
||||
public async init(): Promise<void>
|
||||
{
|
||||
GetCommunication().registerMessageEvent(new GroupBadgePartsEvent(this.onGroupBadgePartsEvent.bind(this)));
|
||||
}
|
||||
@ -60,11 +60,19 @@ export class BadgeImageManager
|
||||
{
|
||||
const loadBadge = async () =>
|
||||
{
|
||||
await GetAssetManager().downloadAsset(url);
|
||||
try
|
||||
{
|
||||
if(!await GetAssetManager().downloadAsset(url)) return;
|
||||
|
||||
const texture = GetAssetManager().getTexture(url);
|
||||
const texture = GetAssetManager().getTexture(url);
|
||||
|
||||
if(texture) GetEventDispatcher().dispatchEvent(new BadgeImageReadyEvent(badgeName, texture));
|
||||
if(texture) GetEventDispatcher().dispatchEvent(new BadgeImageReadyEvent(badgeName, texture));
|
||||
}
|
||||
|
||||
catch (err)
|
||||
{
|
||||
NitroLogger.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
loadBadge();
|
||||
@ -191,4 +199,4 @@ export class BadgeImageManager
|
||||
|
||||
for(const badgeCode of this._groupBadgesQueue.keys()) this.loadGroupBadge(badgeCode);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user