示例#1
0
    def test_calling_of_order(self):
        with application_t.TestCore() as c:
            data_holder = {}

            def _f(self, *args, **kwargs):
                data_holder['args'] = args
                data_holder['kwargs'] = kwargs

            # Move
            c.current_screen.select_actor(0)
            c.current_screen.sim.add_order = _f

            c.current_screen._handle_mousedown(
                pygame.event.Event(MOUSEBUTTONDOWN, button=3,
                                   pos=(1194, 1120)))
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=3, pos=(1194, 1120)))

            self.assertEqual(data_holder, {
                "args": ("move", ),
                "kwargs": {
                    "pos": (1194, 1120)
                }
            })

            # Now test it is queued
            data_holder = {}
            c.current_screen.unselect_all_actors()
            c.current_screen.select_actor(0)
            c.current_screen.sim.queue_order = _f

            pygame.key.set_mods(KMOD_SHIFT)
            mods = pygame.key.get_mods()

            c.current_screen._handle_mousedown(
                pygame.event.Event(MOUSEBUTTONDOWN, button=3,
                                   pos=(1194, 1120)))
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=3, pos=(1194, 1120)))

            # TODO Shift isn't detected as held down so it doesn't work correctly
            # self.assertEqual(data_holder, {
            #     "args":     ("move",),
            #     "kwargs":   {"pos": (1194, 1120)}
            # })

            # Left click, no order should be sent
            data_holder = {}
            c.current_screen.unselect_all_actors()
            c.current_screen.select_actor(0)
            c.current_screen.sim.add_order = _f

            c.current_screen._handle_mousedown(
                pygame.event.Event(MOUSEBUTTONDOWN, button=1,
                                   pos=(1194, 1120)))
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=1, pos=(1194, 1120)))

            self.assertEqual(data_holder, {})
示例#2
0
    def test_place_actor(self):
        with application_t.TestCore() as c:
            sim = c.current_screen.sim

            self.assertEqual(1, len(sim.actors))
            oid = sim.place_actor({"type": "Worker", "team": 1}).oid
            self.assertEqual(2, len(sim.actors))

            self.assertIn(oid, sim.actors)
示例#3
0
    def test_doubleclick_actor(self):
        with application_t.TestCore() as c:
            first_click = pygame.event.Event(MOUSEBUTTONUP,
                                             button=1,
                                             pos=(94, 120))
            second_click = pygame.event.Event(MOUSEBUTTONUP,
                                              button=1,
                                              pos=(94, 120))

            c.current_screen._handle_doubleclick(first_click, second_click)
示例#4
0
    def test_handle_mouseup(self):
        with application_t.TestCore() as c:
            c.current_screen.unselect_all_actors = lambda: 1

            # Left click
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=1, pos=(500, 500)))

            # Left click with a mouse mode
            c.current_screen.mouse_mode = "move"
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=1, pos=(500, 500)))

            # Right click
            c.current_screen.mouse_mode = None
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=3, pos=(500, 500)))
示例#5
0
    def test_selection_and_unselection(self):
        with application_t.TestCore() as c:
            # Using integers/oids
            self.assertEqual(0, len(c.current_screen.selected_actors))
            c.current_screen.select_actor(0)
            self.assertEqual(1, len(c.current_screen.selected_actors))
            c.current_screen.unselect_actor(0)
            self.assertEqual(0, len(c.current_screen.selected_actors))

            # Unsellect all
            c.current_screen.select_actor(0)
            c.current_screen.unselect_all_actors()
            self.assertEqual(0, len(c.current_screen.selected_actors))

            # Get index first, then get reference
            index = c.current_screen.sim.actors.keys()[0]
            first_actor = c.current_screen.sim.actors[index]

            # Using direct references
            c.current_screen.select_actor(first_actor)
            self.assertEqual(1, len(c.current_screen.selected_actors))
            c.current_screen.unselect_actor(first_actor)
            self.assertEqual(0, len(c.current_screen.selected_actors))
示例#6
0
    def test_queue_orders(self):
        with application_t.TestCore() as c:
            sim = c.current_screen.sim

            a = sim.actors[0]

            # First test adding it with an int actor and int target
            sim.orders_to_queue = []
            sim.queue_order(the_actor=a.oid,
                            command="move",
                            pos=[100, 100],
                            target=0)
            self.assertEqual(sim.orders_to_queue, [(0, "move", [100, 100], 0)])

            # Ref actor, int target
            sim.orders_to_queue = []
            sim.queue_order(the_actor=a,
                            command="move",
                            pos=[100, 100],
                            target=0)
            self.assertEqual(sim.orders_to_queue, [(0, "move", [100, 100], 0)])

            # Int actor, ref target
            sim.orders_to_queue = []
            sim.queue_order(the_actor=a.oid,
                            command="move",
                            pos=[100, 100],
                            target=a)
            self.assertEqual(sim.orders_to_queue, [(0, "move", [100, 100], 0)])

            # Ref actor, Ref target
            sim.orders_to_queue = []
            sim.queue_order(the_actor=a,
                            command="move",
                            pos=[100, 100],
                            target=a)
            self.assertEqual(sim.orders_to_queue, [(0, "move", [100, 100], 0)])
