comparison tests/swig_tests/view_tests.py @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children d2f1e81fbe2c
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 #!/usr/bin/env python
2 from swig_test_utils import *
3 import time
4
5 class TestView(unittest.TestCase):
6
7 def setUp(self):
8 self.engine = getEngine()
9 model = self.engine.getModel()
10 map = model.createMap("map001")
11
12 self.grid = fife.SquareGrid()
13 pool = self.engine.getImagePool()
14
15 self.obj1 = model.createObject('0','test_nspace')
16 fife.ObjectVisual.create(self.obj1)
17 imgid = pool.addResourceFromFile('tests/data/mushroom_007.png')
18 self.obj1.get2dGfxVisual().addStaticImage(0, imgid)
19
20 self.obj2 = model.createObject('1','test_nspace')
21 fife.ObjectVisual.create(self.obj2)
22 imgid = pool.addResourceFromFile('tests/data/earth_1.png')
23 self.obj2.get2dGfxVisual().addStaticImage(0, imgid)
24
25 img = pool.getImage(imgid)
26 self.screen_cell_w = img.getWidth()
27 self.screen_cell_h = img.getHeight()
28
29 self.layer = map.createLayer("layer001", self.grid)
30
31 self.camcoord = fife.ExactModelCoordinate(2,0)
32
33
34
35 def tearDown(self):
36 del self.engine
37
38 def testCamera(self):
39 rb = self.engine.getRenderBackend()
40 viewport = fife.Rect(0, 0, rb.getWidth(), rb.getHeight())
41
42 cam = self.engine.getView().addCamera("foo", self.layer, viewport, self.camcoord )
43 cam.setCellImageDimensions(self.screen_cell_w, self.screen_cell_h)
44 cam.setRotation(45)
45 cam.setTilt(40)
46
47 cam.setViewPort(viewport)
48 self.engine.getView().resetRenderers()
49
50 self.engine.initializePumping()
51
52 for y in xrange(4):
53 for x in xrange(4):
54 i = self.layer.createInstance(self.obj2, fife.ModelCoordinate(x,y))
55 fife.InstanceVisual.create(i)
56 self.engine.pump()
57 time.sleep(0.01)
58 i = self.layer.createInstance(self.obj1, fife.ModelCoordinate(0,0))
59 fife.InstanceVisual.create(i)
60 i = self.layer.createInstance(self.obj1, fife.ModelCoordinate(2,1))
61 fife.InstanceVisual.create(i)
62
63 for i in xrange(120):
64 if i > 20 and i < 30:
65 cam.setRotation(cam.getRotation() + 1)
66 elif i > 30 and i < 40:
67 cam.setRotation(cam.getRotation() - 1)
68 elif i > 40 and i < 50:
69 if i % 2 == 0:
70 c = cam.getLocation().getExactLayerCoordinates()
71 c.x += 0.1
72 c = cam.getLocation().setExactLayerCoordinates(c)
73 elif i > 50 and i < 60:
74 if i % 2 == 0:
75 c = cam.getLocation().getExactLayerCoordinates()
76 c.x -= 0.1
77 c = cam.getLocation().setExactLayerCoordinates(c)
78 elif i > 60 and i < 70:
79 cam.setTilt(cam.getTilt() + 1)
80 elif i > 70 and i < 80:
81 cam.setTilt(cam.getTilt() - 1)
82 elif i > 80 and i < 90:
83 cam.setZoom(cam.getZoom() + 0.010)
84 elif i > 90 and i < 100:
85 cam.setZoom(cam.getZoom() - 0.010)
86 self.engine.pump()
87 self.engine.finalizePumping()
88 self.engine.getView().removeCamera(cam)
89
90
91
92 TEST_CLASSES = [TestView]
93
94 if __name__ == '__main__':
95 unittest.main()
96