Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade SpriteKindLegacy in very old projects #6783

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading