Skip to content

Commit

Permalink
upgrade SpriteKindLegacy
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll committed Mar 7, 2025
1 parent 245eec6 commit 62e7c41
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions editor/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 62e7c41

Please sign in to comment.