Skip to content

Commit

Permalink
restart scene
Browse files Browse the repository at this point in the history
  • Loading branch information
dlopezalvas committed Jul 18, 2024
1 parent 82e07aa commit d413485
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -262,4 +263,4 @@
"react-app"
]
}
}
}
4 changes: 3 additions & 1 deletion src/components/blockly/blockly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

export const workspaceToCode = () => javascriptGenerator.workspaceToCode(Blockly.getMainWorkspace())
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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()
25 changes: 25 additions & 0 deletions src/components/challengeView/SceneButtons/Execute.tsx
Original file line number Diff line number Diff line change
@@ -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 <Button variant="contained" color="success" onClick={handleExcecute}>{"Ejecutar"}</Button>

}

class InterpreterFactory {
createInterpreter() : void {

}
}
9 changes: 5 additions & 4 deletions src/components/challengeView/SceneButtons/SceneButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
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 <PBCard>
<Button variant="contained" color="success" >{"Ejecutar"}</Button>
<ExecuteButton/>
</PBCard>
}

export const SceneButtonsVertical = () => {
return <Stack gap={2} alignItems='center'>
<TurboModeSwitch />
<NextStepButton />
<ExecuteButton />
<ExcecuteButtonVertical />
</Stack>
}

Expand All @@ -29,7 +30,7 @@ const NextStepButton = () => {
</IconButton>
}

const ExecuteButton = () => {
const ExcecuteButtonVertical = () => {
return <IconButton className={styles['icon-button']}>
<Stack>
<Circle color='success' className={styles['circle-icon']} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/challengeView/SceneView.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit d413485

Please sign in to comment.