big-refactor #106

Merged
kazhnuz merged 24 commits from big-refactor into master 2021-05-07 19:30:53 +02:00
6 changed files with 32 additions and 25 deletions
Showing only changes of commit 040240492e - Show all commits

View file

@ -161,24 +161,24 @@ function Actor2D:addHitboxFromFrameData(framedata, animationID, frameID, hitboxI
end end
if (type == "main") then if (type == "main") then
self.mainHitbox:modify(ox, oy, w, h) self.mainHitbox:setFromData({ox, oy, w, h})
else else
local hitboxName = anim .. frame .. type .. id local hitboxName = anim .. frame .. type .. id
self:addHitbox(hitboxName, type, ox, oy, w, h, isSolid) self:addHitbox(hitboxName, type, {ox, oy, w, h}, isSolid)
return hitboxName return hitboxName
end end
end end
function Actor2D:initMainHitbox() function Actor2D:initMainHitbox()
self.mainHitbox = Hitbox(self, self.type, 0, 0, self.w, self.h, self.isSolid) self.mainHitbox = Hitbox(self, self.type, {0, 0, self.w, self.h}, self.isSolid)
self.mainHitbox:advertiseAsMainHitbox() self.mainHitbox:advertiseAsMainHitbox()
end end
function Actor2D:addHitbox(name, type, ox, oy, w, h, isSolid) function Actor2D:addHitbox(name, type, data, isSolid)
if (self.hitboxes[name] ~= nil) then if (self.hitboxes[name] ~= nil) then
core.debug:warning("actor2D", "the hitbox " .. name .. " already exists") core.debug:warning("actor2D", "the hitbox " .. name .. " already exists")
else else
local hitbox = Hitbox(self, type, ox, oy, w, h, isSolid) local hitbox = Hitbox(self, type, data, isSolid)
self.hitboxes[name] = hitbox self.hitboxes[name] = hitbox
return hitbox return hitbox
end end

View file

@ -186,24 +186,24 @@ function Actor3D:addHitboxFromFrameData(framedata, animationID, frameID, hitboxI
end end
if (type == "main") then if (type == "main") then
self.mainHitbox:modify(ox, oy, oz, w, h, d) self.mainHitbox:setFromData({ox, oy, oz, w, h, d})
else else
local hitboxName = anim .. frame .. type .. id local hitboxName = anim .. frame .. type .. id
self:addHitbox(hitboxName, type, ox, oy, oz, w, h, d, isSolid) self:addHitbox(hitboxName, type, {ox, oy, oz, w, h, d}, isSolid)
return hitboxName return hitboxName
end end
end end
function Actor3D:initMainHitbox() function Actor3D:initMainHitbox()
self.mainHitbox = Hitbox(self, self.type, 0, 0, 0, self.w, self.h, self.d, self.isSolid) self.mainHitbox = Hitbox(self, self.type, {0, 0, 0, self.w, self.h, self.d}, self.isSolid)
self.mainHitbox:advertiseAsMainHitbox() self.mainHitbox:advertiseAsMainHitbox()
end end
function Actor3D:addHitbox(name, type, ox, oy, oz, w, h, d, isSolid) function Actor3D:addHitbox(name, type, data, isSolid)
if (self.hitboxes[name] ~= nil) then if (self.hitboxes[name] ~= nil) then
core.debug:warning("actor3D", "the hitbox " .. name .. " already exists") core.debug:warning("actor3D", "the hitbox " .. name .. " already exists")
else else
local hitbox = Hitbox(self, type, ox, oy, oz, w, h, d, isSolid) local hitbox = Hitbox(self, type, data, isSolid)
self.hitboxes[name] = hitbox self.hitboxes[name] = hitbox
return hitbox return hitbox
end end

View file

@ -27,9 +27,8 @@ local BaseActor = Object:extend()
-- INIT FUNCTIONS -- INIT FUNCTIONS
-- Initialise the actor and its base functions -- Initialise the actor and its base functions
function BaseActor:init(world, type, x, y, z, w, h, d, isSolid) function BaseActor:init(world, type)
self.type = type or "" self.type = type or ""
self.isSolid = isSolid or false
self.depth = 0 self.depth = 0
self.updateFunctions = {} self.updateFunctions = {}

View file

@ -27,16 +27,13 @@ local Hitbox2D = Object:extend()
-- INIT FUNCTIONS -- INIT FUNCTIONS
-- Initialise the actor and its base functions -- Initialise the actor and its base functions
function Hitbox2D:new(owner, type, ox, oy, w, h, isSolid) function Hitbox2D:new(owner, type, data, isSolid)
self.owner = owner self.owner = owner
self.world = owner.world self.world = owner.world
self.type = type self.type = type
self.ox = ox self:setFromData(data)
self.oy = oy
self.x, self.y = self:getPosition() self.x, self.y = self:getPosition()
self.w = w
self.h = h
self.isSolid = isSolid self.isSolid = isSolid
self.isMainHitBox = false self.isMainHitBox = false
@ -57,6 +54,13 @@ function Hitbox2D:modify(ox, oy, w, h)
self.h = h self.h = h
end end
function Hitbox2D:setFromData(data)
self.ox = data[1]
self.oy = data[2]
self.w = data[3]
self.h = data[4]
end
function Hitbox2D:setDebugColor(r,g,b) function Hitbox2D:setDebugColor(r,g,b)
self.debug = {} self.debug = {}
self.debug.r = r self.debug.r = r

View file

@ -27,18 +27,13 @@ local Hitbox3D = Object:extend()
-- INIT FUNCTIONS -- INIT FUNCTIONS
-- Initialise the actor and its base functions -- Initialise the actor and its base functions
function Hitbox3D:new(owner, type, ox, oy, oz, w, h, d, isSolid) function Hitbox3D:new(owner, type, data, isSolid)
self.owner = owner self.owner = owner
self.world = owner.world self.world = owner.world
self.type = type self.type = type
self.ox = ox self:setFromData(data)
self.oy = oy
self.oz = oz
self.x, self.y, self.z = self:getPosition() self.x, self.y, self.z = self:getPosition()
self.w = w
self.h = h
self.d = d
self.isSolid = isSolid self.isSolid = isSolid
self.isMainHitBox = false self.isMainHitBox = false
@ -61,6 +56,15 @@ function Hitbox3D:modify(ox, oy, oz, w, h, d)
self.d = d self.d = d
end end
function Hitbox3D:setFromData(data)
self.ox = data[1]
self.oy = data[2]
self.oz = data[3]
self.w = data[4]
self.h = data[5]
self.d = data[6]
end
function Hitbox3D:setDebugColor(r,g,b) function Hitbox3D:setDebugColor(r,g,b)
self.debug = {} self.debug = {}
self.debug.r = r self.debug.r = r

View file

@ -33,7 +33,7 @@ function Gizmo:applyProperties()
self.isSolid = self.properties.isSolid self.isSolid = self.properties.isSolid
self.mainHitbox.isSolid = self.properties.isSolid self.mainHitbox.isSolid = self.properties.isSolid
if (self.isSolid) then if (self.isSolid) then
self:addHitbox("btnInput", "btnInput", -1, -1, self.w + 2, self.h + 2, false) self:addHitbox("btnInput", "btnInput", {-1, -1, self.w + 2, self.h + 2}, false)
end end
self.needButton = self.properties.needButton self.needButton = self.properties.needButton
self.charId = self.properties.charId or 1 self.charId = self.properties.charId or 1