ya2 · news · projects · code · about

enforced resolution
authorFlavio Calva <f.calva@gmail.com>
Wed, 18 May 2022 18:40:55 +0000 (19:40 +0100)
committerFlavio Calva <f.calva@gmail.com>
Wed, 18 May 2022 18:40:55 +0000 (19:40 +0100)
game/menu.py
game/scene.py
lib/engine/functional.py
lib/engine/log.py
lib/tools/functional_test.py

index 919bcc5246aa3c97935a899d42d7f33dc50b8823..57f628aff7d80845882c92eadb445314a6b68680 100644 (file)
@@ -11,14 +11,16 @@ from direct.gui.DirectGui import DirectButton, DirectCheckButton, \
     DirectOptionMenu, DirectSlider, DirectCheckButton
 from direct.gui.DirectGuiGlobals import FLAT
 from direct.gui.OnscreenText import OnscreenText
+from direct.showbase.DirectObject import DirectObject
 from lib.engine.gui.cursor import MouseCursor
 from game.scene import Scene
 from panda3d.bullet import BulletWorld
 
 
-class Menu:
+class Menu(DirectObject):
 
     def __init__(self, fsm, lang_mgr, opt_file, music, pipeline, scenes, fun_test):
+        super().__init__()
         self._fsm = fsm
         self._lang_mgr = lang_mgr
         self._opt_file = opt_file
@@ -26,6 +28,7 @@ class Menu:
         self._pipeline = pipeline
         self._scenes = scenes
         self._fun_test = fun_test
+        self._enforced_res = ''
         self._cursor = MouseCursor(
             'assets/images/buttons/arrowUpLeft.dds', (.04, 1, .04), (.5, .5, .5, 1),
             (.01, .01))
@@ -67,6 +70,10 @@ class Menu:
         del self._common_slider['clickSound']
         self._set_main()
 
+    def enforce_res(self, val):
+        self._enforced_res = val
+        info('enforced resolution: ' + val)
+
     def _set_main(self):
         self._widgets = []
         self._widgets += [DirectButton(
@@ -82,6 +89,7 @@ class Menu:
             text=_('Exit'), pos=(0, 1, -.6), command=lambda: exit(),
             **self._common_btn)]
         self._rearrange_width()
+        self.accept('enforce_resolution', self.enforce_res)
 
     def _set_options(self):
         self._widgets = []
@@ -147,6 +155,7 @@ class Menu:
         self._widgets += [DirectButton(
             text=_('Back'), pos=(0, 1, -.8), command=self.on_back,
             **self._common_btn)]
+        self.accept('enforce_resolution', self.enforce_res)
 
     def _set_credits(self):
         self._widgets = []
@@ -169,6 +178,7 @@ class Menu:
         self._widgets += [DirectButton(
             text=_('Back'), pos=(0, 1, -.8), command=self.on_back,
             **self._common_btn)]
+        self.accept('enforce_resolution', self.enforce_res)
 
     def on_play(self):
         self.destroy()
@@ -252,6 +262,9 @@ class Menu:
         self._opt_file.store()
 
     def on_resolution(self, arg):
+        info('on resolution: %s (%s)' % (arg, self._enforced_res))
+        arg = self._enforced_res or arg
+        info('set resolution: %s' % arg)
         props = WindowProperties()
         props.set_size(LVector2i(*[int(_res) for _res in arg.split('x')]))
         base.win.request_properties(props)
@@ -288,3 +301,4 @@ class Menu:
     def destroy(self):
         [wdg.destroy() for wdg in self._widgets]
         self._cursor.destroy()
+        self.ignore('enforce_resolution')
index a2e4e45e248a845068f5fb238d6e000f8ae4ff7a..9d4861daa00256d03326bccc03a4859487824d81 100644 (file)
@@ -1,7 +1,7 @@
 from os.path import exists
 from os import makedirs
 from glob import glob
-from logging import debug
+from logging import debug, info
 from importlib import import_module
 from inspect import isclass
 from panda3d.core import AmbientLight, DirectionalLight, Point3, Texture, \
