Skip to content

Commit

Permalink
update default data to use speak instead of returning a string, see
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Sep 17, 2024
1 parent 44049c2 commit 3f55fd5
Show file tree
Hide file tree
Showing 22 changed files with 11,103 additions and 27 deletions.
24 changes: 18 additions & 6 deletions server/LocalFileDataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ class LocalFileDataService extends IDataService {
return () => fsPromises.readdir( directoryPath );
}

/**
* Sanitizes the file name by removing or replacing invalid characters.
* @param {string} filePath - The original file path.
* @returns {string} - The sanitized file path.
*/
sanitizeName( filePath ) {
return filePath.replace( /[<>:"/\\|?*]+/g, '_' ); // Removes invalid characters
}

/**
* Deletes a file from the fiile system, wrapped so that it is easily added to the queue.
*/
Expand Down Expand Up @@ -812,9 +821,11 @@ class LocalFileDataService extends IDataService {
}
else {

const sanitizedName = this.sanitizeName( templateName );

// The data to write to the file
const templateData = {
name: templateName,
name: sanitizedName,
description: description,
keyWords: keyWords,
projectData: projectData,
Expand All @@ -823,11 +834,11 @@ class LocalFileDataService extends IDataService {
};

// Write the file
const templatePath = path.join( templatesDirectoryPath, `${templateName}.json` );
const templatePath = path.join( templatesDirectoryPath, `${sanitizedName}.json` );
this.addToQueue( this.writeFile( templatePath, JSON.stringify( templateData, null, 2 ) ) ).then( () => {
response.status( 200 ).json( {} );
} ).catch( err => {
console.error( `Error creating template ${templateName}: ${err}` );
console.error( `Error creating template ${sanitizedName}: ${err}` );
response.status( Constants.UNKNOWN_ERROR ).send( 'An error occurred while saving the template' );
} );
}
Expand All @@ -845,11 +856,12 @@ class LocalFileDataService extends IDataService {
else {

// The path to the template file
const templatePath = path.join( templatesDirectoryPath, `${templateName}.json` );
const sanitizedName = this.sanitizeName( templateName );
const templatePath = path.join( templatesDirectoryPath, `${sanitizedName}.json` );

// The data to write to the file
const templateData = {
name: templateName,
name: sanitizedName,
description: description,
keyWords: keyWords,
projectData: projectData,
Expand All @@ -861,7 +873,7 @@ class LocalFileDataService extends IDataService {
this.addToQueue( this.writeFile( templatePath, JSON.stringify( templateData, null, 2 ) ) ).then( () => {
response.status( 200 ).json( {} );
} ).catch( err => {
console.error( `Error saving template ${templateName}: ${err}` );
console.error( `Error saving template ${sanitizedName}: ${err}` );
response.status( 500 ).send( 'Error saving template' );
} );
}
Expand Down
1,035 changes: 1,034 additions & 1 deletion server/default-data/spaces/games/projects/brick-breaker.json

Large diffs are not rendered by default.

2,160 changes: 2,159 additions & 1 deletion server/default-data/spaces/games/projects/electric-field-hockey.json

Large diffs are not rendered by default.

882 changes: 881 additions & 1 deletion server/default-data/spaces/games/projects/find-the-cupcake.json

Large diffs are not rendered by default.

1,201 changes: 1,200 additions & 1 deletion server/default-data/spaces/games/projects/rps-elements.json

Large diffs are not rendered by default.

939 changes: 938 additions & 1 deletion server/default-data/spaces/games/projects/simon.json

Large diffs are not rendered by default.

440 changes: 439 additions & 1 deletion server/default-data/spaces/games/projects/simple-dice-war.json

Large diffs are not rendered by default.

924 changes: 923 additions & 1 deletion server/default-data/spaces/games/projects/skater.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1,109 @@
{"programs":[{"number":7,"title":"Servo Control by Rotation","keywords":"rotation, servo, microbit, uart","description":"Sends rotation value mapped from 0 - 180 as UART string to be read by micro:bit and set servo pin in order to set servo position.","expanded":true,"topWhiskerLength":0.2,"rightWhiskerLength":0.2,"bottomWhiskerLength":0.2,"leftWhiskerLength":0.2,"positionProperty":{"x":194.49221091091607,"y":285.21493020035035},"modelContainer":{"namedBooleanProperties":[],"namedVector2Properties":[],"namedNumberProperties":[{"name":"servoPositionNumber","propertyType":"NumberProperty","min":"-90","max":"270","defaultValue":"90"}],"namedEnumerationProperties":[],"namedDerivedProperties":[],"namedBounds2Properties":[],"namedObservableArrays":[],"namedArrayItems":[],"namedArrayItemReferences":[],"namedStringProperties":[{"name":"servoValueString","propertyType":"StringProperty","defaultValue":""}]},"controllerContainer":{"vector2PropertyControllers":[],"boundsPropertyControllers":[],"booleanPropertyControllers":[],"numberPropertyControllers":[{"name":"setServoPosition","controlledComponentName":"servoPositionNumber","controlType":"ROTATION","controlTypeFamily":"PAPER_MOVEMENT","markerColor":"all","relationshipControlType":"LINEAR"}],"enumerationPropertyControllers":[]},"viewContainer":{"soundViews":[],"descriptionViews":[],"textViews":[],"shapeViews":[],"backgroundViews":[],"imageViews":[]},"listenerContainer":{"linkListeners":[{"name":"numberToStringforUART","controlledPropertyNames":["servoValueString"],"controlFunctionString":"//Only send integers to the servo, easier on the makecode string to number parser to have an integer\r\nsetServoValueString(String(Math.round(servoPositionNumber)));","dependencyNames":["servoPositionNumber"],"referenceComponentNames":[]}],"animationListeners":[],"bluetoothListeners":[{"name":"sendServoPositionToMicroBitRX","controlledPropertyNames":[],"controlFunctionString":"writeToCharacteristic(servoValueString);\r\n\r\nconsole.log(`Sending ${servoValueString} to microbit`);","dependencyNames":["servoValueString"],"referenceComponentNames":[],"writeToCharacteristic":true,"serviceId":"6e400001-b5a3-f393-e0a9-e50e24dcca9e","characteristicId":"6e400003-b5a3-f393-e0a9-e50e24dcca9e"}]},"customCodeContainer":{"onProgramAddedCode":"","onProgramRemovedCode":"","onProgramChangedPositionCode":"","onProgramMarkersAddedCode":"","onProgramMarkersRemovedCode":"","onProgramMarkersChangedPositionCode":"","onProgramAdjacentCode":"","onProgramSeparatedCode":""}}]}
{
"programs": [
{
"number": 7,
"title": "Servo Control by Rotation",
"keywords": "rotation, servo, microbit, uart",
"description": "Sends rotation value mapped from 0 - 180 as UART string to be read by micro:bit and set servo pin in order to set servo position.",
"expanded": true,
"topWhiskerLength": 0.2,
"rightWhiskerLength": 0.2,
"bottomWhiskerLength": 0.2,
"leftWhiskerLength": 0.2,
"positionProperty": {
"x": 194.49221091091607,
"y": 285.21493020035035
},
"modelContainer": {
"namedBooleanProperties": [],
"namedVector2Properties": [],
"namedNumberProperties": [
{
"name": "servoPositionNumber",
"propertyType": "NumberProperty",
"min": "-90",
"max": "270",
"defaultValue": "90"
}
],
"namedEnumerationProperties": [],
"namedDerivedProperties": [],
"namedBounds2Properties": [],
"namedObservableArrays": [],
"namedArrayItems": [],
"namedArrayItemReferences": [],
"namedStringProperties": [
{
"name": "servoValueString",
"propertyType": "StringProperty",
"defaultValue": ""
}
]
},
"controllerContainer": {
"vector2PropertyControllers": [],
"boundsPropertyControllers": [],
"booleanPropertyControllers": [],
"numberPropertyControllers": [
{
"name": "setServoPosition",
"controlledComponentName": "servoPositionNumber",
"controlType": "ROTATION",
"controlTypeFamily": "PAPER_MOVEMENT",
"markerColor": "all",
"relationshipControlType": "LINEAR"
}
],
"enumerationPropertyControllers": []
},
"viewContainer": {
"soundViews": [],
"descriptionViews": [],
"textViews": [],
"shapeViews": [],
"backgroundViews": [],
"imageViews": []
},
"listenerContainer": {
"linkListeners": [
{
"name": "numberToStringforUART",
"controlledPropertyNames": [
"servoValueString"
],
"controlFunctionString": "//Only send integers to the servo, easier on the makecode string to number parser to have an integer\r\nsetServoValueString(String(Math.round(servoPositionNumber)));",
"dependencyNames": [
"servoPositionNumber"
],
"referenceComponentNames": []
}
],
"animationListeners": [],
"bluetoothListeners": [
{
"name": "sendServoPositionToMicroBitRX",
"controlledPropertyNames": [],
"controlFunctionString": "writeToCharacteristic(servoValueString);\r\n\r\nconsole.log(`Sending ${servoValueString} to microbit`);",
"dependencyNames": [
"servoValueString"
],
"referenceComponentNames": [],
"writeToCharacteristic": true,
"serviceId": "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
"characteristicId": "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
}
]
},
"customCodeContainer": {
"onProgramAddedCode": "",
"onProgramRemovedCode": "",
"onProgramChangedPositionCode": "",
"onProgramMarkersAddedCode": "",
"onProgramMarkersRemovedCode": "",
"onProgramMarkersChangedPositionCode": "",
"onProgramAdjacentCode": "",
"onProgramSeparatedCode": ""
}
}
]
}
104 changes: 103 additions & 1 deletion server/default-data/spaces/paper-craft/projects/craft-popup.json
Original file line number Diff line number Diff line change
@@ -1 +1,103 @@
{"programs":[{"number":1693,"title":"Froggie","keywords":"pop-up","description":"This program plays a simple sound file.","expanded":true,"topWhiskerLength":0.2,"rightWhiskerLength":0.2,"bottomWhiskerLength":0.2,"leftWhiskerLength":0.2,"positionProperty":{"x":270.6429420898877,"y":209.01529356754682},"modelContainer":{"namedBooleanProperties":[],"namedVector2Properties":[{"name":"imagePosition","propertyType":"Vector2Property","defaultX":0,"defaultY":0}],"namedNumberProperties":[{"name":"imageRotation","propertyType":"NumberProperty","min":0,"max":"6.28","defaultValue":"0"},{"name":"imageScale","propertyType":"NumberProperty","min":"0.1","max":"2","defaultValue":"1"}],"namedEnumerationProperties":[],"namedDerivedProperties":[],"namedBounds2Properties":[],"namedObservableArrays":[],"namedArrayItems":[],"namedArrayItemReferences":[],"namedStringProperties":[]},"controllerContainer":{"vector2PropertyControllers":[{"name":"imagePositionController","controlledComponentName":"imagePosition","controlType":"MATCH_CENTER","controlTypeFamily":""}],"boundsPropertyControllers":[],"booleanPropertyControllers":[],"numberPropertyControllers":[],"enumerationPropertyControllers":[]},"viewContainer":{"soundViews":[{"name":"frogNoise","modelComponentNames":["imagePosition"],"referenceComponentNames":[],"controlFunctionString":"play();","lazyLink":false,"soundFileName":"Frog-sound-ribbit.mp3","loop":true,"autoplay":false}],"speechViews":[],"textViews":[],"shapeViews":[],"backgroundViews":[],"imageViews":[]},"listenerContainer":{"linkListeners":[],"animationListeners":[],"bluetoothListeners":[]},"customCodeContainer":{"onProgramAddedCode":"","onProgramRemovedCode":"","onProgramChangedPositionCode":"","onProgramMarkersAddedCode":"","onProgramMarkersRemovedCode":"","onProgramMarkersChangedPositionCode":"","onProgramAdjacentCode":"","onProgramSeparatedCode":""}}]}
{
"programs": [
{
"number": 1693,
"title": "Froggie",
"keywords": "pop-up",
"description": "This program plays a simple sound file.",
"expanded": true,
"topWhiskerLength": 0.2,
"rightWhiskerLength": 0.2,
"bottomWhiskerLength": 0.2,
"leftWhiskerLength": 0.2,
"positionProperty": {
"x": 270.6429420898877,
"y": 209.01529356754682
},
"modelContainer": {
"namedBooleanProperties": [],
"namedVector2Properties": [
{
"name": "imagePosition",
"propertyType": "Vector2Property",
"defaultX": 0,
"defaultY": 0
}
],
"namedNumberProperties": [
{
"name": "imageRotation",
"propertyType": "NumberProperty",
"min": 0,
"max": "6.28",
"defaultValue": "0"
},
{
"name": "imageScale",
"propertyType": "NumberProperty",
"min": "0.1",
"max": "2",
"defaultValue": "1"
}
],
"namedEnumerationProperties": [],
"namedDerivedProperties": [],
"namedBounds2Properties": [],
"namedObservableArrays": [],
"namedArrayItems": [],
"namedArrayItemReferences": [],
"namedStringProperties": []
},
"controllerContainer": {
"vector2PropertyControllers": [
{
"name": "imagePositionController",
"controlledComponentName": "imagePosition",
"controlType": "MATCH_CENTER",
"controlTypeFamily": ""
}
],
"boundsPropertyControllers": [],
"booleanPropertyControllers": [],
"numberPropertyControllers": [],
"enumerationPropertyControllers": []
},
"viewContainer": {
"soundViews": [
{
"name": "frogNoise",
"modelComponentNames": [
"imagePosition"
],
"referenceComponentNames": [],
"controlFunctionString": "play();",
"lazyLink": false,
"soundFileName": "Frog-sound-ribbit.mp3",
"loop": true,
"autoplay": false
}
],
"speechViews": [],
"textViews": [],
"shapeViews": [],
"backgroundViews": [],
"imageViews": []
},
"listenerContainer": {
"linkListeners": [],
"animationListeners": [],
"bluetoothListeners": []
},
"customCodeContainer": {
"onProgramAddedCode": "",
"onProgramRemovedCode": "",
"onProgramChangedPositionCode": "",
"onProgramMarkersAddedCode": "",
"onProgramMarkersRemovedCode": "",
"onProgramMarkersChangedPositionCode": "",
"onProgramAdjacentCode": "",
"onProgramSeparatedCode": ""
}
}
]
}
Loading

0 comments on commit 3f55fd5

Please sign in to comment.