Skateside / pocket-grimoire

A mobile version of the Blood on the Clocktower grimoire
https://www.pocketgrimoire.co.uk
GNU General Public License v3.0
34 stars 14 forks source link

Tweak the template interface #47

Closed Skateside closed 1 year ago

Skateside commented 1 year ago
class Template {
    // ...
    draw(populates) {

        const clone = this.template.content.cloneNode(true);

        Object.entries(populates).forEach(([selector, populate]) => {
            lookup(selector, clone).forEach((element) => populate(element));
        });

        return clone;

    }
}

This allows a simpler interface and gets rid of the default population interfaces

template.draw({
    ".js--character--leaves"(element) {

        element.classList.toggle("character--setup", setup);
        element.classList.toggle("character--left-1", firstNight);
        element.classList.toggle("character--right-1", otherNight);
        const top = reminders.length + remindersGlobal.length;
        element.classList.toggle(`character--top-${top}`, top);

    },
    ".js--character--image"(element) {
        element.src = image;
    },
    ".js--character--name"(element) {
        element.textContent = name;
    }
});

Might reduce the code a little, speeding things up a tad