project ser/de

This commit is contained in:
Tanasart 2024-06-09 11:27:50 +07:00
parent c566ca84ba
commit 770aa23d81
10 changed files with 212 additions and 204 deletions

View file

@ -51,15 +51,15 @@ function __Node_Base(x, y) constructor {
static step = function() {} static step = function() {}
static update = function(frame = CURRENT_FRAME) {} static update = function(frame = CURRENT_FRAME) {}
static valueUpdate = function(index) {} static valueUpdate = function(index) {}
static triggerRender = function() {} static triggerRender = function() {}
static onValidate = function() {} static onValidate = function() {}
static onDestroy = function() {} static onDestroy = function() {}
static clearCache = function() {} static clearCache = function() {}
static clearCacheForward = function() {} static clearCacheForward = function() {}
static serialize = function() {} static serialize = function() {}
static deserialize = function(_map) {} static deserialize = function(_map) {}
} }

View file

@ -48,10 +48,12 @@ function FileObject(_name, _path) constructor { #region
} #endregion } #endregion
static getSpr = function() { #region static getSpr = function() { #region
if(spr != -1) return spr; if(spr != -1 && sprite_exists(spr))
return spr;
if(sprFetchID != noone) return -1; if(sprFetchID != noone) return -1;
if(array_length(spr_path) == 0) { if(array_empty(spr_path)) {
if(loadThumbnailAsync) { if(loadThumbnailAsync) {
sprFetchID = sprite_add_ext(self.path, 0, 0, 0, true); sprFetchID = sprite_add_ext(self.path, 0, 0, 0, true);
IMAGE_FETCH_MAP[? sprFetchID] = function(load_result) { IMAGE_FETCH_MAP[? sprFetchID] = function(load_result) {
@ -62,6 +64,7 @@ function FileObject(_name, _path) constructor { #region
spr = sprite_add(self.path, 0, 0, 0, 0, 0); spr = sprite_add(self.path, 0, 0, 0, 0, 0);
if(spr) sprite_set_offset(spr, sprite_get_width(spr) / 2, sprite_get_height(spr) / 2); if(spr) sprite_set_offset(spr, sprite_get_width(spr) / 2, sprite_get_height(spr) / 2);
} }
return spr; return spr;
} }

View file

@ -141,7 +141,6 @@ function LOAD_AT(path, readonly = false, override = false) { #region
try { try {
var _node_list = _load_content.nodes; var _node_list = _load_content.nodes;
for(var i = 0, n = array_length(_node_list); i < n; i++) { for(var i = 0, n = array_length(_node_list); i < n; i++) {
// printIf(log, $" >> Loading nodes : {_node_list[i].type}");
var _node = nodeLoad(_node_list[i]); var _node = nodeLoad(_node_list[i]);
if(_node) array_push(create_list, _node); if(_node) array_push(create_list, _node);
} }
@ -150,68 +149,7 @@ function LOAD_AT(path, readonly = false, override = false) { #region
} }
} }
printIf(log, $" > Load nodes : {(get_timer() - t1) / 1000} ms"); t1 = get_timer(); PROJECT.deserialize(_load_content);
try {
if(struct_has(_load_content, "animator")) {
var _anim_map = _load_content.animator;
PROJECT.animator.frames_total = struct_try_get(_anim_map, "frames_total", 30);
PROJECT.animator.framerate = struct_try_get(_anim_map, "framerate", 30);
PROJECT.animator.frame_range = struct_try_get(_anim_map, "frame_range", noone);
}
} catch(e) {
log_warning("LOAD, animator", exception_print(e));
}
if(struct_has(_load_content, "onion_skin"))
struct_override(PROJECT.onion_skin, _load_content.onion_skin);
if(struct_has(_load_content, "previewGrid"))
struct_override(PROJECT.previewGrid, _load_content.previewGrid);
if(struct_has(_load_content, "graphGrid"))
struct_override(PROJECT.graphGrid, _load_content.graphGrid);
if(struct_has(_load_content, "attributes")) {
struct_override(PROJECT.attributes, _load_content.attributes);
}
PROJECT.setPalette();
if(struct_has(_load_content, "notes")) {
PROJECT.notes = array_create(array_length(_load_content.notes));
for( var i = 0, n = array_length(_load_content.notes); i < n; i++ )
PROJECT.notes[i] = new Note.deserialize(_load_content.notes[i]);
}
try {
if(struct_has(_load_content, "metadata"))
PROJECT.meta.deserialize(_load_content.metadata);
} catch(e) {
log_warning("LOAD, metadata", exception_print(e));
}
PROJECT.globalNode = new Node_Global();
try {
if(struct_has(_load_content, "global"))
PROJECT.globalNode.deserialize(_load_content.global);
else if(struct_has(_load_content, "global_node"))
PROJECT.globalNode.deserialize(_load_content.global_node);
} catch(e) {
log_warning("LOAD, global", exception_print(e));
}
try {
if(struct_has(_load_content, "addon")) {
var _addon = _load_content.addon;
PROJECT.addons = _addon;
struct_foreach(_addon, function(_name, _value) { addonLoad(_name, false); });
} else
PROJECT.addons = {};
} catch(e) {
log_warning("LOAD, addon", exception_print(e));
}
printIf(log, $" > Load data : {(get_timer() - t1) / 1000} ms"); t1 = get_timer();
ds_queue_clear(CONNECTION_CONFLICT); ds_queue_clear(CONNECTION_CONFLICT);

View file

@ -368,8 +368,13 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
mapButton = button(function() { mapButton = button(function() {
attributes.mapped = !attributes.mapped; attributes.mapped = !attributes.mapped;
var val = getValue(); var val = getValue();
if( attributes.mapped && is_numeric(val)) setValue([0, val]);
if(!attributes.mapped && is_array(val)) setValue(array_safe_get_fast(val, 0)); if( attributes.mapped)
setValue([0, 0]);
if(!attributes.mapped && is_array(def_val))
setValue(def_val);
setArrayDepth(attributes.mapped); setArrayDepth(attributes.mapped);
node.triggerRender(); node.triggerRender();
@ -410,6 +415,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
inp.visible = vis; inp.visible = vis;
node.refreshNodeDisplay(); node.refreshNodeDisplay();
} }
} #endregion } #endregion
/////========== ANIMATION ========== /////========== ANIMATION ==========

View file

@ -141,6 +141,9 @@ function Panel_Collection() : PanelContent() constructor {
}); });
tb_search.auto_update = true; tb_search.auto_update = true;
grid_size = ui(64);
grid_size_to = grid_size;
contentView = 0; contentView = 0;
contentPane = new scrollPane(content_w - ui(6), content_h, function(_y, _m) { #region contentPane = new scrollPane(content_w - ui(6), content_h, function(_y, _m) { #region
draw_clear_alpha(c_white, 0); draw_clear_alpha(c_white, 0);
@ -180,9 +183,10 @@ function Panel_Collection() : PanelContent() constructor {
updated_prog = lerp_linear(updated_prog, 0, 0.01); updated_prog = lerp_linear(updated_prog, 0, 0.01);
if(contentView == 0) { if(contentView == 0) {
var grid_size = ui(64); var grid_width = round(grid_size * 1.25);
var grid_width = ui(80); if(grid_width > ui(80)) grid_width = grid_size;
var grid_space = ui(12);
var grid_space = round(grid_size * 0.1875);
var col = max(1, floor(_cw / (grid_width + grid_space))); var col = max(1, floor(_cw / (grid_width + grid_space)));
var row = ceil(node_count / col); var row = ceil(node_count / col);
@ -277,7 +281,7 @@ function Panel_Collection() : PanelContent() constructor {
} }
draw_set_text(f_p3, fa_center, fa_top, COLORS._main_text_inner); draw_set_text(f_p3, fa_center, fa_top, COLORS._main_text_inner);
var _txtH = draw_text_ext_add(_boxx + grid_size / 2, yy + grid_size + ui(4), _node.name, -1, grid_width,, true); var _txtH = draw_text_ext_add(_boxx + grid_size / 2, yy + grid_size + ui(4), _node.name, -1, grid_width, 1, true);
name_height = max(name_height, _txtH + 8); name_height = max(name_height, _txtH + 8);
} }
@ -286,6 +290,12 @@ function Panel_Collection() : PanelContent() constructor {
yy += hght; yy += hght;
} }
if(pHOVER && key_mod_press(CTRL) && point_in_rectangle(_m[0], _m[1], 0, 0, contentPane.surface_w, contentPane.surface_h)) {
if(mouse_wheel_down()) grid_size_to = clamp(grid_size_to - ui(4), ui(32), ui(160));
if(mouse_wheel_up()) grid_size_to = clamp(grid_size_to + ui(4), ui(32), ui(160));
}
grid_size = lerp_float(grid_size, grid_size_to, 5);
} else { } else {
var list_width = _cw; var list_width = _cw;
var list_height = ui(28); var list_height = ui(28);

View file

@ -114,13 +114,14 @@
} #endregion } #endregion
function checkPanelValid() { #region function checkPanelValid() { #region
var val = true; var val = true;
if(!is_instanceof(PANEL_GRAPH.panel, Panel)) val = false; var _mst = "";
if(!is_instanceof(PANEL_PREVIEW.panel, Panel)) val = false; if(!is_instanceof(PANEL_GRAPH.panel, Panel)) { val = false; _mst += "Graph, " };
if(!is_instanceof(PANEL_INSPECTOR.panel, Panel)) val = false; if(!is_instanceof(PANEL_PREVIEW.panel, Panel)) { val = false; _mst += "Preview, " };
if(!is_instanceof(PANEL_INSPECTOR.panel, Panel)) { val = false; _mst += "Inspector, " };
if(!val) { if(!val) {
noti_warning("Invalid Panel Layout, layout and UI scale will be reset to the default value.\n\nRestart recommended."); noti_warning($"Invalid Panel Layout, missing {_mst} panel(s). Reset to the default layout and restart recommened.");
PREFERENCES.panel_layout_file = "Vertical"; PREFERENCES.panel_layout_file = "Vertical";
PREFERENCES._display_scaling = 1; PREFERENCES._display_scaling = 1;

View file

@ -160,6 +160,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
self.project = project; self.project = project;
nodes_list = project.nodes; nodes_list = project.nodes;
// layer_index = noone;
setTitle(); setTitle();
} }
setProject(project); setProject(project);
@ -1509,100 +1510,100 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
function connectDraggingValueTo(target) { #region function connectDraggingValueTo(target) { #region
var _connect = [ 0, noone, noone ]; var _connect = [ 0, noone, noone ];
if(PANEL_INSPECTOR && PANEL_INSPECTOR.attribute_hovering != noone) { if(is_instanceof(PANEL_INSPECTOR, Panel_Inspector) && PANEL_INSPECTOR.attribute_hovering != noone) {
PANEL_INSPECTOR.attribute_hovering(value_dragging); PANEL_INSPECTOR.attribute_hovering(value_dragging);
} else if(target != noone) { } else if(target != noone) {
if(target.connect_type == value_dragging.connect_type) { if(target.connect_type == value_dragging.connect_type) {
if(value_dragging.connect_type == JUNCTION_CONNECT.input) { if(value_dragging.connect_type == JUNCTION_CONNECT.input) {
if(target.value_from) { if(target.value_from) {
value_dragging.setFrom(target.value_from); value_dragging.setFrom(target.value_from);
target.removeFrom(); target.removeFrom();
}
} else if(value_dragging.connect_type == JUNCTION_CONNECT.output) {
var _tos = target.getJunctionTo();
for (var i = 0, n = array_length(_tos); i < n; i++)
_tos[i].setFrom(value_dragging);
} }
} else { } else if(value_dragging.connect_type == JUNCTION_CONNECT.output) {
var _addInput = target.value_from == noone && target.connect_type == JUNCTION_CONNECT.input && target.node.auto_input; var _tos = target.getJunctionTo();
if(value_dragging.connect_type == JUNCTION_CONNECT.input) { for (var i = 0, n = array_length(_tos); i < n; i++)
if(array_empty(value_draggings)) { _tos[i].setFrom(value_dragging);
_connect = [ value_dragging.setFrom(target), value_dragging, target ];
} else {
for( var i = 0, n = array_length(value_draggings); i < n; i++ )
value_draggings[i].setFrom(target);
}
} else if(_addInput && !array_empty(value_draggings)) {
for( var i = 0, n = array_length(value_draggings); i < n; i++ )
target.node.addInput(value_draggings[i]);
} else {
_connect = [ target.setFrom(value_dragging), target, value_dragging ];
}
} }
} else { } else {
if(value_dragging.connect_type == JUNCTION_CONNECT.input) var _addInput = target.value_from == noone && target.connect_type == JUNCTION_CONNECT.input && target.node.auto_input;
value_dragging.removeFrom();
value_dragging.node.triggerRender();
if(value_focus != value_dragging) { if(value_dragging.connect_type == JUNCTION_CONNECT.input) {
var ctx = is_instanceof(frame_hovering, Node_Collection_Inline)? frame_hovering : getCurrentContext(); if(array_empty(value_draggings)) {
if(value_dragging.node.inline_context && !key_mod_press(SHIFT)) _connect = [ value_dragging.setFrom(target), value_dragging, target ];
ctx = value_dragging.node.inline_context; } else {
for( var i = 0, n = array_length(value_draggings); i < n; i++ )
with(dialogCall(o_dialog_add_node, mouse_mx + 8, mouse_my + 8, { context: ctx })) { value_draggings[i].setFrom(target);
node_target_x = other.mouse_grid_x;
node_target_y = other.mouse_grid_y;
node_called = other.value_dragging;
alarm[0] = 1;
} }
} else if(_addInput && !array_empty(value_draggings)) {
for( var i = 0, n = array_length(value_draggings); i < n; i++ )
target.node.addInput(value_draggings[i]);
} else {
_connect = [ target.setFrom(value_dragging), target, value_dragging ];
} }
} }
value_dragging = noone; } else {
connection_draw_mouse = noone; if(value_dragging.connect_type == JUNCTION_CONNECT.input)
value_dragging.removeFrom();
value_dragging.node.triggerRender();
if(_connect[0] == -9) { if(value_focus != value_dragging) {
if(_connect[1].value_from_loop != noone) var ctx = is_instanceof(frame_hovering, Node_Collection_Inline)? frame_hovering : getCurrentContext();
_connect[1].value_from_loop.destroy(); if(value_dragging.node.inline_context && !key_mod_press(SHIFT))
ctx = value_dragging.node.inline_context;
var menu = [ with(dialogCall(o_dialog_add_node, mouse_mx + 8, mouse_my + 8, { context: ctx })) {
menuItem("Feedback", function(data) { node_target_x = other.mouse_grid_x;
var junc_in = data.params.junc_in; node_target_y = other.mouse_grid_y;
var junc_out = data.params.junc_out; node_called = other.value_dragging;
var feed = nodeBuild("Node_Feedback_Inline", 0, 0); alarm[0] = 1;
// feed.connectJunctions(junc_in, junc_out); }
feed.attributes.junc_in = [ junc_in .node.node_id, junc_in .index ];
feed.attributes.junc_out = [ junc_out.node.node_id, junc_out.index ];
feed.scanJunc();
}, THEME.feedback_24,,, { junc_in : _connect[1], junc_out : _connect[2] }),
menuItem("Loop", function(data) {
var junc_in = data.params.junc_in;
var junc_out = data.params.junc_out;
var feed = nodeBuild("Node_Iterate_Inline", 0, 0);
feed.attributes.junc_in = [ junc_in .node.node_id, junc_in .index ];
feed.attributes.junc_out = [ junc_out.node.node_id, junc_out.index ];
feed.scanJunc();
}, THEME.loop_24,,, { junc_in : _connect[1], junc_out : _connect[2] }),
];
menuCall(,,, menu);
} }
}
value_dragging = noone;
connection_draw_mouse = noone;
if(_connect[0] == -9) {
if(_connect[1].value_from_loop != noone)
_connect[1].value_from_loop.destroy();
var menu = [
menuItem("Feedback", function(data) {
var junc_in = data.params.junc_in;
var junc_out = data.params.junc_out;
var feed = nodeBuild("Node_Feedback_Inline", 0, 0);
// feed.connectJunctions(junc_in, junc_out);
feed.attributes.junc_in = [ junc_in .node.node_id, junc_in .index ];
feed.attributes.junc_out = [ junc_out.node.node_id, junc_out.index ];
feed.scanJunc();
}, THEME.feedback_24,,, { junc_in : _connect[1], junc_out : _connect[2] }),
menuItem("Loop", function(data) {
var junc_in = data.params.junc_in;
var junc_out = data.params.junc_out;
var feed = nodeBuild("Node_Iterate_Inline", 0, 0);
feed.attributes.junc_in = [ junc_in .node.node_id, junc_in .index ];
feed.attributes.junc_out = [ junc_out.node.node_id, junc_out.index ];
feed.scanJunc();
}, THEME.loop_24,,, { junc_in : _connect[1], junc_out : _connect[2] }),
];
menuCall(,,, menu);
}
} #endregion } #endregion
function draggingValue() { function draggingValue() {

View file

@ -35,12 +35,12 @@ function Inspector_Spacer(height, line = false) constructor { self.h = height; s
function Panel_Inspector() : PanelContent() constructor { function Panel_Inspector() : PanelContent() constructor {
#region ---- main ---- #region ---- main ----
title = __txt("Inspector");
context_str = "Inspector"; context_str = "Inspector";
title = __txt("Inspector");
icon = THEME.panel_inspector_icon; icon = THEME.panel_inspector_icon;
w = ui(400); w = ui(400);
h = ui(640); h = ui(640);
min_w = ui(160); min_w = ui(160);
locked = false; locked = false;
@ -73,6 +73,8 @@ function Panel_Inspector() : PanelContent() constructor {
picker_index = 0; picker_index = 0;
picker_change = false; picker_change = false;
attribute_hovering = noone;
#endregion #endregion
globalvar_viewer_init(); globalvar_viewer_init();

View file

@ -3,6 +3,13 @@
PROJECT = noone; PROJECT = noone;
#endregion #endregion
#region layer
function Layer() constructor {
name = "New Layer";
nodes = [];
}
#endregion
#region project #region project
function Project() constructor { function Project() constructor {
active = true; /// @is {bool} active = true; /// @is {bool}
@ -23,6 +30,8 @@
nodeMap = ds_map_create(); nodeMap = ds_map_create();
nodeNameMap = ds_map_create(); nodeNameMap = ds_map_create();
composer = noone;
animator = new AnimationManager(); animator = new AnimationManager();
globalNode = new Node_Global(); globalNode = new Node_Global();
nodeController = new __Node_Controller(self); nodeController = new __Node_Controller(self);
@ -144,6 +153,85 @@
} #endregion } #endregion
static toString = function() { return $"ProjectObject [{path}]"; } static toString = function() { return $"ProjectObject [{path}]"; }
static serialize = function() {
var _map = {};
_map.version = SAVE_VERSION;
var _anim_map = {};
_anim_map.frames_total = animator.frames_total;
_anim_map.framerate = animator.framerate;
_anim_map.frame_range = animator.frame_range;
_map.animator = _anim_map;
_map.metadata = meta.serialize();
_map.global_node = globalNode.serialize();
_map.onion_skin = onion_skin;
_map.previewGrid = previewGrid;
_map.graphGrid = graphGrid;
_map.attributes = attributes;
_map.timelines = timelines.serialize();
_map.notes = array_map(notes, function(note) { return note.serialize(); } );
_map.composer = composer == noone? -4 : composer.serialize();
__node_list = [];
array_foreach(allNodes, function(node) { if(node.active) array_push(__node_list, node.serialize()); })
_map.nodes = __node_list;
var prev = PANEL_PREVIEW.getNodePreviewSurface();
if(!is_surface(prev)) _map.preview = "";
else _map.preview = surface_encode(surface_size_lim(prev, 128, 128));
var _addon = {};
with(_addon_custom) {
var _ser = lua_call(thread, "serialize");
_addon[$ name] = PREFERENCES.save_file_minify? json_stringify_minify(_ser) : json_stringify(_ser);
}
_map.addon = _addon;
return _map;
}
static deserialize = function(_map) {
if(struct_has(_map, "animator")) {
var _anim_map = _map.animator;
animator.frames_total = struct_try_get(_anim_map, "frames_total", 30);
animator.framerate = struct_try_get(_anim_map, "framerate", 30);
animator.frame_range = struct_try_get(_anim_map, "frame_range", noone);
}
if(struct_has(_map, "onion_skin")) struct_override(onion_skin, _map.onion_skin);
if(struct_has(_map, "previewGrid")) struct_override(previewGrid, _map.previewGrid);
if(struct_has(_map, "graphGrid")) struct_override(graphGrid, _map.graphGrid);
if(struct_has(_map, "attributes")) struct_override(attributes, _map.attributes);
if(struct_has(_map, "metadata")) meta.deserialize(_map.metadata);
setPalette();
if(struct_has(_map, "notes")) {
notes = array_create(array_length(_map.notes));
for( var i = 0, n = array_length(_map.notes); i < n; i++ )
notes[i] = new Note.deserialize(_map.notes[i]);
}
globalNode = new Node_Global();
if(struct_has(_map, "global")) globalNode.deserialize(_map.global);
else if(struct_has(_map, "global_node")) globalNode.deserialize(_map.global_node);
if(struct_has(_map, "composer") && _map.composer != -4)
composer.deserialize(_map.composer);
addons = {};
if(struct_has(_map, "addon")) {
var _addon = _map.addon;
addons = _addon;
struct_foreach(_addon, function(_name, _value) { addonLoad(_name, false); });
}
}
} }
function __initProject() { function __initProject() {

View file

@ -14,50 +14,9 @@ function NEW() { #region
} #endregion } #endregion
function save_serialize(project = PROJECT, _outMap = false) { #region function save_serialize(project = PROJECT, _outMap = false) { #region
var _map = {}; var _map = project.serialize();
_map.version = SAVE_VERSION;
var _node_list = [];
var amo = array_length(project.allNodes);
var i = 0;
repeat(amo) {
var _node = project.allNodes[i++];
if(_node.active) array_push(_node_list, _node.serialize());
}
_map.nodes = _node_list;
var _anim_map = {};
_anim_map.frames_total = project.animator.frames_total;
_anim_map.framerate = project.animator.framerate;
_anim_map.frame_range = project.animator.frame_range;
_map.animator = _anim_map;
_map.metadata = PROJECT.meta.serialize();
_map.global_node = project.globalNode.serialize();
_map.onion_skin = project.onion_skin;
_map.previewGrid = project.previewGrid;
_map.graphGrid = project.graphGrid;
_map.attributes = project.attributes;
_map.timelines = project.timelines.serialize();
_map.notes = array_map(project.notes, function(note) { return note.serialize(); } );
var prev = PANEL_PREVIEW.getNodePreviewSurface();
if(!is_surface(prev)) _map.preview = "";
else _map.preview = surface_encode(surface_size_lim(prev, 128, 128));
var _addon = {};
with(_addon_custom) {
var _ser = lua_call(thread, "serialize");
_addon[$ name] = PREFERENCES.save_file_minify? json_stringify_minify(_ser) : json_stringify(_ser);
}
_map.addon = _addon;
if(_outMap) return _map; if(_outMap) return _map;
return PREFERENCES.save_file_minify? json_stringify_minify(_map) : json_stringify(_map, true); return PREFERENCES.save_file_minify? json_stringify_minify(_map) : json_stringify(_map, true);
} #endregion } #endregion