Fix layer order

This commit is contained in:
Bill 2022-12-25 15:53:24 -05:00
parent e2cad3b9fe
commit 3f09425622
5 changed files with 57 additions and 22 deletions

View File

@ -6,6 +6,5 @@ export interface IAssetPlaneVisualization
size?: number; size?: number;
horizontalAngle?: number; horizontalAngle?: number;
verticalAngle?: number; verticalAngle?: number;
layers?: IAssetPlaneVisualizationLayer[]; allLayers?: (IAssetPlaneVisualizationLayer | IAssetPlaneVisualizationAnimatedLayer)[];
animatedLayers?: IAssetPlaneVisualizationAnimatedLayer[];
} }

View File

@ -155,6 +155,8 @@ export class RoomVisualizationMapper extends Mapper
for (const planeVisualizationXML of xml) for (const planeVisualizationXML of xml)
{ {
if (planeVisualizationXML.size === 32) continue;
const visualization: IAssetPlaneVisualization = {}; const visualization: IAssetPlaneVisualization = {};
if (planeVisualizationXML.size !== undefined) visualization.size = planeVisualizationXML.size; if (planeVisualizationXML.size !== undefined) visualization.size = planeVisualizationXML.size;
@ -162,23 +164,24 @@ export class RoomVisualizationMapper extends Mapper
if (planeVisualizationXML.horizontalAngle !== undefined) visualization.horizontalAngle = planeVisualizationXML.horizontalAngle; if (planeVisualizationXML.horizontalAngle !== undefined) visualization.horizontalAngle = planeVisualizationXML.horizontalAngle;
if (planeVisualizationXML.verticalAngle !== undefined) visualization.verticalAngle = planeVisualizationXML.verticalAngle; if (planeVisualizationXML.verticalAngle !== undefined) visualization.verticalAngle = planeVisualizationXML.verticalAngle;
if (planeVisualizationXML.layers !== undefined) if (planeVisualizationXML.allLayers !== undefined)
{ {
if (planeVisualizationXML.layers.length) if (planeVisualizationXML.allLayers.length)
{ {
visualization.layers = []; visualization.allLayers = [];
RoomVisualizationMapper.mapPlaneVisualizationLayers(planeVisualizationXML.layers, visualization.layers); for (const layer of planeVisualizationXML.allLayers)
} {
} if (layer instanceof PlaneVisualizationLayerXML)
{
RoomVisualizationMapper.mapPlaneVisualizationLayers([layer], visualization.allLayers);
}
if (planeVisualizationXML.animatedLayers !== undefined) else if (layer instanceof PlaneVisualizationAnimatedLayerXML)
{ {
if (planeVisualizationXML.animatedLayers.length) RoomVisualizationMapper.mapPlaneVisualizationAnimatedLayers([layer], visualization.allLayers);
{ }
visualization.animatedLayers = []; }
RoomVisualizationMapper.mapPlaneVisualizationAnimatedLayers(planeVisualizationXML.animatedLayers, visualization.animatedLayers);
} }
} }
@ -186,7 +189,7 @@ export class RoomVisualizationMapper extends Mapper
} }
} }
private static mapPlaneVisualizationLayers(xml: PlaneVisualizationLayerXML[], output: IAssetPlaneVisualizationLayer[]): void private static mapPlaneVisualizationLayers(xml: PlaneVisualizationLayerXML[], output: (IAssetPlaneVisualizationLayer | IAssetPlaneVisualizationAnimatedLayer)[]): void
{ {
if (!xml || !output) return; if (!xml || !output) return;
@ -203,7 +206,7 @@ export class RoomVisualizationMapper extends Mapper
} }
} }
private static mapPlaneVisualizationAnimatedLayers(xml: PlaneVisualizationAnimatedLayerXML[], output: IAssetPlaneVisualizationAnimatedLayer[]): void private static mapPlaneVisualizationAnimatedLayers(xml: PlaneVisualizationAnimatedLayerXML[], output: (IAssetPlaneVisualizationLayer | IAssetPlaneVisualizationAnimatedLayer)[]): void
{ {
if (!xml || !output) return; if (!xml || !output) return;
@ -252,6 +255,8 @@ export class RoomVisualizationMapper extends Mapper
for (const planeMaterialXML of xml) for (const planeMaterialXML of xml)
{ {
if (planeMaterialXML.id.startsWith('floor_32_') || planeMaterialXML.id.startsWith('wall_32_') || planeMaterialXML.id.startsWith('landscape_32_')) continue;
const planeMaterial: IAssetPlaneMaterial = {}; const planeMaterial: IAssetPlaneMaterial = {};
if (planeMaterialXML.id !== undefined) planeMaterial.id = planeMaterialXML.id; if (planeMaterialXML.id !== undefined) planeMaterial.id = planeMaterialXML.id;
@ -353,6 +358,8 @@ export class RoomVisualizationMapper extends Mapper
for (const planeTextureXML of xml) for (const planeTextureXML of xml)
{ {
if (planeTextureXML.id.startsWith('floor_32_') || planeTextureXML.id.startsWith('wall_32_') || planeTextureXML.id.startsWith('landscape_32_')) continue;
const planeTexture: IAssetPlaneTexture = {}; const planeTexture: IAssetPlaneTexture = {};
if (planeTextureXML.id !== undefined) planeTexture.id = planeTextureXML.id; if (planeTextureXML.id !== undefined) planeTexture.id = planeTextureXML.id;
@ -409,6 +416,8 @@ export class RoomVisualizationMapper extends Mapper
for (const planeMaskVisualizationXML of planeMaskXML.visualizations) for (const planeMaskVisualizationXML of planeMaskXML.visualizations)
{ {
if (planeMaskVisualizationXML.size === 32) continue;
const planeMaskVisualization: IAssetPlaneMaskVisualization = {}; const planeMaskVisualization: IAssetPlaneMaskVisualization = {};
if (planeMaskVisualizationXML.size !== undefined) planeMaskVisualization.size = planeMaskVisualizationXML.size; if (planeMaskVisualizationXML.size !== undefined) planeMaskVisualization.size = planeMaskVisualizationXML.size;

View File

@ -6,6 +6,7 @@ export class PlaneVisualizationXML
private readonly _size: number; private readonly _size: number;
private readonly _horizontalAngle: number; private readonly _horizontalAngle: number;
private readonly _verticalAngle: number; private readonly _verticalAngle: number;
private readonly _allLayers: (PlaneVisualizationLayerXML | PlaneVisualizationAnimatedLayerXML)[];
private readonly _layers: PlaneVisualizationLayerXML[]; private readonly _layers: PlaneVisualizationLayerXML[];
private readonly _animatedLayers: PlaneVisualizationAnimatedLayerXML[]; private readonly _animatedLayers: PlaneVisualizationAnimatedLayerXML[];
@ -20,7 +21,25 @@ export class PlaneVisualizationXML
if (attributes.verticalAngle !== undefined) this._verticalAngle = parseFloat(attributes.verticalAngle); if (attributes.verticalAngle !== undefined) this._verticalAngle = parseFloat(attributes.verticalAngle);
} }
if ((xml.visualizationLayer !== undefined) && Array.isArray(xml.visualizationLayer)) if ((xml.$$ !== undefined) && Array.isArray(xml.$$))
{
this._allLayers = [];
for (const layer of xml.$$)
{
switch (layer['#name'])
{
case 'visualizationLayer':
this._allLayers.push(new PlaneVisualizationLayerXML(layer));
break;
case 'animationLayer':
this._allLayers.push(new PlaneVisualizationAnimatedLayerXML(layer));
break;
}
}
}
/* if ((xml.visualizationLayer !== undefined) && Array.isArray(xml.visualizationLayer))
{ {
this._layers = []; this._layers = [];
@ -32,7 +51,7 @@ export class PlaneVisualizationXML
this._animatedLayers = []; this._animatedLayers = [];
for (const layer of xml.animationLayer) this._animatedLayers.push(new PlaneVisualizationAnimatedLayerXML(layer)); for (const layer of xml.animationLayer) this._animatedLayers.push(new PlaneVisualizationAnimatedLayerXML(layer));
} } */
} }
public get size(): number public get size(): number
@ -50,6 +69,11 @@ export class PlaneVisualizationXML
return this._verticalAngle; return this._verticalAngle;
} }
public get allLayers(): (PlaneVisualizationLayerXML | PlaneVisualizationAnimatedLayerXML)[]
{
return this._allLayers;
}
public get layers(): PlaneVisualizationLayerXML[] public get layers(): PlaneVisualizationLayerXML[]
{ {
return this._layers; return this._layers;

View File

@ -3,11 +3,11 @@ import { UncompressSWF } from './UncompressSWF';
export const ReadSWF = async (buffer: Buffer) => export const ReadSWF = async (buffer: Buffer) =>
{ {
if(Buffer.isBuffer(buffer)) return await UncompressSWF(buffer); if (Buffer.isBuffer(buffer)) return await UncompressSWF(buffer);
buffer = await readFile(buffer); buffer = await readFile(buffer);
if(!buffer) return null; if (!buffer) return null;
return await UncompressSWF(buffer); return await UncompressSWF(buffer);
}; };

View File

@ -101,7 +101,10 @@ export class SWFUtilities
if (!binaryData) return null; if (!binaryData) return null;
return await parseStringPromise(this.removeComments(binaryData.binaryData)); return await parseStringPromise(this.removeComments(binaryData.binaryData), {
explicitChildren: true,
preserveChildrenOrder: true
});
} }
public static async getAnimationXML(habboAssetSWF: HabboAssetSWF, snakeCase: boolean = false): Promise<any> public static async getAnimationXML(habboAssetSWF: HabboAssetSWF, snakeCase: boolean = false): Promise<any>