From 62e7c415d749f590fc0fb85fb2cb8b43da06c757 Mon Sep 17 00:00:00 2001 From: Richard Knoll Date: Fri, 7 Mar 2025 15:43:13 -0800 Subject: [PATCH] upgrade SpriteKindLegacy --- editor/extension.ts | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/editor/extension.ts b/editor/extension.ts index d7e94d37e30..05bd9ff2d7a 100644 --- a/editor/extension.ts +++ b/editor/extension.ts @@ -311,28 +311,35 @@ namespace pxt.editor { } }); - - // The kind field used by the legacy animation editor switched to including the numerical - // enum value in the field (e.g. Walking -> 0Walking) - const actionKinds = pxt.U.toArray(dom.querySelectorAll("variable[type=ActionKind]")); - - if (actionKinds.length) { - pxt.U.toArray(dom.querySelectorAll("block[type=action_enum_shim]>field[name=MEMBER]")) - .concat(pxt.U.toArray(dom.querySelectorAll("shadow[type=action_enum_shim]>field[name=MEMBER]"))) - .forEach(node => { - const value = node.textContent; - if (!/^\d/.test(value)) { - // The correct numerical value will be in the variables - for (const kind of actionKinds) { - const match = /^\d+(.*)/.exec(kind.textContent); - if (match?.[1] === value) { - node.textContent = kind.textContent; - break; + const performOldEnumShimUpgrade = (variableType: string, blockType: string) => { + const variableKinds = pxt.U.toArray(dom.querySelectorAll(`variable[type=${variableType}]`)); + + if (variableKinds.length) { + pxt.U.toArray(dom.querySelectorAll(`block[type=${blockType}]>field[name=MEMBER]`)) + .concat(pxt.U.toArray(dom.querySelectorAll(`shadow[type=${blockType}]>field[name=MEMBER]`))) + .forEach(node => { + const value = node.textContent; + if (!/^\d/.test(value)) { + // The correct numerical value will be in the variables + for (const kind of variableKinds) { + const match = /^\d+(.*)/.exec(kind.textContent); + if (match?.[1] === value) { + node.textContent = kind.textContent; + break; + } } } - } - }); + }); + } } + + + // The kind field used by the legacy animation editor switched to including the numerical + // enum value in the field (e.g. Walking -> 0Walking) + performOldEnumShimUpgrade("ActionKind", "action_enum_shim"); + + // same for SpriteKindLegacy + performOldEnumShimUpgrade("SpriteKindLegacy", "spritetype"); } // Added the "use system keyboard" options to the ask for number and ask for string blocks