@rbxts/objecat
v1.1.1
Published
Yet Another Way To Create Instances
Downloads
3
Readme
Objecat is a very simple library coming with only three functions and one variable. It is used to create Instances in a less verbose way. To put it simply, making an Instance on Roblox and setting its properties is ugly. Objecat makes it less ugly.
Objecat uses standard naming conventions when it comes to properties and methods. Property names and method names are in camelCase
. This currently does not apply to after it is created, only on creation, this may be changed in a future release.
Installation
Objecat can be installed in these ways:
- Using Wally (recommended for Rojo projects)
- Using NPM (recommended for roblox-ts projects)
- Or The Roblox Model
Installation Using Wally
To install using Wally, you just need to add the following to your wally.toml
file:
[dependencies]
Objecat = "alexinite/[email protected]"
Then run wally install
in your terminal.
Installation Using NPM
If you're using roblox-ts, this will be the preferred way to download it. It's worth noting that using the roblox-ts package that it is fully type-safe. This currently is not in effect for events, but will be in a future release.
npm install @rbxts/objecat
Usage
Objecat has three main exports: create()
, event()
, and children
. These are all documented below.
create(className: string, properties?: table): Instance
create<T extends keyof CreatableInstances>(className: T, properties?: ObjecatWritableProperties<Instances[T]>): Instances[T]
create()
is the main function of Objecat. Used for creating instances, in general this should be the only top-level function you use from Objecat, the other two are used to define properties and events when creating instances.
local Objecat = require(path.to.objecat.package)
local create = Objecat.create
local part = create("Part", {
anchored = true,
position = Vector3.new(0, 5, 0),
parent = workspace
})
part.Anchored = false -- This may be changed in the future to be lowercase
import { create } from "@rbxts/objecat";
const part = create("Part", {
anchored: true,
position: new Vector3(0, 5, 0),
parent: game.Workspace,
});
part.Anchored = false;
event(str: string): string
event<K extends string>(str: K): \
_event${K}__``
event()
just takes a string and returns a string to be used as a symbol for an event. This is used to define events when creating instances. When destroying an Instance created by Objecat, any event will be automatically disconnected for you.
local event = Objecat.event
local part = create("Part", {
[event "touched"] = function (otherPart)
print("Touched by " .. otherPart.Name .. "!")
end
})
-- This may be changed in the future to support event()
part.ChildAdded:Connect(function (child)
print("Child added!")
end)
import { create, event } from "@rbxts/objecat";
const part = create("Part", {
[event("touched")] = (otherPart: BasePart) => {
print(`Touched by ${otherPart.Name}!`);
},
});
part.ChildAdded.Connect((child) => {
print("Child added!");
});
children: string
children: "__children__"
children
is a string that just refers to a symbol for adding children to an Instance being created with Objecat. When destroying the parent Instance, all children will be automatically destroyed for you, including their events.
Children can either be an Array
(or table) of Instances, or a single Instance.
local children = Objecat.children
local part = create("Part", {
[children] = {
create("PointLight")
}
})
import { create, children } from "@rbxts/objecat";
const part = create("Part", {
[children]: [
create("PointLight")
],
});
clone(instance: Instance, properties?: table): Instance
clone<T extends Instance>(instance: T, properties?: ObjecatWritableProperties<T>): T
clone()
is a function that clones an Instance and returns the clone. If properties.parent
is not set, it will default to the parent of the Instance being cloned. The properties table works the same as the create()
method. Also, when making a clone it will automatically bind all descendants to a clean-up task.
local clone = Objecat.clone
local part = create("Part", {
anchored = true
})
local newPart = clone(part, {
color = Color3.fromRGB(255, 0, 0)
})
import { create, clone } from "@rbxts/objecat";
const part = create("part", {
anchored: true,
});
const newPart = clone(part, {
color: Color3.fromRGB(255, 0, 0),
});
Current Roadmap
- [ ] Make the
create()
method behave more like Elttob'sNew()
method for Fusion. - [ ] Maybe add support for after a Instance is created via
create()
to be able to define properties, children, and events as if you were still in thecreate()
function. - [ ] Add
self
to events created withevent()
so you can access the Instance that the event is attached to. - [ ] Somehow make
event()
know what events can and can't be created?