Skip to content

Commit

Permalink
| Overhauled the Event system to introduce the functionality of multi…
Browse files Browse the repository at this point in the history
…ple functions per Event and universal Event copying / | Surface.setActive(): Simplified the check for the Surface being active before deactivation / - Font: Fixed event data not being copied on constructor copy
  • Loading branch information
Mtax-Development committed Feb 10, 2022
1 parent 300b276 commit 1466a92
Show file tree
Hide file tree
Showing 17 changed files with 1,508 additions and 333 deletions.
3 changes: 1 addition & 2 deletions GML-OOP.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion options/main/options_main.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 80 additions & 16 deletions scripts/Arrow/Arrow.gml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,42 @@ function Arrow() constructor

if (is_struct(_other.event))
{
event.beforeRender.callback = _other.event.beforeRender.callback;
event.beforeRender.argument = _other.event.beforeRender.argument;
event.afterRender.callback = _other.event.afterRender.callback;
event.afterRender.argument = _other.event.afterRender.argument;
event = {};

var _eventList = variable_struct_get_names(_other.event);

var _i = [0, 0];
repeat (array_length(_eventList))
{
var _event = {};
var _other_event = variable_struct_get(_other.event,
_eventList[_i[0]]);
var _eventPropertyList = variable_struct_get_names(_other_event);

_i[1] = 0;
repeat (array_length(_eventPropertyList))
{
var _property = variable_struct_get(_other_event,
_eventPropertyList[_i[1]]);

var _value = _property;

if (is_array(_property))
{
_value = [];

array_copy(_value, 0, _property, 0, array_length(_property));
}

variable_struct_set(_event, _eventPropertyList[_i[1]], _value);

++_i[1];
}

variable_struct_set(event, _eventList[_i[0]], _event);

++_i[0];
}
}
else
{
Expand Down Expand Up @@ -115,28 +147,60 @@ function Arrow() constructor

if (self.isFunctional())
{
if (alpha > 0)
if ((is_struct(event)) and (event.beforeRender.callback != undefined))
{
if ((is_struct(event))) and (is_method(event.beforeRender.callback))
var _callback = ((is_array(event.beforeRender.callback))
? event.beforeRender.callback
: [event.beforeRender.callback]);
var _callback_count = array_length(_callback);
var _argument = ((is_array(event.beforeRender.argument))
? event.beforeRender.argument
: array_create(_callback_count,
event.beforeRender.argument));

var _i = 0;
repeat (_callback_count)
{
script_execute_ext(method_get_index(event.beforeRender.callback),
((is_array(event.beforeRender.argument)
? event.beforeRender.argument
: [event.beforeRender.argument])));
if (is_method(_callback[_i]))
{
script_execute_ext(method_get_index(_callback[_i]),
((is_array(_argument[_i]) ? _argument[_i]
: [_argument[_i]])));
}

++_i;
}

}

if (alpha > 0)
{
draw_set_alpha(alpha);
draw_set_color(color);

draw_arrow(round(location.x1), round(location.y1), round(location.x2),
round(location.y2), size);
}

if ((is_struct(event)) and (event.afterRender.callback != undefined))
{
var _callback = ((is_array(event.afterRender.callback))
? event.afterRender.callback : [event.afterRender.callback]);
var _callback_count = array_length(_callback);
var _argument = ((is_array(event.afterRender.argument))
? event.afterRender.argument
: array_create(_callback_count, event.afterRender.argument));

if ((is_struct(event))) and (is_method(event.afterRender.callback))
var _i = 0;
repeat (_callback_count)
{
script_execute_ext(method_get_index(event.afterRender.callback),
((is_array(event.afterRender.argument)
? event.afterRender.argument
: [event.afterRender.argument])));
if (is_method(_callback[_i]))
{
script_execute_ext(method_get_index(_callback[_i]),
((is_array(_argument[_i]) ? _argument[_i]
: [_argument[_i]])));
}

++_i;
}
}
}
Expand Down
92 changes: 78 additions & 14 deletions scripts/Circle/Circle.gml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,42 @@ function Circle() constructor

if (is_struct(_other.event))
{
event.beforeRender.callback = _other.event.beforeRender.callback;
event.beforeRender.argument = _other.event.beforeRender.argument;
event.afterRender.callback = _other.event.afterRender.callback;
event.afterRender.argument = _other.event.afterRender.argument;
event = {};

var _eventList = variable_struct_get_names(_other.event);

var _i = [0, 0];
repeat (array_length(_eventList))
{
var _event = {};
var _other_event = variable_struct_get(_other.event,
_eventList[_i[0]]);
var _eventPropertyList = variable_struct_get_names(_other_event);

_i[1] = 0;
repeat (array_length(_eventPropertyList))
{
var _property = variable_struct_get(_other_event,
_eventPropertyList[_i[1]]);

var _value = _property;

if (is_array(_property))
{
_value = [];

array_copy(_value, 0, _property, 0, array_length(_property));
}

variable_struct_set(_event, _eventPropertyList[_i[1]], _value);

++_i[1];
}

variable_struct_set(event, _eventList[_i[0]], _event);

++_i[0];
}
}
else
{
Expand Down Expand Up @@ -359,12 +391,29 @@ function Circle() constructor

if (self.isFunctional())
{
if ((is_struct(event))) and (is_method(event.beforeRender.callback))
if ((is_struct(event)) and (event.beforeRender.callback != undefined))
{
script_execute_ext(method_get_index(event.beforeRender.callback),
((is_array(event.beforeRender.argument)
? event.beforeRender.argument
: [event.beforeRender.argument])));
var _callback = ((is_array(event.beforeRender.callback))
? event.beforeRender.callback
: [event.beforeRender.callback]);
var _callback_count = array_length(_callback);
var _argument = ((is_array(event.beforeRender.argument))
? event.beforeRender.argument
: array_create(_callback_count,
event.beforeRender.argument));

var _i = 0;
repeat (_callback_count)
{
if (is_method(_callback[_i]))
{
script_execute_ext(method_get_index(_callback[_i]),
((is_array(_argument[_i]) ? _argument[_i]
: [_argument[_i]])));
}

++_i;
}
}

var _location_x = round(location.x);
Expand Down Expand Up @@ -398,12 +447,27 @@ function Circle() constructor
outline_color, true);
}

if ((is_struct(event))) and (is_method(event.afterRender.callback))
if ((is_struct(event)) and (event.afterRender.callback != undefined))
{
script_execute_ext(method_get_index(event.afterRender.callback),
((is_array(event.afterRender.argument)
? event.afterRender.argument
: [event.afterRender.argument])));
var _callback = ((is_array(event.afterRender.callback))
? event.afterRender.callback : [event.afterRender.callback]);
var _callback_count = array_length(_callback);
var _argument = ((is_array(event.afterRender.argument))
? event.afterRender.argument
: array_create(_callback_count, event.afterRender.argument));

var _i = 0;
repeat (_callback_count)
{
if (is_method(_callback[_i]))
{
script_execute_ext(method_get_index(_callback[_i]),
((is_array(_argument[_i]) ? _argument[_i]
: [_argument[_i]])));
}

++_i;
}
}
}
else
Expand Down
92 changes: 78 additions & 14 deletions scripts/Ellipse/Ellipse.gml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,42 @@ function Ellipse() constructor

