source: nagslang/tests/test_level.py@ 145:0c49627920eb

Last change on this file since 145:0c49627920eb was 145:0c49627920eb, checked in by Jeremy Thurgood <firxen@…>, 8 years ago

Load game objects from level.

File size: 2.5 KB
Line 
1from unittest import TestCase
2
3from nagslang import game_object as go
4from nagslang.level import Level
5
6
7class FakeSpace(object):
8 def add(self, *objs):
9 pass
10
11
12class TestLevel(TestCase):
13 def make_level(self, name, data):
14 level = Level(name)
15 level._get_data = lambda: data
16 return level
17
18 def test_empty_level(self):
19 level = self.make_level('foo', {
20 'size': [5, 10],
21 'base_tile': 'tiles/floor.png',
22 'polygons': {},
23 })
24 level.load(FakeSpace())
25 self.assertEqual((5, 10), level.get_size())
26 self.assertEqual([], level.get_walls())
27 self.assertEqual([], level.get_drawables())
28
29 def test_level_walls(self):
30 level = self.make_level('foo', {
31 'size': [5, 10],
32 'base_tile': 'tiles/floor.png',
33 'polygons': {
34 1: [[1, 1], [2, 1], [1, 2]],
35 },
36 })
37 level.load(FakeSpace())
38 self.assertEqual((5, 10), level.get_size())
39 self.assertEqual([[(1, 1), (2, 1), (1, 2)]], level.get_walls())
40 self.assertEqual([], level.get_drawables())
41
42 def test_level_game_objects(self):
43 level = self.make_level('foo', {
44 'size': [5, 10],
45 'base_tile': 'tiles/floor.png',
46 'polygons': {},
47 'game_objects': [
48 {
49 'classname': 'Box',
50 'args': [[3, 3]],
51 },
52 {
53 'name': 'foo',
54 'classname': 'FloorSwitch',
55 'args': [[4, 4]],
56 },
57 {
58 'name': 'foo_proxy',
59 'classname': 'StateProxyPuzzler',
60 'args': ['foo'],
61 },
62 ],
63 })
64 level.load(FakeSpace())
65 self.assertEqual((5, 10), level.get_size())
66 self.assertEqual([], level.get_walls())
67 [box, switch] = level.get_drawables()
68 self.assertTrue(isinstance(box, go.Box))
69 self.assertEqual(box.shape.body.position, (3, 3))
70 self.assertTrue(isinstance(switch, go.FloorSwitch))
71 self.assertEqual(switch.shape.body.position, (4, 4))
72
73 puzzle_bits = level._glue._components
74 self.assertEqual(['foo', 'foo_proxy'], sorted(puzzle_bits.keys()))
75 self.assertTrue(
76 isinstance(puzzle_bits['foo_proxy'], go.StateProxyPuzzler))
77 self.assertEqual('foo', puzzle_bits['foo_proxy']._state_source)
78 self.assertTrue(isinstance(puzzle_bits['foo'], go.FloorSwitchPuzzler))
Note: See TracBrowser for help on using the repository browser.