Pawel's Editor Scripts and UI collection

Here I will be sharing my Editor Scripts and UI :slight_smile:

I invite you to also share yours, directly or link it here :wink:

Also, share your ideas and wishes on what can be added!


I didn’t want to hijack this awesome place with @Jerakin’s Editor Script, but I will link it here for references:


Source:

I put them in a single repository. You can use them all by linking as Dependency in Defold, or copy and paste the editor scripts you find useful.

The license is MIT.

Don’t forget to click ProjectReload Editor Scripts or a shortcut Ctrl+Shift+R or Cmd+Shift+R.


GUI related scripts

gui-add-script :scroll:

It creates a .gui_script file and links it to the given.gui file immediately (to Script property).

  1. Right click on any .gui file in Assets.
  2. Select Add GUI Script.

add-gui-script

It really rarely happens that you create a .gui component file without a .gui_script, so I hope it will be useful :wink: When it will be possible to add command to a menu when clicked on a directory - I will add a script that add both .gui and .gui_script files in it.


gui-add-to-collection :window:

A more advanced version of the above functionality. It creates both .gui component and .gui_script files binded together and puts a game object with gui component with this gui directly in collection. It also has a UI popup, where you can type a name!

  1. Right click on root in your collection Outline pane.
  2. Select Add GUI to collection.
  3. Type in a name and click Enter.
  4. Click Create.

add-gui-collection


Those scripts can be easily suited to your needs - try to check out the code - modify for example strings, names or contents of files that are created, etc. :wink:

17 Likes

Added Sound related Editor Scripts and UI :partying_face: :notes:

You can reffer to it as v1.1 (added release on Github).

It gives you powerful capabilities over sound files in Defold (“prehear” sound, convert, etc), but it might be complex to install, because it relies on FFMPEG (but once installed it requires no additional actions).

Current scripts run only on Windows. OS-independent scripts (e.g. creating components) should work on all platforms. I might do Linux too in the future. MacOS PRs are welcomed.


Installation - FFmpeg dependency

Currently, there is no possibility to do anything with sounds in Editor Scripts, afaik. So I used powerful execute and utilised FFmpeg.

In order to use them, you have to install FFmpeg then. Download executables from:

https://www.ffmpeg.org/download.html

You can eventually add installation localization to PATH (windows).

On Windows you can also:

  1. Open Windows Powershell
  2. winget install ffmpeg
  3. Y to confirm
  4. Check installation path: where ffmpeg
    ( should give e.g. → C:\ffmpeg\bin\ffmpeg.exe)

On Linux you can (though scripts are Windows only - they need modifications to run on Linux):

  1. Open terminal
  2. sudo apt install ffmpeg (or sudo snap install ffmpeg)
  3. Y to confirm
  4. Check installation path: which -a ffmpeg
    (should give e.g. → /usr/bin/ffmpeg or /bin/ffmpeg)

If your path is different, please modify it in scripts (perhaps there should be a script to install ffmpeg and add its path here, but for now… heh :sweat_smile:) in the common ffmpeg_helper.lua module:

-- Adjust the paths if needed
local FFMPEG_PATH = "C:/ffmpeg/bin/ffmpeg.exe"
local FFPLAY_PATH = "C:/ffmpeg/bin/ffplay.exe"
local FFPROBE_PATH = "C:/ffmpeg/bin/ffprobe.exe"

FFplay and FFprobe dependency

Additionally, sound-play Editor Script utilizes ffplay and sound-cut utilizes ffprobe.
Ensure that ffplay and ffprobe comes with your installation. They might be in .../ffmpeg/bin/.
Check ffplay -version and ffprobe -version in terminal. If not, download them and copy there.

Editor Scripts


sound-convert :recycle:

It allows you to convert sound file(s) (.mp3, .wav., .ogg, .flac or .aac) to one of Defold compatible sound files (.wav, .ogg).

  1. Right click on any sound file (or selected multiple sound files).
  2. Select Convert Sound.
  3. Select output file format from a dropdown list (OGG or WAV)
  4. Click Convert

For each source file, it creates a file with the same name as a source file, in the same location, but with .wav / .ogg extension. Ogg file is at 44100 Hz.

sound-convert


sound-play :arrow_forward:

It allows you to “prehear” given sound. Plays .mp3, .wav, .ogg, .flac or .aac. It plays the sound once either until end of file or until the moment when the popup UI is closed.

  1. Right click on any sound file.
  2. Select Play

play_sound

P.S.
There are two versions of this script actually, but second is commented out:

  1. Play
    when you run it first time your OS might go crazy - it plays in background, but because of this, it requires your explicit permissions, e.g. Windows asks for permission to run from Unknown Publisher (sorry, it’s in Polish):

    You can uncheck this bottom checkbox saying "Always ask before opening this file" and it should never prompt again.
    Your antivirus might also block or quantine it - you can make an exception for it.
    opens terminal window additionally. You can then either close this window or closing the UI popup in Defold will also close it.
  2. Play in Terminal
    because of issues above, I leave there another version that is “safe” - plays in separate Terminal Window. If you like it more, you can use this (just comment out Play in Terminal command in the script).

