jaipack17 / Nature2D

A 2D physics engine for Roblox. Create versatile physics simulations and mechanics with GUIs!
https://jaipack17.github.io/Nature2D/
MIT License
147 stars 8 forks source link

Refactor Creation methods to a single :Create() method #7

Closed jaipack17 closed 2 years ago

jaipack17 commented 2 years ago

Due to frequent updates and me particularly dumping new methods to the API, its quite cluttered which makes it harder to work with. Newcomers will be impacted due to this, making it confusing/harder for them to get the hang of it. I aim to clean and refactor the API with a couple of changes which may improve developer experiences, thus I wish to collect inputs from your side to help evaluate.

Refactor Creation methods to a single :Create() method.

Something which causes clutter are the methods that do almost the same task as others. The potential addition of new objects such as Joints may make object creation perplexing. I wish to refactor the following methods of the Engine to the latter.

Engine:CreateRigidBody()
Engine:CreatePoint()
Engine:CreateConstraint()

-- to

Engine:Create()

How Engine:Create() would work is that it would take in 2 parameters, firstly the type of the object we are trying to create - RigidBody, Point or Constraint and the 2nd parameter for specifying their properties. An example would be:

local body = Engine:Create("RigidBody", {
    guiObject = frame
    collidable = true,
    anchored = false
})

local point = Engine:Create("Point", {
    position = Vector2.new(500, 0),
    visible = false,
    snap = true
})

local constraint = Engine:Create("Constraint", {
    type = "Spring", 
    point1 = point, 
    point2 = body:GetVertices()[1], 
    visible = true, 
    thickness = 2, 
    restLength = 100
})

While this seems like a good idea for cleaning up the API and making object creation easy to understand, we'd have to make a sacrifice. And, that is intellisense. It makes it harder to give suggestions for the type of the object but more importantly their properties when trying to create them. Thus this is something I wish to discuss upon.

Moreover, do you wish to see the properties be in camelCase or PascalCase?

Is it a good step foward?