Preview generator: generating a preview by layer number

This commit is contained in:
He4eT 2021-08-27 17:59:49 +05:00
commit a5d894b84a
3 changed files with 31 additions and 10 deletions

View file

@ -1,4 +1,5 @@
const HALVES_GAP = 5
const NUMBER_OF_ROWS = 8
const row = (keys, start, gapOffset) => [
{x: start},
@ -15,13 +16,22 @@ const row4 = (keys, rowIndex) => ({
5: row(keys, 4, 0),
6: row(keys, 6, -4),
7: row(keys, 6, -4),
}[rowIndex % 8])
}[rowIndex % NUMBER_OF_ROWS])
const buildRow = (keys, rowIndex) => ({
12: row12(keys),
4: row4(keys, rowIndex)
}[keys.length] || ['Oh no...'])
const layerRange = layerIndex =>
layerIndex === -1
? []
: Array(2)
.fill(layerIndex)
.map((x, i) => x + i)
.map(x => x * NUMBER_OF_ROWS)
module.exports = {
layerRange,
buildRow
}

View file

@ -5,26 +5,28 @@
const fs = require('fs')
const {buildRow} = require('./parts/rows')
const {buildRow, layerRange} = require('./parts/rows')
const {cleanKeys, printLegends} = require('./parts/keys')
const keymapToKLERawData = fileContent =>
const keymapToKLERawData = (fileContent, layerIndex) =>
fileContent
.split('\n')
.map(row => row.split(','))
.filter(keys => keys.length > 1)
.slice(...layerRange(layerIndex))
.map(cleanKeys)
.map(printLegends)
.map(buildRow)
.map(JSON.stringify)
// .slice(0, 8)
// .slice(8, 16)
// .slice(16)
.join(',\n')
/* */
const keymapFilePath = process.argv[2]
const layerIndex = Number(process.argv[3])
const fileContent = fs.readFileSync(keymapFilePath, 'utf8')
const rawData = keymapToKLERawData(fileContent)
const rawData = keymapToKLERawData(fileContent, layerIndex)
console.log(rawData)