From 6f0e03f207c3db1d2a8b4e7bac000ab223955df6 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Thu, 13 Jun 2019 22:49:37 -0700 Subject: [PATCH] Get a single unified xml object and use that for deriving images --- experiments/modern/src/App.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/experiments/modern/src/App.js b/experiments/modern/src/App.js index c81c3217..e5b1913c 100644 --- a/experiments/modern/src/App.js +++ b/experiments/modern/src/App.js @@ -29,15 +29,17 @@ async function getSkin() { ); const blob = await resp.blob(); const zip = await JSZip.loadAsync(blob); - const elementsDoc = await Utils.readXml(zip, "xml/player-elements.xml"); + const skinXml = await Utils.inlineIncludes( + await Utils.readXml(zip, "skin.xml"), + zip + ); const images = {}; - // TODO: Clearly more complicated than it needed to be. - const elements = elementsDoc.children[0].children; - for (const element of elements) { - switch (element.name) { + await Utils.asyncTreeMap(skinXml, async node => { + // TODO: This is probalby only valid if in an `` node + switch (node.name) { case "bitmap": { - const { file, gammagroup, h, id, w, x, y } = element.attributes; + const { file, gammagroup, h, id, w, x, y } = node.attributes; // TODO: Escape file for regex const img = Utils.getCaseInsensitveFile(zip, file); const imgBlob = await img.async("blob"); @@ -50,10 +52,11 @@ async function getSkin() { break; } default: { - console.error(`Unknonw node ${element.name}`); + console.error(`Unknonw node ${node.name}`); } } - } + return node; + }); const player = await Utils.readXml(zip, "xml/player-normal.xml"); // Gross hack returing a tuple here. We're just doing some crazy stuff to get