-
Notifications
You must be signed in to change notification settings - Fork 0
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
Chane ML Events from enum to classes so they can be expanded in autogenerated file. #4
Conversation
//% block="Circle" | ||
Circle = 3, | ||
namespace mlrunner { | ||
export namespace Action { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a nested namespace to make the Javascript code more readable and, since this is user defined, it avoids accidental overshadowing of existing variables/functions in the top mlrunner
namespace.
pxtextension.ts
Outdated
@@ -35,7 +31,7 @@ namespace mlrunner { | |||
} | |||
const actionLabels = actions.map((action, i) => ({ | |||
name: action, | |||
value: i + 1, | |||
value: i + 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because "None" needs to have a non-zero value, the user labels start at value "2", so I assumed this needs to be increased, but I'm not able to test it.
Alternatively we could check if the events can take negative values and make None = -1, but this is easier.
pxtextension.ts
Outdated
} | ||
// End simulator code. | ||
|
||
|
||
//% fixedInstances | ||
//% blockNamespace=mlrunner | ||
class MlEvent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why, but it didn't work if the class was defined inside the namespace, so had to break it out.
Update autogenerated code so None can be triggered from the sim.
@microbit-carlos I've changed the actions so they are an array of MlEvent instances and moved it inside the Actions namespace. The autogenerated has also been updated so we always have the ability to simulate "None". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I've tested this, including with the changing and addition of action names by uploading different data.json files via the editor extension. The class method handles these changes very well unlike the enum version which resulted in errors.
The blocks end up looking the same:
![image](https://private-user-images.githubusercontent.com/29712657/336793963-b1d725d7-b484-4890-bc64-a78fecc5df64.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA3MjIxNzEsIm5iZiI6MTcyMDcyMTg3MSwicGF0aCI6Ii8yOTcxMjY1Ny8zMzY3OTM5NjMtYjFkNzI1ZDctYjQ4NC00ODkwLWJjNjQtYTc4ZmVjYzVkZjY0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzExVDE4MTc1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI3ZjUxZjk4MGNiMTBhMWY1Yjc0OTJiNWZhZWVkMzM4YWUzZjdmOGNmOGMzZGZkNTE1ZDQ2MDdmZmMzYzgzODImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.fOkTMtszixvwS1vSlJIZ9yRt13Eu1Zhp_dHOlwn4zRc)
But rather than having an enum and types, which might force us through MakeCode features that we know have some bugs (microsoft/pxt-microbit#5695) we can use classes, with each "Ml event" being an instance of the class. This way we can create multiple instances in different files, so we can start with the "None" event (we'll need to think of a better name) and add extra events in the editor extension autogenerated files with the model and the labels.
@microbit-robert I've only tested this locally, are you able to test it in your environments to confirm if it works?