diff --git a/kelner/images/97734452_672361656930688_396231838525292544_n.jpg b/kelner/images/97734452_672361656930688_396231838525292544_n.jpg deleted file mode 100644 index 06706d4..0000000 Binary files a/kelner/images/97734452_672361656930688_396231838525292544_n.jpg and /dev/null differ diff --git a/kelner/images/testDishes/apple_pie/0.jpg b/kelner/images/testDishes/apple_pie/0.jpg new file mode 100644 index 0000000..0e8503b Binary files /dev/null and b/kelner/images/testDishes/apple_pie/0.jpg differ diff --git a/kelner/images/testDishes/apple_pie/1.jpg b/kelner/images/testDishes/apple_pie/1.jpg new file mode 100644 index 0000000..6a8fe52 Binary files /dev/null and b/kelner/images/testDishes/apple_pie/1.jpg differ diff --git a/kelner/images/testDishes/apple_pie/2.jpg b/kelner/images/testDishes/apple_pie/2.jpg new file mode 100644 index 0000000..64b5428 Binary files /dev/null and b/kelner/images/testDishes/apple_pie/2.jpg differ diff --git a/kelner/images/testDishes/apple_pie/3.jpg b/kelner/images/testDishes/apple_pie/3.jpg new file mode 100644 index 0000000..0439067 Binary files /dev/null and b/kelner/images/testDishes/apple_pie/3.jpg differ diff --git a/kelner/images/testDishes/apple_pie/4.jpg b/kelner/images/testDishes/apple_pie/4.jpg new file mode 100644 index 0000000..c679f64 Binary files /dev/null and b/kelner/images/testDishes/apple_pie/4.jpg differ diff --git a/kelner/images/testDishes/carrot_cake/0.jpg b/kelner/images/testDishes/carrot_cake/0.jpg new file mode 100644 index 0000000..c4f23ef Binary files /dev/null and b/kelner/images/testDishes/carrot_cake/0.jpg differ diff --git a/kelner/images/testDishes/carrot_cake/1.jpg b/kelner/images/testDishes/carrot_cake/1.jpg new file mode 100644 index 0000000..b52586f Binary files /dev/null and b/kelner/images/testDishes/carrot_cake/1.jpg differ diff --git a/kelner/images/testDishes/carrot_cake/2.jpg b/kelner/images/testDishes/carrot_cake/2.jpg new file mode 100644 index 0000000..8c793ae Binary files /dev/null and b/kelner/images/testDishes/carrot_cake/2.jpg differ diff --git a/kelner/images/testDishes/carrot_cake/3.jpg b/kelner/images/testDishes/carrot_cake/3.jpg new file mode 100644 index 0000000..b52586f Binary files /dev/null and b/kelner/images/testDishes/carrot_cake/3.jpg differ diff --git a/kelner/images/testDishes/carrot_cake/4.jpg b/kelner/images/testDishes/carrot_cake/4.jpg new file mode 100644 index 0000000..fbeda7e Binary files /dev/null and b/kelner/images/testDishes/carrot_cake/4.jpg differ diff --git a/kelner/images/testDishes/donuts/0.jpg b/kelner/images/testDishes/donuts/0.jpg new file mode 100644 index 0000000..ada0809 Binary files /dev/null and b/kelner/images/testDishes/donuts/0.jpg differ diff --git a/kelner/images/testDishes/donuts/1.jpg b/kelner/images/testDishes/donuts/1.jpg new file mode 100644 index 0000000..31b753a Binary files /dev/null and b/kelner/images/testDishes/donuts/1.jpg differ diff --git a/kelner/images/testDishes/donuts/2.jpg b/kelner/images/testDishes/donuts/2.jpg new file mode 100644 index 0000000..a956527 Binary files /dev/null and b/kelner/images/testDishes/donuts/2.jpg differ diff --git a/kelner/images/testDishes/donuts/3.jpg b/kelner/images/testDishes/donuts/3.jpg new file mode 100644 index 0000000..1922571 Binary files /dev/null and b/kelner/images/testDishes/donuts/3.jpg differ diff --git a/kelner/images/testDishes/donuts/4.jpg b/kelner/images/testDishes/donuts/4.jpg new file mode 100644 index 0000000..31b753a Binary files /dev/null and b/kelner/images/testDishes/donuts/4.jpg differ diff --git a/kelner/images/testDishes/hamburger/0.jpg b/kelner/images/testDishes/hamburger/0.jpg new file mode 100644 index 0000000..907ef44 Binary files /dev/null and b/kelner/images/testDishes/hamburger/0.jpg differ diff --git a/kelner/images/testDishes/hamburger/1.jpg b/kelner/images/testDishes/hamburger/1.jpg new file mode 100644 index 0000000..1ef15ca Binary files /dev/null and b/kelner/images/testDishes/hamburger/1.jpg differ diff --git a/kelner/images/testDishes/hamburger/2.jpg b/kelner/images/testDishes/hamburger/2.jpg new file mode 100644 index 0000000..8d07a80 Binary files /dev/null and b/kelner/images/testDishes/hamburger/2.jpg differ diff --git a/kelner/images/testDishes/hamburger/3.jpg b/kelner/images/testDishes/hamburger/3.jpg new file mode 100644 index 0000000..10db67b Binary files /dev/null and b/kelner/images/testDishes/hamburger/3.jpg differ diff --git a/kelner/images/testDishes/hamburger/4.jpg b/kelner/images/testDishes/hamburger/4.jpg new file mode 100644 index 0000000..61c2cb9 Binary files /dev/null and b/kelner/images/testDishes/hamburger/4.jpg differ diff --git a/kelner/images/testDishes/hot_dog/0.jpg b/kelner/images/testDishes/hot_dog/0.jpg new file mode 100644 index 0000000..de925c8 Binary files /dev/null and b/kelner/images/testDishes/hot_dog/0.jpg differ diff --git a/kelner/images/testDishes/hot_dog/1.jpg b/kelner/images/testDishes/hot_dog/1.jpg new file mode 100644 index 0000000..f0bbc37 Binary files /dev/null and b/kelner/images/testDishes/hot_dog/1.jpg differ diff --git a/kelner/images/testDishes/hot_dog/2.jpg b/kelner/images/testDishes/hot_dog/2.jpg new file mode 100644 index 0000000..ca8dd17 Binary files /dev/null and b/kelner/images/testDishes/hot_dog/2.jpg differ diff --git a/kelner/images/testDishes/hot_dog/3.jpg b/kelner/images/testDishes/hot_dog/3.jpg new file mode 100644 index 0000000..c9995cd Binary files /dev/null and b/kelner/images/testDishes/hot_dog/3.jpg differ diff --git a/kelner/images/testDishes/hot_dog/4.jpg b/kelner/images/testDishes/hot_dog/4.jpg new file mode 100644 index 0000000..6105a3a Binary files /dev/null and b/kelner/images/testDishes/hot_dog/4.jpg differ diff --git a/kelner/images/testDishes/mussels/0.jpg b/kelner/images/testDishes/mussels/0.jpg new file mode 100644 index 0000000..4d6de37 Binary files /dev/null and b/kelner/images/testDishes/mussels/0.jpg differ diff --git a/kelner/images/testDishes/mussels/1.jpg b/kelner/images/testDishes/mussels/1.jpg new file mode 100644 index 0000000..2215ab0 Binary files /dev/null and b/kelner/images/testDishes/mussels/1.jpg differ diff --git a/kelner/images/testDishes/mussels/2.jpg b/kelner/images/testDishes/mussels/2.jpg new file mode 100644 index 0000000..ffa7269 Binary files /dev/null and b/kelner/images/testDishes/mussels/2.jpg differ diff --git a/kelner/images/testDishes/mussels/3.jpg b/kelner/images/testDishes/mussels/3.jpg new file mode 100644 index 0000000..029455a Binary files /dev/null and b/kelner/images/testDishes/mussels/3.jpg differ diff --git a/kelner/images/testDishes/mussels/4.jpg b/kelner/images/testDishes/mussels/4.jpg new file mode 100644 index 0000000..8549464 Binary files /dev/null and b/kelner/images/testDishes/mussels/4.jpg differ diff --git a/kelner/images/testDishes/nachos/0.jpg b/kelner/images/testDishes/nachos/0.jpg new file mode 100644 index 0000000..5ff57a7 Binary files /dev/null and b/kelner/images/testDishes/nachos/0.jpg differ diff --git a/kelner/images/testDishes/nachos/1.jpg b/kelner/images/testDishes/nachos/1.jpg new file mode 100644 index 0000000..ae9acc9 Binary files /dev/null and b/kelner/images/testDishes/nachos/1.jpg differ diff --git a/kelner/images/testDishes/nachos/2.jpg b/kelner/images/testDishes/nachos/2.jpg new file mode 100644 index 0000000..fd3ae24 Binary files /dev/null and b/kelner/images/testDishes/nachos/2.jpg differ diff --git a/kelner/images/testDishes/nachos/3.jpg b/kelner/images/testDishes/nachos/3.jpg new file mode 100644 index 0000000..30a3339 Binary files /dev/null and b/kelner/images/testDishes/nachos/3.jpg differ diff --git a/kelner/images/testDishes/nachos/4.jpg b/kelner/images/testDishes/nachos/4.jpg new file mode 100644 index 0000000..a06e19c Binary files /dev/null and b/kelner/images/testDishes/nachos/4.jpg differ diff --git a/kelner/images/testDishes/omelette/0.jpg b/kelner/images/testDishes/omelette/0.jpg new file mode 100644 index 0000000..40b89f1 Binary files /dev/null and b/kelner/images/testDishes/omelette/0.jpg differ diff --git a/kelner/images/testDishes/omelette/1.jpg b/kelner/images/testDishes/omelette/1.jpg new file mode 100644 index 0000000..b8b203a Binary files /dev/null and b/kelner/images/testDishes/omelette/1.jpg differ diff --git a/kelner/images/testDishes/omelette/2.jpg b/kelner/images/testDishes/omelette/2.jpg new file mode 100644 index 0000000..c72a07c Binary files /dev/null and b/kelner/images/testDishes/omelette/2.jpg differ diff --git a/kelner/images/testDishes/omelette/3.jpg b/kelner/images/testDishes/omelette/3.jpg new file mode 100644 index 0000000..1530c51 Binary files /dev/null and b/kelner/images/testDishes/omelette/3.jpg differ diff --git a/kelner/images/testDishes/omelette/4.jpg b/kelner/images/testDishes/omelette/4.jpg new file mode 100644 index 0000000..5967812 Binary files /dev/null and b/kelner/images/testDishes/omelette/4.jpg differ diff --git a/kelner/images/testDishes/pho/0.jpg b/kelner/images/testDishes/pho/0.jpg new file mode 100644 index 0000000..96c3472 Binary files /dev/null and b/kelner/images/testDishes/pho/0.jpg differ diff --git a/kelner/images/testDishes/pho/1.jpg b/kelner/images/testDishes/pho/1.jpg new file mode 100644 index 0000000..129bfbb Binary files /dev/null and b/kelner/images/testDishes/pho/1.jpg differ diff --git a/kelner/images/testDishes/pho/2.jpg b/kelner/images/testDishes/pho/2.jpg new file mode 100644 index 0000000..71ce489 Binary files /dev/null and b/kelner/images/testDishes/pho/2.jpg differ diff --git a/kelner/images/testDishes/pho/3.jpg b/kelner/images/testDishes/pho/3.jpg new file mode 100644 index 0000000..9fc32d8 Binary files /dev/null and b/kelner/images/testDishes/pho/3.jpg differ diff --git a/kelner/images/testDishes/pho/4.jpg b/kelner/images/testDishes/pho/4.jpg new file mode 100644 index 0000000..ae121a4 Binary files /dev/null and b/kelner/images/testDishes/pho/4.jpg differ diff --git a/kelner/images/testDishes/pizza/0.jpg b/kelner/images/testDishes/pizza/0.jpg new file mode 100644 index 0000000..9cfd72b Binary files /dev/null and b/kelner/images/testDishes/pizza/0.jpg differ diff --git a/kelner/images/testDishes/pizza/1.jpg b/kelner/images/testDishes/pizza/1.jpg new file mode 100644 index 0000000..ef59b12 Binary files /dev/null and b/kelner/images/testDishes/pizza/1.jpg differ diff --git a/kelner/images/testDishes/pizza/2.jpg b/kelner/images/testDishes/pizza/2.jpg new file mode 100644 index 0000000..ed1dab5 Binary files /dev/null and b/kelner/images/testDishes/pizza/2.jpg differ diff --git a/kelner/images/testDishes/pizza/3.jpg b/kelner/images/testDishes/pizza/3.jpg new file mode 100644 index 0000000..2ac15e8 Binary files /dev/null and b/kelner/images/testDishes/pizza/3.jpg differ diff --git a/kelner/images/testDishes/pizza/4.jpg b/kelner/images/testDishes/pizza/4.jpg new file mode 100644 index 0000000..c308bbf Binary files /dev/null and b/kelner/images/testDishes/pizza/4.jpg differ diff --git a/kelner/images/testDishes/sushi/0.jpg b/kelner/images/testDishes/sushi/0.jpg new file mode 100644 index 0000000..53560ff Binary files /dev/null and b/kelner/images/testDishes/sushi/0.jpg differ diff --git a/kelner/images/testDishes/sushi/1.jpg b/kelner/images/testDishes/sushi/1.jpg new file mode 100644 index 0000000..2b86fdf Binary files /dev/null and b/kelner/images/testDishes/sushi/1.jpg differ diff --git a/kelner/images/testDishes/sushi/2.jpg b/kelner/images/testDishes/sushi/2.jpg new file mode 100644 index 0000000..185e053 Binary files /dev/null and b/kelner/images/testDishes/sushi/2.jpg differ diff --git a/kelner/images/testDishes/sushi/3.jpg b/kelner/images/testDishes/sushi/3.jpg new file mode 100644 index 0000000..abcf320 Binary files /dev/null and b/kelner/images/testDishes/sushi/3.jpg differ diff --git a/kelner/images/testDishes/sushi/4.jpg b/kelner/images/testDishes/sushi/4.jpg new file mode 100644 index 0000000..d0eda1c Binary files /dev/null and b/kelner/images/testDishes/sushi/4.jpg differ diff --git a/kelner/images/testDishes/tiramisu/0.jpg b/kelner/images/testDishes/tiramisu/0.jpg new file mode 100644 index 0000000..60c7bb5 Binary files /dev/null and b/kelner/images/testDishes/tiramisu/0.jpg differ diff --git a/kelner/images/testDishes/tiramisu/1.jpg b/kelner/images/testDishes/tiramisu/1.jpg new file mode 100644 index 0000000..b06c773 Binary files /dev/null and b/kelner/images/testDishes/tiramisu/1.jpg differ diff --git a/kelner/images/testDishes/tiramisu/2.jpg b/kelner/images/testDishes/tiramisu/2.jpg new file mode 100644 index 0000000..0c6dfcc Binary files /dev/null and b/kelner/images/testDishes/tiramisu/2.jpg differ diff --git a/kelner/images/testDishes/tiramisu/3.jpg b/kelner/images/testDishes/tiramisu/3.jpg new file mode 100644 index 0000000..cab6762 Binary files /dev/null and b/kelner/images/testDishes/tiramisu/3.jpg differ diff --git a/kelner/images/testDishes/tiramisu/4.jpg b/kelner/images/testDishes/tiramisu/4.jpg new file mode 100644 index 0000000..6f247a9 Binary files /dev/null and b/kelner/images/testDishes/tiramisu/4.jpg differ diff --git a/kelner/images/testDishes/waffles/0.jpg b/kelner/images/testDishes/waffles/0.jpg new file mode 100644 index 0000000..8b5696e Binary files /dev/null and b/kelner/images/testDishes/waffles/0.jpg differ diff --git a/kelner/images/testDishes/waffles/1.jpg b/kelner/images/testDishes/waffles/1.jpg new file mode 100644 index 0000000..517e398 Binary files /dev/null and b/kelner/images/testDishes/waffles/1.jpg differ diff --git a/kelner/images/testDishes/waffles/2.jpg b/kelner/images/testDishes/waffles/2.jpg new file mode 100644 index 0000000..379d0f0 Binary files /dev/null and b/kelner/images/testDishes/waffles/2.jpg differ diff --git a/kelner/images/testDishes/waffles/3.jpg b/kelner/images/testDishes/waffles/3.jpg new file mode 100644 index 0000000..25284c0 Binary files /dev/null and b/kelner/images/testDishes/waffles/3.jpg differ diff --git a/kelner/images/testDishes/waffles/4.jpg b/kelner/images/testDishes/waffles/4.jpg new file mode 100644 index 0000000..337d28f Binary files /dev/null and b/kelner/images/testDishes/waffles/4.jpg differ diff --git a/kelner/main.py b/kelner/main.py index 28ed3e0..b7c478d 100644 --- a/kelner/main.py +++ b/kelner/main.py @@ -8,6 +8,7 @@ from kelner.src.managers.MenuManager import MenuManager from kelner.src.managers.TableManager import TableManager from kelner.src.managers.WaiterManager import WaiterManager from kelner.src.algorithms.DecisionTree import Tree_Builder +from kelner.src.managers.KitchenManager import KitchenManager # create screen consts Scale = 2 # scale for all images used within project @@ -78,6 +79,8 @@ drawableManager.add(waiter1) # TODO: create kitchen kitchen = Kitchen(5, GridCountX - 5, 5, GridCountY - 5, CellSize, PaintOffset) drawableManager.add(kitchen) +kitchenManager = KitchenManager(drawableManager, gridBoard) + # My comment # initialize a number of tables given in range @@ -91,7 +94,7 @@ tableTask = TableManager(drawableManager, menuManager) tableTask.start() # new thread controlling waiter -waiter1Task = WaiterManager(drawableManager, [waiter1]) +waiter1Task = WaiterManager(drawableManager, [waiter1], kitchenManager) waiter1Task.start() # waiter2Task = WaiterManager(drawableManager, [waiter2]) @@ -160,6 +163,7 @@ while running: # repaints all objects to the screen # is set only on initial paint or after keyboard event or call to forceRepaint() if drawableManager.mustRepaint(): - gridBoard.reinitialize() - gridBoard.draw(drawableManager) - gridBoard.udpdate() + if not kitchenManager.is_running(): + gridBoard.reinitialize() + gridBoard.draw(drawableManager) + gridBoard.udpdate() diff --git a/kelner/src/components/Drawable.py b/kelner/src/components/Drawable.py index f8da18c..50c8ba3 100644 --- a/kelner/src/components/Drawable.py +++ b/kelner/src/components/Drawable.py @@ -60,11 +60,14 @@ class Drawable: def drawAux(self, screen): pass - def getImage(self, imageKind): + def getImage(self, imageKind, img_path=None): if imageKind in [Images.Guest1, Images.Guest2, Images.Guest3, Images.Plate]: size = int(self.getCellSize() / 3) - elif imageKind in [Images.Kitchen]: + elif imageKind in [Images.Kitchen, Images.Dishes]: size = int(self.getCellSize()) else: size = int(1.4 * self.getCellSize()) - return ImageCache.getInstance().getImage(imageKind, size, size) + if img_path: + return ImageCache.getInstance().getImage(imageKind, size, size, img_path) + else: + return ImageCache.getInstance().getImage(imageKind, size, size) diff --git a/kelner/src/components/GridBoard.py b/kelner/src/components/GridBoard.py index 334aa9c..723d5a9 100644 --- a/kelner/src/components/GridBoard.py +++ b/kelner/src/components/GridBoard.py @@ -1,6 +1,6 @@ import pygame from kelner.src.managers.ImageCache import ImageCache, Images - +import time class GridBoard: @@ -30,3 +30,10 @@ class GridBoard: # updates screen def udpdate(self): pygame.display.update() + + def update_and_sleep(self, sec): + pygame.display.update() + time.sleep(sec) + + def get_screen(self): + return self.__screen \ No newline at end of file diff --git a/kelner/src/components/Kitchen.py b/kelner/src/components/Kitchen.py index e7e2dca..0d53422 100644 --- a/kelner/src/components/Kitchen.py +++ b/kelner/src/components/Kitchen.py @@ -5,34 +5,95 @@ from kelner.src.components.Drawable import Drawable from kelner.src.managers.ImageCache import ImageCache, Images from kelner.src.algorithms.DecisionTree import Tree_Builder import os - +import copy +import time +import pygame class Kitchen(Drawable): def __init__(self, minX, maxX, minY, maxY, cellSize, offset): # call base class constructor super().__init__(14, 0, minX, maxX, minY, maxY, cellSize, offset) - self._preparing_orders = [] + self._preparing_orders = None self._ready_orders = None self._photos_path = os.path.join(os.getcwd(), 'foodImages') - def pass_new_orders(self, orders): - for table, order in orders.items(): - self._preparing_orders.append((table, order)) - # print("Orders prepared in kitchen: {}".format(self._preparing_orders)) - + def add_orders(self, orders): + if not self._preparing_orders: + self._preparing_orders = [] + for order in orders.items(): + self._preparing_orders.append(order) + print("Added {} to kitchen".format(order)) def get_ready_orders(self): + print("Ready orders on kitchen: {}".format(self._ready_orders)) if self._ready_orders: out = self._ready_orders[:] - self._ready_orders.clear() - self._ready_orders = self._preparing_orders + self._ready_orders = None + if self._preparing_orders: + self._ready_orders = self._preparing_orders[:] return out else: - self._ready_orders = self._preparing_orders - return [] + self._ready_orders = self.get_prepairing_orders() + return None + + def only_get_ready_orders(self): + return self._ready_orders + + + def get_prepairing_orders(self): + return self._preparing_orders + + + + + # def pick_ready_orders(self): + # return self._ready_orders + # + + # + # + # def pass_and_return_order(self, orders): + # for table, dish in orders: + # self._preparing_orders.append((table, dish)) + # + # if not self._ready_orders == []: + # out = self._ready_orders[:] + # self._ready_orders.clear() + # self._ready_orders = self._preparing_orders[:] + # return out + # else: + # self._ready_orders = self._preparing_orders + # + # def pass_new_orders(self, orders): + # for table, dish in orders: + # self._preparing_orders.append((table, dish)) + # + def clear_orders(self): + if self._preparing_orders: + self._ready_orders = self._preparing_orders[:] + self._preparing_orders = None + + + # + # def clear_preparing_orders(self): + # self._preparing_orders.clear() + + def draw_order(self, dishes, screen): + draw_screen = screen.get_screen() + for i, dish in enumerate(dishes): + img_path = str(dish) + '/' + str(random.randint(0, 4)) + '.jpg' + print("Image drawing: {}".format(img_path)) + image = self.getImage(Images.Dishes, img_path) + size = int(self.getCellSize()) + print(os.getcwd()) + image = pygame.transform.scale((pygame.image.load(os.path.join(os.getcwd(), 'images', 'testDishes', img_path))), (size, size)) + print((13 - i) * self.getCellSize(), 1 * self.getCellSize()) + draw_screen.blit(image, ((13 - i) * self.getCellSize(), 1 * self.getCellSize())) + screen.udpdate() + + # screen.update_and_sleep(5) + - def clear_preparing_orders(self): - self._preparing_orders.clear() def draw(self, screen): xBase = self.getX() * self.getCellSize() + self.getOffset() @@ -43,4 +104,17 @@ class Kitchen(Drawable): screen.blit(image, (xBase - tableXYOffset, yBase - tableXYOffset)) def drawAux(self, screen): + # orders = self.only_get_ready_orders() + # if orders: + # for order in orders: + # dishes = order[1] + # if dishes: + # for i, dish in enumerate(dishes): + # img_path = str(dish) + '/' + str(random.randint(0, 4)) + '.jpg' + # image = self.getImage(Images.Dishes, img_path) + # print((13 - i) * self.getCellSize(), 1 * self.getCellSize()) + # print((13 - i) * self.getCellSize(), 1 * self.getCellSize()) + # screen.blit(image, ((13 - i) * self.getCellSize(), 1 * self.getCellSize())) pass + + diff --git a/kelner/src/components/Waiter.py b/kelner/src/components/Waiter.py index 36bff29..b9ed4b1 100644 --- a/kelner/src/components/Waiter.py +++ b/kelner/src/components/Waiter.py @@ -24,6 +24,7 @@ class Waiter(Drawable): self.__acceptedOrders = dict() self.__currentPath = [] self._ready = True + self._target = 'table' def moveUp(self): if self.getY() > self.getMinY(): @@ -179,3 +180,9 @@ class Waiter(Drawable): textXOffset = toolTipXOffset + int((toolTipWidth - textWidth) / 2) textYOffset = toolTipYOffset + int((toolTipHeight - textHeight) / 2) screen.blit(imageText, (self.__xBase + textXOffset, self.__yBase + textYOffset)) + + def get_target(self): + return self._target + + def set_target(self, target): + self._target = target \ No newline at end of file diff --git a/kelner/src/managers/DrawableCollection.py b/kelner/src/managers/DrawableCollection.py index ea80edd..88c88d8 100644 --- a/kelner/src/managers/DrawableCollection.py +++ b/kelner/src/managers/DrawableCollection.py @@ -125,6 +125,9 @@ class DrawableCollection: def mustRepaint(self): return self.__mustRepaint + def stopRepaint(self): + self.__mustRepaint = False + # draws all objects stored in collection def draw(self, screen): for item in self.__drawables: diff --git a/kelner/src/managers/ImageCache.py b/kelner/src/managers/ImageCache.py index a34aa77..e807e72 100644 --- a/kelner/src/managers/ImageCache.py +++ b/kelner/src/managers/ImageCache.py @@ -22,6 +22,7 @@ class Images(Enum): Guest3 = 15 ToolTip = 16 Kitchen = 17 + Dishes = 18 class ImageCache: @@ -58,19 +59,25 @@ class ImageCache: Images.Guest2: './images/wiking_rudy.png', Images.Guest3: './images/wiking_rudy2.png', Images.ToolTip: './images/tooltip.png', - Images.Kitchen: './images/kitchen.png'} + Images.Kitchen: './images/kitchen.png', + Images.Dishes: './images/testDishes/' + } def __getFont(self): if self.__font is None: self.__font = pygame.font.SysFont('comicsansms', 24, True) return self.__font - def getImage(self, imageKind, width, height): + def getImage(self, imageKind, width, height, img_path=None): key = imageKind.name + ':' + str(width) + 'x' + str(height) image = self.__images.get(key, None) if image is None: - image = pygame.transform.scale((pygame.image.load(self.__paths[imageKind])), (width, height)) - self.__images[key] = image + if not img_path: + image = pygame.transform.scale((pygame.image.load(self.__paths[imageKind])), (width, height)) + self.__images[key] = image + else: + image = pygame.transform.scale((pygame.image.load(self.__paths[imageKind] + img_path)), (width, height)) + self.__images[key] = image return image def getTextImage(self, text, color, height): diff --git a/kelner/src/managers/KitchenManager.py b/kelner/src/managers/KitchenManager.py index 117b20a..357d7e5 100644 --- a/kelner/src/managers/KitchenManager.py +++ b/kelner/src/managers/KitchenManager.py @@ -4,10 +4,14 @@ import sys # creates new thread -class KitchenManager(): +class KitchenManager(threading.Thread): - def __init__(self, drawable_manager): + def __init__(self, drawable_manager, gridboard): + super().__init__() self._drawable_manager = drawable_manager + self._gridboard = gridboard + self.__runThread = False + def prepare_dish(self): pass @@ -16,21 +20,38 @@ class KitchenManager(): kitchen.pass_new_orders(orders) def get_ready_orders(self, kitchen): - return kitchen.get_ready_orders() - - def draw_orders(self, kitchen): - orders_to_print = kitchen.get_ready_orders() - dishes = [] - if orders_to_print: - for order in orders_to_print: - dishes.append(order[1]) - print(order[0]) - - kitchen.clear_preparing_orders() + out = kitchen.get_ready_orders() + kitchen.clear_orders() + return out + def pass_and_return_order(self, orders, kitchen): + return kitchen.pass_and_return_order(orders) + + def draw_orders(self, orders, kitchen): + if orders: + for order in orders: + dishes = order[1] + if dishes: + kitchen.draw_order(dishes, self._gridboard) + + def run(self, orders, kitchen): + self.__runThread = True + self.draw_orders(orders, kitchen) + time.sleep(10) + + def stop(self): + self.__runThread = False + + def is_running(self): + return self.__runThread + # def draw_orders(self, kitchen, orders, draw_manager): + # for order in orders: + # dishes = order[1] + # i = 0 + # print("DISHES TO PRINT: {}".format(dishes)) - print(orders_to_print) - print(dishes) \ No newline at end of file + + # TODO: draw real images diff --git a/kelner/src/managers/WaiterManager.py b/kelner/src/managers/WaiterManager.py index 64da4e4..a969197 100644 --- a/kelner/src/managers/WaiterManager.py +++ b/kelner/src/managers/WaiterManager.py @@ -4,18 +4,17 @@ import sys from kelner.src.components.Table import Status from kelner.src.algorithms.AStar.Finder import Finder from kelner.src.algorithms.BFS.BFS import BFS -from kelner.src.managers.KitchenManager import KitchenManager # creates new thread class WaiterManager(threading.Thread): - def __init__(self, drawableManager, waiters): + def __init__(self, drawableManager, waiters, kitchenManager): super().__init__() self.__drawableManager = drawableManager self.__waiters = waiters self.__runThread = True - self._kitchen_manager = KitchenManager(drawableManager) + self._kitchen_manager = kitchenManager def __getNearestTargetPath(self, waiter, target): distance = sys.maxsize @@ -94,7 +93,7 @@ class WaiterManager(threading.Thread): def receive_ready_orders(self, waiter): kitchen = self.__drawableManager.get_kitchen() try: - ready_orders = kitchen.get_ready_orders() + ready_orders = self._kitchen_manager.get_ready_orders(kitchen) for dish in ready_orders: print("Orders ready to take", end=" ") print(dish[1]) @@ -103,6 +102,7 @@ class WaiterManager(threading.Thread): waiter.make_ready() waiter.clear_accepted_orders() print("Ready to go") + return ready_orders @@ -112,10 +112,9 @@ class WaiterManager(threading.Thread): while self.__runThread: if self.__waiters: for waiter in self.__waiters: - target = 'table' if len(waiter.getAcceptedOrders()) > 0: - target = 'kitchen' - path = self.__getNearestTargetPath(waiter, target=target) + waiter.set_target('kitchen') + path = self.__getNearestTargetPath(waiter, target=waiter.get_target()) waiter.make_busy() else: @@ -127,15 +126,34 @@ class WaiterManager(threading.Thread): self.__changeWaiterDirection(waiter, step[0], step[1]) self.__moveWaiter(waiter, step[0], step[1]) - if len(waiter.get_current_path()) == 0 and target == 'kitchen': - kitchen = self.__drawableManager.get_kitchen() - self.pass_orders_to_kitchen(waiter.getAcceptedOrders()) - # print(waiter.getAcceptedOrders()) - if self.receive_ready_orders(waiter): - self._kitchen_manager.draw_orders(kitchen) + if (waiter.getX(), waiter.getY()) == (14, 1) or (waiter.getX(), waiter.getY()) == (13, 0): + if waiter.get_target() == 'kitchen': - target = 'table' - print(1) + kitchen = self.__drawableManager.get_kitchen() + waiter_orders = waiter.getAcceptedOrders() + print(type(waiter_orders)) + print("Waiter near kitchen. Collected orders: {}".format(waiter_orders)) + kitchen.add_orders(waiter_orders) + received_orders = kitchen.get_ready_orders() + waiter.clear_accepted_orders() + + if received_orders: + # self._kitchen_manager.draw_orders(received_orders) + KM = self._kitchen_manager + KM.run(received_orders, kitchen) + KM.stop() + + + + + # TODO: recognize images + # TODO: choose proper tableo + # TODO: set path to tables, another target + print('should blit') + + kitchen.clear_orders() + waiter.make_ready() + waiter.set_target('table') else: self.__collectOrder(waiter)