[JSON File Out] Add option to attempt serialization if possible.

This commit is contained in:
Tanasart 2024-12-29 08:35:05 +07:00
parent 4b7c3d4bb0
commit 558249e742
5 changed files with 81 additions and 84 deletions

View file

@ -1,57 +1,40 @@
function __Bone(_parent = noone, _distance = 0, _direction = 0, _angle = 0, _length = 0, _node = noone) constructor {
ID = UUID_generate();
name = "New bone";
node = _node;
parent = _parent;
ID = UUID_generate();
name = "New bone";
node = _node;
parent = _parent;
is_main = false;
tb_name = new textBox(TEXTBOX_INPUT.text, function(n) /*=>*/ { name = n; if(node) node.triggerRender(); }).setFont(f_p2).setHide(true);
childs = [];
parent_anchor = true;
distance = _distance; pose_distance = _distance;
direction = _direction; pose_direction = _direction;
angle = _angle; pose_angle = _angle;
length = _length; pose_length = _length;
pose_posit = [ 0, 0 ];
pose_rotate = 0;
pose_scale = 1;
pose_posit = [ 0, 0 ]; pose_local_posit = [ 0, 0 ]; pose_apply_posit = [ 0, 0 ];
pose_rotate = 0; pose_local_rotate = 0; pose_apply_rotate = 0;
pose_scale = 1; pose_local_scale = 1; pose_apply_scale = 1;
pose_local_posit = [ 0, 0 ]; pose_apply_posit = [ 0, 0 ];
pose_local_rotate = 0; pose_apply_rotate = 0;
pose_local_scale = 1; pose_apply_scale = 1;
bone_head_init = new __vec2(); bone_head_pose = new __vec2();
bone_tail_init = new __vec2(); bone_tail_pose = new __vec2();
bone_head_init = new __vec2(); bone_head_pose = new __vec2();
bone_tail_init = new __vec2(); bone_tail_pose = new __vec2();
apply_scale = true;
apply_rotation = true;
apply_scale = true;
apply_rotation = true;
childs = [];
is_main = false;
parent_anchor = true;
tb_name = new textBox(TEXTBOX_INPUT.text, function(_name) /*=>*/ { name = _name; if(node) node.triggerRender(); });
tb_name.font = f_p2;
tb_name.hide = true;
updated = false;
IKlength = 0;
IKTargetID = "";
IKTarget = noone;
constrains = [];
freeze_data = {};
IKlength = 0;
IKTargetID = "";
IKTarget = noone;
constrains = [];
control_x0 = 0; control_y0 = 0; control_i0 = 0;
control_x1 = 0; control_y1 = 0; control_i1 = 0;
static addChild = function(bone) { array_push(childs, bone); bone.parent = self; return self; }
static childCount = function() { return array_reduce(childs, function(amo, ch) /*=>*/ { return amo + ch.childCount(); }, array_length(childs)); }
static freeze = function() {
freeze_data = { angle, length, distance, direction };
array_foreach(childs, function(c) /*=>*/ {return c.freeze()});
}
////- Find
static findBone = function(_id) {

View file

@ -44,7 +44,7 @@
LATEST_VERSION = 1_18_00_0;
VERSION = 1_18_06_2;
SAVE_VERSION = 1_18_05_0;
VERSION_STRING = MAC? "1.18.003m" : "1.18.6.2.001";
VERSION_STRING = MAC? "1.18.003m" : "1.18.6.2.002";
BUILD_NUMBER = 1_18_06_2;
PREF_VERSION = 1_17_1;

View file

@ -2,18 +2,21 @@ function Node_Json_File_Write(_x, _y, _group = noone) : Node(_x, _y, _group) con
name = "JSON File Out";
color = COLORS.node_blend_input;
w = 128;
newInput(0, nodeValue_Path("Path", self, ""))
.setDisplay(VALUE_DISPLAY.path_save, { filter: "json file|*.json" })
.rejectArray();
newInput(1, nodeValue_Struct("Struct", self, {}))
.shortenDisplay()
.setVisible(true, true);
newInput(2, nodeValue_Bool("Pretty print", self, false));
input_display_list = [ 0, 1, 2 ]
newInput(3, nodeValue_Bool("Serialize", self, true));
input_display_list = [ 0, 1,
["Formatting", false], 2, 3
];
static writeFile = function() {
var path = getInputData(0);
@ -24,6 +27,10 @@ function Node_Json_File_Write(_x, _y, _group = noone) : Node(_x, _y, _group) con
var cont = getInputData(1);
var pret = getInputData(2);
var seri = getInputData(3);
if(seri && struct_has(cont, "serialize"))
cont = cont.serialize();
json_save_struct(path, cont, pret);
}

View file

@ -124,15 +124,16 @@ function Node_Struct(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var key = getInputData(i + 0);
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)
str[$ key] = new Buffer(val);
else
str[$ key] = val;
var _typ = frm == noone? VALUE_TYPE.any : frm.type;
switch(_typ) {
case VALUE_TYPE.surface : str[$ key] = new Surface(val); break;
case VALUE_TYPE.buffer : str[$ key] = new Buffer(val); break;
default : str[$ key] = val;
}
}
outputs[0].setValue(str);

View file

@ -42,26 +42,29 @@ function outputBox() : widget() constructor {
return _hh;
}
var _txt = string(_value);
var _bh = string_height("l");
var _sh = string_height_ext(_txt, -1, w - ui(16));
var _hh = (expand? _sh : _bh) + ui(16);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _hh, COLORS._main_icon_light);
if(expand || _sh <= _bh)
if(!expand) {
var _hh = _bh + ui(16);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _hh, COLORS._main_icon_light);
draw_text_add(_x + ui(8), _y + ui(8), "Output...");
} else {
var _txt = string(_value);
var _sh = string_height_ext(_txt, -1, w - ui(16));
var _hh = _sh + ui(16);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _hh, COLORS._main_icon_light);
draw_text_ext_add(_x + ui(8), _y + ui(8), _txt, -1, _w - ui(16));
else
draw_text_add(_x + ui(8), _y + ui(8), "Output...");
if(_sh > _bh) {
var _bs = _bh;
var _bx = _x + _w - ui(8) - _bs;
var _by = _y + ui(8);
if(buttonInstant(THEME.button_hide, _bx, _by, _bs, _bs, _m, ihover, iactive, "", THEME.arrow, expand? 3 : 0) == 2)
expand = !expand;
}
}
var _bs = _bh;
var _bx = _x + _w - ui(8) - _bs;
var _by = _y + ui(8);
if(buttonInstant(THEME.button_hide, _bx, _by, _bs, _bs, _m, ihover, iactive, "", THEME.arrow, expand? 3 : 0) == 2)
expand = !expand;
return _hh;
}
@ -94,26 +97,29 @@ function outputStructBox() : widget() constructor {
return _hh;
}
var _txt = json_stringify(_value, true);
var _bh = string_height("l");
var _sh = string_height_ext(_txt, -1, w - ui(16));
var _hh = (expand? _sh : _bh) + ui(16);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _hh, COLORS._main_icon_light);
if(expand || _sh <= _bh)
draw_text_ext_add(_x + ui(8), _y + ui(8), _txt, -1, _w - ui(16));
else
draw_text_add(_x + ui(8), _y + ui(8), $"[{instanceof(_value)}]");
if(_sh > _bh) {
var _bs = _bh;
var _bx = _x + _w - ui(8) - _bs;
var _by = _y + ui(8);
if(!expand) {
var _hh = _bh + ui(16);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _hh, COLORS._main_icon_light);
draw_text_add(_x + ui(8), _y + ui(8), $"[{instanceof(_value)}]");
if(buttonInstant(THEME.button_hide, _bx, _by, _bs, _bs, _m, ihover, iactive, "", THEME.arrow, expand? 3 : 0) == 2)
expand = !expand;
}
} else {
var _txt = json_stringify(_value, true);
var _sh = string_height_ext(_txt, -1, w - ui(16));
var _hh = _sh + ui(16);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _hh, COLORS._main_icon_light);
draw_text_ext_add(_x + ui(8), _y + ui(8), _txt, -1, _w - ui(16));
}
var _bs = _bh;
var _bx = _x + _w - ui(8) - _bs;
var _by = _y + ui(8);
if(buttonInstant(THEME.button_hide, _bx, _by, _bs, _bs, _m, ihover, iactive, "", THEME.arrow, expand? 3 : 0) == 2)
expand = !expand;
return _hh;
}