Merge pull request #172 from ryleykimmel/issue169

Pass the new Position of Players to area listeners
This commit is contained in:
Major
2016-02-09 16:02:29 +00:00
3 changed files with 24 additions and 23 deletions
+6 -6
View File
@@ -32,18 +32,18 @@ class AreaAction
end
# Called when the player has entered an area this action is registered to.
def entered(player)
@on_enter.call(player) unless @on_enter.nil?
def entered(player, position)
@on_enter.call(player, position) unless @on_enter.nil?
end
# Called while the player is in area this action is registered to.
def inside(player)
@while_in.call(player) unless @while_in.nil?
def inside(player, position)
@while_in.call(player, position) unless @while_in.nil?
end
# Called when the player has exited an area this action is registered to.
def exited(player)
@on_exit.call(player) unless @on_exit.nil?
def exited(player, position)
@on_exit.call(player, position) unless @on_exit.nil?
end
end
+10 -9
View File
@@ -51,18 +51,18 @@ class Area
end
# Called when the player has entered the area.
def entered(player)
@actions.each { |action| action.entered(player) }
def entered(player, position)
@actions.each { |action| action.entered(player, position) }
end
# Called when the player has moved, but is still inside the area (and was in the area before).
def inside(player)
@actions.each { |action| action.inside(player) }
def inside(player, position)
@actions.each { |action| action.inside(player, position) }
end
# Called when the player has exited the area.
def exited(player)
@actions.each { |action| action.exited(player) }
def exited(player, position)
@actions.each { |action| action.exited(player, position) }
end
end
@@ -81,14 +81,15 @@ on :mob_position_update do |event|
next unless mob.entity_type == EntityType::PLAYER
old = mob.position
updated = event.next
@areas.each do |area|
was_inside = old.inside(area)
next_inside = event.next.inside(area)
next_inside = updated.inside(area)
if was_inside
next_inside ? area.inside(mob) : area.exited(mob)
next_inside ? area.inside(mob, updated) : area.exited(mob, updated)
else
area.entered(mob) if next_inside
area.entered(mob, updated) if next_inside
end
end
end