fireclawthefox / FRAME

The modular Game Editor for Panda3D
BSD 2-Clause "Simplified" License
15 stars 2 forks source link

A way to add Custom Editors #2

Closed raytopianprojects closed 2 years ago

raytopianprojects commented 2 years ago

One thing that could be nice is the ability to add custom editors to FRAME by simply hitting a button a selecting a folder that contains the relevant Python code. A use case for this is people who want custom tooling that may not be in the base distribution. For instance I was thinking of making a Terrain/Foliage editor since I do a lot of Photogrammetry stuff.

I'm more then will to contribute to make this happen.

fireclawthefox commented 2 years ago

This is actually a thing I did have in mind while working on it and will definitely implement soon to also make my and other contributors life simpler to add new editors. The main parts that are missing is a definition for the way of how to define new editors which is a thing I wanted to do after implementing some editors to see what would be important and of course changing the hardcoded parts to use these definition files which would be quite simple. Now that I have multiple editors, I can probably tackle this task.

As for the way of defining editors, I do have a json file format in mind, since that would be easy to create and read. But I'm also open for other ideas.

raytopianprojects commented 2 years ago

JSON would work amazing!

fireclawthefox commented 2 years ago

I've thought about the JSON format and I the following is an example of what I came up with so far which will include all current requirements and some future ones.

{
    "name":"Scene Editor",
    "module":"SceneEditor.SceneEditor",
    "class":"SceneEditor",
    "configToEnable":"frame-enable-scene-editor",
    "order":10,
    "icon":"EditorSelectionSE.png",
    "fileExtension":".scene",
    "extraArgsFunc":"",
    "extraArgs":[]
}

I think most of them are self-explanatory. The extraArgsFunc will be used to call a function to get arguments to be passed to the editor at initialization. Currently there's only one editor requiring extra arguments so this may be extended in the future as needed. The extraArgs will be a list of whatever is given which will be passed as is to the editor. If both are given, I may join them together somehow, but not sure yet. The icon will be loaded relative to the location of the json file.

Having one JSON definition file per editor is probably the way I will go to not have to fiddle with one global definition that needs to be updated by each installed editor. I'm a little uncertain where to put those files though, at best, they would be shipped with the distribution of the editor, which would mostly be PyPi. Though, searching through all pip installed packages for editor definitions is probably not good so I thought about one or more configurable folders to put these in. These folders should probably reside somewhere in the users home folder as in multiuser installments, different editors may be installed for different users.

I will look around and see if I can find a good solution for that, until then, ideas and recommendations are welcome.

fireclawthefox commented 2 years ago

Alright, a first version for adding custom editors is up. I've decided to put the definition files in two folders for now, one would be in the editors source root in an editors folder and additionally, in ~/.FRAME/editors/ In the future I may also add a config variable to add further custom folders, but I think for now, this will be good. Also I've extended the readme for how to create and add custom editors.

I hope this will be suffice for you to be able to create your Terrain and Foliage editor. If you need any advice or help creating the editor just let me know, looking forward to see your results.

In case you need something special for instantiating your editor in the FRAME, just reopen this feature issue or create a new one.

Also, thanks for sharing your thoughts and ideas.