undo data refresh

This commit is contained in:
Tanasart 2024-05-23 19:40:30 +07:00
parent ef2d8aaa2f
commit b422fdcf65
7 changed files with 41 additions and 26 deletions

View file

@ -444,6 +444,8 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor {
static insertKey = function(_key, _index) { ds_list_insert(values, _index, _key); } 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 static setKeyTime = function(_key, _time, _replace = true, record = false) { #region
if(!ds_list_exist(values, _key)) return 0; if(!ds_list_exist(values, _key)) return 0;
if(_key.time == _time && !_replace) 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); setKeyTime(data.key, data.time, false);
data.time = _prevTime; data.time = _prevTime;
}, { key : _key, time : _prevTime }); }, { key : _key, time : _prevTime }, onUndo);
ds_list_insert(values, i, _key); ds_list_insert(values, i, _key);
if(_replace) updateKeyMap(); if(_replace) updateKeyMap();
@ -494,7 +496,7 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor {
setKeyTime(data.key, data.time, false); setKeyTime(data.key, data.time, false);
data.time = _prevTime; data.time = _prevTime;
}, { key : _key, time : _prevTime }); }, { key : _key, time : _prevTime }, onUndo);
ds_list_add(values, _key); ds_list_add(values, _key);
if(_replace) updateKeyMap(); if(_replace) updateKeyMap();
@ -536,7 +538,7 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor {
if(isEqual(values[| 0].value, _val)) if(isEqual(values[| 0].value, _val))
return false; 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; values[| 0].value = _val;
return true; 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 if(ds_list_size(values) == 0) { // Should not be called normally
var k = new valueKey(_time, _val, self, ease_in, ease_out); var k = new valueKey(_time, _val, self, ease_in, ease_out);
ds_list_add(values, k); 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; return true;
} }
@ -555,7 +557,7 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor {
if(!global.FLAG.keyframe_override) return false; if(!global.FLAG.keyframe_override) return false;
if(_key.value != _val) { 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; _key.value = _val;
return true; return true;
} }
@ -563,14 +565,14 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor {
} else if(_key.time > _time) { } else if(_key.time > _time) {
var k = new valueKey(_time, _val, self, ease_in, ease_out); var k = new valueKey(_time, _val, self, ease_in, ease_out);
ds_list_insert(values, i, k); 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(); updateKeyMap();
return true; return true;
} }
} }
var k = new valueKey(_time, _val, self, ease_in, ease_out); 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); ds_list_add(values, k);
updateKeyMap(); updateKeyMap();
return true; return true;

View file

@ -191,7 +191,11 @@ function Node_Lua_Compute(_x, _y, _group = noone) : Node(_x, _y, _group) constru
doCompile(); doCompile();
} #endregion } #endregion
static onDestroy = function() { #region static onDestroy = function() {
lua_state_destroy(lua_state); lua_state_destroy(lua_state);
} #endregion }
static onRestore = function() {
lua_state = lua_create();
}
} }

View file

@ -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); } catch(e) { noti_warning(exception_print(e),, self); }
} #endregion } #endregion
static onDestroy = function() { #region static onDestroy = function() {
lua_state_destroy(lua_state); lua_state_destroy(lua_state);
} #endregion }
static onRestore = function() {
lua_state = lua_create();
}
} }

View file

@ -191,7 +191,11 @@ function Node_Lua_Surface(_x, _y, _group = noone) : Node(_x, _y, _group) constru
doCompile(); doCompile();
} #endregion } #endregion
static onDestroy = function() { #region static onDestroy = function() {
lua_state_destroy(lua_state); lua_state_destroy(lua_state);
} #endregion }
static onRestore = function() {
lua_state = lua_create();
}
} }

View file

@ -24,12 +24,11 @@ function Node_Struct(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
ds_list_add(_in, inputs[| i]); ds_list_add(_in, inputs[| i]);
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) { 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 + 0]);
ds_list_add(_in, inputs[| i + 1].setVisible(false, true)); 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) { static onValueUpdate = function(index = 0) {
if(LOADING || APPENDING) return; if(LOADING || APPENDING) return;
if(index < 0) return;
if(safe_mod(index - input_fix_len, data_length) == 0)
inputs[| index + 1].name = $"{getInputData(index)} value";
refreshDynamicInput(); refreshDynamicInput();
if(index < 0) return;
if(safe_mod(index - input_fix_len, data_length) == 0)
inputs[| index + 1].name = getInputData(index) + " value";
} }
static step = function() { 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 val = getInputData(i + 1);
var frm = inputs[| i + 1].value_from; var frm = inputs[| i + 1].value_from;
if(key == "") continue;
if(frm != noone && frm.type == VALUE_TYPE.surface) if(frm != noone && frm.type == VALUE_TYPE.surface)
str[$ key] = new Surface(val); str[$ key] = new Surface(val);
else if(frm != noone && frm.type == VALUE_TYPE.buffer) else if(frm != noone && frm.type == VALUE_TYPE.buffer)

View file

@ -40,16 +40,13 @@ function Node_Switch(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
array_resize(input_display_list, input_display_len); array_resize(input_display_list, input_display_len);
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) { 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 + 0]);
ds_list_add(_in, inputs[| i + 1]); ds_list_add(_in, inputs[| i + 1]);
inputs[| i + 1].setVisible(false, true); inputs[| i + 1].setVisible(false, true);
array_push(input_display_list, i + 0); array_push(input_display_list, i + 0);
array_push(input_display_list, i + 1); 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 static onValueFromUpdate = function(index) { #region
if(LOADING || APPENDING) return; if(LOADING || APPENDING) return;
if(index < 0) return;
inputs[| 1].setType(inputs[| 1].value_from? inputs[| 1].value_from.type : VALUE_TYPE.any); 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(LOADING || APPENDING) return;
if(safe_mod(index - input_fix_len, data_length) == 0) //Variable name 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(); refreshDynamicInput();
} #endregion } #endregion

View file

@ -2163,6 +2163,8 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
return controlNode.rendered; return controlNode.rendered;
} #endregion } #endregion
static triggerSetFrom = function() { node.valueUpdate(index); }
static setFrom = function(_valueFrom, _update = true, checkRecur = true, log = false) { #region ////Set from static setFrom = function(_valueFrom, _update = true, checkRecur = true, log = false) { #region ////Set from
//print($"Connecting {_valueFrom.name} to {name}"); //print($"Connecting {_valueFrom.name} to {name}");