Skip to content

Commit

Permalink
Release v0.6.1. Bug fixes and improvements (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaipack17 authored Jan 21, 2022
1 parent 470ab5b commit 0a9fbc0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<img src="https://doy2mn9upadnk.cloudfront.net/uploads/default/original/4X/e/7/0/e709b34f89add2336a7d74faee3b2a839a9391b0.png" width="480" /><br/><br/>
<a href="https://devforum.roblox.com/t/physics-library-nature2d-bring-ui-elements-to-life/1510935/75"><img alt="version" src="https://img.shields.io/badge/v0.6.0--beta-version-%231FD67F"></img></a>
<a href="https://devforum.roblox.com/t/physics-library-nature2d-bring-ui-elements-to-life/1510935/75"><img alt="version" src="https://img.shields.io/badge/v0.6.1--beta-version-%231FD67F"></img></a>
<br/>
<a href="https://devforum.roblox.com/t/physics-library-nature2d-bring-ui-elements-to-life/1510935/"><img alt="devforum" src="https://img.shields.io/badge/topic-devforum-white"></img></a>
<a href="https://www.roblox.com/library/7625799164/Nature2D"><img alt="model" src="https://img.shields.io/badge/asset-roblox-white"></img></a>
Expand Down Expand Up @@ -37,7 +37,7 @@ https://www.roblox.com/library/7625799164/Nature2D
**Using wally** - Use [wally](https://github.com/UpliftGames/wally), a package manager for roblox to install Nature2D in your external code editor. This requires wally to be installed on your device. Then, add Nature2D to the dependencies listed in your `wally.toml` file.<br/>
```toml
[dependencies]
Nature2D = "jaipack17/[email protected].0"
Nature2D = "jaipack17/[email protected].1"
```
After that, Run `wally install` in the cli. Nature2D should be installed in your root directory. If you encounter any errors or problems installing Nature2D using wally, [open an issue!](https://github.com/jaipack17/Nature2D/issues)

Expand Down
16 changes: 9 additions & 7 deletions src/Debugging/Exceptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ local TYPES = {
INVALID_CONSTRAINT_THICKNESS = "Received Invalid Constraint Thickness.",
SAME_ID = "Cannot ignore collisions for the same RigidBodies.",
INVALID_RIGIDBODY = "Received Invalid RigidBody.",
INVALID_OBJECT = "Received an Invalid Object. Valid objects - RigidBody, Point and Constraint",
INVALID_OBJECT = "Received an Invalid Object. Valid objects - RigidBody, Point and Constraint.",
INVALID_PROPERTY = "Received an Invalid Object Property.",
MUST_HAVE_PROPERTY = "Missing must-have properties.",
CANVAS_FRAME_NOT_FOUND = "No canvas frame found, initialize the canvas's frame to render custom Points and Constraints!",
INVALID_TIME = "Received invalid time to apply force for.",
ALREADY_STARTED = "Engine is already running."
}

return function (TASK: string, TYPE: string)
if TYPES[TYPE] then
if TASK == "warn" then
warn(TYPES[TYPE])
elseif TASK == "error" then
error("[Nature2D]: "..TYPES[TYPE], 2)
return function (TASK: string, TYPE: string, details: string?)
if TYPES[TYPE] then
local exception = string.format("[Nature2D]: %s%s", TYPES[TYPE], if details then " "..details else "")

if TASK == "warn" then
warn(exception)
elseif TASK == "error" then
error(exception, 2)
end
end
end
26 changes: 19 additions & 7 deletions src/Engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local function CollisionResponse(body: Types.RigidBody, other: Types.RigidBody,
-- Fire the touched event
if body.Touched._handlerListHead and body.Touched._handlerListHead.Connected then
if not SearchTable(oldCollidingWith, other, function(a, b) return a.id == b.id end) then
body.Touched:Fire(other.id)
body.Touched:Fire(other.id, Collision)
end
end

Expand Down Expand Up @@ -247,8 +247,14 @@ function Engine:Create(object: string, properties: Types.Properties)

-- Validate property table
for prop, value in pairs(properties) do
if not table.find(Globals.VALID_OBJECT_PROPS, prop) or not table.find(Globals[string.lower(object)].props, prop) then
throwException("error", "INVALID_PROPERTY")
if not table.find(Globals.VALID_OBJECT_PROPS, prop) then
throwException("error", "INVALID_PROPERTY", string.format("%q is not a valid property!", prop))
return
end

if not table.find(Globals[string.lower(object)].props, prop) then
throwException("error", "INVALID_PROPERTY", string.format("%q is not a valid property for a %s!", prop, object))
return
end

if Globals.OBJECT_PROPS_TYPES[prop] and typeof(value) ~= Globals.OBJECT_PROPS_TYPES[prop] then
Expand All @@ -274,7 +280,8 @@ function Engine:Create(object: string, properties: Types.Properties)
end

if throw then
throwException("error", "MUST_HAVE_PROPERTY")
throwException("error", "MUST_HAVE_PROPERTY", string.format("You must specify the %q property for a %s!", prop, object))
return
end
end
end
Expand Down Expand Up @@ -303,8 +310,13 @@ function Engine:Create(object: string, properties: Types.Properties)
end

-- Validate restlength and thickness of the constraint
if properties.RestLength and properties.RestLength <= 0 then throwException("error", "INVALID_CONSTRAINT_LENGTH") end
if properties.Thickness and properties.Thickness <= 0 then throwException("error", "INVALID_CONSTRAINT_THICKNESS") end
if properties.RestLength and properties.RestLength <= 0 then
throwException("error", "INVALID_CONSTRAINT_LENGTH")
end

if properties.Thickness and properties.Thickness <= 0 then
throwException("error", "INVALID_CONSTRAINT_THICKNESS")
end

if properties.Point1 and properties.Point2 and properties.Type then
-- Calculate distance
Expand Down Expand Up @@ -564,4 +576,4 @@ function Engine:FrameRateIndependent(independent: boolean)
self.independent = independent
end

return Engine
return Engine
39 changes: 21 additions & 18 deletions src/Physics/Point.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,35 @@ end
function Point:KeepInCanvas()
-- vx = velocity.X
-- vy = velocity.Y
local vx = self.pos.x - self.oldPos.x
local vy = self.pos.y - self.oldPos.y
local vx = self.pos.X - self.oldPos.X
local vy = self.pos.Y - self.oldPos.Y

local width = self.canvas.size.x
local height = self.canvas.size.y
local boundX = self.canvas.topLeft.X + self.canvas.size.X
local boundY = self.canvas.topLeft.Y + self.canvas.size.Y

local collision = false
local edge

if self.pos.y > height then
self.pos = Vector2.new(self.pos.x, height)
self.oldPos = Vector2.new(self.oldPos.x, self.pos.y + vy * self.bounce)
if self.pos.Y > boundY then
self.pos = Vector2.new(self.pos.X, boundY)
self.oldPos = Vector2.new(self.oldPos.X, self.pos.Y + vy * self.bounce)
collision = true
edge = "Bottom"
elseif self.pos.y < self.canvas.topLeft.y then
self.pos = Vector2.new(self.pos.x, self.canvas.topLeft.y)
self.oldPos = Vector2.new(self.oldPos.x, self.pos.y - vy * self.bounce)
elseif self.pos.Y < self.canvas.topLeft.Y then
self.pos = Vector2.new(self.pos.X, self.canvas.topLeft.Y)
self.oldPos = Vector2.new(self.oldPos.X, self.pos.Y - vy * self.bounce)
collision = true
edge = "Top"
end

if self.pos.x < self.canvas.topLeft.x then
self.pos = Vector2.new(self.canvas.topLeft.x, self.pos.y)
self.oldPos = Vector2.new(self.pos.x + vx * self.bounce, self.oldPos.y)
if self.pos.X < self.canvas.topLeft.X then
self.pos = Vector2.new(self.canvas.topLeft.X, self.pos.Y)
self.oldPos = Vector2.new(self.pos.X + vx * self.bounce, self.oldPos.Y)
collision = true
edge = "Left"
elseif self.pos.x > width then
self.pos = Vector2.new(width, self.pos.y)
self.oldPos = Vector2.new(self.pos.x - vx * self.bounce, self.oldPos.y)
elseif self.pos.X > boundX then
self.pos = Vector2.new(boundX, self.pos.Y)
self.oldPos = Vector2.new(self.pos.X - vx * self.bounce, self.oldPos.Y)
collision = true
edge = "Right"
end
Expand All @@ -158,8 +158,11 @@ function Point:KeepInCanvas()
-- Fire CanvasEdgeTouched event
if body and body.Parent then
if collision then
local prev = body.Parent.Collisions.CanvasEdge
body.Parent.Collisions.CanvasEdge = true
body.Parent.CanvasEdgeTouched:Fire(edge)
if prev == false then
body.Parent.CanvasEdgeTouched:Fire(edge)
end
else
body.Parent.Collisions.CanvasEdge = false
end
Expand Down Expand Up @@ -244,4 +247,4 @@ function Point:SetMaxForce(maxForce: number)
self.maxForce = math.abs(maxForce)
end

return Point
return Point
3 changes: 1 addition & 2 deletions src/Types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export type Properties = {
AirFriction: number?,
Structure: {}?,
Mass: number?,
CanTouch: boolean?
}

export type Custom = {
Expand Down Expand Up @@ -152,4 +151,4 @@ export type DebugInfo = {
}
}

return nil
return nil
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "jaipack17/nature2d"
description = "Create versatile physics simulations and mechanics with Guis on Roblox!"
authors = ["jaipack17"]
version = "0.6.0"
version = "0.6.1"
license = "MIT"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
Expand Down

0 comments on commit 0a9fbc0

Please sign in to comment.