Pixel-Composer/scripts/project_data/project_data.gml

313 lines
8.6 KiB
Plaintext
Raw Normal View History

2023-10-12 07:07:24 +02:00
#region global
globalvar PROJECTS, PROJECT;
2024-02-11 14:53:33 +01:00
PROJECT = noone;
2023-10-12 07:07:24 +02:00
#endregion
2024-06-09 06:27:50 +02:00
#region layer
function Layer() constructor {
name = "New Layer";
nodes = [];
}
#endregion
2023-10-12 07:07:24 +02:00
#region project
function Project() constructor {
active = true; /// @is {bool}
2023-12-08 03:50:09 +01:00
meta = __getdefaultMetaData();
path = ""; /// @is {string}
2023-12-08 03:50:09 +01:00
thumbnail = "";
version = SAVE_VERSION; /// @is {number}
seed = irandom_range(100000, 999999); /// @is {number}
2023-10-12 07:07:24 +02:00
2024-03-14 14:35:19 +01:00
modified = false; /// @is {bool}
readonly = false; /// @is {bool}
2024-03-14 14:35:19 +01:00
safeMode = false;
2023-10-12 07:07:24 +02:00
allNodes = [];
nodes = [];
nodeTopo = [];
2023-10-12 07:07:24 +02:00
nodeMap = ds_map_create();
nodeNameMap = ds_map_create();
2024-06-09 06:27:50 +02:00
composer = noone;
2023-12-18 08:27:31 +01:00
animator = new AnimationManager();
globalNode = new Node_Global();
nodeController = new __Node_Controller(self);
2023-10-12 07:07:24 +02:00
load_layout = false;
previewNode = "";
previewGrid = {
2023-10-12 07:07:24 +02:00
show : false,
snap : false,
size : [ 16, 16 ],
opacity : 0.5,
color : cola(COLORS.panel_preview_grid),
2024-05-08 07:27:29 +02:00
pixel : false,
}
2023-10-12 07:07:24 +02:00
graphGrid = {
2023-10-12 07:07:24 +02:00
show : true,
2023-10-18 14:58:55 +02:00
show_origin : false,
2023-10-12 07:07:24 +02:00
snap : true,
2023-10-18 14:58:55 +02:00
size : 16,
2023-10-12 07:07:24 +02:00
opacity : 0.05,
color : cola(c_white),
2023-10-18 14:58:55 +02:00
highlight : 12,
}
graph_display_parameter = {
show_grid : true,
show_dimension : true,
show_compute : true,
avoid_label : true,
preview_scale : 100,
highlight : false,
show_control : false,
}
2023-10-12 07:07:24 +02:00
addons = {};
onion_skin = {
2023-10-12 07:07:24 +02:00
enabled: false,
range: [ -1, 1 ],
step: 1,
color: [ cola(c_red), cola(c_blue) ],
2023-10-12 07:07:24 +02:00
alpha: 0.5,
on_top: true,
};
2023-10-12 07:07:24 +02:00
#region =================== ATTRIBUTES ===================
2024-05-17 05:19:11 +02:00
attributes = variable_clone(PROJECT_ATTRIBUTES);
attributeEditor = [
2024-05-17 05:19:11 +02:00
[ "Default Surface", "surface_dimension", new vectorBox(2,
function(val, index) {
attributes.surface_dimension[index] = val;
2024-05-17 05:19:11 +02:00
PROJECT_ATTRIBUTES.surface_dimension = array_clone(attributes.surface_dimension);
RENDER_ALL
return true;
}),
2024-03-14 14:35:19 +01:00
function(junc) {
if(!is_struct(junc)) return;
if(!is_instanceof(junc, NodeValue)) return;
var attr = attributes.surface_dimension;
var _val = junc.getValue();
var _res = [ attr[0], attr[1] ];
switch(junc.type) {
case VALUE_TYPE.float :
case VALUE_TYPE.integer :
if(is_real(_val))
_res = [ _val, _val ];
else if(is_array(_val) && array_length(_val) >= 2) {
_res[0] = is_real(_val[0])? _val[0] : 1;
_res[1] = is_real(_val[1])? _val[1] : 1;
}
break;
case VALUE_TYPE.surface :
2024-03-31 05:36:11 +02:00
if(is_array(_val)) _val = array_safe_get_fast(_val, 0);
2024-03-14 14:35:19 +01:00
if(is_surface(_val))
_res = surface_get_dimension(_val);
break;
}
attr[0] = _res[0];
attr[1] = _res[1];
} ],
2024-04-23 11:53:16 +02:00
[ "Palette", "palette", new buttonPalette(function(pal) { setPalette(pal); RENDER_ALL return true; }),
2024-03-14 14:35:19 +01:00
function(junc) {
if(!is_struct(junc)) return;
if(!is_instanceof(junc, NodeValue)) return;
if(junc.type != VALUE_TYPE.color) return;
if(junc.display_type != VALUE_DISPLAY.palette) return;
setPalette(junc.getValue());
}
],
2024-04-23 11:53:16 +02:00
2024-04-23 14:29:26 +02:00
//[ "Strict", "strict", new checkBox(function() { attributes.strict = !attributes.strict; RENDER_ALL return true; }), function() {} ],
];
static setPalette = function(pal = noone) {
2024-05-17 05:19:11 +02:00
if(pal != noone) {
for (var i = 0, n = array_length(pal); i < n; i++)
pal[i] = cola(pal[i], _color_get_alpha(pal[i]));
attributes.palette = pal;
PROJECT_ATTRIBUTES.palette = array_clone(pal);
}
2024-05-16 15:28:45 +02:00
palettes = paletteToArray(attributes.palette);
2024-05-16 15:28:45 +02:00
} setPalette();
#endregion
2023-10-12 07:07:24 +02:00
timelines = new timelineItemGroup();
2023-10-15 15:04:42 +02:00
notes = [];
static step = function() {
slideShowPreStep();
animator.step();
globalNode.step();
}
static postStep = function() {
slideShowPostStep();
}
useSlideShow = false;
slideShow = {};
slideShow_keys = [];
slideShow_index = 0;
slideShow_amount = 0;
slideShow_current = noone;
static slideShowPreStep = function() { slideShow = {}; }
static slideShowPostStep = function() {
slideShow_keys = variable_struct_get_names(slideShow);
array_sort(slideShow_keys, true);
slideShow_amount = array_length(slideShow_keys);
useSlideShow = slideShow_amount > 0;
slideShow_current = struct_try_get(slideShow, array_safe_get(slideShow_keys, slideShow_index, 0), noone);
}
static slideShowSet = function(index) {
slideShow_index = index;
slideShow_current = struct_try_get(slideShow, array_safe_get(slideShow_keys, slideShow_index, 0), noone);
return slideShow_current;
}
static cleanup = function() {
array_foreach(allNodes, function(_node) {
_node.active = false;
_node.cleanUp();
});
2023-10-12 07:07:24 +02:00
ds_map_destroy(nodeMap);
ds_map_destroy(nodeNameMap);
gc_collect();
}
2024-02-04 07:33:42 +01:00
static toString = function() { return $"ProjectObject [{path}]"; }
2024-06-09 06:27:50 +02:00
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;
_anim_map.playback = animator.playback;
2024-06-09 06:27:50 +02:00
_map.animator = _anim_map;
_map.metadata = meta.serialize();
_map.global_node = globalNode.serialize();
_map.onion_skin = onion_skin;
var _prev_node = PANEL_PREVIEW? PANEL_PREVIEW.getNodePreview() : noone;
_map.previewNode = _prev_node? _prev_node.node_id : noone;
2024-06-09 06:27:50 +02:00
_map.previewGrid = previewGrid;
_map.graphGrid = graphGrid;
_map.attributes = attributes;
_map.timelines = timelines.serialize();
_map.notes = array_map(notes, function(note) { return note.serialize(); } );
2024-06-09 07:49:43 +02:00
_map.composer = composer;
_map.load_layout = load_layout;
2024-06-09 06:27:50 +02:00
_map.graph_display_parameter = graph_display_parameter;
2024-06-09 06:27:50 +02:00
__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);
animator.playback = struct_try_get(_anim_map, "playback", ANIMATOR_END.loop);
2024-06-09 06:27:50 +02:00
}
if(struct_has(_map, "onion_skin")) struct_override(onion_skin, _map.onion_skin);
previewNode = struct_try_get(_map, "previewNode", noone);
2024-06-09 06:27:50 +02:00
if(struct_has(_map, "previewGrid")) struct_override(previewGrid, _map.previewGrid);
2024-06-09 06:27:50 +02:00
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);
2024-06-09 07:49:43 +02:00
if(struct_has(_map, "composer")) composer = _map.composer;
2024-06-09 06:27:50 +02:00
if(struct_has(_map, "graph_display_parameter")) struct_override(graph_display_parameter, _map.graph_display_parameter);
load_layout = struct_try_get(_map, "load_layout", load_layout);
2024-06-09 06:27:50 +02:00
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);
addons = {};
if(struct_has(_map, "addon")) {
var _addon = _map.addon;
addons = _addon;
struct_foreach(_addon, function(_name, _value) { addonLoad(_name, false); });
}
if(PANEL_PREVIEW && previewNode != "") {
var _node = nodeMap[? previewNode];
if(_node) PANEL_PREVIEW.setNodePreview(_node);
}
}
static postDeserialize = function() {
2024-06-09 06:27:50 +02:00
}
2023-10-12 07:07:24 +02:00
}
function __initProject() {
PROJECT = new Project();
PROJECTS = [ PROJECT ];
}
#endregion