|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import * as React from 'react';
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import { useEffect, useState, useRef } from 'react';
|
|
|
|
|
import '@fontsource/roboto/300.css';
|
|
|
|
|
import '@fontsource/roboto/400.css';
|
|
|
|
|
import '@fontsource/roboto/500.css';
|
|
|
|
|
@ -11,11 +11,11 @@ import LeftPanel from './LeftPanel';
|
|
|
|
|
import InputZone from './InputZone';
|
|
|
|
|
import Message from './Message';
|
|
|
|
|
import TacticState from './TacticState';
|
|
|
|
|
import * as rpc from 'vscode-ws-jsonrpc';
|
|
|
|
|
import Editor from 'lean4web/client/src/Editor'
|
|
|
|
|
import { LeanClient } from 'lean4web/client/src/editor/leanclient';
|
|
|
|
|
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js'
|
|
|
|
|
|
|
|
|
|
interface LevelProps {
|
|
|
|
|
rpcConnection: null|rpc.MessageConnection;
|
|
|
|
|
leanClient: null|LeanClient;
|
|
|
|
|
nbLevels: any;
|
|
|
|
|
level: any;
|
|
|
|
|
setCurLevel: any;
|
|
|
|
|
@ -23,7 +23,7 @@ interface LevelProps {
|
|
|
|
|
setFinished: any
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Level({ rpcConnection, nbLevels, level, setCurLevel, setLevelTitle, setFinished }: LevelProps) {
|
|
|
|
|
function Level({ leanClient, nbLevels, level, setCurLevel, setLevelTitle, setFinished }: LevelProps) {
|
|
|
|
|
const [index, setIndex] = useState(level) // Level number
|
|
|
|
|
const [tacticDocs, setTacticDocs] = useState([])
|
|
|
|
|
const [lemmaDocs, setLemmaDocs] = useState([])
|
|
|
|
|
@ -32,6 +32,7 @@ function Level({ rpcConnection, nbLevels, level, setCurLevel, setLevelTitle, set
|
|
|
|
|
const [history, setHistory] = useState([])
|
|
|
|
|
const [lastTactic, setLastTactic] = useState("")
|
|
|
|
|
const [errors, setErrors] = useState([])
|
|
|
|
|
const codeviewRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
|
|
const [message, setMessage] = useState("")
|
|
|
|
|
const [messageOpen, setMessageOpen] = useState(false)
|
|
|
|
|
@ -53,26 +54,53 @@ function Level({ rpcConnection, nbLevels, level, setCurLevel, setLevelTitle, set
|
|
|
|
|
|
|
|
|
|
// The next function will be called when the level changes
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (rpcConnection) {
|
|
|
|
|
rpcConnection.sendRequest("loadLevel", {number: level}).then((res) => {
|
|
|
|
|
setLevelTitle("Level " + res["index"] + ": " + res["title"])
|
|
|
|
|
setIndex(parseInt(res["index"]))
|
|
|
|
|
setTacticDocs(res["tactics"])
|
|
|
|
|
setLemmaDocs(res["lemmas"])
|
|
|
|
|
processResponse(res)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, [level, rpcConnection])
|
|
|
|
|
const uri = monaco.Uri.parse('file:///LeanProject/Level1.lean')
|
|
|
|
|
const model = monaco.editor.createModel('', 'lean4', uri)
|
|
|
|
|
const editor = monaco.editor.create(codeviewRef.current!, {
|
|
|
|
|
model,
|
|
|
|
|
glyphMargin: true,
|
|
|
|
|
lightbulb: {
|
|
|
|
|
enabled: true
|
|
|
|
|
},
|
|
|
|
|
unicodeHighlight: {
|
|
|
|
|
ambiguousCharacters: false,
|
|
|
|
|
},
|
|
|
|
|
automaticLayout: true,
|
|
|
|
|
minimap: {
|
|
|
|
|
enabled: false
|
|
|
|
|
},
|
|
|
|
|
lineNumbersMinChars: 3,
|
|
|
|
|
'semanticHighlighting.enabled': true,
|
|
|
|
|
theme: 'vs-code-theme-converted'
|
|
|
|
|
})
|
|
|
|
|
// setEditor(editor)
|
|
|
|
|
// new AbbreviationRewriter(new AbbreviationProvider(), model, editor)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const infoProvider = new InfoProvider(leanClient)
|
|
|
|
|
// const div: HTMLElement = infoviewRef.current!
|
|
|
|
|
// const infoviewApi = renderInfoview(infoProvider.getApi(), div)
|
|
|
|
|
// setInfoProvider(infoProvider)
|
|
|
|
|
// setInfoviewApi(infoviewApi)
|
|
|
|
|
|
|
|
|
|
leanClient.sendRequest("loadLevel", {number: level}).then((res) => {
|
|
|
|
|
setLevelTitle("Level " + res["index"] + ": " + res["title"])
|
|
|
|
|
setIndex(parseInt(res["index"]))
|
|
|
|
|
setTacticDocs(res["tactics"])
|
|
|
|
|
setLemmaDocs(res["lemmas"])
|
|
|
|
|
processResponse(res)
|
|
|
|
|
});
|
|
|
|
|
}, [level, leanClient])
|
|
|
|
|
|
|
|
|
|
function sendTactic(input) {
|
|
|
|
|
rpcConnection.sendRequest("runTactic", {tactic: input}).then(processResponse);
|
|
|
|
|
leanClient.sendRequest("runTactic", {tactic: input}).then(processResponse);
|
|
|
|
|
setLastTactic(input);
|
|
|
|
|
setHistory(history.concat([input]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function undo() {
|
|
|
|
|
if (errors.length === 0) {
|
|
|
|
|
rpcConnection.sendRequest('undo').then(processResponse);
|
|
|
|
|
leanClient.sendRequest('undo', {}).then(processResponse);
|
|
|
|
|
}
|
|
|
|
|
if (history.length > 1) {
|
|
|
|
|
setLastTactic(history[history.length - 1]);
|
|
|
|
|
@ -104,8 +132,7 @@ function Level({ rpcConnection, nbLevels, level, setCurLevel, setLevelTitle, set
|
|
|
|
|
<LeftPanel spells={tacticDocs} inventory={lemmaDocs} />
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid xs={4}>
|
|
|
|
|
<Editor setRestart={() => {}}
|
|
|
|
|
value={""} onDidChangeContent={() => {}}/>
|
|
|
|
|
<div ref={codeviewRef} className="codeview" style={{height: "20em"}}></div>
|
|
|
|
|
{/* <InputZone index={index} history={history} messageOpen={messageOpen} setMessageOpen={setMessageOpen} completed={completed} sendTactic={sendTactic} nbLevels={nbLevels} loadNextLevel={loadNextLevel}
|
|
|
|
|
errors={errors} lastTactic={lastTactic} undo={undo} finishGame={finishGame} /> */}
|
|
|
|
|
<Message isOpen={messageOpen} content={message} close={closeMessage} />
|
|
|
|
|
|