I would love if someone could figure out and propose better solutions :smiley:


sound-cut :scissors:

It allows you to cut a subtrack out of the source track (.mp3, .wav, .ogg, .flac or .aac). It needs start and end timestamps and creates one subtrack saved into file of same format, where X is start (in seconds from original sound beginning) and Y is stop timestamp (in s).
end has to be larger than start.
end can’t be larger than source sound duration (provided as information in popup)

  1. Right click on any sound file.
  2. Select Cut Subtrack.
  3. Set Start Time and End Time timestamps (in seconds). Eventually change output file name.
  4. You can eventually “prehear” the cut subtrack by clicking Play Subtrack button. Close the popup to stop it playing.
  5. Click Extract to extract the cut subtrack to a file.

cut_sound

P.S. It checks for input validity and also asks if you want to overwrite if file with same name exists. Also, make sure you click “somewhere” after editing inputs - value is changed “on release” not on input changes, so before you click “Play Subtrack”, ensure the changed values are “in”.

P.P.S. I know, it would be great to have a visual waveform on a timeline with start and end markers for it to be convenient, but anyway - it simplifies this process a lot and you don’t need to explicitly use external programs :wink:


sound-component :loud_sound:

It allows you to create a Defold Sound Component out of a compatible sound file (.wav or .ogg).

  1. Right click on a sound file.
  2. Select Create Sound Component.
  3. Eventually change default properties.
  4. Click Create.

create_sound_comp

10 Likes

This is really opening up for some nice workflow additions and it makes me want more things exposed.

Great job!

2 Likes

I updated the library to 1.2:

Added Model components creation UI from GLTF files.

This allows to create Model component files in batch from a selection of GLTF file - all will be having the same material (pretty common use case, where you want to add e.g. multiple buildings assets, or characters, etc)
You can also access it from ProjectCreate Models from GLTF and define list of GLTF files on your own adding one by one or using Add Many that opens another popup to select multiple files at once (it automatically detects all GLTF files in the project).

models_from_gltf

Allowed Sound components to be created from multiple wav/ogg files in a convenient UI table.

Updated this editor script to also support creating multiple Sound component files at once - it will take only supported wav and ogg files from the selection and include them in a list. You can define for each gain, group, pan, etc.

sound-components

Allowed to “Add GUI Script” to multiple GUI Files

Also updated this script, so that now you can also select multiple .gui files and for each there will be created a .gui_script file and attached to it automatically.

Refactored code and added helpers.

Editor scripts are now in folder related to managed resources/domains, like “gui”, “model” and “sound”.

As many stuff in all editor_scripts will be repeating I separated helpers catalogue which includes:

  • ui_helper - some common UI related stuff, creating most popular UI widgets, helping with designing them, so it can also include some more advanced combinations of available widgets for common use cases (lists, tables, etc)
  • file_helper - operations on files, creating, reading, writing, deleting, checking for existence
  • string_helper - string operations, especially a lot of them related to path creation, modification and checks
  • log_helper - for printing info and errors in console
  • os_helper - for platform specific stuff
  • table_helper - for common table operations
  • ffmpeg_helper - for FFMPEG dependency, for the sound playing, cutting, etc

This will be for sure evolving and being refactored over time, but it’s already useful (used in all scripts), so it might be helpful for the community to make other scripts and UIs easier.

editor_scripts.md

There is a bonus file included in the repo, it’s a dump of the documentation and some other editor scripts for LLMs context, so if you want to get AI help on making editor scripts or UIs it might be useful. I used Codex for some of the stuff there and it was really useful as long as I was defining small refactor tasks and explaining rules and dependencies. It’s really helpful with tedious work, e.g. just tell it to “make spacing between those properties LARGE in X file” and it adds correct properties everywhere for you!

Moved License to a separate file.

So it nicely displays in Github. It’s MIT :wink:

10 Likes

Thank you, this is an absolute must-have tool for everyone.
It would be super awesome if we could have a store for this and other editor extensions and also for all the native extensions we talked about earlier. I think @AGulev had some preparations on GitHub for serving JSON.

2 Likes

Yes, we already have release related data in the asset JSONs and a header.json file with timestamps, so the JSONs can be requested as https://path_to_json?timestamp=... to take advantage of caching (not sure if editor scripts support request caching, though…) GitHub - defold/asset-portal: List of Defold assets, libraries and extensions

Another remaining task (certainly not the final one, there’s plenty to improve) is to publish it somewhere, for example on defold.com

3 Likes