From 457322e3d26a96ccd64e5cd35ba1f91a6d024b13 Mon Sep 17 00:00:00 2001 From: Daniel Ferro Date: Fri, 10 May 2024 17:21:58 -0300 Subject: [PATCH 1/2] blocks first --- locales/en-us/blocks.json | 8 ++++- locales/es-ar/blocks.json | 8 ++++- src/components/blockly/blockly.ts | 58 +++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/locales/en-us/blocks.json b/locales/en-us/blocks.json index 001b73c2..09833c8c 100644 --- a/locales/en-us/blocks.json +++ b/locales/en-us/blocks.json @@ -83,7 +83,13 @@ "while": "Repeat until", "chargerHere": "Is there a charger here?", "trophyHere": "Is there a trophy here?", - "saladBowlHere": "Is there a salad bowl here?" + "saladBowlHere": "Is there a salad bowl here?", + "writeA": "Write 'A'", + "writeB": "Write 'B'", + "writeC": "Write 'C'", + "puddleHere": "Is there a puddle here?", + "write": "'%1 write: %2'", + "currentCharacter": "'%1 Is the current letter an %2 ?'" }, "procedures": { "definition": "Define", diff --git a/locales/es-ar/blocks.json b/locales/es-ar/blocks.json index 18ad3d3f..022b4409 100644 --- a/locales/es-ar/blocks.json +++ b/locales/es-ar/blocks.json @@ -82,7 +82,13 @@ "while": "Repetir hasta que", "chargerHere": "¿Hay un cargador acá?", "trophyHere": "¿Hay un trofeo acá?", - "saladBowlHere": "¿Hay una ensaladera acá?" + "saladBowlHere": "¿Hay una ensaladera acá?", + "writeA": "Escribir 'A'", + "writeB": "Escribir 'B'", + "writeC": "Escribir 'C'", + "puddleHere": "¿Hay un charco?", + "write": "'%1 Escribir: %2'", + "currentCharacter": "'%1 ¿La letra actual es una %2 ?'" }, "procedures": { "definition": "Definir", diff --git a/src/components/blockly/blockly.ts b/src/components/blockly/blockly.ts index b6478ce8..41d6d28a 100644 --- a/src/components/blockly/blockly.ts +++ b/src/components/blockly/blockly.ts @@ -683,6 +683,24 @@ const createPrimitiveBlocks = (t: (key: string) => string) => { }, 'icono.abajo.png' ); + createPrimitiveBlock('EscribirA', t("blocks.writeA"), { + 'comportamiento': 'EscribirEnComputadora', + 'argumentos': '{idTransicion: "escribirA"}', + }, 'icono.letter-a.svg' + ); + + createPrimitiveBlock('EscribirB', t("blocks.writeB"), { + 'comportamiento': 'EscribirEnComputadora', + 'argumentos': '{idTransicion: "escribirB"}', + }, 'icono.letter-b.svg' + ); + + createPrimitiveBlock('EscribirC', t("blocks.writeC"), { + 'comportamiento': 'EscribirEnComputadora', + 'argumentos': '{idTransicion: "escribirC"}', + }, 'icono.letter-c.svg' + ); + createPrimitiveBlock('MoverA', t(`blocks.moveTo`), { 'comportamiento': '', 'argumentos': '{}' }, '', { message0: `${t(`blocks.moveTo`)} %1`, @@ -765,6 +783,22 @@ const createPrimitiveBlocks = (t: (key: string) => string) => { ` }); + createPrimitiveBlock('EscribirTextoDadoEnOtraCuadricula', t(`blocks.write`), { 'comportamiento': '', 'argumentos': '{}' }, 'icono.DibujarLinea.png', + { + message0: `${t(`write`)}`, + colour: primitivesColor, + inputsInline: true, + previousStatement: true, + nextStatement: true, + args0: [ + { + "type": "field_input", + "name": "texto", + "text": "" + } + ], + code: 'hacer(actor_id, "EscribirTextoDadoEnOtraCuadricula", {texto: "texto"});' + }); } const createSensorBlocks = (t: (key: string) => string) => { @@ -986,6 +1020,30 @@ const createSensorBlocks = (t: (key: string) => string) => { 'funcionSensor': 'tocando("Trofeo")', }, 'icono.trofeo.png' ); + createSensorBlock('HayCharco', t('blocks.puddleHere'), { + 'funcionSensor': 'hayEnEscena("Charco")', + }, 'icono.charco.png' + ); + + createSensorBlock('HayVocalRMT', t('blocks.currentCharacter'), { + 'funcionSensor': '{}', + }, 'icono.DibujarLinea.png', + { + message0: `${t(`blocks.currentCharacter`)}`, + colour: sensorsColor, + args0: [ + { + "type": "field_dropdown", + "name": "letra", + "options": [ + ["R", "r"], ["M", "m"], ["T", "t"], ["A", "a"], ["E", "e"], ["I", "i"], ["O", "o"], ["U", "u"] + ] + } + ], + "output": null, + code: 'hacer(actor_id, "Rotar", {angulo: - ($grados), voltearAlIrAIzquierda: false, velocidad: 60});', + } + ); } const createValueBlocks = (t: (key: string) => string) => { From 88cadcb01d11e0c2dd63526a8f2736ae3cd349a3 Mon Sep 17 00:00:00 2001 From: Daniel Ferro Date: Fri, 10 May 2024 20:19:55 -0300 Subject: [PATCH 2/2] translates and specific blocks --- locales/en-us/blocks.json | 54 +++- locales/es-ar/blocks.json | 54 +++- locales/pt-br/blocks.json | 39 ++- src/components/blockly/blocks.ts | 307 +++++++++++++++++++++ src/components/serializedChallenge.ts | 370 ++++++++++++++------------ 5 files changed, 650 insertions(+), 174 deletions(-) diff --git a/locales/en-us/blocks.json b/locales/en-us/blocks.json index 09833c8c..d8530c44 100644 --- a/locales/en-us/blocks.json +++ b/locales/en-us/blocks.json @@ -88,8 +88,58 @@ "writeB": "Write 'B'", "writeC": "Write 'C'", "puddleHere": "Is there a puddle here?", - "write": "'%1 write: %2'", - "currentCharacter": "'%1 Is the current letter an %2 ?'" + "write": "write", + "currentCharacter": "Is the current letter an ?'", + "takeTelescope": "Take telescope", + "turnComputerOff": "Turn the computer off", + "advance": "Move forward", + "move1Km": "Move 1 Km forward", + "putIntoTheTrashBin": "Put into the trash bin", + "countStar": "Count a star", + "countPlanet": "Count a planet", + "giveCharger": "Give charger and invite Yvoty", + "giveBall": "Give ball and take charger", + "giveTelescope": "Give telescope and take ball", + "writeLetter": "Write the letter I am touching", + "atTheSquare": "Am I in one corner?", + "atColumnEnd": "Am I at the end of the column?", + "atColumnBeginning": "Am I at the beginning of the column?", + "installGame": "Install the game", + "goInAlligator": "Go in alligator", + "kmToTravel": "Kilometers to travel", + "currentColumnLength": "Current column length", + "moveAndDrawDown": "Move down and draw", + "moveAndDrawUp": "Move up and draw", + "moveAndDrawRight": "Move right and draw", + "moveAndDrawLeft": "Move left and draw", + "moveTelescope": "Move telescope", + "lookWithFriends": "Look at the sky with friends", + "nextComputer": "next computer", + "turnComputerOn": "Turn computer on", + "bounceFootRubberBall": "Bounce with foot the rubber ball", + "pickRubberBall": "Pick the rubber ball", + "back": "Go back", + "volleyRubberBall": "Volley the rubber ball", + "jumpDown": "Jump down", + "jumpUp": "Jump up", + "jumpRight": "Jump right", + "jumpLeft": "Jump left", + "nextColumn": "Go to the next column", + "nextLine": "Go to the next line", + "moveNextTelescope": "Move to next telescope", + "pickBird": "Pick Guyrá", + "guyraHere": "Is Guyrá here?", + "atTheBeginning": "Am I at the beginning?", + "takeCan": "Tale a can", + "takePaper": "Take a paper", + "goToLeftBorder": "Go to left border", + "backToLeftBorder": "Get back to the left border", + "drawSide": "Draw a side of", + "writeAnotherText": "Write text in another cel", + "rotateGrades": "Rotate grades", + "isAVowel": "Is a vowel ?", + "repeatEmpty": "Repeat", + "JumpForward": "Jump forward" }, "procedures": { "definition": "Define", diff --git a/locales/es-ar/blocks.json b/locales/es-ar/blocks.json index 022b4409..d31ed549 100644 --- a/locales/es-ar/blocks.json +++ b/locales/es-ar/blocks.json @@ -87,8 +87,58 @@ "writeB": "Escribir 'B'", "writeC": "Escribir 'C'", "puddleHere": "¿Hay un charco?", - "write": "'%1 Escribir: %2'", - "currentCharacter": "'%1 ¿La letra actual es una %2 ?'" + "write": "Escribir:", + "currentCharacter": "¿La letra actual es una ?'", + "takeTelescope": "Agarrar telescopio", + "turnComputerOff": "Apagar computadora", + "advance": "Avanzar", + "move1Km": "Avanzar 1 Km", + "putIntoTheTrashBin": "Poner en el tacho", + "countStar": "Contar una estrella", + "countPlanet": "Contar un planeta", + "giveCharger": "Dar cargador e invitar a Yvoty", + "giveBall": "Dar pelota y agarrar cargador", + "giveTelescope": "Dar telescopio y agarrar pelota", + "writeLetter": "Escribir letra que estoy tocando", + "atTheSquare": "¿Estoy en una esquina?", + "atColumnEnd": "¿Estoy al final de la columna?", + "atColumnBeginning": "¿Estoy al inicio de la columna?", + "installGame": "Instalar juego", + "goInAlligator": "Irse en yacaré", + "kmToTravel": "Kilómetros a recorrer", + "currentColumnLength": "Largo de la columna actual", + "moveAndDrawDown": "Mover abajo dibujando", + "moveAndDrawUp": "Mover arriba dibujando", + "moveAndDrawRight": "Mover derecha dibujando", + "moveAndDrawLeft": "Mover izquierda dibujando", + "moveTelescope": "Mover telescopio", + "lookWithFriends": "Observar el cielo con amigos", + "nextComputer": "Próxima computadora", + "turnComputerOn": "Prender computador", + "bounceFootRubberBall": "Rebotar con el pie la pelota de goma", + "pickRubberBall": "Agarrar pelota de goma", + "back": "Retroceder", + "volleyRubberBall": "Lanzar al aire la pelota de goma", + "jumpDown": "Saltar abajo", + "jumpUp": "Saltar arriba", + "jumpRight": "Saltar derecha", + "jumpLeft": "Saltar izquierda", + "nextColumn": "Pasar a la siguiente columna", + "nextLine": "Pasar a la siguiente fila", + "moveNextTelescope": "Pasar al siguiente telescopio", + "pickBird": "Subir a Guyrá", + "guyraHere": "¿Guyrá está acá?", + "atTheBeginning": "¿Estoy al inicio?", + "takeCan": "Tomar lata", + "takePaper": "Tomar papel", + "goToLeftBorder": "Volver a borde izquierdo", + "backToLeftBorder": "Volver al borde izquierdo", + "drawSide": "Dibujar lado", + "writeAnotherText": "Escribir texto dado en otra cuadricula", + "rotateGrades": "Girar grados", + "isAVowel": "¿ Hay vocal ?", + "repeatEmpty": "Repetir", + "JumpForward": "Saltar hacia adelante" }, "procedures": { "definition": "Definir", diff --git a/locales/pt-br/blocks.json b/locales/pt-br/blocks.json index 8bd56ec1..1fb9237d 100644 --- a/locales/pt-br/blocks.json +++ b/locales/pt-br/blocks.json @@ -83,7 +83,44 @@ "while": "Repetir até que", "chargerHere": "Há um cargador aqui?", "trophyHere": "Há um troféu aqui?", - "saladBowlHere": "Há uma tigela de salada aqui?" + "saladBowlHere": "Há uma tigela de salada aqui?", + "drawSide": "Desenhar o lado de", + "turnComputerOff": "Apagar computador", + "advance": "Avançar", + "move1Km": "Avançar 1 Km", + "bounceFootRubberBall": "Chutar com ó pe uma bola de borracha", + "putIntoTheTrashBin": "colocar na lata de lixo", + "currentColumnLength": "Comprimento da coluna atual", + "countPlanet": "Contar um planeta", + "countStar": "Contar uma estrela", + "writeA": "Escrever 'A'", + "writeB": "Escrever 'B'", + "writeC": "Escrever 'C'", + "writeLetter": "Escrever a letra que estou tocando", + "atTheSquare": "Estou em uma esquina?", + "atTheBeginning": "Estou no começo?", + "atColumnEnd": "Estou no final da coluna?", + "atColumnBeginning": "Estou no inicio da coluna?", + "puddleHere": "Há uma poça?", + "installGame": "Instale jogo", + "nextColumn": "Ir para a linha anterior", + "nextLine": "Ir para a próxima linha", + "moveNextTelescope": "Ir para a próximo telescópio", + "volleyRubberBall": "Lançar ao ar a bola de borracha", + "moveAndDrawDown": "Mova para baixo desenhando", + "moveAndDrawRight": "Mover para a direita desenhando", + "moveAndDrawLeft": "Mover para a esquerda desenhando", + "moveAndDrawUp": "Mover para cima desenhando", + "moveTelescope": "Mover telescópio", + "pickRubberBall": "Pegar uma bola de borracha", + "lookWithFriends": "Perceber o céu com amigos", + "kmToTravel": "Quilômetros para viajar", + "jumpRight": "Saltar para a direita", + "jumpLeft": "Saltar para a esquerda", + "jumpDown": "Saltar para baixo", + "jumpUp": "Saltar para cima", + "goInAlligator": "Vai em jacaré", + "backToLeftBorder": "Voltar para a margem esquerda" }, "procedures": { "definition": "Definir", diff --git a/src/components/blockly/blocks.ts b/src/components/blockly/blocks.ts index e5fd4c06..c4ed9c3c 100644 --- a/src/components/blockly/blocks.ts +++ b/src/components/blockly/blocks.ts @@ -137,9 +137,116 @@ export const commonBlocks: BlockType[] = [ id: 'Procedimiento', intlId: 'Procedures', categoryId: 'myprocedures' + }, + { + id: 'Avanzar', + intlId: 'advance', + categoryId: 'primitives' + }, + { + id: 'PuedeMoverAbajo', + intlId: 'canMoveDown', + categoryId: 'sensors' + }, + { + id: 'PuedeMoverDerecha', + intlId: 'canMoveRight', + categoryId: 'sensors' + }, + + { + id: 'EscribirA', + intlId: 'writeA', + categoryId: 'primitives' + }, + { + id: 'EscribirB', + intlId: 'writeB', + categoryId: 'primitives' + }, + { + id: 'EscribirC', + intlId: 'writeC', + categoryId: 'primitives' + }, + { + id: 'EscribirLetraActualEnOtraCuadricula', + intlId: 'writeLetter', + categoryId: 'primitives' + }, + { + id: 'EstoyEnEsquina', + intlId: 'atTheSquare', + categoryId: 'sensors' + }, + { + id: 'Retroceder', + intlId: 'back', + categoryId: 'primitives' + }, + { + id: 'SaltarAbajo', + intlId: 'jumpDown', + categoryId: 'primitives' + }, + { + id: 'SaltarArriba', + intlId: 'jumpUp', + categoryId: 'primitives' + }, + { + id: 'SaltarDerecha', + intlId: 'jumpRight', + categoryId: 'primitives' + }, + { + id: 'SaltarIzquierda', + intlId: 'jumpLeft', + categoryId: 'primitives' + }, + { + id: 'SiguienteColumna', + intlId: 'nextColumn', + categoryId: 'primitives' + }, + { + id: 'SiguienteFila', + intlId: 'nextLine', + categoryId: 'primitives' + }, + { + id: 'SiguienteFilaTotal', + intlId: 'nextLine', + categoryId: 'primitives' + }, + { + id: 'TocandoInicio', + intlId: 'atTheBeginning', + categoryId: 'sensors' + }, + { + id: 'VolverABordeIzquierdo', + intlId: 'goToLeftBorder', + categoryId: 'primitives' + }, + { + id: 'VolverAlBordeIzquierdo', + intlId: 'backToLeftBorder', + categoryId: 'primitives' + }, + { + id: 'RepetirVacio', + intlId: 'repeatEmpty', + categoryId: 'repetitions' + }, + { + id: 'SaltarHaciaAdelante', + intlId: 'JumpForward', + categoryId: 'primitives' } ] + export const sceneBlocks: BlockType[] = [ { id: 'RecogerTrofeo', @@ -211,6 +318,11 @@ export const sceneBlocks: BlockType[] = [ intlId: 'holdPaper', categoryId: 'primitives' }, + { + id: 'Colocar', + intlId: 'putIntoTheTrashBin', + categoryId: 'primitives' + }, { id: 'LlenarTacho', intlId: 'fillBin', @@ -335,6 +447,201 @@ export const sceneBlocks: BlockType[] = [ id: 'HayTrofeo', intlId: 'trophyHere', categoryId: 'sensors' + }, + { + id: 'ContarEstrella', + intlId: 'countStar', + categoryId: 'primitives' + }, + { + id: 'ContarPlaneta', + intlId: 'countPlanet', + categoryId: 'primitives' + }, + { + id: 'EntregarCargador', + intlId: 'giveCharger', + categoryId: 'primitives' + }, + { + id: 'EntregarPelota', + intlId: 'giveBall', + categoryId: 'primitives' + }, + { + id: 'EntregarTelescopio', + intlId: 'giveTelescope', + categoryId: 'primitives' + }, + { + id: 'AgarrarTelescopio', + intlId: 'takeTelescope', + categoryId: 'primitives' + }, + { + id: 'ApagarComputadora', + intlId: 'turnComputerOff', + categoryId: 'primitives' + }, + { + id: 'Avanzar1kmChuy', + intlId: 'move1Km', + categoryId: 'primitives' + }, + { + id: 'EstoySobreElFinalManic', + intlId: 'atColumnEnd', + categoryId: 'sensors' + }, + { + id: 'EstoySobreElInicioManic', + intlId: 'atColumnBeginning', + categoryId: 'sensors' + }, + { + id: 'InstalarJuego', + intlId: 'installGame', + categoryId: 'primitives' + }, + { + id: 'IrseEnYacare', + intlId: 'goInAlligator', + categoryId: 'primitives' + }, + { + id: 'KmsTotales', + intlId: 'kmToTravel', + categoryId: 'sensors' + }, + { + id: 'LargoColumnaActual', + intlId: 'currentColumnLength', + categoryId: 'sensors' + }, + { + id: 'MoverAbajoDibujando', + intlId: 'moveAndDrawDown', + categoryId: 'primitives' + }, + { + id: 'MoverArribaDibujando', + intlId: 'moveAndDrawUp', + categoryId: 'primitives' + }, + { + id: 'MoverDerechaDibujando', + intlId: 'moveAndDrawRight', + categoryId: 'primitives' + }, + { + id: 'MoverIzquierdaDibujando', + intlId: 'moveAndDrawLeft', + categoryId: 'primitives' + }, + { + id: 'MoverLeyendoAbajo', + intlId: 'moveDown', + categoryId: 'primitives' + }, + { + id: 'MoverLeyendoArriba', + intlId: 'moveUp', + categoryId: 'primitives' + }, + { + id: 'MoverLeyendoDerecha', + intlId: 'moveRight', + categoryId: 'primitives' + }, + { + id: 'MoverLeyendoIzquierda', + intlId: 'moveLeft', + categoryId: 'primitives' + }, + { + id: 'MoverTelescopio', + intlId: 'moveTelescope', + categoryId: 'primitives' + }, + { + id: 'ObservarConAmigos', + intlId: 'lookWithFriends', + categoryId: 'primitives' + }, + { + id: 'PasarASiguienteComputadora', + intlId: 'nextComputer', + categoryId: 'primitives' + }, + { + id: 'PrenderComputadora', + intlId: 'turnComputerOn', + categoryId: 'primitives' + }, + { + id: 'RebotarPiePulpito', + intlId: 'bounceFootRubberBall', + categoryId: 'primitives' + }, + { + id: 'RebotarUnaVezPingPong', + intlId: 'bouncePingPong', + categoryId: 'primitives' + }, + { + id: 'RecogerPulpito', + intlId: 'pickRubberBall', + categoryId: 'primitives' + }, + { + id: 'RevolearPulpito', + intlId: 'volleyRubberBall', + categoryId: 'primitives' + }, + { + id: 'SiguienteTelescopio', + intlId: 'moveNextTelescope', + categoryId: 'primitives' + }, + { + id: 'SubirPajarito', + intlId: 'pickBird', + categoryId: 'primitives' + }, + { + id: 'TocandoGuyra', + intlId: 'guyraHere', + categoryId: 'sensors' + }, + { + id: 'TomarLata', + intlId: 'takeCan', + categoryId: 'primitives' + }, + { + id: 'TomarPapel', + intlId: 'takePaper', + categoryId: 'primitives' + }, + { + id: 'DibujarLado', + intlId: 'drawSide', + categoryId: 'primitives' + }, + { + id: 'EscribirTextoDadoEnOtraCuadricula', + intlId: 'writeAnotherText', + categoryId: 'primitives' + }, + { + id: 'GirarGrados', + intlId: 'rotateGrades', + categoryId: 'primitives' + }, + { + id: 'hayVocalRMT', + intlId: 'isAVowel', + categoryId: 'sensors' } ] diff --git a/src/components/serializedChallenge.ts b/src/components/serializedChallenge.ts index 24c5a0c5..7b091b8b 100644 --- a/src/components/serializedChallenge.ts +++ b/src/components/serializedChallenge.ts @@ -5,25 +5,25 @@ import { ACTOR, EMPTY } from './creator/Editor/SceneEdition/mapUtils'; export const creatorVersion = 1 export type SerializedChallenge = { - fileVersion: number, - title: string, - statement: { - description: string, - clue?: string - }, - scene: Scene, - toolbox: { - blocks: string[], // for now, block ids, future: could be objects. - categorized?: boolean // default true - }, - stepByStep?: boolean, - predefinedSolution?: string, - assesments?: Assesments, - sharedId?: string + fileVersion: number, + title: string, + statement: { + description: string, + clue?: string + }, + scene: Scene, + toolbox: { + blocks: string[], // for now, block ids, future: could be objects. + categorized?: boolean // default true + }, + stepByStep?: boolean, + predefinedSolution?: string, + assesments?: Assesments, + sharedId?: string } -const sceneTypes = ["Lita", "Duba", "Toto", "Coty", "Manic", "Chuy", "Yvoty", "Capy", "Custom"] as const //Used for file validity checking +const sceneTypes = ["Lita", "Duba", "Toto", "Coty", "Manic", "Chuy", "Yvoty", "Capy", "Custom"] as const //Used for file validity checking export type SceneType = typeof sceneTypes[number] type Cell = string @@ -31,197 +31,229 @@ type Cell = string export type SceneMap = Cell[][] export type Scene = { - type: SceneType - maps: SceneMap[] + type: SceneType + maps: SceneMap[] } type SceneObject = { - validCells: Cell[] - specificBlocksIds: string[] + validCells: Cell[] + specificBlocksIds: string[] } -export const sceneObjectByType = (type:SceneType): SceneObject => { - switch (type ) { - case "Lita": - return { - validCells: ['L','T','E'], - specificBlocksIds: [ - 'AgarrarTomate', - 'AgarrarLechuga', - 'PrepararEnsalada', - 'HayLechuga', - 'HayTomate', - 'HayEnsaladera' - ] - } - case "Duba": - return { - validCells: ['P'], - specificBlocksIds: [ - 'ComerChurrasco', - 'HayChurrasco' - ] - } - case "Manic": - return { - validCells: ['T','E','P'], - specificBlocksIds: [ - 'TocandoTelescopio', - 'TocandoEstrellaManic', - 'TocandoPlaneta', - 'ObservarEstrella', - 'ObservarPlaneta', - 'RepararTelescopio' - ] - } - case "Chuy": - return { - validCells: ['T','E','U','P','G'], - specificBlocksIds: [ - 'RecogerTrofeo', - 'RebotarPingPong', - 'PatearPulpito', - 'PatearPelotaChuy', - 'TocandoPulpito', - 'TocandoPingPong', - 'TocandoPaleta', - 'RecogerPaleta', - 'TocandoPelotaChuy', - 'HayTrofeo' - ] - } - case "Yvoty": - return { - validCells: ['C','K','L','M'], - specificBlocksIds: [ - 'DespertarLuciernaga', - 'FotografiarMariposa', - 'DesbloquearCelular', - 'AgarrarCargador', - 'TocandoMariposa', - 'TocandoCelular', - 'TocandoLuciernaga', - 'CargarCelular', - 'HayCargador' - ] - } - case "Capy": - return { - validCells: ['L','P'], - specificBlocksIds: [ - 'RecogerLata', - 'RecogerPapel', - /*'SostenerPapel', - 'LlenarTacho', */ - 'TocandoPapel', - 'TocandoLata' - ] - } - default: - return { - validCells: [], - specificBlocksIds: [] - } - } +export const sceneObjectByType = (type: SceneType): SceneObject => { + switch (type) { + case "Lita": + return { + validCells: ['L', 'T', 'E'], + specificBlocksIds: [ + 'AgarrarTomate', + 'AgarrarLechuga', + 'PrepararEnsalada', + 'HayLechuga', + 'HayTomate', + 'HayEnsaladera' + ] + } + case "Duba": + return { + validCells: ['P'], + specificBlocksIds: [ + 'ComerChurrasco', + 'HayChurrasco' + ] + } + case "Manic": + return { + validCells: ['T', 'E', 'P'], + specificBlocksIds: [ + 'TocandoTelescopio', + 'TocandoEstrellaManic', + 'TocandoPlaneta', + 'ObservarEstrella', + 'ObservarPlaneta', + 'RepararTelescopio', + 'AgarrarTelescopio', + 'ContarEstrella', + 'ContarPlaneta', + 'EntregarTelescopio', + 'EstoySobreElFinalManic', + 'EstoySobreElInicioManic', + 'GirarGrados', + 'MoverAbajoDibujando', + 'MoverArribaDibujando', + 'MoverDerechaDibujando', + 'MoverIzquierdaDibujando', + 'MoverTelescopio', + 'ObservarConAmigos', + 'SiguienteTelescopio', + 'DibujarLado' + ] + } + case "Chuy": + return { + validCells: ['T', 'E', 'U', 'P', 'G'], + specificBlocksIds: [ + 'RecogerTrofeo', + 'RebotarPingPong', + 'PatearPulpito', + 'PatearPelotaChuy', + 'TocandoPulpito', + 'TocandoPingPong', + 'TocandoPaleta', + 'RecogerPaleta', + 'TocandoPelotaChuy', + 'HayTrofeo', + 'Avanzar1kmChuy', + 'EntregarPelota', + 'KmsTotales', + 'RebotarPiePulpito', + 'RebotarUnaVezPingPong', + 'RecogerPulpito', + 'RevolearPulpito' + ] + } + case "Yvoty": + return { + validCells: ['C', 'K', 'L', 'M'], + specificBlocksIds: [ + 'DespertarLuciernaga', + 'FotografiarMariposa', + 'DesbloquearCelular', + 'AgarrarCargador', + 'TocandoMariposa', + 'TocandoCelular', + 'TocandoLuciernaga', + 'CargarCelular', + 'HayCargador', + 'ApagarComputadora', + 'EntregarCargador', + 'InstalarJuego', + 'PasarASiguienteComputadora', + 'PrenderComputadora' + ] + } + case "Capy": + return { + validCells: ['L', 'P'], + specificBlocksIds: [ + 'RecogerLata', + 'RecogerPapel', + /*'SostenerPapel', + 'LlenarTacho', */ + 'TocandoPapel', + 'TocandoLata', + 'IrseEnYacare', + 'SubirPajarito', + 'Colocar', + 'TocandoGuyra', + 'TomarLata', + 'TomarPapel'] + } + default: + return { + validCells: [], + specificBlocksIds: [] + } + } } export const defaultScene = (type: SceneType): Scene => { - return { - type: type, - maps: [[[ACTOR, EMPTY, EMPTY], - [EMPTY, EMPTY, EMPTY], - [EMPTY, EMPTY, EMPTY]]] - } + return { + type: type, + maps: [[[ACTOR, EMPTY, EMPTY], + [EMPTY, EMPTY, EMPTY], + [EMPTY, EMPTY, EMPTY]]] + } } -export const defaultChallenge = (type: SceneType, defaultDescription = "", defaultTitle=""): SerializedChallenge => { - return { - fileVersion: 1, - title: defaultTitle, - statement: { - description: defaultDescription - }, - scene: defaultScene(type), - toolbox: { - blocks: [] // ['MoverACasillaDerecha'] - }, - stepByStep: true - } +export const defaultChallenge = (type: SceneType, defaultDescription = "", defaultTitle = ""): SerializedChallenge => { + return { + fileVersion: 1, + title: defaultTitle, + statement: { + description: defaultDescription + }, + scene: defaultScene(type), + toolbox: { + blocks: [] // ['MoverACasillaDerecha'] + }, + stepByStep: true + } } -type Assesments = { - itWorks?: boolean, // old "debeFelicitar", default true - decomposition?: DecompositionAssessment, - simpleRepetition?: boolean, - conditionalRepetition?: boolean, - conditionalAlternative?: boolean, +type Assesments = { + itWorks?: boolean, // old "debeFelicitar", default true + decomposition?: DecompositionAssessment, + simpleRepetition?: boolean, + conditionalRepetition?: boolean, + conditionalAlternative?: boolean, } type DecompositionAssessment = { maxProgramLength: number } export const isValidChallenge = (json: unknown): json is SerializedChallenge => { - const structureIsValid: boolean = simpleTypeGuard(json, { - fileVersion: SimpleNumber, - title: SimpleString, - statement: {description: SimpleString, clue: SimpleStringOptional}, - toolbox: {blocks: new SimpleArray(SimpleString), categorized: SimpleBooleanOptional}, - stepByStep: SimpleBooleanOptional, - predefinedSolution: SimpleStringOptional, - scene: SimpleSkip, //We cant check if the scene values are valid here, so we need to check them manually. This is because "SimpleExactMatch" seems to be broken. - assesments: new SimpleObjectOptional({ - itWorks: SimpleBooleanOptional, - simpleRepetition: SimpleBooleanOptional, - conditionalRepetition: SimpleBooleanOptional, - conditionalAlternative: SimpleBooleanOptional, - decomposition: new SimpleObjectOptional({ - maxProgramLength: SimpleNumber - }) - }), - sharedId: SimpleStringOptional - }) - - return structureIsValid && sceneIsValid((json as any).scene) + const structureIsValid: boolean = simpleTypeGuard(json, { + fileVersion: SimpleNumber, + title: SimpleString, + statement: { description: SimpleString, clue: SimpleStringOptional }, + toolbox: { blocks: new SimpleArray(SimpleString), categorized: SimpleBooleanOptional }, + stepByStep: SimpleBooleanOptional, + predefinedSolution: SimpleStringOptional, + scene: SimpleSkip, //We cant check if the scene values are valid here, so we need to check them manually. This is because "SimpleExactMatch" seems to be broken. + assesments: new SimpleObjectOptional({ + itWorks: SimpleBooleanOptional, + simpleRepetition: SimpleBooleanOptional, + conditionalRepetition: SimpleBooleanOptional, + conditionalAlternative: SimpleBooleanOptional, + decomposition: new SimpleObjectOptional({ + maxProgramLength: SimpleNumber + }) + }), + sharedId: SimpleStringOptional + }) + + return structureIsValid && sceneIsValid((json as any).scene) } export const sceneIsValid = (serializedScene: unknown): serializedScene is Scene => { - const sceneStructureIsValid: boolean = simpleTypeGuard(serializedScene, { //Verify if the structure of the scene is valid, without checking if the values are valid. - type: SimpleString, - maps: new SimpleArray(new SimpleArray(new SimpleArray(SimpleString))) - }) + const sceneStructureIsValid: boolean = simpleTypeGuard(serializedScene, { //Verify if the structure of the scene is valid, without checking if the values are valid. + type: SimpleString, + maps: new SimpleArray(new SimpleArray(new SimpleArray(SimpleString))) + }) - if(!sceneStructureIsValid) return false + if (!sceneStructureIsValid) return false - const type: string | SceneType = (serializedScene as any).type - const maps: [string[][]] | SceneMap[] = (serializedScene as any).maps + const type: string | SceneType = (serializedScene as any).type + const maps: [string[][]] | SceneMap[] = (serializedScene as any).maps - if (!isSceneType(type) || !mapsAreValidForType(maps, type)) return false + if (!isSceneType(type) || !mapsAreValidForType(maps, type)) return false - const scene: Scene = {type, maps} //This line is needed to let typescript verify on compile time if this function (sceneIsValid) completely satisfies the type of Scene. (e.g. if we add a field to scene, this line breaks, and we want that to bring the attention to this function, which probably will need changes) + const scene: Scene = { type, maps } //This line is needed to let typescript verify on compile time if this function (sceneIsValid) completely satisfies the type of Scene. (e.g. if we add a field to scene, this line breaks, and we want that to bring the attention to this function, which probably will need changes) - return !!scene + return !!scene } const mapsAreValidForType = (maps: SceneMap[], type: SceneType): boolean => - maps.every(map => mapIsValidForType(map, type)) + maps.every(map => mapIsValidForType(map, type)) const mapIsValidForType = (map: SceneMap, type: SceneType): map is SceneMap => { - const rowIsValid = (row: Cell[]) => row.every(cell => cellIsValidForType(cell, type)) - return map.every(rowIsValid) + const rowIsValid = (row: Cell[]) => row.every(cell => cellIsValidForType(cell, type)) + return map.every(rowIsValid) } const cellIsValidForType = (cell: Cell, type: SceneType): boolean => { - return cellIsIncluded(sceneObjectByType(type).validCells, cell) + return cellIsIncluded(sceneObjectByType(type).validCells, cell) } - -const cellIsIncluded = (typeCells: string[], cell: string) =>{ - const basicCells: string[] = ['A','O','-'] - return basicCells.concat(typeCells).concat(multipleObjectsCells(typeCells)).includes(cell) + +const cellIsIncluded = (typeCells: string[], cell: string) => { + const basicCells: string[] = ['A', 'O', '-'] + return basicCells.concat(typeCells).concat(multipleObjectsCells(typeCells)).includes(cell) } const multipleObjectsCells = (typeCells: string[]) => typeCells.map(prize => `A&${prize}`).concat(typeCells.map(prize => `${prize}&A`)) -const isSceneType = (type: any): type is SceneType => - sceneTypes.includes(type) +const isSceneType = (type: any): type is SceneType => + sceneTypes.includes(type)