game.js
/* Bind a menu control to a field on a config object.
 */
Bind a menu control to a field on a config object.
Bind a menu control to a field on a config object .
function control(id, config, min, max, cb) {
    let buttons = document.querySelectorAll('#' + id + ' button');
    let span = document.querySelector('#' + id + ' span');
    buttons[0].addEventListener('click', function() {
        config[id] = Math.max(min, config[id] - 1);
        span.textContent = config[id];
        if (cb) cb();
    });
    buttons[1].addEventListener('click', function() {
        config[id] = Math.min(max, config[id] + 1);
        span.textContent = config[id];
        if (cb) cb();
    });
    span.textContent = config[id];
}
function control ( id , config , min , max , cb ) { let buttons = document . querySelectorAll ( '#' + id + ' button' ) ; let span = document . querySelector ( '#' + id + ' span' ) ; buttons [ 0 ] . addEventListener ( 'click' , function ( ) { config [ id ] = Math . max ( min , config [ id ] - 1 ) ; span . textContent = config [ id ] ; if ( cb ) cb ( ) ; } ) ; buttons [ 1 ] . addEventListener ( 'click' , function ( ) { config [ id ] = Math . min ( max , config [ id ] + 1 ) ; span . textContent = config [ id ] ; if ( cb ) cb ( ) ; } ) ; span . textContent = config [ id ] ; }
Bind a menu control to a field on a config object.
Bind a menu control to a field on a config object .