From 867543de42a0c3d7fa6554e5e9672fe469ae9386 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 17 Nov 2021 01:04:33 +0800 Subject: *Rect --- .../BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua | 44 +++++++++++++++++++--- Data/BuiltIn/Libraries/GameLab/init.lua | 2 + 2 files changed, 41 insertions(+), 5 deletions(-) (limited to 'Data/BuiltIn/Libraries') diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua b/Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua index e7f29c6..afadee8 100644 --- a/Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua +++ b/Data/BuiltIn/Libraries/GameLab/Engine/Math/Rect.lua @@ -1,4 +1,5 @@ local Rect = GameLab.GlobalClass("GameLab.Engine.Math.Rect") +local Vector2 = GameLab.Include("GameLab.Engine.Math.Vector2") Rect.Ctor = function(self, x, y, width, height) self.x = x or 0 @@ -8,12 +9,12 @@ Rect.Ctor = function(self, x, y, width, height) end Rect.Set = function(self, rect) - if rect._type and rect._type.fullName == "GameLab.Engine.Math.Rect" then + if rect.Is and rect:Is(Rect) then self.x = rect.x or rect.x self.y = rect.y or rect.y self.width = rect.z or rect.width self.height = rect.w or rect.height - else + else self.x = rect.x or rect[1] self.y = rect.y or rect[2] self.width = rect.z or rect[3] @@ -21,13 +22,46 @@ Rect.Set = function(self, rect) end end -Rect.GetPosition = function(self) - local v = GameLab.Engine.Math.Vector2(self.x, self.y) +Rect.get_xy = function(self) + local v = Vector2(self.x, self.y) return v end +Rect.get_location = function(self) + local v = Vector2(self.x, self.y) + return v +end + +Rect.get_position = Rect.get_location + +Rect.get_wh = function(self) + local v = Vector2(self.width, self.height) + return v +end + +Rect.get_size = function(self) + local v = Vector2(self.width, self.height) + return v +end + +Rect.get_w = function(self) + return self.width +end + +Rect.set_w = function(self, w) + self.width = w +end + +Rect.get_h = function(self) + return self.height +end + +Rect.set_h = function(self, h) + self.height = h +end + Rect.GetSize = function(self) - local v = GameLab.Engine.Math.Vector2(self.width, self.height) + local v = Vector2(self.width, self.height) return v end diff --git a/Data/BuiltIn/Libraries/GameLab/init.lua b/Data/BuiltIn/Libraries/GameLab/init.lua index b0c3780..de60ca3 100644 --- a/Data/BuiltIn/Libraries/GameLab/init.lua +++ b/Data/BuiltIn/Libraries/GameLab/init.lua @@ -27,6 +27,8 @@ GameLab.Find = function(name) return m end +GameLab.Include = GameLab.Find + local import = GameLab.Import(...) import "Package" -- cgit v1.1-26-g67d0