2023-01-04 02:30:04 +01:00
|
|
|
function Node_Lua_Global(_x, _y, _group = -1) : Node(_x, _y, _group) constructor {
|
2023-01-25 06:49:00 +01:00
|
|
|
name = "Lua Global";
|
2023-01-04 02:30:04 +01:00
|
|
|
preview_channel = 1;
|
|
|
|
previewable = false;
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Lua code", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "", o_dialog_lua_reference)
|
2023-01-04 02:30:04 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.code);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 1] = nodeValue("Run order", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
2023-01-04 02:30:04 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "On start", "Every frame" ]);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 2] = nodeValue("Execution thread", self, JUNCTION_CONNECT.input, VALUE_TYPE.node, noone)
|
2023-01-04 02:30:04 +01:00
|
|
|
.setVisible(false, true);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0] = nodeValue("Execution thread", self, JUNCTION_CONNECT.output, VALUE_TYPE.node, noone );
|
2023-01-04 02:30:04 +01:00
|
|
|
|
|
|
|
input_display_list = [
|
|
|
|
["Main", false], 2, 1, 0,
|
2023-01-09 03:14:20 +01:00
|
|
|
];
|
2023-01-04 02:30:04 +01:00
|
|
|
|
|
|
|
lua_state = lua_create();
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
error_notification = noone;
|
2023-01-04 02:30:04 +01:00
|
|
|
compiled = false;
|
|
|
|
|
|
|
|
static stepBegin = function() {
|
|
|
|
var _type = inputs[| 1].getValue();
|
|
|
|
|
|
|
|
if(ANIMATOR.frame_progress && (ANIMATOR.current_frame == 0 || _type == 1)) {
|
|
|
|
setRenderStatus(false);
|
|
|
|
UPDATE |= RENDER_TYPE.partial;
|
|
|
|
}
|
|
|
|
|
|
|
|
setHeight();
|
|
|
|
doStepBegin();
|
|
|
|
|
|
|
|
value_validation[VALIDATION.error] = !compiled;
|
2023-02-14 05:32:32 +01:00
|
|
|
if(!compiled && error_notification == noone) {
|
|
|
|
error_notification = noti_error("Lua node [" + string(name) + "] not compiled.");
|
|
|
|
error_notification.onClick = function() { PANEL_GRAPH.focusNode(self); };
|
|
|
|
}
|
|
|
|
|
|
|
|
if(compiled && error_notification != noone) {
|
|
|
|
noti_remove(error_notification);
|
|
|
|
error_notification = noone;
|
|
|
|
}
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static getState = function() {
|
|
|
|
if(inputs[| 2].value_from == noone)
|
|
|
|
return lua_state;
|
|
|
|
return inputs[| 2].value_from.node.getState();
|
|
|
|
}
|
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
static onValueFromUpdate = function(index) {
|
|
|
|
if(index == 0 || index == 2) compiled = false;
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
static onValueUpdate = function(index = 0) {
|
2023-01-09 03:14:20 +01:00
|
|
|
if(index == 0 || index == 2) compiled = false;
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
static update = function(frame = ANIMATOR.current_frame) {
|
2023-01-04 02:30:04 +01:00
|
|
|
if(!compiled) return;
|
|
|
|
|
|
|
|
var _code = inputs[| 0].getValue();
|
|
|
|
|
|
|
|
try {
|
|
|
|
lua_add_code(getState(), _code);
|
|
|
|
} catch(e) {
|
2023-01-25 06:49:00 +01:00
|
|
|
noti_warning(exception_print(e),, self);
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
static onInspectorUpdate = function() { //compile
|
2023-01-04 02:30:04 +01:00
|
|
|
var _code = inputs[| 0].getValue();
|
|
|
|
compiled = true;
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(outputs[| 0].value_to); i++ ) {
|
|
|
|
var _j = outputs[| 0].value_to[| i];
|
|
|
|
if(_j.value_from != outputs[| 0]) continue;
|
|
|
|
_j.node.inspectorUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
doUpdate();
|
|
|
|
}
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
static onDestroy = function() {
|
|
|
|
if(error_notification != noone)
|
|
|
|
noti_remove(error_notification);
|
|
|
|
}
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|