From d413485a0634bb8975339fd617b007c711f9b9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diana=20L=C3=B3pez=20Alvas?= Date: Thu, 18 Jul 2024 14:52:20 -0300 Subject: [PATCH] restart scene --- package-lock.json | 20 +++++++++++++++ package.json | 3 ++- src/components/blockly/blockly.ts | 4 ++- .../challengeView/{ => Scene}/scene.ts | 9 +++++-- .../challengeView/SceneButtons/Execute.tsx | 25 +++++++++++++++++++ .../SceneButtons/SceneButtons.tsx | 9 ++++--- src/components/challengeView/SceneView.tsx | 2 +- 7 files changed, 63 insertions(+), 9 deletions(-) rename src/components/challengeView/{ => Scene}/scene.ts (92%) create mode 100644 src/components/challengeView/SceneButtons/Execute.tsx diff --git a/package-lock.json b/package-lock.json index a5e5e6bd..9effee98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,6 +53,7 @@ "identity-obj-proxy": "^3.0.0", "jest-resolve": "^27.4.2", "jest-watch-typeahead": "^2.2.2", + "js-interpreter": "^5.1.2", "makensis": "^2.0.8", "mini-css-extract-plugin": "^2.4.5", "pilas-bloques-exercises": "^1.4.31", @@ -17377,6 +17378,17 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, + "node_modules/js-interpreter": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/js-interpreter/-/js-interpreter-5.1.2.tgz", + "integrity": "sha512-UaGCF7yuCvMBfeVSnSdpXu8lTLW48HIr5b46qSMwqFBDO1tgb/Yxlx3LRuEDpN2DlLnFTcvfoBseUxVTjFA6zg==", + "dependencies": { + "minimist": "^1.2.8" + }, + "bin": { + "js-interpreter": "lib/cli.min.js" + } + }, "node_modules/js-sdsl": { "version": "4.3.0", "license": "MIT", @@ -38992,6 +39004,14 @@ } } }, + "js-interpreter": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/js-interpreter/-/js-interpreter-5.1.2.tgz", + "integrity": "sha512-UaGCF7yuCvMBfeVSnSdpXu8lTLW48HIr5b46qSMwqFBDO1tgb/Yxlx3LRuEDpN2DlLnFTcvfoBseUxVTjFA6zg==", + "requires": { + "minimist": "^1.2.8" + } + }, "js-sdsl": { "version": "4.3.0" }, diff --git a/package.json b/package.json index c9e84df5..f3b91ed6 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "identity-obj-proxy": "^3.0.0", "jest-resolve": "^27.4.2", "jest-watch-typeahead": "^2.2.2", + "js-interpreter": "^5.1.2", "makensis": "^2.0.8", "mini-css-extract-plugin": "^2.4.5", "pilas-bloques-exercises": "^1.4.31", @@ -262,4 +263,4 @@ "react-app" ] } -} \ No newline at end of file +} diff --git a/src/components/blockly/blockly.ts b/src/components/blockly/blockly.ts index 250b0b7d..f634d172 100644 --- a/src/components/blockly/blockly.ts +++ b/src/components/blockly/blockly.ts @@ -1485,4 +1485,6 @@ export const setupBlockly = (container: Element, workspaceConfiguration: Blockly container.replaceChildren() //Removes previous injection, otherwise it might keep inserting below the current workspace container.ariaValueText = 'child-blockly' Blockly.inject(container, workspaceConfiguration) -} \ No newline at end of file +} + +export const workspaceToCode = () => javascriptGenerator.workspaceToCode(Blockly.getMainWorkspace()) \ No newline at end of file diff --git a/src/components/challengeView/scene.ts b/src/components/challengeView/Scene/scene.ts similarity index 92% rename from src/components/challengeView/scene.ts rename to src/components/challengeView/Scene/scene.ts index c9eeb3c3..1c8054d5 100644 --- a/src/components/challengeView/scene.ts +++ b/src/components/challengeView/Scene/scene.ts @@ -1,5 +1,5 @@ -import { adaptURL } from "../../scriptLoader"; -import { Challenge } from "../../staticData/challenges"; +import { adaptURL } from "../../../scriptLoader"; +import { Challenge } from "../../../staticData/challenges"; class Scene { iframe(): HTMLIFrameElement { @@ -76,6 +76,11 @@ class Scene { const name = sceneDescriptor.match(/new\s+(\w+)\s*\(/) return name ? name[1] : sceneDescriptor } + + async restartScene(descriptor: Challenge["sceneDescriptor"]) { + this.eval('pilas.reiniciar()') + await this.setChallenge(descriptor) + } } export const scene = new Scene() \ No newline at end of file diff --git a/src/components/challengeView/SceneButtons/Execute.tsx b/src/components/challengeView/SceneButtons/Execute.tsx new file mode 100644 index 00000000..4143b4b9 --- /dev/null +++ b/src/components/challengeView/SceneButtons/Execute.tsx @@ -0,0 +1,25 @@ +import { Button } from "@mui/material" +import { workspaceToCode } from "../../blockly/blockly" +//@ts-ignore +import Interpreter from 'js-interpreter' +import { scene } from "../Scene/scene" + +export const ExecuteButton = () => { + + const handleExcecute = async () => { + await scene.restartScene('new EscenaLita(["[[A,-,-],[-,-,-],[-,-,-]]"])') //TODO context para el challenge? de donde lo saco? esta en muchos lugares como parametro???? vale la pena? + const interpreter = new Interpreter(workspaceToCode()) + + //create interpreter new Interpreter + //execute until end + } + + return + +} + +class InterpreterFactory { + createInterpreter() : void { + + } +} \ No newline at end of file diff --git a/src/components/challengeView/SceneButtons/SceneButtons.tsx b/src/components/challengeView/SceneButtons/SceneButtons.tsx index b5952faa..850d0d3b 100644 --- a/src/components/challengeView/SceneButtons/SceneButtons.tsx +++ b/src/components/challengeView/SceneButtons/SceneButtons.tsx @@ -1,14 +1,15 @@ -import { Button, IconButton, Stack } from "@mui/material" +import { IconButton, Stack } from "@mui/material" import { PBCard } from "../../PBCard" import { Circle, Info, PlayArrow, SkipNext } from "@mui/icons-material" import { PBSwitch, pbIconStyle } from "../../PBSwitch" import styles from './sceneButtons.module.css' import BoltIcon from '@mui/icons-material/Bolt'; import { useThemeContext } from "../../../theme/ThemeContext"; +import { ExecuteButton } from "./Execute" export const SceneButtons = () => { return - + } @@ -16,7 +17,7 @@ export const SceneButtonsVertical = () => { return - + } @@ -29,7 +30,7 @@ const NextStepButton = () => { } -const ExecuteButton = () => { +const ExcecuteButtonVertical = () => { return diff --git a/src/components/challengeView/SceneView.tsx b/src/components/challengeView/SceneView.tsx index b2bcc80f..a7c6243f 100644 --- a/src/components/challengeView/SceneView.tsx +++ b/src/components/challengeView/SceneView.tsx @@ -1,6 +1,6 @@ import { Challenge } from "../../staticData/challenges" import { PBCard } from "../PBCard" -import { scene } from "./scene" +import { scene } from "./Scene/scene" import { useMediaQuery } from "@mui/material" import { useThemeContext } from "../../theme/ThemeContext" import { useState } from "react"