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

movement.is_moving works, add event 'movement_follow_path_done' #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions spockbot/plugins/helpers/movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
directions.
"""

import logging

from spockbot.plugins.base import PluginBase, pl_announce
from spockbot.plugins.tools.event import EVENT_UNREGISTER
from spockbot.vector import Vector3

logger = logging.getLogger('spockbot')


class MovementCore(object):
def __init__(self, plug):
Expand All @@ -19,7 +23,9 @@ def stop(self):

@property
def is_moving(self):
return self.__plug.path_nodes is not None
is_processing = self.__plug.pathfinding.is_processing
is_moving = self.__plug.path_nodes is not None
return (is_moving or is_processing)

@property
def current_path(self):
Expand Down Expand Up @@ -83,6 +89,7 @@ def path_cb(self, result):
def follow_path(self, _, __):
if not self.path_nodes:
self.movement.stop()
self.event.emit('movement_follow_path_done')
return EVENT_UNREGISTER
target = self.path_nodes[0]
jumped = False
Expand All @@ -91,5 +98,3 @@ def follow_path(self, _, __):
jumped = True
if self.physics.move_target(target) or jumped:
self.path_nodes.popleft()
if not self.path_nodes:
self.movement.stop()
20 changes: 15 additions & 5 deletions spockbot/plugins/helpers/pathfinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import collections
import logging

from spockbot.mcdata import blocks, constants as const
from spockbot.mcdata.utils import BoundingBox
Expand All @@ -14,6 +15,7 @@
from spockbot.plugins.tools.event import EVENT_UNREGISTER
from spockbot.vector import Vector3

logger = logging.getLogger('spockbot')

FOUND_VALID_PATH = 0x01
TIMEOUT_REACHED = 0x02
Expand All @@ -22,8 +24,13 @@


class PathfindingCore(object):
def __init__(self, start_path):
self.pathfind = start_path
def __init__(self, plug):
self.__plug = plug
self.pathfind = plug.start_path

@property
def is_processing(self):
return self.__plug.path_job is not None


class Path(object):
Expand Down Expand Up @@ -68,7 +75,7 @@ def __init__(self, ploader, settings):
self.col = MTVTest(
self.world, BoundingBox(const.PLAYER_WIDTH, const.PLAYER_HEIGHT)
)
ploader.provides('Pathfinding', PathfindingCore(self.start_path))
ploader.provides('Pathfinding', PathfindingCore(self))

def build_list_from_node(self, node):
ret = collections.deque()
Expand All @@ -92,12 +99,15 @@ def do_job(self, _=None, __=None):
path, scb, fcb = self.path_job
ret = self.pathfind(path)
if ret == FOUND_VALID_PATH:
self.path_job = None
scb(self.build_list_from_node(path.result))
# Unset path_job after scb in order to plug race in
# movment.is_moving test
self.path_job = None
return EVENT_UNREGISTER
elif ret == NO_VALID_PATH and fcb:
self.path_job = None
fcb(None)
self.path_job = None
return EVENT_UNREGISTER

def pathfind(self, path):
while path.open_list and self.timers.get_timeout():
Expand Down