From c7ce02ab51d6b48e2661e0a371bca7833fb56727 Mon Sep 17 00:00:00 2001 From: guyguy2001 Date: Mon, 10 Jun 2024 21:10:46 +0300 Subject: [PATCH] Extract the 'select_folder' api to an external file --- src/eterna/eternaScript/SelectFolderAPI.ts | 13 +++++++++++++ src/eterna/mode/PoseEdit/PoseEditMode.ts | 8 +++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 src/eterna/eternaScript/SelectFolderAPI.ts diff --git a/src/eterna/eternaScript/SelectFolderAPI.ts b/src/eterna/eternaScript/SelectFolderAPI.ts new file mode 100644 index 00000000..ee9f9d1f --- /dev/null +++ b/src/eterna/eternaScript/SelectFolderAPI.ts @@ -0,0 +1,13 @@ +import {ExternalInterfaceCtx} from 'eterna/util/ExternalInterface'; + +/** + * Adds the ability to modify the folder (via its name) to the EternaScript API. +*/ +export default function addSelectFolderAPIToInterface({selectFolder, scriptInterface}: { + selectFolder: (folderName: string) => boolean, + scriptInterface: ExternalInterfaceCtx, +}) { + scriptInterface.addCallback( + 'select_folder', (folderName: string): boolean => selectFolder(folderName) + ); +} diff --git a/src/eterna/mode/PoseEdit/PoseEditMode.ts b/src/eterna/mode/PoseEdit/PoseEditMode.ts index b7ced3dd..2c518d45 100644 --- a/src/eterna/mode/PoseEdit/PoseEditMode.ts +++ b/src/eterna/mode/PoseEdit/PoseEditMode.ts @@ -79,6 +79,7 @@ import NuPACK from 'eterna/folding/NuPACK'; import PasteStructureDialog from 'eterna/ui/PasteStructureDialog'; import ConfirmTargetDialog from 'eterna/ui/ConfirmTargetDialog'; import FoldingContextScriptAPI from 'eterna/eternaScript/FoldingAPI'; +import addSelectFolderAPIToInterface from 'eterna/eternaScript/SelectFolderAPI'; import GameMode from '../GameMode'; import SubmittingDialog from './SubmittingDialog'; import SubmitPoseDialog from './SubmitPoseDialog'; @@ -1276,9 +1277,10 @@ export default class PoseEditMode extends GameMode { }).registerToScriptInterface(this._scriptInterface); if (this._puzzle.puzzleType === PuzzleType.EXPERIMENTAL) { - this._scriptInterface.addCallback( - 'select_folder', (folderName: string): boolean => this.selectFolder(folderName) - ); + addSelectFolderAPIToInterface({ + selectFolder: this.selectFolder, + scriptInterface: this._scriptInterface + }); this._scriptInterface.addCallback('load_parameters_from_buffer', (_str: string): boolean => { log.info('TODO: load_parameters_from_buffer');