示例#7
0
    def test_click_actor(self):
        # Left click
        with application_t.TestCore() as c:
            self.assertEqual(0, len(c.current_screen.selected_actors))
            c.current_screen._handle_mousedown(
                pygame.event.Event(MOUSEBUTTONDOWN, button=1, pos=(94, 120)))
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=1, pos=(94, 120)))
            self.assertEqual(1, len(c.current_screen.selected_actors))

        # Left click miss
        with application_t.TestCore() as c:
            self.assertEqual(0, len(c.current_screen.selected_actors))
            c.current_screen._handle_mousedown(
                pygame.event.Event(MOUSEBUTTONDOWN, button=1,
                                   pos=(1194, 1120)))
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=1, pos=(1194, 1120)))
            self.assertEqual(0, len(c.current_screen.selected_actors))

        # Right click
        with application_t.TestCore() as c:
            self.assertEqual(0, len(c.current_screen.selected_actors))
            c.current_screen._handle_mousedown(
                pygame.event.Event(MOUSEBUTTONDOWN, button=3, pos=(94, 120)))
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=3, pos=(94, 120)))
            self.assertEqual(0, len(c.current_screen.selected_actors))

        # Right click miss
        with application_t.TestCore() as c:
            self.assertEqual(0, len(c.current_screen.selected_actors))
            c.current_screen._handle_mousedown(
                pygame.event.Event(MOUSEBUTTONDOWN, button=3,
                                   pos=(1194, 1120)))
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=3, pos=(1194, 1120)))
            self.assertEqual(0, len(c.current_screen.selected_actors))

        # Drag
        with application_t.TestCore() as c:
            self.assertEqual(0, len(c.current_screen.selected_actors))
            c.current_screen._handle_mousedown(
                pygame.event.Event(MOUSEBUTTONDOWN, button=1, pos=(10, 10)))
            c.current_screen._handle_mousemotion(
                pygame.event.Event(MOUSEMOTION, button=1, pos=(20, 20)))
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=1, pos=(100, 100)))
            self.assertEqual(1, len(c.current_screen.selected_actors))

        # Drag miss
        with application_t.TestCore() as c:
            self.assertEqual(0, len(c.current_screen.selected_actors))
            c.current_screen._handle_mousedown(
                pygame.event.Event(MOUSEBUTTONDOWN, button=1,
                                   pos=(1000, 1000)))
            c.current_screen._handle_mousemotion(
                pygame.event.Event(MOUSEMOTION, button=1, pos=(2000, 2000)))
            c.current_screen._handle_mouseup(
                pygame.event.Event(MOUSEBUTTONUP, button=1, pos=(3000, 3000)))
            self.assertEqual(0, len(c.current_screen.selected_actors))
示例#8
0
 def test_handle_mousedragup(self):
     with application_t.TestCore() as c:
         event = pygame.event.Event(MOUSEBUTTONUP, button=1, pos=(100, 100))
         c.current_screen._handle_mousedragup(event)
示例#9
0
 def test_handle_mousedrag(self):
     with application_t.TestCore() as c:
         event = pygame.event.Event(MOUSEMOTION, pos=(100, 100))
         c.current_screen._handle_mousedrag(event)
示例#10
0
 def test_handle_mousemotion(self):
     with application_t.TestCore() as c:
         event = None
         c.current_screen._handle_mousemotion(event)
示例#11
0
 def test_handle_keyup(self):
     with application_t.TestCore() as c:
         event = pygame.event.Event(KEYUP, key=113)
         c.current_screen._handle_keyup(event)
示例#12
0
 def test_handle_keyhold(self):
     with application_t.TestCore() as c:
         event = None
         c.current_screen._handle_keyhold()
示例#13
0
 def test_handle_active(self):
     with application_t.TestCore() as c:
         c.current_screen._handle_active(pygame.event.Event(ACTIVEEVENT))
示例#14
0
 def test_several_loop_cycles(self):
     with application_t.TestCore() as c:
         c.loop()