You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 23:16:20 +00:00
Move to Renderer V2
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { inflate } from 'pako';
|
||||
import { Assets, Texture } from 'pixi.js';
|
||||
import { ArrayBufferToBase64 } from './ArrayBufferToBase64';
|
||||
import { BinaryReader } from './BinaryReader';
|
||||
|
||||
export class NitroBundle
|
||||
{
|
||||
private static TEXT_DECODER: TextDecoder = new TextDecoder('utf-8');
|
||||
|
||||
private _jsonFile: Object = null;
|
||||
private _texture: Texture = null;
|
||||
|
||||
public static async from(buffer: ArrayBuffer): Promise<NitroBundle>
|
||||
{
|
||||
const bundle = new NitroBundle();
|
||||
|
||||
await bundle.parse(buffer);
|
||||
|
||||
return bundle;
|
||||
}
|
||||
|
||||
public async parse(arrayBuffer: ArrayBuffer): Promise<void>
|
||||
{
|
||||
const binaryReader = new BinaryReader(arrayBuffer);
|
||||
|
||||
let fileCount = binaryReader.readShort();
|
||||
|
||||
while(fileCount > 0)
|
||||
{
|
||||
const fileNameLength = binaryReader.readShort();
|
||||
const fileName = binaryReader.readBytes(fileNameLength).toString();
|
||||
const fileLength = binaryReader.readInt();
|
||||
const buffer = binaryReader.readBytes(fileLength);
|
||||
const inflatedBuffer = inflate(buffer.toArrayBuffer());
|
||||
|
||||
if(fileName.endsWith('.json'))
|
||||
{
|
||||
this._jsonFile = JSON.parse(NitroBundle.TEXT_DECODER.decode(inflatedBuffer));
|
||||
}
|
||||
else
|
||||
{
|
||||
this._texture = await Assets.load<Texture>(`data:image/png;base64,${ ArrayBufferToBase64(inflatedBuffer) }`);
|
||||
}
|
||||
|
||||
fileCount--;
|
||||
}
|
||||
}
|
||||
|
||||
public get jsonFile(): Object
|
||||
{
|
||||
return this._jsonFile;
|
||||
}
|
||||
|
||||
public get texture(): Texture
|
||||
{
|
||||
return this._texture;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user