mirror of
https://github.com/duckietm/Nitro-Cool-UI-Renderer.git
synced 2025-06-21 23:16: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;
|
getAsset(name: string): IGraphicAsset;
|
||||||
getCollection(name: string): IGraphicAssetCollection;
|
getCollection(name: string): IGraphicAssetCollection;
|
||||||
createCollection(data: IAssetData, spritesheet: Spritesheet): IGraphicAssetCollection;
|
createCollection(data: IAssetData, spritesheet: Spritesheet): IGraphicAssetCollection;
|
||||||
loadTextureFromUrl(url: string, name?: string): Promise<Texture>
|
|
||||||
downloadAssets(urls: string[]): Promise<boolean>;
|
downloadAssets(urls: string[]): Promise<boolean>;
|
||||||
downloadAsset(url: string): Promise<boolean>;
|
downloadAsset(url: string): Promise<boolean>;
|
||||||
readonly collections: Map<string, IGraphicAssetCollection>;
|
readonly collections: Map<string, IGraphicAssetCollection>;
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nitrots/api": "1.0.0",
|
"@nitrots/api": "1.0.0",
|
||||||
"@nitrots/utils": "1.0.0",
|
"@nitrots/utils": "1.0.0",
|
||||||
"pixi.js": "^8.2.5",
|
"@pixi/gif": "^3.0.1",
|
||||||
"@pixi/gif": "^3.0.0"
|
"pixi.js": "^8.5.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "~5.5.4"
|
"typescript": "~5.5.4"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { IAssetData, IAssetManager, IGraphicAsset, IGraphicAssetCollection } from '@nitrots/api';
|
import { IAssetData, IAssetManager, IGraphicAsset, IGraphicAssetCollection } from '@nitrots/api';
|
||||||
import { NitroBundle, NitroLogger } from '@nitrots/utils';
|
import { NitroBundle, NitroLogger } from '@nitrots/utils';
|
||||||
|
import { AnimatedGIF } from '@pixi/gif';
|
||||||
import { Assets, Spritesheet, SpritesheetData, Texture } from 'pixi.js';
|
import { Assets, Spritesheet, SpritesheetData, Texture } from 'pixi.js';
|
||||||
import { GraphicAssetCollection } from './GraphicAssetCollection';
|
import { GraphicAssetCollection } from './GraphicAssetCollection';
|
||||||
|
|
||||||
@ -73,33 +74,6 @@ export class AssetManager implements IAssetManager
|
|||||||
return collection;
|
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>
|
public async downloadAssets(urls: string[]): Promise<boolean>
|
||||||
{
|
{
|
||||||
if(!urls || !urls.length) return Promise.resolve(true);
|
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 || !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);
|
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 contentType = response.headers.get('Content-Type');
|
||||||
|
|
||||||
|
switch(contentType)
|
||||||
|
{
|
||||||
|
case 'application/octet-stream': {
|
||||||
const buffer = await response.arrayBuffer();
|
const buffer = await response.arrayBuffer();
|
||||||
const nitroBundle = await NitroBundle.from(buffer);
|
const nitroBundle = await NitroBundle.from(buffer);
|
||||||
|
|
||||||
await this.processAsset(nitroBundle.texture, nitroBundle.jsonFile as IAssetData);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import { Assets } from 'pixi.js';
|
||||||
import { AssetManager } from './AssetManager';
|
import { AssetManager } from './AssetManager';
|
||||||
|
|
||||||
|
Assets.init();
|
||||||
|
|
||||||
const assetManager = new AssetManager();
|
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 { GetCommunication, GroupBadgePartsEvent } from '@nitrots/communication';
|
||||||
import { GetConfiguration } from '@nitrots/configuration';
|
import { GetConfiguration } from '@nitrots/configuration';
|
||||||
import { BadgeImageReadyEvent, GetEventDispatcher } from '@nitrots/events';
|
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 { Container, Sprite, Texture } from 'pixi.js';
|
||||||
import { BadgeInfo } from './BadgeInfo';
|
import { BadgeInfo } from './BadgeInfo';
|
||||||
import { GroupBadge } from './GroupBadge';
|
import { GroupBadge } from './GroupBadge';
|
||||||
@ -20,7 +20,7 @@ export class BadgeImageManager
|
|||||||
private _groupBadgesQueue: Map<string, boolean> = new Map();
|
private _groupBadgesQueue: Map<string, boolean> = new Map();
|
||||||
private _readyToGenerateGroupBadges: boolean = false;
|
private _readyToGenerateGroupBadges: boolean = false;
|
||||||
|
|
||||||
public init(): void
|
public async init(): Promise<void>
|
||||||
{
|
{
|
||||||
GetCommunication().registerMessageEvent(new GroupBadgePartsEvent(this.onGroupBadgePartsEvent.bind(this)));
|
GetCommunication().registerMessageEvent(new GroupBadgePartsEvent(this.onGroupBadgePartsEvent.bind(this)));
|
||||||
}
|
}
|
||||||
@ -60,11 +60,19 @@ export class BadgeImageManager
|
|||||||
{
|
{
|
||||||
const loadBadge = async () =>
|
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();
|
loadBadge();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user