-
Notifications
You must be signed in to change notification settings - Fork 6
Custom Nodes
The Editor supports an experimental feature for adding basic user-made custom nodes without the need to recompile the entire editor. More complex nodes will be supported in future updates (as well as image loading for toolbox and nodes in the tree).
!!Warning!! This is a very experimental feature at the moment, expect some crashes or disfunction, do NOT use it for full-fledged projects.
Another warning: Since this system uses a sandbox for loading lua files into the editor, be careful where you download custom nodes as the current system is not (yet) made to be secure. These lua files can inject malicious code.
This page is updated for LuaSTG Editor Sharp-X 0.75.1.
You can create a new node by creating a <node name>.lua file inside the /CustomNodes/ folder (where the Init.lua file is.)
After creating this file, open Init.lua. In the InitNodes() function, you can see a Registered_Nodes table. Put your node file name in this table.
Example (with a file named MyNode.lua):
local Registered_Nodes = {
"Example Node 1",
"_Separator",
"MyNode"
}You can put the file name with or without the .lua file extension.
You can see a _Separator string, this is for separating node blocks (put a space between two nodes). This is a registered node name, don't name any of your node like this.
For your node to work, it needs to have 5 functions:
-
InitNode()- The node initialize function (node name, icon, parameters, ...) -
ToLuaHead()- The code at the head of the node. -
ToLuaBody()- The core code of the node, this is what you most likely want to edit. -
ToLuaTail()- The code at the end of the node. -
ToString()- What will be displayed on the editor when you add this node to your project.
All those functions MUST return a string except for the InitNode() function which must return a table.
The InitNode function is the core of your node, this is where you will put the name displayed on the editor, the icon on the toolbox and the node parameters/arguments.
Example properties table:
local properties = {
name = "My Node",
image = "folder.png",
isLeaf = true, -- (Upcoming in 0.75.2)
Parameters = {
{"Unit", "self", "target"},
{"Position", "0,0", "position"}
}
}
return propertiesLet's look at this line by line.
-
name(string) is the name displayed on the toolbox when you hover the icon. -
image(string) is the icon displayed on the toolbox for this node. Currently, it doesn't support custom images, only already existing node images (this will be added in the future) -
isLeaf(Upcoming in 0.75.2) (boolean) is an optional value, if set to true, this node won't be able to have children nodes. -
Parameters(table) is the table of the node parameters. Inside this table, you must put tables with 3 arguments, in order:name of the parameter,the default value,the input window type(see )
After populating this table, return it.
For the Parameters's input window type, it can be one of those:
-
bool- A boolean (trueoffalse) -
bubble_style- The dialog bubble style (normal, thinking, ...) -
sineinterpolation- Accel, decel or both -
target- The object target (self, last, unit, ...) -
yield- Only used for the_infinitevariable -
nullabletarget- Same astargetbut with a blank string -
blend- Object blend options ("", "mul+add", "mul+alpha", ...) -
event- The object event type (frame, kill, del, colli). Don't use this for therenderevent -
interpolation- Ease interpolation (normal, accel, decel, acc_dec) -
modification- Type of operation (set, add, mul, ...) -
group- The object's group (GHOST, ENEMY, PLAYER, ...) -
layer- The object's layer (BG-5, BG, BG+5, ...) -
stageGroup- The difficulty options (Easy, Normal, Hard, ...) -
objDifficulty- Same asstageGroupbut with theAlloption -
difficulty- Same asstageGroupbut in anintformat (1 = Easy, 2 = Normal, ...) -
SCName- The spell card default names -
bulletStyle- Bullet selector screen -
laserStyle- Same asbulletStylebut for lasers -
alignInput- Alignment for text (or images) -
color- A color selector -
nullableColor- Same ascolorbut with a blank color -
objimage- The default built-in images (img_void, white, leaf) -
image- Same asobjimage(why?) -
BG- Built-in THlib stage backgrounds -
prop- Object's properties (x, y, rot, timer, ...) -
valprop- Same aspropbut with less options -
se- Built-in sound effects -
seWithQuotes- Same assebut with quotes around the options' values -
item- Built-in THlib items -
lrstr- Left or Right -
directionMode- Direction movement mode, most likely used for mouvement nodes (boss wander, ...) -
curve- Bezier, CR or Basis2 -
renderOp- Rendering operations (push or pop) -
warptarget- Capture or Apply (most likely used for shaders) -
viewmode- Used for changing the view mode of the game (interface, world or background) -
viewpoint- 3D background camera parameters.
This is the bases, there is a little bit more, you can see more of them in LuaSTGNode.Legacy.Windows/InputWindowSelectorRegister.cs in the source code.
Those functions are here to transform your node into lua code when compiling your project.
They MUST return a string object containing your lua code.
Example ToLuaBody() (this is the same principle for all three functions):
function ToLuaBody()
local lua_code = [===[-- Put the lua code here.
{0}.x, {0}.y = {1}
-- Example Comment.
]===]
return lua_code
endThis function creates a string and returns it.
"What is going on the {}?" you ask?
This is not the usual behaviour of lua. This is a string formatting special character. The numbers inside the {} are the indexes of the parameters' values IN THE ORDER YOU PUT THEM IN InitNode().
That means that in this case, {0}.x, {0}.y = {1} is equal to <Unit>.x, <Unit>.y = <Position>. You can have as many parameters as you want, but be careful in the order you use them. If you change the order of the parameters, your node will throw a Mismatched Attribute error and won't compile.
This function works the same way as ToLuaHead/Body/Tail() but is used to display a string in the editor.
Example:
function ToString()
local node_description = "Sets {0}'s position to ({1})"
return node_description
endFor example, this will display Sets self's position to (0, 120) in the node tree.