From b032f945cad9b02a0191eae1c07a681c86e21328 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 12 Dec 2024 07:28:20 +0000 Subject: [PATCH] fixing genaiscript --- .../de/jacdac-gamepad-jsdoc-strings.json | 21 ++++++++++++ .../_locales/de/jacdac-gamepad-strings.json | 32 +++++++++++++++++++ .../jacdac-gamepad-jsdoc-strings.json | 21 ++++++++++++ gamepad/_locales/jacdac-gamepad-strings.json | 32 +++++++++++++++++++ gen-locs.mjs | 19 +++++++---- gen-locs.sh | 6 ---- genaisrc/loc-strings.genai.mts | 2 +- setup-locs.sh | 8 +++++ wind-speed/pxt.json | 16 +++++----- 9 files changed, 136 insertions(+), 21 deletions(-) create mode 100644 gamepad/_locales/de/jacdac-gamepad-jsdoc-strings.json create mode 100644 gamepad/_locales/de/jacdac-gamepad-strings.json create mode 100644 gamepad/_locales/jacdac-gamepad-jsdoc-strings.json create mode 100644 gamepad/_locales/jacdac-gamepad-strings.json create mode 100644 setup-locs.sh diff --git a/gamepad/_locales/de/jacdac-gamepad-jsdoc-strings.json b/gamepad/_locales/de/jacdac-gamepad-jsdoc-strings.json new file mode 100644 index 000000000..ef74cc98a --- /dev/null +++ b/gamepad/_locales/de/jacdac-gamepad-jsdoc-strings.json @@ -0,0 +1,21 @@ +{ + "jacdac.GamepadEvent.ButtonsChanged": "Argument: buttons Buttons (uint32_t). Wird immer dann ausgelöst, wenn sich der Zustand der Tasten ändert.\n* ```\nconst [buttons] = jdunpack<[jacdac.GamepadButtons]>(buf, \"u32\")\n```", + "jacdac.GamepadEventPack.ButtonsChanged": "Packformat für 'buttons_changed' Daten.", + "jacdac.GamepadReg.ButtonsAvailable": "Konstante Tasten (uint32_t). Gibt eine Bitmaske der Tasten an, die auf dem Gamepad montiert sind.\nWenn die `Left`/`Up`/`Right`/`Down` Tasten hier als verfügbar markiert sind, ist das Gamepad digital.\nSelbst wenn sie als nicht verfügbar markiert sind, werden sie dennoch basierend auf dem analogen Gamepad simuliert.\n* ```\nconst [buttonsAvailable] = jdunpack<[jacdac.GamepadButtons]>(buf, \"u32\")\n```", + "jacdac.GamepadReg.Direction": "Wenn das Gamepad analog ist, sollten die Richtungstasten basierend auf der Gamepad-Position \"simuliert\" werden\n(`Left` ist `{ x = -1, y = 0 }`, `Up` ist `{ x = 0, y = -1}`).\nWenn das Gamepad digital ist, dann wird jede Richtung entweder als `-1`, `0` oder `1` gelesen (in fester Darstellung).\nDie primäre Taste auf dem Gamepad ist `A`.\n* ```\nconst [buttons, x, y] = jdunpack<[jacdac.GamepadButtons, number, number]>(buf, \"u32 i1.15 i1.15\")\n```", + "jacdac.GamepadReg.Variant": "Konstanter Variant (uint8_t). Der Typ des physischen Gamepads.\n* ```\nconst [variant] = jdunpack<[jacdac.GamepadVariant]>(buf, \"u8\")\n```", + "jacdac.GamepadRegPack.ButtonsAvailable": "Packformat für 'buttons_available' Daten.", + "jacdac.GamepadRegPack.Direction": "Packformat für 'direction' Daten.", + "jacdac.GamepadRegPack.Variant": "Packformat für 'variant' Daten.", + "modules": "Jacdac-Module", + "modules.GamepadClient": "Ein zweiachssiger Richtungs-Joystick", + "modules.GamepadClient.buttons": "Wenn der Joystick analog ist, sollten die Richtungstasten basierend auf der Joystick-Position \"simuliert\" werden\n(`Left` ist `{ x = -1, y = 0 }`, `Up` ist `{ x = 0, y = -1}`).\nWenn der Joystick digital ist, dann wird jede Richtung entweder als `-1`, `0` oder `1` gelesen (in fester Darstellung).\nDie primäre Taste auf dem Joystick ist `A`.", + "modules.GamepadClient.buttonsAvailable": "Gibt eine Bitmaske der Tasten an, die auf dem Joystick montiert sind.\nWenn die `Left`/`Up`/`Right`/`Down` Tasten hier als verfügbar markiert sind, ist der Joystick digital.\nSelbst wenn sie als nicht verfügbar markiert sind, werden sie dennoch basierend auf dem analogen Joystick simuliert.", + "modules.GamepadClient.isButtonDown": "Gibt an, ob die Taste (oder Kombination) gedrückt ist.", + "modules.GamepadClient.isButtonDown|param|button": "@returns true, wenn ausgewählte Tasten gedrückt sind", + "modules.GamepadClient.onButtonsChanged": "Wird immer dann ausgelöst, wenn sich der Zustand der Tasten ändert.", + "modules.GamepadClient.onEvent": "Code registrieren, der ausgeführt wird, wenn ein Ereignis ausgelöst wird", + "modules.GamepadClient.variant": "Der Typ des physischen Joysticks.", + "modules.GamepadClient.x": "Wenn der Joystick analog ist, sollten die Richtungstasten basierend auf der Joystick-Position \"simuliert\" werden\n(`Left` ist `{ x = -1, y = 0 }`, `Up` ist `{ x = 0, y = -1}`).\nWenn der Joystick digital ist, dann wird jede Richtung entweder als `-1`, `0` oder `1` gelesen (in fester Darstellung).\nDie primäre Taste auf dem Joystick ist `A`.", + "modules.GamepadClient.y": "Wenn der Joystick analog ist, sollten die Richtungstasten basierend auf der Joystick-Position \"simuliert\" werden\n(`Left` ist `{ x = -1, y = 0 }`, `Up` ist `{ x = 0, y = -1}`).\nWenn der Joystick digital ist, dann wird jede Richtung entweder als `-1`, `0` oder `1` gelesen (in fester Darstellung).\nDie primäre Taste auf dem Joystick ist `A`." +} \ No newline at end of file diff --git a/gamepad/_locales/de/jacdac-gamepad-strings.json b/gamepad/_locales/de/jacdac-gamepad-strings.json new file mode 100644 index 000000000..24390b6f2 --- /dev/null +++ b/gamepad/_locales/de/jacdac-gamepad-strings.json @@ -0,0 +1,32 @@ +{ + "jacdac.GamepadButtons.A|block": "a", + "jacdac.GamepadButtons.B|block": "b", + "jacdac.GamepadButtons.Down|block": "unten", + "jacdac.GamepadButtons.Exit|block": "beenden", + "jacdac.GamepadButtons.Left|block": "links", + "jacdac.GamepadButtons.Menu|block": "menü", + "jacdac.GamepadButtons.Reset|block": "zurücksetzen", + "jacdac.GamepadButtons.Right|block": "rechts", + "jacdac.GamepadButtons.Select|block": "auswählen", + "jacdac.GamepadButtons.Up|block": "oben", + "jacdac.GamepadButtons.X|block": "x", + "jacdac.GamepadButtons.Y|block": "y", + "jacdac.GamepadEvent.ButtonsChanged": "Argument: Buttons (uint32_t). Wird immer ausgegeben, wenn sich der Zustand der Tasten ändert.\n* ```\nconst [buttons] = jdunpack<[jacdac.GamepadButtons]>(buf, \"u32\")\n```", + "jacdac.GamepadEvent.ButtonsChanged|block": "Tasten geändert", + "jacdac.GamepadReg.ButtonsAvailable": "Konstante Tasten (uint32_t). Zeigt eine Bitmaske der Tasten an, die auf dem Gamepad angebracht sind.\nWenn die `Links`/`Oben`/`Rechts`/`Unten`-Tasten hier als verfügbar markiert sind, ist das Gamepad digital.\nSelbst wenn sie als nicht verfügbar markiert sind, werden sie dennoch basierend auf dem analogen Gamepad simuliert.\n* ```\nconst [buttonsAvailable] = jdunpack<[jacdac.GamepadButtons]>(buf, \"u32\")\n```", + "jacdac.GamepadReg.Direction": "Wenn das Gamepad analog ist, sollten die Richtungstasten basierend auf der Gamepad-Position \"simuliert\" werden\n(`Links` ist `{ x = -1, y = 0 }`, `Oben` ist `{ x = 0, y = -1 }`).\nWenn das Gamepad digital ist, wird jede Richtung als entweder `-1`, `0` oder `1` gelesen (in fester Darstellung).\nDie Primärtaste des Gamepads ist `A`.\n* ```\nconst [buttons, x, y] = jdunpack<[jacdac.GamepadButtons, number, number]>(buf, \"u32 i1.15 i1.15\")\n```", + "jacdac.GamepadReg.Variant": "Konstante Variante (uint8_t). Der Typ des physischen Gamepads.\n* ```\nconst [variant] = jdunpack<[jacdac.GamepadVariant]>(buf, \"u8\")\n```", + "jacdac.GamepadVariant.ArcadeBall|block": "Arcade-Kugel", + "jacdac.GamepadVariant.ArcadeStick|block": "Arcade-Stick", + "jacdac.GamepadVariant.Gamepad|block": "Gamepad", + "jacdac.GamepadVariant.Thumb|block": "Daumen", + "modules.GamepadClient.isButtonDown|block": "%joystick ist Taste $button unten", + "modules.GamepadClient.onEvent|block": "wenn %gamepad %event", + "modules.GamepadClient.x|block": "%joystick x", + "modules.GamepadClient.y|block": "%joystick y", + "modules.gamepad1|block": "Gamepad1", + "modules|block": "Module", + "{id:category}Jacdac": "Jacdac", + "{id:category}Modules": "Module", + "{id:group}Button": "Knopf" +} \ No newline at end of file diff --git a/gamepad/_locales/jacdac-gamepad-jsdoc-strings.json b/gamepad/_locales/jacdac-gamepad-jsdoc-strings.json new file mode 100644 index 000000000..2a2d4fa1d --- /dev/null +++ b/gamepad/_locales/jacdac-gamepad-jsdoc-strings.json @@ -0,0 +1,21 @@ +{ + "jacdac.GamepadEvent.ButtonsChanged": "Argument: buttons Buttons (uint32_t). Emitted whenever the state of buttons changes.\n* ```\nconst [buttons] = jdunpack<[jacdac.GamepadButtons]>(buf, \"u32\")\n```", + "jacdac.GamepadEventPack.ButtonsChanged": "Pack format for 'buttons_changed' data.", + "jacdac.GamepadReg.ButtonsAvailable": "Constant Buttons (uint32_t). Indicates a bitmask of the buttons that are mounted on the gamepad.\nIf the `Left`/`Up`/`Right`/`Down` buttons are marked as available here, the gamepad is digital.\nEven when marked as not available, they will still be simulated based on the analog gamepad.\n* ```\nconst [buttonsAvailable] = jdunpack<[jacdac.GamepadButtons]>(buf, \"u32\")\n```", + "jacdac.GamepadReg.Direction": "If the gamepad is analog, the directional buttons should be \"simulated\", based on gamepad position\n(`Left` is `{ x = -1, y = 0 }`, `Up` is `{ x = 0, y = -1}`).\nIf the gamepad is digital, then each direction will read as either `-1`, `0`, or `1` (in fixed representation).\nThe primary button on the gamepad is `A`.\n* ```\nconst [buttons, x, y] = jdunpack<[jacdac.GamepadButtons, number, number]>(buf, \"u32 i1.15 i1.15\")\n```", + "jacdac.GamepadReg.Variant": "Constant Variant (uint8_t). The type of physical gamepad.\n* ```\nconst [variant] = jdunpack<[jacdac.GamepadVariant]>(buf, \"u8\")\n```", + "jacdac.GamepadRegPack.ButtonsAvailable": "Pack format for 'buttons_available' data.", + "jacdac.GamepadRegPack.Direction": "Pack format for 'direction' data.", + "jacdac.GamepadRegPack.Variant": "Pack format for 'variant' data.", + "modules": "Jacdac modules", + "modules.GamepadClient": "A two axis directional joystick", + "modules.GamepadClient.buttons": "If the joystick is analog, the directional buttons should be \"simulated\", based on joystick position\n(`Left` is `{ x = -1, y = 0 }`, `Up` is `{ x = 0, y = -1}`).\nIf the joystick is digital, then each direction will read as either `-1`, `0`, or `1` (in fixed representation).\nThe primary button on the joystick is `A`.", + "modules.GamepadClient.buttonsAvailable": "Indicates a bitmask of the buttons that are mounted on the joystick.\nIf the `Left`/`Up`/`Right`/`Down` buttons are marked as available here, the joystick is digital.\nEven when marked as not available, they will still be simulated based on the analog joystick.", + "modules.GamepadClient.isButtonDown": "Indicates if the button (or combination of) is down.", + "modules.GamepadClient.isButtonDown|param|button": "@returns true if selected buttons are down", + "modules.GamepadClient.onButtonsChanged": "Emitted whenever the state of buttons changes.", + "modules.GamepadClient.onEvent": "Register code to run when an event is raised", + "modules.GamepadClient.variant": "The type of physical joystick.", + "modules.GamepadClient.x": "If the joystick is analog, the directional buttons should be \"simulated\", based on joystick position\n(`Left` is `{ x = -1, y = 0 }`, `Up` is `{ x = 0, y = -1}`).\nIf the joystick is digital, then each direction will read as either `-1`, `0`, or `1` (in fixed representation).\nThe primary button on the joystick is `A`.", + "modules.GamepadClient.y": "If the joystick is analog, the directional buttons should be \"simulated\", based on joystick position\n(`Left` is `{ x = -1, y = 0 }`, `Up` is `{ x = 0, y = -1}`).\nIf the joystick is digital, then each direction will read as either `-1`, `0`, or `1` (in fixed representation).\nThe primary button on the joystick is `A`." +} \ No newline at end of file diff --git a/gamepad/_locales/jacdac-gamepad-strings.json b/gamepad/_locales/jacdac-gamepad-strings.json new file mode 100644 index 000000000..9384b4fae --- /dev/null +++ b/gamepad/_locales/jacdac-gamepad-strings.json @@ -0,0 +1,32 @@ +{ + "jacdac.GamepadButtons.A|block": "a", + "jacdac.GamepadButtons.B|block": "b", + "jacdac.GamepadButtons.Down|block": "down", + "jacdac.GamepadButtons.Exit|block": "exit", + "jacdac.GamepadButtons.Left|block": "left", + "jacdac.GamepadButtons.Menu|block": "menu", + "jacdac.GamepadButtons.Reset|block": "reset", + "jacdac.GamepadButtons.Right|block": "right", + "jacdac.GamepadButtons.Select|block": "select", + "jacdac.GamepadButtons.Up|block": "up", + "jacdac.GamepadButtons.X|block": "x", + "jacdac.GamepadButtons.Y|block": "y", + "jacdac.GamepadEvent.ButtonsChanged": "Argument: buttons Buttons (uint32_t). Emitted whenever the state of buttons changes.\n* ```\nconst [buttons] = jdunpack<[jacdac.GamepadButtons]>(buf, \"u32\")\n```", + "jacdac.GamepadEvent.ButtonsChanged|block": "buttons changed", + "jacdac.GamepadReg.ButtonsAvailable": "Constant Buttons (uint32_t). Indicates a bitmask of the buttons that are mounted on the gamepad.\nIf the `Left`/`Up`/`Right`/`Down` buttons are marked as available here, the gamepad is digital.\nEven when marked as not available, they will still be simulated based on the analog gamepad.\n* ```\nconst [buttonsAvailable] = jdunpack<[jacdac.GamepadButtons]>(buf, \"u32\")\n```", + "jacdac.GamepadReg.Direction": "If the gamepad is analog, the directional buttons should be \"simulated\", based on gamepad position\n(`Left` is `{ x = -1, y = 0 }`, `Up` is `{ x = 0, y = -1}`).\nIf the gamepad is digital, then each direction will read as either `-1`, `0`, or `1` (in fixed representation).\nThe primary button on the gamepad is `A`.\n* ```\nconst [buttons, x, y] = jdunpack<[jacdac.GamepadButtons, number, number]>(buf, \"u32 i1.15 i1.15\")\n```", + "jacdac.GamepadReg.Variant": "Constant Variant (uint8_t). The type of physical gamepad.\n* ```\nconst [variant] = jdunpack<[jacdac.GamepadVariant]>(buf, \"u8\")\n```", + "jacdac.GamepadVariant.ArcadeBall|block": "arcade ball", + "jacdac.GamepadVariant.ArcadeStick|block": "arcade stick", + "jacdac.GamepadVariant.Gamepad|block": "gamepad", + "jacdac.GamepadVariant.Thumb|block": "thumb", + "modules.GamepadClient.isButtonDown|block": "%joystick is button $button down", + "modules.GamepadClient.onEvent|block": "on %gamepad %event", + "modules.GamepadClient.x|block": "%joystick x", + "modules.GamepadClient.y|block": "%joystick y", + "modules.gamepad1|block": "gamepad1", + "modules|block": "modules", + "{id:category}Jacdac": "Jacdac", + "{id:category}Modules": "Modules", + "{id:group}Button": "Button" +} \ No newline at end of file diff --git a/gen-locs.mjs b/gen-locs.mjs index 2424a15e0..8a188e74f 100644 --- a/gen-locs.mjs +++ b/gen-locs.mjs @@ -1,6 +1,7 @@ import "zx/globals" +import { run } from "genaiscript/api" -const target = "microbit" +const targets = ["microbit", "arcade"] const langs = ["de"] const libs = (await fs.readdir(".", { withFileTypes: true })) @@ -17,14 +18,20 @@ for (const lib of libs) { if (lib !== ".") cd(lib) try { const pkg = fs.readJSONSync("pxt.json") - if (!pkg.supportedTargets?.includes(target)) continue + if (!targets.some(target => pkg.supportedTargets?.includes(target))) + continue await $`pxt install` await $`pxt gendocs --locs` await $`git checkout -- 'pxt.json'`.nothrow() - // update translations as needed - const tool = `${lib === "." ? "" : "../"}genaisrc/loc-strings.genai.js` - for (const lang of langs) - await $`genaiscript run ${tool} "_locales/*-strings.json" --apply-edits --vars target=${target} lang=${lang}`.nothrow() + const tool = `${lib === "." ? "" : "../"}genaisrc/loc-strings.genai.mjs` + for (const lang of langs) { + console.log(`generating locs ${lib} for ${lang}`) + $`genaiscript run ${tool} _locales/*-strings.json --vars lang=${lang}`.nothrow() + // await run(tool, files, { + // applyEdits: true, + // varsMap: { lang: lang }, + // }) + } // add generated files to pxt.json let modded = false const locs = await glob(`_locales/*/*.json`) diff --git a/gen-locs.sh b/gen-locs.sh index 54051f56f..ef3a4b0fd 100644 --- a/gen-locs.sh +++ b/gen-locs.sh @@ -1,9 +1,3 @@ #!/bin/sh - set -e - -npm install -g pxt -npm install -g genaiscript -npm install -g zx -pxt target microbit node gen-locs.mjs diff --git a/genaisrc/loc-strings.genai.mts b/genaisrc/loc-strings.genai.mts index eda21a9fd..0ca7a11ac 100644 --- a/genaisrc/loc-strings.genai.mts +++ b/genaisrc/loc-strings.genai.mts @@ -26,7 +26,7 @@ const langName = { if (!langName) cancel(`unknown language ${langCode}`) const files = env.files.filter(({ filename }) => - /\/_locales\/[a-z0-9\-_]+-strings\.json$/i.test(filename) + /^_locales\/[a-z0-9\-_]+-strings\.json$/i.test(filename) ) for (const file of files) { await translateFile(file) diff --git a/setup-locs.sh b/setup-locs.sh new file mode 100644 index 000000000..bd9c53f84 --- /dev/null +++ b/setup-locs.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +npm install -g pxt +npm install -D genaiscript@1.84.3 +npm install -D zx +pxt target microbit diff --git a/wind-speed/pxt.json b/wind-speed/pxt.json index 1363387a8..e02871c52 100644 --- a/wind-speed/pxt.json +++ b/wind-speed/pxt.json @@ -2,23 +2,23 @@ "name": "jacdac-wind-speed", "version": "1.9.28", "description": "A sensor that measures wind speed.", + "dependencies": { + "core": "*", + "jacdac": "github:microsoft/pxt-jacdac" + }, "files": [ "constants.ts", "client.g.ts", "_locales/de/jacdac-wind-speed-strings.json" ], "testFiles": [], + "testDependencies": { + "nucleo-f411re": "*" + }, "supportedTargets": [ "arcade", "microbit", "maker", "calliopemini" - ], - "dependencies": { - "core": "*", - "jacdac": "github:microsoft/pxt-jacdac" - }, - "testDependencies": { - "nucleo-f411re": "*" - } + ] }