if (is_struct(_other.event))
{
event.beforeRender.callback = _other.event.beforeRender.callback;
event.beforeRender.argument = _other.event.beforeRender.argument;
event.afterRender.callback = _other.event.afterRender.callback;
event.afterRender.argument = _other.event.afterRender.argument;
event = {};

var _eventList = variable_struct_get_names(_other.event);

var _i = [0, 0];
repeat (array_length(_eventList))
{
var _event = {};
var _other_event = variable_struct_get(_other.event,
_eventList[_i[0]]);
var _eventPropertyList = variable_struct_get_names(_other_event);

_i[1] = 0;
repeat (array_length(_eventPropertyList))
{
var _property = variable_struct_get(_other_event,
_eventPropertyList[_i[1]]);

var _value = _property;

if (is_array(_property))
{
_value = [];

array_copy(_value, 0, _property, 0, array_length(_property));
}

variable_struct_set(_event, _eventPropertyList[_i[1]], _value);

++_i[1];
}

variable_struct_set(event, _eventList[_i[0]], _event);

++_i[0];
}
}
else
{
Expand Down Expand Up @@ -183,12 +215,29 @@ function Ellipse() constructor

if (self.isFunctional())
{
if ((is_struct(event))) and (is_method(event.beforeRender.callback))
if ((is_struct(event)) and (event.beforeRender.callback != undefined))
{
script_execute_ext(method_get_index(event.beforeRender.callback),
((is_array(event.beforeRender.argument)
? event.beforeRender.argument
: [event.beforeRender.argument])));
var _callback = ((is_array(event.beforeRender.callback))
? event.beforeRender.callback
: [event.beforeRender.callback]);
var _callback_count = array_length(_callback);
var _argument = ((is_array(event.beforeRender.argument))
? event.beforeRender.argument
: array_create(_callback_count,
event.beforeRender.argument));

var _i = 0;
repeat (_callback_count)
{
if (is_method(_callback[_i]))
{
script_execute_ext(method_get_index(_callback[_i]),
((is_array(_argument[_i]) ? _argument[_i]
: [_argument[_i]])));
}

++_i;
}
}

var _location_x1 = round(location.x1);
Expand Down Expand Up @@ -225,12 +274,27 @@ function Ellipse() constructor
outline_color, outline_color, true);
}

if ((is_struct(event))) and (is_method(event.afterRender.callback))
if ((is_struct(event)) and (event.afterRender.callback != undefined))
{
script_execute_ext(method_get_index(event.afterRender.callback),
((is_array(event.afterRender.argument)
? event.afterRender.argument
: [event.afterRender.argument])));
var _callback = ((is_array(event.afterRender.callback))
? event.afterRender.callback : [event.afterRender.callback]);
var _callback_count = array_length(_callback);
var _argument = ((is_array(event.afterRender.argument))
? event.afterRender.argument
: array_create(_callback_count, event.afterRender.argument));

var _i = 0;
repeat (_callback_count)
{
if (is_method(_callback[_i]))
{
script_execute_ext(method_get_index(_callback[_i]),
((is_array(_argument[_i]) ? _argument[_i]
: [_argument[_i]])));
}

++_i;
}
}
}
else
Expand Down
Loading

0 comments on commit 1466a92

Please sign in to comment.