- [PCX] self keyword.

This commit is contained in:
MakhamDev 2023-10-12 19:14:08 +07:00
parent 81d54ea3e3
commit 5173301279
9 changed files with 72 additions and 25 deletions

View file

@ -5,8 +5,7 @@ function Node_Area(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
w = 96;
inputs[| 0] = nodeValue("Postion", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ] )
inputs[| 0] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ] )
.setDisplay(VALUE_DISPLAY.vector)
.setVisible(true, true);
inputs[| 1] = nodeValue("Size", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 16, 16 ] )

View file

@ -94,7 +94,8 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
outputs = ds_list_create();
inputMap = ds_map_create();
outputMap = ds_map_create();
input_value_map = {};
use_display_list = true;
input_display_list = -1;
output_display_list = -1;
@ -439,11 +440,18 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
return array_safe_get(inputs_data, index, def);
} #endregion
static setInputData = function(index, value) { #region
gml_pragma("forceinline");
inputs_data[index] = value;
input_value_map[$ inputs[| index].internalName] = value;
} #endregion
static getInputs = function(frame = CURRENT_FRAME) { #region
inputs_data = array_create(ds_list_size(inputs), undefined);
for(var i = 0; i < ds_list_size(inputs); i++)
inputs_data[i] = inputs[| i].getValue(frame,,, false);
setInputData(i, inputs[| i].getValue(frame,,, false));
} #endregion
static forceUpdate = function() { #region

View file

@ -43,7 +43,7 @@ function Node_Number(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co
w = 96;
min_h = 56;
switch(disp) {
case 0 :
inputs[| 3].setVisible(false);

View file

@ -261,7 +261,7 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct
if(amo == 1) val = val[0]; //spread single array
amo = max(1, amo);
inputs_data[i] = val;
setInputData(i, val);
inputs_is_array[i] = inputs[| i].isArray(val);
switch(attributes.array_process) {

View file

@ -465,7 +465,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
static updateName = function(_name) {
name = _name;
internalName = string_lower(string_replace_all(name, " ", "_"));
internalName = string_to_var(name);
name_custom = true;
} updateName(_name);
@ -541,6 +541,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
attributes = {};
node.inputs_data[index] = _value;
node.input_value_map[$ internalName] = _value;
#endregion
#region ---- draw ----
@ -592,12 +593,19 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
expUse = false;
expression = "";
expTree = noone;
expContext = {
name: name,
node_name: node.display_name,
value: 0,
node_values: node.input_value_map,
};
express_edit = new textArea(TEXTBOX_INPUT.text, function(str) {
expression = str;
expressionUpdate();
});
express_edit.autocomplete_server = pxl_autocomplete_server;
express_edit.autocomplete_context = expContext;
express_edit.function_guide_server = pxl_function_guide_server;
express_edit.parser_server = pxl_document_parser;
express_edit.format = TEXT_AREA_FORMAT.codeLUA;
@ -1456,14 +1464,14 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
//printCallStack();
global.EVALUATE_HEAD = self;
var params = {
expContext = {
name: name,
node_name: node.display_name,
node: self,
value: val[0]
value: val[0],
node_values: node.input_value_map,
};
var _exp_res = expTree.eval(variable_clone(params));
var _exp_res = expTree.eval(variable_clone(expContext));
//print(json_stringify(expTree, true));
//print($"======= {_exp_res}");
@ -1639,7 +1647,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(connect_type == JUNCTION_CONNECT.output) return;
node.inputs_data[self.index] = animator.getValue(time);
node.setInputData(self.index, animator.getValue(time));
if(tags != VALUE_TAG.none) return true;
@ -2356,7 +2364,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(APPENDING) def_val = getValue(0);
if(connect_type == JUNCTION_CONNECT.input && index >= 0) {
node.inputs_data[index] = animator.getValue(0);
setInputData(index, animator.getValue(0));
//print($"Set input {node.name} - {index} = {node.inputs_data[index]} | {node.inputs_data}");
}

View file

@ -275,9 +275,11 @@
return struct_try_get(params, val);
val = string_trim(val);
if(_string(val)) return _string_trim(val);
if(_string(val))
return _string_trim(val);
var _str = string_splice(val, ".");
if(array_length(_str) > 1 && _str[0] == "self" && struct_has(params, "node_values"))
return struct_try_get(params.node_values, _str[1]);
return nodeGetData(val);
} #endregion

View file

@ -1,4 +1,5 @@
global.NODE_SUB_CATAG = [ "input", "output" ];
global.PCX_CONSTANT = [ "value", "self" ];
function pxl_document_parser(prompt) {
var params = [];
@ -20,13 +21,28 @@ function pxl_document_parser(prompt) {
return params;
}
function pxl_autocomplete_server(prompt, params = []) {
function pxl_autocomplete_server(prompt, params = [], context = {}) {
var res = [];
var pr_list = ds_priority_create();
//////////////////////////////////
ds_priority_clear(pr_list);
for( var i = 0, n = array_length(global.PCX_CONSTANT); i < n; i++ ) {
var gl = global.PCX_CONSTANT[i];
var match = string_partial_match(string_lower(gl), string_lower(prompt));
if(match == -9999) continue;
ds_priority_add(pr_list, [[THEME.ac_constant, 2], gl, "local", gl], match);
}
repeat(ds_priority_size(pr_list))
array_push(res, ds_priority_delete_max(pr_list));
//////////////////////////////////
ds_priority_clear(pr_list);
for( var i = 0, n = array_length(params); i < n; i++ ) {
var gl = params[i];
@ -36,10 +52,6 @@ function pxl_autocomplete_server(prompt, params = []) {
ds_priority_add(pr_list, [[THEME.ac_constant, 2], gl, "local", gl], match);
}
gl = "value";
var match = string_partial_match(string_lower(gl), string_lower(prompt));
if(match != -9999) ds_priority_add(pr_list, [[THEME.ac_constant, 2], gl, "local", gl], match);
repeat(ds_priority_size(pr_list))
array_push(res, ds_priority_delete_max(pr_list));
@ -98,6 +110,18 @@ function pxl_autocomplete_server(prompt, params = []) {
ds_priority_add(pr_list, [[THEME.ac_constant, 0], _key, sp[0], $"{sp[0]}.{_key}"], match);
}
} else if(sp[0] == "self" && array_length(sp) == 2) {
var _val = context[$ "node_values"];
var _arr = variable_struct_get_names(_val);
for( var i = 0, n = array_length(_arr); i < n; i++ ) {
var _key = _arr[i];
var match = string_partial_match(string_lower(_key), string_lower(sp[1]));
if(match == -9999 && sp[1] != "")
continue;
ds_priority_add(pr_list, [[THEME.ac_constant, 2], _key, "self", $"{sp[0]}.{_key}"], match);
}
} else if(ds_map_exists(PROJECT.nodeNameMap, sp[0])) {
if(array_length(sp) == 2) {
for( var i = 0, n = array_length(global.NODE_SUB_CATAG); i < n; i++ ) {

View file

@ -58,9 +58,14 @@ function string_real(val, digMax = 999) { #region
function string_char_last(str, shift = 0) { #region
gml_pragma("forceinline");
return string_char_at(str, string_length(str) - shift);
} #region
} #endregion
function filename_name_only(name) { #region
name = filename_name(name);
return string_replace(name, filename_ext(name), "")
} #endregion
function string_to_var(str) { #region
gml_pragma("forceinline");
return string_replace_all(string_lower(str), " ", "_");
} #endregion

View file

@ -51,6 +51,7 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
autocomplete_box.textbox = self;
autocomplete_server = noone;
autocomplete_object = noone;
autocomplete_context = {};
function_guide_box = instance_create(0, 0, o_dialog_textbox_function_guide);
function_guide_box.textbox = self;
@ -103,11 +104,11 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
var slp = string_splice(crop, [" ", "(", "[", "{", ",", "\n"]);
var pmt = array_safe_get(slp, -1,, ARRAY_OVERFLOW.loop);
var params = [];
var localParams = [];
if(parser_server != noone)
params = parser_server(crop, autocomplete_object);
localParams = parser_server(crop, autocomplete_object);
var data = autocomplete_server(pmt, params);
var data = autocomplete_server(pmt, localParams, autocomplete_context);
if(array_length(data)) {
autocomplete_box.data = data;