Create record sheet dynamically when map is loaded

This commit is contained in:
2025-06-16 22:41:29 -07:00
parent 7455dd0173
commit 17fd1c813b
14 changed files with 426 additions and 228 deletions

View File

@@ -16,6 +16,35 @@ object.addEventListener('load', function (e) {
const svg = this.contentDocument.querySelector('svg');
panzoom.start(svg);
gameboard.start(svg);
recordSheet.clear();
const recordTemplate = document.querySelector('template#soldier-record-block');
const startLoc = svg.querySelector('.start-locations');
const forces = recordSheet.createRecords(gameboard.getUnits(), recordTemplate);
for (const affiliation in forces) {
const container = document.querySelector(`#${affiliation}-record`);
const name = startLoc.dataset[`${affiliation}Name`];
if (name) {
container.querySelector('.name').textContent = name;
}
forces[affiliation].forEach(r => container.appendChild(r));
}
document.querySelectorAll('.soldier-record').forEach(el =>
el.addEventListener('click', () => {
if (el.classList.contains('selected')) {
el.classList.remove('selected');
gameboard.unSelect();
recordSheet.unSelect();
} else {
gameboard.select(el);
}
})
);
window.game = gameboard;
});
gameboard.setDistanceCallback((count = '-') => {
@@ -26,18 +55,6 @@ gameboard.setDistanceCallback((count = '-') => {
gameboard.setProneFlagCallback(checked => proneToggle.checked = checked);
gameboard.setSelectCallback(data => recordSheet.select(data));
document.querySelectorAll('.soldier-record').forEach(el =>
el.addEventListener('click', () => {
if (el.classList.contains('selected')) {
el.classList.remove('selected');
gameboard.unSelect();
recordSheet.unSelect();
} else {
gameboard.select(el);
}
})
);
document.querySelectorAll('.end-move').forEach(el => el.addEventListener('click', () => {
recordSheet.endMove();
gameboard.endMove();