Editor Scripts šŸ”„: Alpha Release

Since it looks like people are posting their editor scripts here, I figured Iā€™d chip in and post my lifecycle script that auto-implements this fix for slow HTML5 bundles on certain browsers. The only caveat is that you have to output the bundle into the project directory so Lua can access it. Iā€™m also not very experienced with IO and string manipulation, so feel free to suggest improvements! Anyways, here it is:

Code
local M = {}

local function read(file)
    local data = ""
    for l in file:lines() do
        data = data .. l .. "\n"
    end
    return data
end

function M.on_bundle_finished(opts)
    if opts.platform == "js-web" and opts.success then
        local title = sys.get_config("project.title", "Desktop Game")
        local file = io.open(opts.output_directory .. "/" .. title .. "/index.html", "r")
        local fixed = string.gsub(read(file), "engine_arguments: %[%]", "engine_arguments: [\"--verify-graphics-calls=false\"]")
        file:close()

        file = io.open(opts.output_directory .. "/" .. title .."/index.html", "wb")
        file:write(fixed)
        file:flush()
        file:close()
    end
end

return M
5 Likes

editor-script-lua-format - Format your Lua code!

Adds a right click context menu item ā€œFormat Documentā€ for .lua, .script, .editor_script, .render_script, .gui_script files to format them with lua-format.

Installation

Download repo as .zip, simply copy ā€œeditor-script-lua-formatā€ folder to your project and reload editor scripts. Done!

Known Issues

  • Not tested yet on Linux and macOS.
  • Binary executable files are from vscode-lua-format repo.
  • Canā€™t be used as dependency library :sob:. Simply copy paste the script folder into your project.

Changelog

2020-01-11: I added Git pre-commit hook sample to the repo. It formats staged Lua files to keep your code fabulous!
2020-01-13: Binary executable files are built using Travis CI and AppVeyor.

4 Likes

Why? Ah, because of the binary file you need to run to format the code?

Thatā€™s great!
Shame that we donā€™t support binaries in dependencies, seems like a very demanded featureā€¦

3 Likes

Maybe disallow it for lib ones but do allow it for ones actually in the project folder? Or is that how it already is?

1 Like

Yes, because of that.

Yes, itā€™s already that.

1 Like

I added Git pre-commit hook sample to the repo. It formats staged Lua files to keep your code fabulous :smile:

1 Like

Why donā€™t we support that?
Itā€™s a zip file, and it supports exe files. Do we do something special in the editor to remove executables?
@vlaaad @britzl

4 Likes

We donā€™t do anything special to prevent using binaries from dependencies, itā€™s just not possible currently because dependent library is a zip file, and to execute binary we need to extract it first from the archive.

4 Likes

Ah, good point.
Well, so if weā€™d add a method to write a resource out to disc, one could then execute it.

4 Likes

Feature request:
ā€œadd shortcuts (hotkeys) for editor scriptsā€
Would be useful for scripts that work with nodes transformation (ordering, aligns, transform reset etc).

12 Likes

A little collection of editor scripts for isometric scene:

Grab it here:

This is what I would like hotkeys for.

14 Likes

We need a right click context menu in the viewport. :slight_smile:

3 Likes

as variant, this dramatically reduces a day cursor movement :slight_smile:

2 Likes

Also in the text editor with the items from the ā€œEditā€ menu.

2 Likes

The one I would love the most to get personally is still editor.get(id, "parent") #2815. It would make quite a lot more stuff possible, a ā€œbig bang for the buckā€ :stuck_out_tongue: .

8 Likes

It would be useful to have a builtin Editor Scripts way to create folders so we donā€™t have to use actions / other scripts.

2 Likes

Iā€™ve come upon the issue where JDK locks the a file that was opened and closed with Lua io.open() in Editor Scripts which means I canā€™t delete the touched file until closing the editor or using a file unlocker tool. If I try to delete the file from the editor it shows a dialog but does nothing, if I try to delete it from the OS it warns that JDK is using it.

2 Likes

Edited 22-07-2022: take a look at the upgraded version of the script ā†’ Defold Shaders (2021 shader practice / learning edition) - #4 by Pkeod

I use Mali Offline Compiler wrapped into Editor Script to avoid bugs/mistakes, and to test the performance of shaders.

image

The source code is here: Editor script for Defold IDE. The script adds the menu items "Compile Fragment Shader" and "Compile Vertex Shader" for .fp/.vp files. Ā· GitHub

*Only for Windows. If someone is going to use it, I will add paths to ā€œmaliocā€ for macOS/Linux.

12 Likes

Hi, Iā€™m trying to do the same thing (3 years after :sweat_smile:), creating an empty folder using an editor script function. Did you ever manage to solve it by any chance and have some knowledge to share?
Thank you!