Skip to content

Commit

Permalink
physics: ability to add/sub/mul/div. Closes #1819
Browse files Browse the repository at this point in the history
  • Loading branch information
alek13 committed Dec 7, 2024
1 parent b3f9a4a commit dd3acd7
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions mods/lord/Core/physics/src/physics/PlayerPhysics.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local table_merge, setmetatable
= table.merge, setmetatable
local table_merge, table_add_values, table_sub_values, table_mul_values, table_div_values, setmetatable
= table.merge, table.add_values, table.sub_values, table.mul_values, table.div_values, setmetatable

local Event = require('physics.Event')

Expand Down Expand Up @@ -37,24 +37,55 @@ function PlayerPhysics:refresh_player(player)
return self
end

--- @param physics table
function PlayerPhysics:set(physics)
self.physics = table_merge(self.physics, physics)
--- @overload fun()
--- @param name string
--- @return number|table<string,number>
function PlayerPhysics:get(name)
return name
and (self.physics[name] or nil)
or self.physics
end

--- @private
function PlayerPhysics:set_override()
self.player:set_physics_override(table_merge(
self.player:get_physics_override(), self.physics
))
end

--- @param physics physics_override_table
function PlayerPhysics:set(physics)
self.physics = table_merge(self.physics, physics)
self:set_override()
Event:trigger(Event.Type.on_change, self.player, self)
end

--- @overload fun()
--- @param name string
--- @return number|table<string,number>
function PlayerPhysics:get(name)
return name
and (self.physics[name] or nil)
or self.physics
--- @param physics physics_override_table
function PlayerPhysics:add(physics)
self.physics = table_add_values(self.physics, physics)
self:set_override()
Event:trigger(Event.Type.on_change, self.player, self)
end

--- @param physics physics_override_table
function PlayerPhysics:sub(physics)
self.physics = table_sub_values(self.physics, physics)
self:set_override()
Event:trigger(Event.Type.on_change, self.player, self)
end

--- @param physics physics_override_table
function PlayerPhysics:mul(physics)
self.physics = table_mul_values(self.physics, physics)
self:set_override()
Event:trigger(Event.Type.on_change, self.player, self)
end

--- @param physics physics_override_table
function PlayerPhysics:div(physics)
self.physics = table_div_values(self.physics, physics)
self:set_override()
Event:trigger(Event.Type.on_change, self.player, self)
end


Expand Down

0 comments on commit dd3acd7

Please sign in to comment.