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

[PoemBot][HOC] Validation Code #42243

Merged
merged 5 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/i18n/spritelab/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,9 @@
"thirdClickButNoSpeech": "You clicked on more than two sprites but one of your clicks didn't cause a sprite to say anything. Add a `say` block under each `when clicked` event. <xml><block type=\"gamelab_spriteSay\"><title name=\"SPEECH\">Hello, world!</title><value name=\"SPRITE\"><block type=\"gamelab_allSpritesWithAnimation\"><title name=\"ANIMATION\">\"default\"</title></block></value></block></xml>",
"changeOrSetSize": "None of your sprites changed size.",
"changeOrSetCostume": "None of your sprites changed costumes.",
"changeBackground": "The background was not changed."
"changeBackground": "The background was not changed.",
"poemBotMakeBackground": "You need to add a background effect.",
"poemBotMakeForeground": "You need to add a foreground effect.",
"poemBotRemovedSprite": "It looks like you removed a sprite. You can add it back from the **Sprites** toolbox.",
"poemBotSetSize": "Use a `set size` block to change the size of your sprite. Use a number other than 100."
}
35 changes: 35 additions & 0 deletions apps/src/p5lab/spritelab/libraries/PoemBotLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const POEM_DURATION = 500;
export default class PoemBotLibrary extends CoreLibrary {
constructor(p5) {
super(p5);
// Extra information for validation code to be able to inspect the program state
this.validationInfo = {
endTime: POEM_DURATION
};
this.poemState = {
title: '',
author: '',
Expand Down Expand Up @@ -136,6 +140,37 @@ export default class PoemBotLibrary extends CoreLibrary {
this.lineEvents[lineNum].push(callback);
},

getValidationInfo() {
return this.validationInfo;
},

setSuccessFrame() {
if (!this.validationInfo.successFrame) {
// Only set the success frame if it hasn't already been set (the first
// frame at which we know the student will pass the level).
this.validationInfo.successFrame = this.p5.frameCount;
}
},

drawProgressBar() {
this.p5.push();
this.p5.noStroke();
if (this.validationInfo.successFrame) {
// The student will pass the level
this.p5.fill(this.p5.rgb(0, 173, 188));
} else {
// The student will not pass the level (yet);
this.p5.fill(this.p5.rgb(118, 102, 160));
}
this.p5.rect(
0,
390,
(this.p5.frameCount / POEM_DURATION) * PLAYSPACE_SIZE,
10
);
this.p5.pop();
},

...backgroundEffects,
...foregroundEffects
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {PALETTES} from '../constants';
export const commands = {
// TODO: would it be possible to re-use the background/foreground effect code from dance party?
setBackgroundEffect(effectName, palette) {
this.validationInfo.backgroundEffect = effectName;
switch (effectName) {
case 'colors': {
let amount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as utils from './utils';

export const commands = {
setForegroundEffect(effectName) {
this.validationInfo.foregroundEffect = effectName;
switch (effectName) {
case 'rain': {
const drops = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"preload_asset_list": null,
"encrypted_examples": [

]
],
"validation_code": "var validationInfo = getValidationInfo();\r\nif (validationInfo.backgroundEffect) {\r\n setSuccessFrame();\r\n}\r\ndrawProgressBar();\r\nif (World.frameCount == validationInfo.endTime) {\r\n if (validationInfo.successFrame) {\r\n levelFailure(0, 'genericSuccess');\r\n } else {\r\n levelFailure(3, 'poemBotMakeBackground');\r\n }\r\n}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

},
"game_id": 64,
"published": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"preload_asset_list": null,
"encrypted_examples": [

]
],
"validation_code": "var validationInfo = getValidationInfo();\r\nif (validationInfo.foregroundEffect) {\r\n setSuccessFrame();\r\n}\r\ndrawProgressBar();\r\nif (World.frameCount == validationInfo.endTime) {\r\n if (validationInfo.successFrame) {\r\n levelFailure(0, 'genericSuccess');\r\n } else {\r\n levelFailure(3, 'poemBotMakeForeground');\r\n }\r\n}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

},
"game_id": 64,
"published": true,
Expand Down
1 change: 1 addition & 0 deletions dashboard/config/scripts/levels/poetryHoC_addSprites.level
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"callout_json": "[]",
"parent_level_id": 29613,
"video_key": "hoc_dance_properties",
"validation_code": "var validationInfo = getValidationInfo();\r\nvar spriteIds = getSpriteIdsInUse();\r\n\r\nif (spriteIds.length > 0) {\r\n setSuccessFrame();\r\n}\r\ndrawProgressBar();\r\nif (World.frameCount == validationInfo.endTime) {\r\n if (validationInfo.successFrame) {\r\n levelFailure(0, 'genericSuccess');\r\n } else {\r\n levelFailure(3, 'noSprites');\r\n }\r\n}",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

"preload_asset_list": null
},
"user_id": 1196,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"preload_asset_list": null,
"encrypted_examples": [

]
],
"validation_code": "var validationInfo = getValidationInfo();\r\nvar spriteIds = getSpriteIdsInUse();\r\n\r\nfor (var i = 0; i < spriteIds.length; i++) {\r\n if (getProp({id: spriteIds[i]}, \"scale\") !== 100) {\r\n setSuccessFrame();\r\n }\r\n}\r\n\r\ndrawProgressBar();\r\nif (World.frameCount == validationInfo.endTime) {\r\n if (validationInfo.successFrame) {\r\n levelFailure(0, 'genericSuccess');\r\n } else if (spriteIds.length == 0) {\r\n levelFailure(3, 'poemBotRemovedSprite');\r\n } else {\r\n levelFailure(3, 'poemBotSetSize');\r\n }\r\n}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

},
"game_id": 64,
"published": true,
Expand Down