-
Notifications
You must be signed in to change notification settings - Fork 1
Creating Object Classes
Before you start creating classes, you need to know the terminology that will be referred to here. Object Classes refer to the objects that you can manipulate, blocks, the world etc. Data Classes refer to data types, these aren't part of the ancestry but part of the objects inside the ancestry. This document tells you how to create Object Classes. If you would like to create Data Classes, you may find it here.
Object Classes are managed by Object.lua
, located at /Framework/Object.lua
. Object manages how the ancestry works, parenting, but also is the handler for all the Object Classes you may create.
Within your code, preferably at the beginning, you want to require the Object
module for proper functionality.
require('Framework/Object');
You don't need to set a variable for the module as the module does that for you, in this case it's Object
.
The main function you want to use to create a class is Object.newClass
, arguments this function is shown here. <...> are placeholders.
Object:newClass('Particle', {
<PropertiesList>
}, <Limited>);
PropertiesList contains a list of Property tables with their information etc.
{
<PropertyData>
<PropertyData>
<PropertyData>
...
};
PropertyData are arranged like this
{
Name = '<Name>';
Generator = <Generator>;
Updater = <Updater>;
IsCallback = <IsCallback>;
EditMode = <EditMode>;
Default = <Value>;
};
-
Name is strictly a string, refers to the name of the property, such as
Name
orCanCollide
. - Generator is strictly a boolean, this determines whether or not when the default value will be called, if true default value will be called ONCE and whatever is returned will be saved into the object.
- Updater is strictly a boolean, this determines whether or not when the default value will be called, if true default value will be called as many times as the property is referenced, the index is not saved into the object.
- IsCallback is strictly a boolean, determines whether or not the default value is considered a callback only if the default value is a function. If true, the property can be overridden by another function to set the callback function.
-
EditMode is strictly an integer value, Edit Mode determines the interaction for the property.
- 0 - No read or write permissions
- 1 - Only read permissions
- 2 - Only write permissions
- 3 - Read and write permissions
- Value is any value, be it a function, another Object Class, an event, or even just standard integers, strings, and booleans.
Ripples are managed by Ripple.lua
, in order to create a ripple property, EditMode = 1
and Generator = true
in the PropertyData have to be set. EditMode isn't required but recommended, but Generator is required for it to work properly.
require('Framework/Ripple'); --manages the events
We need to load up Ripple in order for functionality to work correctly.
{
Name = 'RippleName';
Generator = true;
Updater = false;
IsCallback = false;
EditMode = 1;
Default = function(self)
return Ripple:TearRipple('RippleName'); --RippleName is whatever the event name is
end;
};
Note that there are actually two kinds of ripples, the standard one shown above, and proxy ripples. For more information on ripples, you can go here.
If you wish to have a property be a proxy ripple, then simply return the Ripple.AttachProcessor
function instead and after Ripple.TearRipple
.
{
Name = 'RippleName';
Generator = true;
Updater = false;
IsCallback = false;
EditMode = 1;
Default = function(self)
local RippleObject = Ripple:TearRipple('RippleName'); --RippleName is whatever the event name is
return Ripple:AttachProcessor(self, 'RippleName');
end;
};
Proxy Ripples are created so that it's easier to call events that are specified to a specific Object or Data Class, standard ripples are more generalized events, firing an entire standard ripple will send the same arguments to all the connections different or not. However, firing a proxy ripple will only fire a set number of connections for a specific class.
Custom Types are managed by Type.lua
, you're going to have to require the module first before you want to create one, when the module is required the API can be referenced via CustomTypes
.
require('Framework/Type'); --manages custom typing
An example PropertyData can be found below, note Generator = true
is recommended, and IsCallback = false
is suggested. Alternatively you can have the default value be the actual vector object itself too. EditMode = 3
is also suggested. Except for the fact that the Data classes have to be created before you do this.
Note: Generator will run the default value function ONCE, afterward whatever the function returns is then saved internally to be referenced again.
{
Name = 'Position';
Generator = true;
Updater = false;
IsCallback = false;
EditMode = 3;
Default = function(self)
local vector = CustomTypes:createType('Vector');
vector.x = 0;
vector.y = 0;
return vector;
end;
};
Alternative execution can be found below, but note that the Vector has to be created before the property is registered.
{
Name = 'Position';
Generator = false;
Updater = false;
IsCallback = false;
EditMode = 3;
Default = (function(self)
local vector = CustomTypes:createType('Vector');
vector.x = 0;
vector.y = 0;
return vector;
end)();
};
Limited is a boolean value that determines whether or not the object can only be created once per world. If you want to limit the object, has to be true, if you want no limit then has to be false.
--If you want one Object Class per world.
require('Framework/Object');
Object:newClass('Particle', {
<PropertiesList>
}, true);
Work in progress wiki!!