WIP: render radial coord hexes/maps
This commit is contained in:
@@ -180,11 +180,11 @@ export function start(startLoc, units) {
|
||||
for (const affiliation in forces) {
|
||||
const container = document.querySelector(`#${affiliation}-record`);
|
||||
const records = container.querySelector('.records');
|
||||
const name = startLoc?.dataset[`${affiliation}Name`];
|
||||
// const name = startLoc?.dataset[`${affiliation}Name`];
|
||||
|
||||
if (name) {
|
||||
container.querySelector('.name').textContent = name;
|
||||
}
|
||||
// if (name) {
|
||||
// container.querySelector('.name').textContent = name;
|
||||
// }
|
||||
forces[affiliation].forEach(r => records.appendChild(r));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
async function loadScript(scenario, svg) {
|
||||
async function loadScript(scenario, svg, script) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const scriptEl = document.createElementNS("http://www.w3.org/2000/svg", 'script');
|
||||
|
||||
@@ -11,14 +11,15 @@ async function loadScript(scenario, svg) {
|
||||
reject(Error('Script failed to load.'));
|
||||
};
|
||||
|
||||
const dataset = scenario.querySelector('script').dataset;
|
||||
const dataset = scenario.querySelector('script')?.dataset || {};
|
||||
|
||||
if ('cols' in dataset && 'rows' in dataset) {
|
||||
scriptEl.dataset.rows = dataset.rows;
|
||||
scriptEl.dataset.cols = dataset.cols;
|
||||
}
|
||||
|
||||
scriptEl.setAttributeNS(null, 'href', '../../map.js');
|
||||
// scriptEl.setAttributeNS(null, 'href', '../../map.js');
|
||||
scriptEl.setAttributeNS(null, 'href', `../../${script}.js`);
|
||||
svg.append(scriptEl);
|
||||
});
|
||||
}
|
||||
@@ -46,6 +47,7 @@ export async function requestResource(url) {
|
||||
}
|
||||
|
||||
export async function build(svg, request) {
|
||||
const defs = svg.querySelector('defs');
|
||||
const gb = svg.querySelector('.gameboard');
|
||||
const grid = svg.querySelector('.grid');
|
||||
|
||||
@@ -67,8 +69,6 @@ export async function build(svg, request) {
|
||||
await Promise.all(
|
||||
Object.keys(refs).map(filename => requestResource(`assets/images/${filename}`))
|
||||
).then(result => {
|
||||
const defs = svg.querySelector('defs');
|
||||
|
||||
Object.keys(refs).forEach((filename, index) => {
|
||||
const external = result[index];
|
||||
|
||||
@@ -98,5 +98,8 @@ export async function build(svg, request) {
|
||||
grid.replaceWith(svg.ownerDocument.importNode(scenarioGrid, true));
|
||||
}
|
||||
|
||||
return loadScript(scenario, svg);
|
||||
defs.replaceWith(scenario.querySelector('defs'));
|
||||
|
||||
await loadScript(scenario, svg, 'radial')
|
||||
return loadScript(scenario, svg, 'map');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user