Skip to content

Commit

Permalink
Use script animation to get task data
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienTainon committed Jul 26, 2023
1 parent 41eb330 commit a50f49c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions frontend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ declare global {
quickAlgoLanguageStrings: any,
taskStrings?: any,
SmartContractConfig?: SmartContractConfigType,
taskData?: any,
}
}

Expand Down
16 changes: 16 additions & 0 deletions frontend/submission/task_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ export function* getTaskFromId(taskId: string): Generator<any, TaskServer|null>
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion frontend/task/libs/smart_contract/SmartContractStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function SmartContractStorage() {
</p>
<ul>
{storageVariables.map(({name, type}) =>
<li key={name}><code>{name}</code> should be a {type}{window?.taskStrings?.storageDescription[name] ? ': ' + window?.taskStrings?.storageDescription[name] : ''}</li>
<li key={name}><code>{name}</code> should be a {type}{task.gridInfos.taskStrings?.storageDescription[name] ? ': ' + task.gridInfos.taskStrings?.storageDescription[name] : ''}</li>
)}
</ul>
</div>
Expand Down
1 change: 1 addition & 0 deletions frontend/task/task_slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export interface QuickalgoTaskGridInfosNotLevelDependent {
expectedStorage?: string,
initActionDelay?: number,
hints?: TaskHint[],
taskStrings?: any,
}

export interface QuickalgoTaskGridInfos extends QuickalgoTaskGridInfosNotLevelDependent {
Expand Down

0 comments on commit a50f49c

Please sign in to comment.