From a50f49c57fd1f56cd98ce5754b8e33837958e287 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Tainon?=
Date: Wed, 26 Jul 2023 17:40:41 +0200
Subject: [PATCH] Use script animation to get task data
---
frontend/index.tsx | 1 +
frontend/submission/task_platform.ts | 16 ++++++++++++++++
.../libs/smart_contract/SmartContractStorage.tsx | 2 +-
frontend/task/task_slice.ts | 1 +
4 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/frontend/index.tsx b/frontend/index.tsx
index 57f21368..2ff3d037 100644
--- a/frontend/index.tsx
+++ b/frontend/index.tsx
@@ -156,6 +156,7 @@ declare global {
quickAlgoLanguageStrings: any,
taskStrings?: any,
SmartContractConfig?: SmartContractConfigType,
+ taskData?: any,
}
}
diff --git a/frontend/submission/task_platform.ts b/frontend/submission/task_platform.ts
index 4690d5f1..1fe0708a 100644
--- a/frontend/submission/task_platform.ts
+++ b/frontend/submission/task_platform.ts
@@ -136,6 +136,22 @@ export function* getTaskFromId(taskId: string): Generator
}
export function convertServerTaskToCodecastFormat(task: TaskServer): Task {
+ // task.scriptAnimation = "\n window.taskData = subTask = {};\n subTask.gridInfos = {\n context: 'smart_contract',\n importModules: ['smart_contract_config'],\n showLabels: true,\n conceptViewer: true,\n includeBlocks: {\n groupByCategory: true,\n standardBlocks: {\n wholeCategories: ['smart_contract_main_blocks', 'smart_contract_types'],\n },\n },\n expectedStorage: \"(string %names)\",\n taskStrings: {\n \"storageDescription\": {\n \"names\": \"it should contain its initial value then the list of names of the callers, all separated with commas\",\n },\n },\n // expectedStorage: \"(Pair (string %names) (nat %nb_calls))\",\n };\n ";
+ if (task.scriptAnimation) {
+ try {
+ eval(task.scriptAnimation);
+ } catch (ex) {
+ console.error("Couldn't execute script animation", ex);
+ }
+
+ if (window.taskData?.gridInfos) {
+ return {
+ ...task,
+ gridInfos: window.taskData.gridInfos,
+ };
+ }
+ }
+
// Use this for now to check if it's a Smart Contract task. Change this in the future
if (smartContractPlatforms.find(platform => -1 !== task.supportedLanguages.indexOf(platform))) {
return {
diff --git a/frontend/task/libs/smart_contract/SmartContractStorage.tsx b/frontend/task/libs/smart_contract/SmartContractStorage.tsx
index 2ea4694c..47e232e6 100644
--- a/frontend/task/libs/smart_contract/SmartContractStorage.tsx
+++ b/frontend/task/libs/smart_contract/SmartContractStorage.tsx
@@ -22,7 +22,7 @@ export function SmartContractStorage() {
{storageVariables.map(({name, type}) =>
- {name}
should be a {type}{window?.taskStrings?.storageDescription[name] ? ': ' + window?.taskStrings?.storageDescription[name] : ''}
+ {name}
should be a {type}{task.gridInfos.taskStrings?.storageDescription[name] ? ': ' + task.gridInfos.taskStrings?.storageDescription[name] : ''}
)}
diff --git a/frontend/task/task_slice.ts b/frontend/task/task_slice.ts
index 5c2f6061..5d92c723 100644
--- a/frontend/task/task_slice.ts
+++ b/frontend/task/task_slice.ts
@@ -149,6 +149,7 @@ export interface QuickalgoTaskGridInfosNotLevelDependent {
expectedStorage?: string,
initActionDelay?: number,
hints?: TaskHint[],
+ taskStrings?: any,
}
export interface QuickalgoTaskGridInfos extends QuickalgoTaskGridInfosNotLevelDependent {