2023-02-28 09:43:01 +01:00
|
|
|
function Node_Lua_Global(_x, _y, _group = noone) : 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;
|
|
|
|
|
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-09-07 20:59:14 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.codeLUA);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
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-03-07 14:29:47 +01:00
|
|
|
is_beginning = false;
|
2023-02-14 05:32:32 +01:00
|
|
|
error_notification = noone;
|
2023-01-04 02:30:04 +01:00
|
|
|
compiled = false;
|
|
|
|
|
2023-11-23 02:32:26 +01:00
|
|
|
static stepBegin = function() { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _type = getInputData(1);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
if(PROJECT.animator.is_playing && PROJECT.animator.frame_progress && (CURRENT_FRAME == 0 || _type == 1))
|
2023-01-04 02:30:04 +01:00
|
|
|
setRenderStatus(false);
|
|
|
|
|
|
|
|
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-11-23 02:32:26 +01:00
|
|
|
} #endregion
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-11-23 02:32:26 +01:00
|
|
|
static getState = function() { #region
|
2023-10-27 13:55:31 +02:00
|
|
|
if(inputs[| 2].isLeaf()) return lua_state;
|
2023-01-04 02:30:04 +01:00
|
|
|
return inputs[| 2].value_from.node.getState();
|
2023-11-23 02:32:26 +01:00
|
|
|
} #endregion
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-11-23 02:32:26 +01:00
|
|
|
static onValueFromUpdate = function(index) { #region
|
2023-01-09 03:14:20 +01:00
|
|
|
if(index == 0 || index == 2) compiled = false;
|
2023-11-23 02:32:26 +01:00
|
|
|
} #endregion
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-11-23 02:32:26 +01:00
|
|
|
static onValueUpdate = function(index = 0) { #region
|
2023-01-09 03:14:20 +01:00
|
|
|
if(index == 0 || index == 2) compiled = false;
|
2023-11-23 02:32:26 +01:00
|
|
|
} #endregion
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-11-23 02:32:26 +01:00
|
|
|
static update = function(frame = CURRENT_FRAME) { #region
|
2023-01-04 02:30:04 +01:00
|
|
|
if(!compiled) return;
|
2023-07-06 19:49:16 +02:00
|
|
|
//if(!PROJECT.animator.is_playing || !PROJECT.animator.frame_progress) return;
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var _code = getInputData(0);
|
|
|
|
var _type = getInputData(1);
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
//if(CURRENT_FRAME == 0) { //rerfesh state on the first frame
|
2023-03-11 01:40:17 +01:00
|
|
|
// lua_state_destroy(lua_state);
|
|
|
|
// lua_state = lua_create();
|
|
|
|
// addCode();
|
|
|
|
//}
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-03-08 07:35:51 +01:00
|
|
|
lua_projectData(getState());
|
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
if(CURRENT_FRAME == 0 || _type == 1) {
|
2023-05-08 10:50:42 +02:00
|
|
|
try { lua_add_code(getState(), _code); }
|
|
|
|
catch(e) { noti_warning(exception_print(e),, self); }
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
2023-11-23 02:32:26 +01:00
|
|
|
} #endregion
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-11-23 02:32:26 +01:00
|
|
|
static onInspector1Update = function() { #region
|
2023-03-19 09:17:39 +01:00
|
|
|
var thrd = inputs[| 2].value_from;
|
|
|
|
if(thrd == noone) {
|
|
|
|
doCompile();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-28 06:58:28 +02:00
|
|
|
thrd.node.onInspector1Update();
|
2023-11-23 02:32:26 +01:00
|
|
|
} #endregion
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-11-23 02:32:26 +01:00
|
|
|
static doCompile = function() { #region
|
2023-01-04 02:30:04 +01:00
|
|
|
compiled = true;
|
|
|
|
|
2023-12-19 14:30:34 +01:00
|
|
|
for( var i = 0; i < array_length(outputs[| 0].value_to); i++ ) {
|
|
|
|
var _j = outputs[| 0].value_to[i];
|
2023-01-04 02:30:04 +01:00
|
|
|
if(_j.value_from != outputs[| 0]) continue;
|
2023-03-19 09:17:39 +01:00
|
|
|
_j.node.doCompile();
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
doUpdate();
|
2023-11-23 02:32:26 +01:00
|
|
|
} #endregion
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2023-11-23 02:32:26 +01:00
|
|
|
static doApplyDeserialize = function() { doCompile(); }
|
|
|
|
|
|
|
|
static onDestroy = function() { #region
|
2023-03-08 07:35:51 +01:00
|
|
|
lua_state_destroy(lua_state);
|
2023-02-14 05:32:32 +01:00
|
|
|
if(error_notification != noone)
|
|
|
|
noti_remove(error_notification);
|
2023-11-23 02:32:26 +01:00
|
|
|
} #endregion
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|