index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/import_external_resources.js | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/import_external_resources.js b/src/import_external_resources.js index aba29d2..cb1d7fb 100644 --- a/src/import_external_resources.js +++ b/src/import_external_resources.js @@ -1,15 +1,18 @@ import mapsheets from './assets/images/mapsheets.svg'; -import counters from './assets/images/counters.svg'; -const files = { - 'mapsheets.svg': mapsheets, - 'counters.svg': counters -} +const doc = new DOMParser().parseFromString(mapsheets, 'image/svg+xml'); +const refs = []; -document.querySelectorAll('use[data-href*=".svg"').forEach(el => { - const [filename] = el.dataset.href.match(/.+\.svg/g) - , href = el.dataset.href.replace(filename, files[filename].split('/').pop()) - ; - - el.setAttributeNS(null, 'href', href); +document.querySelectorAll('use[href*=".svg"').forEach(el => { + const fragId = el.getAttributeNS(null, 'href').split('.svg').pop(); + const frag = doc.querySelector(fragId); + frag.querySelectorAll('use').forEach(el => refs.push(el.getAttributeNS(null, 'href'))); + if (el.style.transform) frag.style.transform = el.style.transform; + el.replaceWith(frag); }); + +const refsQuery = [...new Set([...refs])].join(', '); +const refNodes = doc.querySelectorAll(refsQuery); +const defs = document.querySelector('defs'); + +refNodes.forEach(n => defs.appendChild(n)); |