Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state_machine: include prev_state_name #69

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions state_machine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local state_machine = class({
function state_machine:new(states, start_in_state)
self.states = states or {}
self.current_state_name = ""
self.prev_state_name = ""
self.reset_state_name = start_in_state or ""
self:reset()
end
Expand Down Expand Up @@ -151,6 +152,7 @@ end
function state_machine:set_state(name, reset)
if self.current_state_name ~= name or reset then
self:_call("exit")
self.prev_state_name = self.current_state_name
self.current_state_name = name
self:_call_and_transition("enter", self)
end
Expand Down
27 changes: 27 additions & 0 deletions vec2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,33 @@ function vec2:maxcomp()
return math.max(self.x, self.y)
end

-- meta functions for mathmatical operations
function vec2.__add(a, b)
return a:vector_add_inplace(b)
end

function vec2.__sub(a, b)
return a:vector_sub_inplace(b)
end

function vec2.__mul(a, b)
if type(a) == "number" then
return b:scalar_mul_inplace(a)
elseif type(b) == "number" then
return a:scalar_mul_inplace(b)
else
return a:vector_mul_inplace(b)
end
end

function vec2.__div(a, b)
if type(b) == "number" then
return a:scalar_div_inplace(b)
else
return a:vector_div_inplace(b)
end
end

-- mask out min component, with preference to keep x
function vec2:major_inplace()
if self.x > self.y then
Expand Down
Loading