From 0a9fbc02dca214a309097e32771910707ee693d9 Mon Sep 17 00:00:00 2001 From: jaipack17 <74130881+jaipack17@users.noreply.github.com> Date: Fri, 21 Jan 2022 16:06:43 +0530 Subject: [PATCH] Release v0.6.1. Bug fixes and improvements (#26) --- README.md | 4 ++-- src/Debugging/Exceptions.lua | 16 ++++++++------- src/Engine.lua | 26 +++++++++++++++++------- src/Physics/Point.lua | 39 +++++++++++++++++++----------------- src/Types.lua | 3 +-- wally.toml | 2 +- 6 files changed, 53 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 7c93601..dc68816 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@


- version + version
devforum model @@ -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.
```toml [dependencies] -Nature2D = "jaipack17/nature2d@0.6.0" +Nature2D = "jaipack17/nature2d@0.6.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) diff --git a/src/Debugging/Exceptions.lua b/src/Debugging/Exceptions.lua index 07bba6a..00b2393 100644 --- a/src/Debugging/Exceptions.lua +++ b/src/Debugging/Exceptions.lua @@ -9,7 +9,7 @@ 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!", @@ -17,12 +17,14 @@ local TYPES = { 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 diff --git a/src/Engine.lua b/src/Engine.lua index dac345b..26c17e9 100644 --- a/src/Engine.lua +++ b/src/Engine.lua @@ -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 @@ -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 @@ -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 @@ -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 @@ -564,4 +576,4 @@ function Engine:FrameRateIndependent(independent: boolean) self.independent = independent end -return Engine +return Engine \ No newline at end of file diff --git a/src/Physics/Point.lua b/src/Physics/Point.lua index b604fc8..ee2c2d9 100644 --- a/src/Physics/Point.lua +++ b/src/Physics/Point.lua @@ -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 @@ -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 @@ -244,4 +247,4 @@ function Point:SetMaxForce(maxForce: number) self.maxForce = math.abs(maxForce) end -return Point +return Point \ No newline at end of file diff --git a/src/Types.lua b/src/Types.lua index cf36f47..2f15f49 100644 --- a/src/Types.lua +++ b/src/Types.lua @@ -113,7 +113,6 @@ export type Properties = { AirFriction: number?, Structure: {}?, Mass: number?, - CanTouch: boolean? } export type Custom = { @@ -152,4 +151,4 @@ export type DebugInfo = { } } -return nil +return nil \ No newline at end of file diff --git a/wally.toml b/wally.toml index 2ed620c..c083061 100644 --- a/wally.toml +++ b/wally.toml @@ -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"