Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/extract scripting api #749

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

guyguy2001
Copy link
Contributor

@guyguy2001 guyguy2001 commented Jun 9, 2024

Summary

In order to prepare the ground for creating a new EternaJS app that just exposes the folding API without any additional state (which would allow fixing eternagame/eternagame.org#378), and in order to just simplify PoseEditMode, this PR extracts logic related the to the folding scripting (booster) API from PoseEditMode to a new class (/function), which would have very few dependencies.

Implementation Notes

Moved the code responsible for exposing the folding API (which only depends on the folding context, i.e read-only access to this._folder and understanding whether or not we are in psuedoknot mode) from PoseEditMode.ts to a separate ScriptsApi.ts flie (name WIP)

Testing

I currently only ran document.getElementById("maingame").fold("AUGGGGGGGGGGGGGGGGGGGGCCCCCCCCCCCCCCCCCCCC") after running the script evaluator (in order to load the script interface)`.

Related Issues

Preparations for fixing eternagame/eternagame.org#378

TODO

Blocking merge:

  • Rename the class and the file name
  • Probably change the class into a function - I decided against it.
  • Move the file
  • Make eslint not angry
  • Testing

Direct Follow-Up / maybe this PR

  • extract setting the folding engine as well

Later

  • Extract the rest of the scripting API to helper classes / functions

Notes / Questions for CR

Notes

  • It's still WIP, but I'd appriciate an early review to make sure I'm on the right track
  • You should probably review this commit by commit, they are much more indicative than the diff

Questions

  • Do you think the idea with _getFolder and _getIsPseudoknot make sense? I couldn't find a better way without a) making a SwitchableFolder proxy object or b) giving this class access to the entire PoseEditMode (now that I think about it, we could define an interface containing folder and isPseudoknot... but I think it's better to just pass these 2, although I haven't done typescript in years)
    • Well apparently there is a SwitchableFolder - it's FolderSwitcher. Should I use it for this? Or the getter thing?
      • FolderSwitcher is coupled to pixi and the GUI, so I think I'm satisfied with the current way.
    • And is isPseudoknot ever going to change?
  • About pseudoknots - what does it mean to be in pseudoknots mode? That we look at tertiary structure when folding? This makes Lib.fold behave differently between different puzzles - but now it will also (or maybe has) behave differently between the editor and the scripts page and the game
  • Where should I put this file? I put this in eterna/eternaScript, but ExternalInterfaceCtx should probably also sit there - however, I'm not sure if they should sit together - the code I moved is "user" code using the interface context, while the interface context itself is more of a "library" thing. Should I move it there as well in a follow up PR?

@guyguy2001 guyguy2001 requested a review from luxaritas June 9, 2024 20:14
@guyguy2001 guyguy2001 marked this pull request as draft June 9, 2024 20:16
@@ -22,6 +22,7 @@
"core-js": "^3.13.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accidentally comitted this file - Should I keep it if this is what npm install gives me?

@@ -1269,140 +1270,11 @@ export default class PoseEditMode extends GameMode {
this._puzzle.getBarcodeHairpin(Sequence.fromSequenceString(seq)).sequenceString()
));

this._scriptInterface.addCallback('current_folder', (): string | null => (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should go commit by commit, since the first commit doesn't modify this code, only moves it (and adds code around it)

@guyguy2001 guyguy2001 force-pushed the refactor/extract-scripting-api branch from 844640e to c7ce02a Compare June 10, 2024 18:12
@guyguy2001 guyguy2001 self-assigned this Jun 10, 2024
@guyguy2001 guyguy2001 marked this pull request as ready for review June 10, 2024 18:18
'select_folder', (folderName: string): boolean => this.selectFolder(folderName)
);
addSelectFolderAPIToInterface({
selectFolder: this.selectFolder,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably broken due to this shenanigans

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant