-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extracted all functions to treat kb data and implemented import…
… RtoR2 Signed-off-by: Alejandro Parcet Gonzalez <[email protected]>
- Loading branch information
1 parent
89e4858
commit 2082e68
Showing
15 changed files
with
492 additions
and
846 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const parseColormapRaw = (colormap: string, ColorLayerSize: number): number[][] => | ||
colormap | ||
.split(" ") | ||
.filter(v => v.length > 0) | ||
.map((k: string) => parseInt(k, 10)) | ||
.reduce((resultArray, item, index) => { | ||
const localResult: number[][] = resultArray; | ||
const chunkIndex = Math.floor(index / ColorLayerSize); | ||
|
||
if (!localResult[chunkIndex]) { | ||
localResult[chunkIndex] = []; // start a new chunk | ||
} | ||
localResult[chunkIndex].push(item); | ||
return localResult; | ||
}, []); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { PaletteType } from "@Renderer/types/layout"; | ||
import { rgb2w } from "../../color"; | ||
|
||
export const convertKeymapRtoR2 = (layer: number[], keyboardType: string) => { | ||
let localLayer = [...layer]; | ||
// restoring thumbcluster | ||
const preT = localLayer.slice(0, 69); | ||
const remT = localLayer[69]; | ||
const movT = localLayer.slice(70, 72); | ||
const restT = localLayer.slice(72); | ||
localLayer = preT.concat(movT.concat(remT)).concat(restT); | ||
|
||
// if ansi | ||
if (keyboardType === "ANSI") { | ||
// Move enter (31<>47) | ||
const symbolK = localLayer[31]; | ||
const enterK = localLayer[47]; | ||
|
||
localLayer[31] = enterK; | ||
localLayer[47] = symbolK; | ||
// Move shift (48<>49) | ||
const shiftK = localLayer[48]; | ||
const extraK = localLayer[49]; | ||
|
||
localLayer[48] = extraK; | ||
localLayer[49] = shiftK; | ||
} | ||
|
||
// if layout !== layout, solve shift & enter | ||
return localLayer; | ||
}; | ||
|
||
export const convertColormapRtoR2 = (layer: number[], keyboardType: string, backupKeyboardType: string) => { | ||
const color = layer[130]; | ||
const rest = layer.slice(0, -1); | ||
const result = rest.concat(new Array(45).fill(color)); | ||
|
||
if (keyboardType === "ANSI") { | ||
// Move enter (31<>47) | ||
const symbolC = result[40]; | ||
const enterC = result[48]; | ||
|
||
result[40] = enterC; | ||
result[48] = symbolC; | ||
} | ||
|
||
if (keyboardType === "ANSI" && backupKeyboardType === "ISO") { | ||
// Move shift (48<>49) | ||
const shiftC = result[19]; | ||
const extraC = result[20]; | ||
|
||
result[20] = extraC; | ||
result[19] = shiftC; | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
export const convertPaletteRtoR2 = (color: PaletteType) => { | ||
const rgbw = rgb2w(color); | ||
return [rgbw.r, rgbw.g, rgbw.b, rgbw.w]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Parsers | ||
import { parseKeymapRaw, serializeKeymap } from "./keymap"; | ||
import { parsePaletteRaw } from "./palette"; | ||
import { parseColormapRaw } from "./colormap"; | ||
import { parseMacrosRaw, serializeMacros } from "./macros"; | ||
import { parseSuperkeysRaw, serializeSuperkeys } from "./superkeys"; | ||
|
||
// Converters | ||
import { convertKeymapRtoR2, convertColormapRtoR2, convertPaletteRtoR2 } from "./conversions/raiseToRaise2"; | ||
|
||
export { | ||
parseKeymapRaw, | ||
serializeKeymap, | ||
parsePaletteRaw, | ||
parseColormapRaw, | ||
parseMacrosRaw, | ||
serializeMacros, | ||
parseSuperkeysRaw, | ||
serializeSuperkeys, | ||
convertKeymapRtoR2, | ||
convertColormapRtoR2, | ||
convertPaletteRtoR2, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { KeyType } from "@Renderer/types/layout"; | ||
import { KeymapDB } from "../keymap"; | ||
|
||
const keymapDB = new KeymapDB(); | ||
|
||
export const parseKeymapRaw = (keymap: string, keyLayerSize: number): number[][] => | ||
keymap | ||
.split(" ") | ||
.filter(v => v.length > 0) | ||
.map((k: string) => parseInt(k, 10)) | ||
.reduce((resultArray, item, index) => { | ||
const localResult = resultArray; | ||
const chunkIndex = Math.floor(index / keyLayerSize); | ||
|
||
if (!localResult[chunkIndex]) { | ||
localResult[chunkIndex] = []; // start a new chunk | ||
} | ||
localResult[chunkIndex].push(item); | ||
return localResult; | ||
}, []); | ||
|
||
export const serializeKeymap = (keymap: KeyType[][]) => | ||
keymap | ||
.flat() | ||
.map(k => (typeof k === "number" ? String(k) : keymapDB.serialize(k).toString())) | ||
.join(" "); |
Oops, something went wrong.