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;
horizontalAngle?: number;
verticalAngle?: number;
layers?: IAssetPlaneVisualizationLayer[];
animatedLayers?: IAssetPlaneVisualizationAnimatedLayer[];
allLayers?: (IAssetPlaneVisualizationLayer | IAssetPlaneVisualizationAnimatedLayer)[];
}

View File

@ -155,6 +155,8 @@ export class RoomVisualizationMapper extends Mapper
for (const planeVisualizationXML of xml)
{
if (planeVisualizationXML.size === 32) continue;
const visualization: IAssetPlaneVisualization = {};
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.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)
{
visualization.animatedLayers = [];
RoomVisualizationMapper.mapPlaneVisualizationAnimatedLayers(planeVisualizationXML.animatedLayers, visualization.animatedLayers);
RoomVisualizationMapper.mapPlaneVisualizationAnimatedLayers([layer], visualization.allLayers);
}
}
}
}
@ -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;
@ -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;
@ -252,6 +255,8 @@ export class RoomVisualizationMapper extends Mapper
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 = {};
if (planeMaterialXML.id !== undefined) planeMaterial.id = planeMaterialXML.id;
@ -353,6 +358,8 @@ export class RoomVisualizationMapper extends Mapper
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 = {};
if (planeTextureXML.id !== undefined) planeTexture.id = planeTextureXML.id;
@ -409,6 +416,8 @@ export class RoomVisualizationMapper extends Mapper
for (const planeMaskVisualizationXML of planeMaskXML.visualizations)
{
if (planeMaskVisualizationXML.size === 32) continue;
const planeMaskVisualization: IAssetPlaneMaskVisualization = {};
if (planeMaskVisualizationXML.size !== undefined) planeMaskVisualization.size = planeMaskVisualizationXML.size;

View File

@ -6,6 +6,7 @@ export class PlaneVisualizationXML
private readonly _size: number;
private readonly _horizontalAngle: number;
private readonly _verticalAngle: number;
private readonly _allLayers: (PlaneVisualizationLayerXML | PlaneVisualizationAnimatedLayerXML)[];
private readonly _layers: PlaneVisualizationLayerXML[];
private readonly _animatedLayers: PlaneVisualizationAnimatedLayerXML[];
@ -20,7 +21,25 @@ export class PlaneVisualizationXML
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 = [];
@ -32,7 +51,7 @@ export class PlaneVisualizationXML
this._animatedLayers = [];
for (const layer of xml.animationLayer) this._animatedLayers.push(new PlaneVisualizationAnimatedLayerXML(layer));
}
} */
}
public get size(): number
@ -50,6 +69,11 @@ export class PlaneVisualizationXML
return this._verticalAngle;
}
public get allLayers(): (PlaneVisualizationLayerXML | PlaneVisualizationAnimatedLayerXML)[]
{
return this._allLayers;
}
public get layers(): PlaneVisualizationLayerXML[]
{
return this._layers;

View File

@ -101,7 +101,10 @@ export class SWFUtilities
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>