Extending Editor API

If we have a set of operations that we would like to add to the core editor API, then we can create a new file in the editor /api root folder, named properly. The layout of the file will need to follow this pattern (example some decal editing API):

lua/ge/extensions/editor/api/myspecial.lua:

-- we declare the editor local table reference local editor
local editor

-- some function, note the local
local function selectDecalTemplate(name)
  -- code here
end
local function createDecalTemplate(decal)
  -- code here
end
local  function  deleteDecalTemplate(name)
  -- code here
end
-- this function is called in the main editor init function,
-- the argument is a reference to the main editor table where
-- you can add your functions
local function initialize(editorInstance)
  -- we keep a ref for ourselves to use it in our local functions
  editor = editorInstance
  -- add our functions to the main editor table
  editor.selectDecalTemplate = selectDecalTemplate
  editor.createDecalTemplate = createDecalTemplate
  editor.deleteDecalTemplate = deleteDecalTemplate
end

-- return this simple table which contains only the initialize function
local M = {}
M.initialize = initialize

return M

After we have written this file, we need to add it to the main editor initialize function. For this, open for edit the /lua/ge/extensions/editor/main.lua and add the proper lines in the initialize function:

-- this will create a table instance with your module
M.mySpecialModule = require("editor/api/myspecial")

-- this will call the module's initialize function with
-- the M argument which is the actual editor table
M.mySpecialModule.initialize(M)

So, from now on your functions can be called from anywhere, as editor.selectDecalTemplate(...)

The core logic of the tools are kept as these modules, no GUI code inside them, just pure operations over the data. The tools GUI found in the /lua/ge/extensions/editor/ are using the various APIs found in these modules to operate over the game data.

Last modified: December 7, 2021

Any further questions?

Join our discord
Our documentation is currently incomplete and undergoing active development. If you have any questions or feedback, please visit this forum thread.