ruiqimao / qmkbuilder

Online GUI for QMK Firmware
http://kbfirmware.com
GNU General Public License v3.0
382 stars 123 forks source link

One layer only does not compile #41

Open nebularnoise opened 6 years ago

nebularnoise commented 6 years ago

I tried to compile a file where I removed all layers except layer 0, and nothing happened. I thought the UI froze, because the Download buttons were deactivated, but I then realised this was intentional.

However, I saw an error message in the console: key[0].keycodes[layer] is undefined

I think the culprate is src/files/generators/keymap.c.js:

for (let layer = 0; layer < C.KEYMAP_MAX_LAYERS; layer ++) {
    let layerMap = '\tKEYMAP(\n\t\t';
    for (let row = 0; row < keyboard.rows; row ++) {
        for (let col = 0; col < keyboard.cols; col ++) {
            const key = keyboard.wiring[row + ',' + col];
            if (!key || !key.length) continue;
                layerMap += key[0].keycodes[layer].getCode() + ', ';
        }
        layerMap += '\n\t\t';
    }
    layerMap = layerMap.substring(0, layerMap.length - 5) + '),\n\n';
    keymaps += layerMap;
}

For some reason, that for loop looks a bit dodgy. It seems to assume that there will always be the max amount of layers.

I don't know if that is supposed to be the case.

I did modify my layout file by hand, and in order to get a clean, human-readable JSON, I removed the unused layers. If that's not supported, that should either fail gracefully or maybe add KC_TRNS keycodes by default ?