Skip to content

Commit b08179e

Browse files
committed
reverse map
1 parent dc4491f commit b08179e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

scripts/lochex.mjs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,23 @@ for (const lang of languages.filter(l => l !== "pxt")) {
8181
.filter(k => !translations[k])
8282
.forEach(k => (translations[k] = tooltips[k]))
8383

84-
// this is for english only (for now)
85-
if (lang == "en") {
86-
const reverseMap = Object.keys(tooltips).filter(k => tooltips[k])
87-
88-
const tooltip2tid = `
84+
const tooltip2tid = `
8985
export function tooltip2tid(id: string): number {
86+
let tid: number = undefined
87+
if (!id) return id
88+
${Object.keys(translations)
89+
// don't emit sample names in hardware
90+
.filter(k => !/^N/.test(k))
91+
// only Tids
92+
.filter(k => /T\d+/.test(k))
93+
.map(k => {
94+
const tid = parseInt(k.slice(1))
95+
return ` else if (id === "${translations[k]}") tid = ${tid};`
96+
})
97+
.join("\n")}
98+
return tid
9099
}
91100
`
92-
}
93101

94102
const ts = `// auto-generated, run 'node scripts/lochex.mjs' to refresh
95103
namespace microcode {
@@ -107,6 +115,8 @@ ${Object.keys(translations)
107115
.join("\n")}
108116
return res
109117
}
118+
119+
${tooltip2tid}
110120
}`
111121

112122
writeFileSync("./tooltips.ts", ts, { encoding: "utf8" })

0 commit comments

Comments
 (0)