From b422fdcf65c6c4255d080315448589594f126889 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Thu, 23 May 2024 19:40:30 +0700 Subject: [PATCH] undo data refresh --- scripts/node_keyframe/node_keyframe.gml | 16 +++++++++------- scripts/node_lua_compute/node_lua_compute.gml | 8 ++++++-- scripts/node_lua_global/node_lua_global.gml | 8 ++++++-- scripts/node_lua_surface/node_lua_surface.gml | 8 ++++++-- scripts/node_struct/node_struct.gml | 17 +++++++++-------- scripts/node_switch/node_switch.gml | 8 +++----- scripts/node_value/node_value.gml | 2 ++ 7 files changed, 41 insertions(+), 26 deletions(-) diff --git a/scripts/node_keyframe/node_keyframe.gml b/scripts/node_keyframe/node_keyframe.gml index e8206707a..f6e6bbdd4 100644 --- a/scripts/node_keyframe/node_keyframe.gml +++ b/scripts/node_keyframe/node_keyframe.gml @@ -444,6 +444,8 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor { static insertKey = function(_key, _index) { ds_list_insert(values, _index, _key); } + function onUndo() { updateKeyMap(); prop.triggerSetFrom(); } + static setKeyTime = function(_key, _time, _replace = true, record = false) { #region if(!ds_list_exist(values, _key)) return 0; if(_key.time == _time && !_replace) return 0; @@ -482,7 +484,7 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor { setKeyTime(data.key, data.time, false); data.time = _prevTime; - }, { key : _key, time : _prevTime }); + }, { key : _key, time : _prevTime }, onUndo); ds_list_insert(values, i, _key); if(_replace) updateKeyMap(); @@ -494,7 +496,7 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor { setKeyTime(data.key, data.time, false); data.time = _prevTime; - }, { key : _key, time : _prevTime }); + }, { key : _key, time : _prevTime }, onUndo); ds_list_add(values, _key); if(_replace) updateKeyMap(); @@ -536,7 +538,7 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor { if(isEqual(values[| 0].value, _val)) return false; - if(_record) recordAction(ACTION_TYPE.var_modify, values[| 0], [ values[| 0].value, "value", prop.name ]); + if(_record) recordAction(ACTION_TYPE.var_modify, values[| 0], [ values[| 0].value, "value", prop.name ], onUndo); values[| 0].value = _val; return true; @@ -545,7 +547,7 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor { if(ds_list_size(values) == 0) { // Should not be called normally var k = new valueKey(_time, _val, self, ease_in, ease_out); ds_list_add(values, k); - if(_record) recordAction(ACTION_TYPE.list_insert, values, [ k, ds_list_size(values) - 1, $"add {prop.name} keyframe" ], function() { updateKeyMap(); }); + if(_record) recordAction(ACTION_TYPE.list_insert, values, [ k, ds_list_size(values) - 1, $"add {prop.name} keyframe" ], onUndo); return true; } @@ -555,7 +557,7 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor { if(!global.FLAG.keyframe_override) return false; if(_key.value != _val) { - if(_record) recordAction(ACTION_TYPE.var_modify, _key, [ _key.value, "value", prop.name ]); + if(_record) recordAction(ACTION_TYPE.var_modify, _key, [ _key.value, "value", prop.name ], onUndo); _key.value = _val; return true; } @@ -563,14 +565,14 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor { } else if(_key.time > _time) { var k = new valueKey(_time, _val, self, ease_in, ease_out); ds_list_insert(values, i, k); - if(_record) recordAction(ACTION_TYPE.list_insert, values, [k, i, $"add {prop.name} keyframe" ], function() { updateKeyMap(); }); + if(_record) recordAction(ACTION_TYPE.list_insert, values, [k, i, $"add {prop.name} keyframe" ], onUndo); updateKeyMap(); return true; } } var k = new valueKey(_time, _val, self, ease_in, ease_out); - if(_record) recordAction(ACTION_TYPE.list_insert, values, [ k, ds_list_size(values), $"add {prop.name} keyframe" ], function() { updateKeyMap(); }); + if(_record) recordAction(ACTION_TYPE.list_insert, values, [ k, ds_list_size(values), $"add {prop.name} keyframe" ], onUndo); ds_list_add(values, k); updateKeyMap(); return true; diff --git a/scripts/node_lua_compute/node_lua_compute.gml b/scripts/node_lua_compute/node_lua_compute.gml index bbb04ca38..eaead61e1 100644 --- a/scripts/node_lua_compute/node_lua_compute.gml +++ b/scripts/node_lua_compute/node_lua_compute.gml @@ -191,7 +191,11 @@ function Node_Lua_Compute(_x, _y, _group = noone) : Node(_x, _y, _group) constru doCompile(); } #endregion - static onDestroy = function() { #region + static onDestroy = function() { lua_state_destroy(lua_state); - } #endregion + } + + static onRestore = function() { + lua_state = lua_create(); + } } \ No newline at end of file diff --git a/scripts/node_lua_global/node_lua_global.gml b/scripts/node_lua_global/node_lua_global.gml index 358bf2bd5..615137b14 100644 --- a/scripts/node_lua_global/node_lua_global.gml +++ b/scripts/node_lua_global/node_lua_global.gml @@ -36,7 +36,11 @@ function Node_Lua_Global(_x, _y, _group = noone) : Node(_x, _y, _group) construc catch(e) { noti_warning(exception_print(e),, self); } } #endregion - static onDestroy = function() { #region + static onDestroy = function() { lua_state_destroy(lua_state); - } #endregion + } + + static onRestore = function() { + lua_state = lua_create(); + } } \ No newline at end of file diff --git a/scripts/node_lua_surface/node_lua_surface.gml b/scripts/node_lua_surface/node_lua_surface.gml index 924614732..403fbbd1c 100644 --- a/scripts/node_lua_surface/node_lua_surface.gml +++ b/scripts/node_lua_surface/node_lua_surface.gml @@ -191,7 +191,11 @@ function Node_Lua_Surface(_x, _y, _group = noone) : Node(_x, _y, _group) constru doCompile(); } #endregion - static onDestroy = function() { #region + static onDestroy = function() { lua_state_destroy(lua_state); - } #endregion + } + + static onRestore = function() { + lua_state = lua_create(); + } } \ No newline at end of file diff --git a/scripts/node_struct/node_struct.gml b/scripts/node_struct/node_struct.gml index 4cb77562e..762305902 100644 --- a/scripts/node_struct/node_struct.gml +++ b/scripts/node_struct/node_struct.gml @@ -24,12 +24,11 @@ function Node_Struct(_x, _y, _group = noone) : Node(_x, _y, _group) constructor ds_list_add(_in, inputs[| i]); for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) { - if(getInputData(i) != "") { + var _val = inputs[| i].getValue(); + + if(_val != "") { ds_list_add(_in, inputs[| i + 0]); ds_list_add(_in, inputs[| i + 1].setVisible(false, true)); - } else { - delete inputs[| i + 0]; - delete inputs[| i + 1]; } } @@ -44,12 +43,12 @@ function Node_Struct(_x, _y, _group = noone) : Node(_x, _y, _group) constructor static onValueUpdate = function(index = 0) { if(LOADING || APPENDING) return; - - refreshDynamicInput(); - if(index < 0) return; + if(safe_mod(index - input_fix_len, data_length) == 0) - inputs[| index + 1].name = getInputData(index) + " value"; + inputs[| index + 1].name = $"{getInputData(index)} value"; + + refreshDynamicInput(); } static step = function() { @@ -68,6 +67,8 @@ function Node_Struct(_x, _y, _group = noone) : Node(_x, _y, _group) constructor var val = getInputData(i + 1); var frm = inputs[| i + 1].value_from; + if(key == "") continue; + if(frm != noone && frm.type == VALUE_TYPE.surface) str[$ key] = new Surface(val); else if(frm != noone && frm.type == VALUE_TYPE.buffer) diff --git a/scripts/node_switch/node_switch.gml b/scripts/node_switch/node_switch.gml index 7896bc3ad..7ad1a72c3 100644 --- a/scripts/node_switch/node_switch.gml +++ b/scripts/node_switch/node_switch.gml @@ -40,16 +40,13 @@ function Node_Switch(_x, _y, _group = noone) : Node(_x, _y, _group) constructor array_resize(input_display_list, input_display_len); for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) { - if(getInputData(i) != "") { + if(inputs[| i].getValue() != "") { ds_list_add(_in, inputs[| i + 0]); ds_list_add(_in, inputs[| i + 1]); inputs[| i + 1].setVisible(false, true); array_push(input_display_list, i + 0); array_push(input_display_list, i + 1); - } else { - delete inputs[| i + 0]; - delete inputs[| i + 1]; } } @@ -64,6 +61,7 @@ function Node_Switch(_x, _y, _group = noone) : Node(_x, _y, _group) constructor static onValueFromUpdate = function(index) { #region if(LOADING || APPENDING) return; + if(index < 0) return; inputs[| 1].setType(inputs[| 1].value_from? inputs[| 1].value_from.type : VALUE_TYPE.any); @@ -79,7 +77,7 @@ function Node_Switch(_x, _y, _group = noone) : Node(_x, _y, _group) constructor if(LOADING || APPENDING) return; if(safe_mod(index - input_fix_len, data_length) == 0) //Variable name - inputs[| index + 1].name = getInputData(index) + " value"; + inputs[| index + 1].name = $"{getInputData(index)} value"; refreshDynamicInput(); } #endregion diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index fc3a2b7ea..52548d294 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -2163,6 +2163,8 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru return controlNode.rendered; } #endregion + static triggerSetFrom = function() { node.valueUpdate(index); } + static setFrom = function(_valueFrom, _update = true, checkRecur = true, log = false) { #region ////Set from //print($"Connecting {_valueFrom.name} to {name}");