Skip to content

Creating Data Classes

Tony Nguyen edited this page May 8, 2020 · 4 revisions

Data Classes are classes that refer to custom data types. You can find how to create your own data types here. Object and Data Classes are not the same, if you want to find out how to create Object Classes you can go here.


Who manages the Data Classes?

Data Classes are managed by Type.lua, located at /Framework/Type.lua. Type reassigns the default type() function to a modified version that takes into account that the variable or object may possess a custom data type.

Creating a Data Type

Requiring the necessary libraries

Preferably at the beginning, you want to require the Type module for proper functionality.

require('Framework/Type')

The global variable referencing the module is CustomTypes.

Creating a Data Type

CustomTypes.newType is the main function you want to use to create a Data Class, example arguments are shown below. <...> are placeholders for what you can add to the arguments.

CustomTypes:newType('Neuron', {
    <PropertyData>
    <PropertyData>
    ...
}, {
    <MetatableEvent>
    <MetatableEvent>
    ...
});

MetatableEvent refers to any form on metatable event on the object, Type uses __index, __newindex, __tostring and __metatable events, it's not recommended to rewrite these events.

PropertyData refers to a table of data on one property of the Data Class, for instance, it could contain information on how the Name property will operate and be handled.


Adding properties

PropertyData is arranged similarly to the PropertyData used for Object Classes, however, the indexes are slightly different. Functionality still remains the same.

{
    index = '<Name>';
    function_dependent = <function>;
    is_callback = <callback>;
    default = <value>;
    edit_mode = <edit_mode>;
};
  • Name is strictly a string, refers to the name of the property such as Name or CanCollide.
  • function_dependent is strictly a boolean, similar to Generator as if true, the default value will be called once and then whatever is returned will be saved into the object.
  • is_callback is strictly a boolean, determines whether or not the function will be allowed to be rewritten.
  • value is a variant, can be any value like another Object Class, Data Class, or even just standard integers and strings.
  • edit_mode is strictly an integer, determines how the property can be interacted with.
    • 0 - No read or write permissions
    • 1 - Only read permissions
    • 2 - Only write permissions
    • 3 - Read and write permissions

Registering Ripple Properties

Ripples are managed by Ripple.lua, in order to create a ripple property, edit_mode = 1 and function_dependent = true options are recommended for the property to work as expected. We need to load up the module for correct functionality.

require('Framework/Ripple');

A standard ripple can be registered like the example below

{
    index = 'Changed';
    function_dependent = true;
    is_callback = false;
    default = function(self)
        local RippleObject = Ripple:TearRipple('Changed'); --Changed is whatever the ripple name is
	return RippleObject;
    end;
    edit_mode = 1;
};

A proxy ripple is similar, just another function shown in the example below

{
    index = 'Changed';
    function_dependent = true;
    is_callback = false;
    default = function(self)
        local RippleObject = Ripple:TearRipple('Changed'); --Changed is whatever the ripple name is
	return Ripple:AttachProcessor(self, 'Changed');
    end;
    edit_mode = 1;
};

Registering Custom Types

To register a custom type, edit_mode = 3 and function_dependent = true is recommended, relatively similar to registering a Data Class to a property for a Object Class.

{
    index = 'Changed';
    function_dependent = true;
    is_callback = false;
    default = function(self)
	return CustomTypes:createType('Vector');
    end;
    edit_mode = 3;
};

Work in progress wiki!!

Clone this wiki locally