@@ -109,7 +109,7 @@ class Scene(DirectObject):
 
     def enforce_res(self, val):
         self._enforce_res = val
-        debug('enforce res: ' + val)
+        info('enforce res: ' + val)
 
     def destroy(self):
         self.ignore('enforce_res')
index 4098a2aef040ab8f692ce223371c0c0cecc5a6d8..dffa67899f20577da37efa0778831267dc2bae0f 100644 (file)
@@ -41,6 +41,8 @@ class ListenerThread(Thread):
                     taskMgr.doMethodLater(.01, self._callbacks[2], 'cb2')
                 elif msg[0] == 'set_idx':
                     taskMgr.doMethodLater(.01, self._callbacks[3], 'cb3', [msg[1]])
+                elif msg[0] == 'enforce_resolution':
+                    taskMgr.doMethodLater(.01, self._callbacks[4], 'cb4', [msg[1]])
             except EOFError:
                 running = False
 
@@ -49,7 +51,7 @@ class FunctionalTest(GameObject):
 
     def __init__(self, ref):
         super().__init__()
-        self._listener = ListenerThread([self._do_screenshot, self._do_enforce_res, self.__verify, self._set_idx])
+        self._listener = ListenerThread([self._do_screenshot, self._do_enforce_res, self.__verify, self._set_idx, self._do_enforce_resolution])
         self._listener.start()
         self.txt = OnscreenText('', fg=(1, 0, 0, 1), scale=.16)
         #self._path = ''
@@ -88,6 +90,10 @@ class FunctionalTest(GameObject):
         info('enforce_res %s' % res)
         messenger.send('enforce_res', [res])
 
+    def _do_enforce_resolution(self, res):
+        info('enforce resolution %s (callback)' % res)
+        messenger.send('enforce_resolution', [res])
+
     #def _screenshot(self, time, name):
         #self._fnames += [self._path + name + '.png']
         #self._tasks += [(
index a5d7ea66f9770f19d1c1992e9df54eee327b7335..ac4920ea53ec6b4a08b29e1b5b13574880f6f147 100755 (executable)
@@ -76,7 +76,8 @@ class LogMgrBase(Colleague):  # headless log manager
         if is_snap:
             return str(Path(par_path).absolute())
         #return getcwd()
-        curr_path = dirname(__file__)
+        #curr_path = dirname(__file__)
+        curr_path = str(Path(__file__).parent.parent.parent.absolute())
         info('current path: %s' % curr_path)
         return curr_path
 
index 47f4718d7fd351a827f417428592e4e0666b2738..e052fa9dfeaf92109bf23e58b4a8429d751c4c07 100644 (file)
@@ -103,6 +103,16 @@ class FunctionalTest(GameObject):
             'enforce res: %s' % res)]
         self._curr_time += time
 
+    def _enforce_resolution(self, time, res):
+        def cback():
+            self._conn.send(['enforce_resolution', res])
+            info('enforce_resolution %s (send)' % res)
+        self._tasks += [(
+            self._curr_time + time,
+            cback,
+            'enforce resolution: %s' % res)]
+        self._curr_time += time
+
     def _verify(self):
         def __verify():
             self._conn.send(['verify'])
@@ -192,10 +202,12 @@ class FunctionalTest(GameObject):
         # resolution
         self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 340), 'left'])
         self._screenshot(FunctionalTest.screenshot_time, 'resolutions')
+        self._enforce_resolution(FunctionalTest.evt_time, '1440x900')
         self._event(FunctionalTest.evt_time, 'mouseclick', [(1000, 440), 'left'])
         self._screenshot(FunctionalTest.screenshot_time, '1440x900')
         self._event(FunctionalTest.evt_time, 'mouseclick', [(740, 400), 'left'])
         self._screenshot(FunctionalTest.screenshot_time, 'resolutions_2')
+        self._enforce_resolution(FunctionalTest.evt_time, '1360x768')
         self._event(FunctionalTest.evt_time, 'mouseclick', [(1110, 80), 'left'])
         self._screenshot(FunctionalTest.screenshot_time, '1360x768')
         # antialiasing