ya2 · news · projects · code · about

fixes for building
authorFlavio Calva <f.calva@gmail.com>
Sat, 4 Feb 2023 10:43:52 +0000 (11:43 +0100)
committerFlavio Calva <f.calva@gmail.com>
Sat, 4 Feb 2023 10:43:52 +0000 (11:43 +0100)
pmachines/application/application.py
pmachines/editor/inspector.py
pmachines/editor/scene.py
pmachines/editor/start_items.py
pmachines/items/item.py
prj.org
tests/functional_test.py
tests/test_functional.py
ya2/utils/log.py

index 77aa71148ee99df4d542daa449b7a20879a16766..0fcc1be4422178506504412d2377179ebd5a71b9 100755 (executable)
@@ -225,7 +225,7 @@ class Pmachines:
                 'debug_items': 0,
                 'mouse_coords': 0,
                 'fps': 0,
                 'debug_items': 0,
                 'mouse_coords': 0,
                 'fps': 0,
-                'editor': 0,
+                'editor': 1,
                 'auto_start_editor': 0}}
         opt_path = LogicsTools.platform_specific_path(data_path + '/' + optfile) if data_path else optfile
         opt_exists = exists(opt_path)
                 'auto_start_editor': 0}}
         opt_path = LogicsTools.platform_specific_path(data_path + '/' + optfile) if data_path else optfile
         opt_exists = exists(opt_path)
index f5f04f07e3504498b4f8a65e49e7510dc9792f95..3c39a357823074836bd24fc7c97243c9d6ae27d7 100644 (file)
@@ -20,7 +20,7 @@ from ya2.utils.gfx import DirectGuiMixin
 
 class Inspector(DirectObject):
 
 
 class Inspector(DirectObject):
 
-    def __init__(self, item, all_items, pos_mgr):
+    def __init__(self, item, all_items, pos_mgr, strategy_items):
         super().__init__()
         self.__item = item
         self.__all_items = all_items
         super().__init__()
         self.__item = item
         self.__all_items = all_items
@@ -74,19 +74,20 @@ class Inspector(DirectObject):
         t, restitution_entry = self.__add_row('restitution', _('restitution'), f'{round(restitution, 3)}', self.on_edit_restitution, _('restitution (default 0.5)'))
         t, friction_entry = self.__add_row('friction', _('friction'), f'{round(f, 3)}', self.on_edit_friction, _('friction (default 0.5)'))
         t, id_entry = self.__add_row('id', _('id'), _id, self.on_edit_id, _('id of the item (for the strategies)'))
         t, restitution_entry = self.__add_row('restitution', _('restitution'), f'{round(restitution, 3)}', self.on_edit_restitution, _('restitution (default 0.5)'))
         t, friction_entry = self.__add_row('friction', _('friction'), f'{round(f, 3)}', self.on_edit_friction, _('friction (default 0.5)'))
         t, id_entry = self.__add_row('id', _('id'), _id, self.on_edit_id, _('id of the item (for the strategies)'))
-        item_modules = glob('pmachines/items/*.py')
-        item_modules = [basename(i)[:-3] for i in item_modules]
-        strategy_items = ['']
-        for item_module in item_modules:
-            mod_name = 'pmachines.items.' + item_module
-            for member in import_module(mod_name).__dict__.values():
-                if isclass(member) and issubclass(member, ItemStrategy) and \
-                        member != ItemStrategy:
-                    strategy_items = list(set(strategy_items + [member.__name__]))
-        t, strategy_entry = self.__add_row_option(_('strategy'), _strategy, strategy_items, self.on_edit_strategy, _('the strategy of the item'))
+        # item_modules = glob('pmachines/items/*.py')
+        # item_modules = [basename(i)[:-3] for i in item_modules]
+        # strategy_items = ['']
+        # for item_module in item_modules:
+        #     mod_name = 'pmachines.items.' + item_module
+        #     for member in import_module(mod_name).__dict__.values():
+        #         if isclass(member) and issubclass(member, ItemStrategy) and \
+        #                 member != ItemStrategy:
+        #             strategy_items = list(set(strategy_items + [member.__name__]))
+        strategy_names = [s.__name__ for s in strategy_items]
+        t, strategy_entry = self.__add_row_option(_('strategy'), _strategy, strategy_names, self.on_edit_strategy, _('the strategy of the item'))
 
         def strategy_set(comps):
 
         def strategy_set(comps):
-            strategy_labels = [f'inspector_strategy_{i.lower()}' for i in strategy_items]
+            strategy_labels = [f'inspector_strategy_{i.lower()}' for i in strategy_names]
             for i in strategy_labels:
                 if i in self.__pos_mgr:
                     del self.__pos_mgr[i]
             for i in strategy_labels:
                 if i in self.__pos_mgr:
                     del self.__pos_mgr[i]
index 84f4eaf9aae98e277e7e6f9b815701225cf29378..f85d0c51c02a9e2fc2001691e322d42e64035876 100644 (file)
@@ -21,6 +21,14 @@ from pmachines.editor.start_items import StartItems
 from ya2.utils.gfx import Point, DirectGuiMixin
 from pmachines.editor.augmented_frame import AugmentedDirectFrame
 from ya2.utils.gui.base_page import DirectOptionMenuTestable
 from ya2.utils.gfx import Point, DirectGuiMixin
 from pmachines.editor.augmented_frame import AugmentedDirectFrame
 from ya2.utils.gui.base_page import DirectOptionMenuTestable
+from pmachines.items.basketball import Basketball
+from pmachines.items.box import Box
+from pmachines.items.domino import Domino
+from pmachines.items.shelf import Shelf
+from pmachines.items.teetertooter import TeeterTooter
+from pmachines.items.item import FixedStrategy, StillStrategy
+from pmachines.items.domino import UpStrategy, DownStrategy
+from pmachines.items.box import HitStrategy
 
 
 class SceneEditor(DirectObject):
 
 
 class SceneEditor(DirectObject):
@@ -52,6 +60,8 @@ class SceneEditor(DirectObject):
         self._font.set_pixels_per_unit(60)
         self._font.set_minfilter(Texture.FTLinearMipmapLinear)
         self._font.set_outline((0, 0, 0, 1), .8, .2)
         self._font.set_pixels_per_unit(60)
         self._font.set_minfilter(Texture.FTLinearMipmapLinear)
         self._font.set_outline((0, 0, 0, 1), .8, .2)
+        self.__item_classes = [Basketball, Box, Domino, Shelf, TeeterTooter]
+        self.__item_strategy_classes = [FixedStrategy, StillStrategy, HitStrategy, UpStrategy, DownStrategy]
         self._common = {
             'scale': .046,
             'text_font': self._font,
         self._common = {
             'scale': .046,
             'text_font': self._font,
@@ -180,15 +190,16 @@ class SceneEditor(DirectObject):
         b.__class__ = type('DirectButtonMixed', (DirectButton, DirectGuiMixin), {})
         self.__pos_mgr['editor_sorting'] = b.pos_pixel()
         b.set_tooltip(_('Set the sorting of the scenes'), *tooltip_args)
         b.__class__ = type('DirectButtonMixed', (DirectButton, DirectGuiMixin), {})
         self.__pos_mgr['editor_sorting'] = b.pos_pixel()
         b.set_tooltip(_('Set the sorting of the scenes'), *tooltip_args)
-        item_modules = glob('pmachines/items/*.py')
-        item_modules = [basename(i)[:-3] for i in item_modules]
+        item_modules = glob('pmachines/items/*.py')
+        item_modules = [basename(i)[:-3] for i in item_modules]
         self.__new_items = {}
         self.__new_items = {}
-        for item_module in item_modules:
-            mod_name = 'pmachines.items.' + item_module
-            for member in import_module(mod_name).__dict__.values():
-                if isclass(member) and issubclass(member, Item) and \
-                        member != Item:
-                    self.__new_items[member.__name__] = member
+        # for item_module in item_modules:
+        #     mod_name = 'pmachines.items.' + item_module
+        #     for member in import_module(mod_name).__dict__.values():
+        #         if isclass(member) and issubclass(member, Item) and \
+        #                 member != Item:
+        #             self.__new_items[member.__name__] = member
+        for i in self.__item_classes: self.__new_items[i.__name__] = i
         OnscreenText(
             _('new item'), pos=(.02, .46), parent=self._frm,
             font=self._common['text_font'],
         OnscreenText(
             _('new item'), pos=(.02, .46), parent=self._frm,
             font=self._common['text_font'],
@@ -370,7 +381,7 @@ class SceneEditor(DirectObject):
         elif item.__class__ == WorldSpaceTestItem:
             self.__inspector = WorldSpaceInspector(item, self.__items, self.__pos_mgr)
         else:
         elif item.__class__ == WorldSpaceTestItem:
             self.__inspector = WorldSpaceInspector(item, self.__items, self.__pos_mgr)
         else:
-            self.__inspector = Inspector(item, self.__items, self.__pos_mgr)
+            self.__inspector = Inspector(item, self.__items, self.__pos_mgr, self.__item_strategy_classes)
 
     def __on_inspector_destroy(self):
         self.__inspector = None
 
     def __on_inspector_destroy(self):
         self.__inspector = None
@@ -381,7 +392,7 @@ class SceneEditor(DirectObject):
         messenger.send('new_scene')
 
     def __on_start_items(self):
         messenger.send('new_scene')
 
     def __on_start_items(self):
-        self.__start_items = StartItems(self.__json['start_items'], self.__pos_mgr)
+        self.__start_items = StartItems(self.__json['start_items'], self.__pos_mgr, self.__item_classes, self.__item_strategy_classes)
 
     def __on_start_items_save(self, start_items):
         self.__json['start_items'] = start_items
 
     def __on_start_items_save(self, start_items):
         self.__json['start_items'] = start_items
index a899452f2315a34b97e9ec130aa8cad2ab8891e4..3eac6f56e861e396c30e6d408ca12a16814cfe27 100644 (file)
@@ -17,7 +17,7 @@ from ya2.utils.gui.base_page import DirectOptionMenuTestable
 
 class StartItems(DirectObject):
 
 
 class StartItems(DirectObject):
 
-    def __init__(self, json_items, pos_mgr):
+    def __init__(self, json_items, pos_mgr, item_classes, strategy_items):
         super().__init__()
         self.__items = json_items
         self.__json = self.__items[0]
         super().__init__()
         self.__items = json_items
         self.__json = self.__items[0]
@@ -49,19 +49,20 @@ class StartItems(DirectObject):
                                          pos_mgr=pos_mgr,
                                          frame_name='start')
         self.__z = -.08
                                          pos_mgr=pos_mgr,
                                          frame_name='start')
         self.__z = -.08
-        item_modules = glob('pmachines/items/*.py')
-        item_modules = [basename(i)[:-3] for i in item_modules]
-        new_items = ['']
-        for item_module in item_modules:
-            mod_name = 'pmachines.items.' + item_module
-            for member in import_module(mod_name).__dict__.values():
-                if isclass(member) and issubclass(member, Item) and \
-                        member != Item:
-                    new_items = list(set(new_items + [member.__name__]))
-        t, item_class_entry = self.__add_row_option(_('class'), '', new_items, self.on_edit_class, _('class of the item'))
+        # item_modules = glob('pmachines/items/*.py')
+        # item_modules = [basename(i)[:-3] for i in item_modules]
+        # new_items = ['']
+        # for item_module in item_modules:
+        #     mod_name = 'pmachines.items.' + item_module
+        #     for member in import_module(mod_name).__dict__.values():
+        #         if isclass(member) and issubclass(member, Item) and \
+        #                 member != Item:
+        #             new_items = list(set(new_items + [member.__name__]))
+        item_names = [i.__name__ for i in item_classes]
+        t, item_class_entry = self.__add_row_option(_('class'), '', item_names, self.on_edit_class, _('class of the item'))
 
         def item_class_set(comps):
 
         def item_class_set(comps):
-            class_labels = [f'start_class_{i.lower()}' for i in new_items]
+            class_labels = [f'start_class_{i.lower()}' for i in item_names]
             for i in class_labels:
                 if i in self.__pos_mgr:
                     del self.__pos_mgr[i]
             for i in class_labels:
                 if i in self.__pos_mgr:
                     del self.__pos_mgr[i]
@@ -78,17 +79,18 @@ class StartItems(DirectObject):
         t, restitution_entry = self.__add_row('restitution', _('restitution'), '', self.on_edit_restitution, _('restitution (default 0.5)'))
         t, friction_entry = self.__add_row('friction', _('friction'), '', self.on_edit_friction, _('friction (default 0.5)'))
         t, id_entry = self.__add_row('id', _('id'), '', self.on_edit_id, _('id'))
         t, restitution_entry = self.__add_row('restitution', _('restitution'), '', self.on_edit_restitution, _('restitution (default 0.5)'))
         t, friction_entry = self.__add_row('friction', _('friction'), '', self.on_edit_friction, _('friction (default 0.5)'))
         t, id_entry = self.__add_row('id', _('id'), '', self.on_edit_id, _('id'))
-        strategy_items = ['']
-        for item_module in item_modules:
-            mod_name = 'pmachines.items.' + item_module
-            for member in import_module(mod_name).__dict__.values():
-                if isclass(member) and issubclass(member, ItemStrategy) and \
-                        member != ItemStrategy:
-                    strategy_items = list(set(strategy_items + [member.__name__]))
-        t, strategy_entry = self.__add_row_option(_('strategy'), '', strategy_items, self.on_edit_strategy, _('the strategy of the item'))
+        # strategy_items = ['']
+        # for item_module in item_modules:
+        #     mod_name = 'pmachines.items.' + item_module
+        #     for member in import_module(mod_name).__dict__.values():
+        #         if isclass(member) and issubclass(member, ItemStrategy) and \
+        #                 member != ItemStrategy:
+        #             strategy_items = list(set(strategy_items + [member.__name__]))
+        strategy_names = [s.__name__ for s in strategy_items]
+        t, strategy_entry = self.__add_row_option(_('strategy'), '', strategy_names, self.on_edit_strategy, _('the strategy of the item'))
 
         def strategy_set(comps):
 
         def strategy_set(comps):
-            strategy_labels = [f'start_strategy_{i.lower()}' for i in strategy_items]
+            strategy_labels = [f'start_strategy_{i.lower()}' for i in strategy_names]
             for i in strategy_labels:
                 if i in self.__pos_mgr:
                     del self.__pos_mgr[i]
             for i in strategy_labels:
                 if i in self.__pos_mgr:
                     del self.__pos_mgr[i]
index 5922f4530bce393a789cfab6b9fe497e8dbc11e5..a0dd204cdb2755338d800ea0fab29012743770e9 100644 (file)
@@ -100,8 +100,8 @@ class Item(DirectObject):
         self._outline_model.hide(BitMask32(0x01))
         self._start_drag_pos = None
         self._prev_rot_info = None
         self._outline_model.hide(BitMask32(0x01))
         self._start_drag_pos = None
         self._prev_rot_info = None
-        self._last_nonoverlapping_pos = None
-        self._last_nonoverlapping_rot = None
+        self._last_nonoverlapping_pos = (0, 0, 0)
+        self._last_nonoverlapping_rot = 0
         self._instantiated = not count
         self._box_tsk = taskMgr.add(self.on_frame, 'item_on_frame')
         if count:
         self._instantiated = not count
         self._box_tsk = taskMgr.add(self.on_frame, 'item_on_frame')
         if count:
diff --git a/prj.org b/prj.org
index 061dc038caa45a1a18ad39fce6b17638222ea2fe..06bfb4bc425d064353a73bcef1faa2dfe29e85d9 100644 (file)
--- a/prj.org
+++ b/prj.org
@@ -9,7 +9,7 @@
 * BACKLOG actions: rewind, prev, next
 * BACKLOG (python 3.11) manylinux2014_x86_64
 * BACKLOG (when panda3d provides it) android build (test with the emulator of android studio)
 * BACKLOG actions: rewind, prev, next
 * BACKLOG (python 3.11) manylinux2014_x86_64
 * BACKLOG (when panda3d provides it) android build (test with the emulator of android studio)
-* BACKLOG (test with wine 8.0 | when itch.io's client works with wine) functional tests for windows-itch.io
+* BACKLOG (when itch.io's client works with wine) functional tests for windows-itch.io
 * calendar                                                         :calendar:
 ** publish post q1; reschedule
 SCHEDULED: <2023-03-20 Mon +1y>
 * calendar                                                         :calendar:
 ** publish post q1; reschedule
 SCHEDULED: <2023-03-20 Mon +1y>
index 5f293f6d9da8566e9e5ceecad35839457aba6a43..123a212bdab51258f36764ce53d24e628396a51d 100644 (file)
@@ -1,6 +1,6 @@
 from panda3d.core import load_prc_file_data
 load_prc_file_data('', 'window-type none')
 from panda3d.core import load_prc_file_data
 load_prc_file_data('', 'window-type none')
-import datetime
+import datetime, sys
 from pathlib import Path
 from time import sleep
 from os import system
 from pathlib import Path
 from time import sleep
 from os import system
@@ -11,11 +11,12 @@ from sys import exit, argv
 from direct.showbase.ShowBase import ShowBase
 import asyncio
 import xmlrpc
 from direct.showbase.ShowBase import ShowBase
 import asyncio
 import xmlrpc
-from logging import basicConfig, debug, info, DEBUG, getLogger, Formatter, FileHandler
+from logging import basicConfig, debug, info, DEBUG, getLogger, Formatter, FileHandler, StreamHandler
 
 
 basicConfig(level=DEBUG, format='(evt-test) %(asctime)s.%(msecs)03d %(message)s', datefmt='%H:%M:%S')
 getLogger().setLevel(DEBUG)  # it doesn't work otherwise
 
 
 basicConfig(level=DEBUG, format='(evt-test) %(asctime)s.%(msecs)03d %(message)s', datefmt='%H:%M:%S')
 getLogger().setLevel(DEBUG)  # it doesn't work otherwise
+getLogger().addHandler(StreamHandler(sys.stdout))
 
 
 class FunctionalTest:
 
 
 class FunctionalTest:
@@ -29,15 +30,15 @@ class FunctionalTest:
         debug('creating FunctionalTest (%s)' % id(self))
         super().__init__()
 
         debug('creating FunctionalTest (%s)' % id(self))
         super().__init__()
 
-        timestamp = datetime.datetime.now().strftime('%y%m%d%H%M%S')
-        logFormatter = Formatter('%(asctime)s.%(msecs)03d %(message)s', datefmt='%H:%M:%S')
-        path = str(Path.home()) + '/.local/share/pmachines/logs/evt/'
-        if not exists(path):
-            makedirs(path)
-        lpath = path + 'evt_%s.log' % timestamp
-        fileHandler = FileHandler(lpath)
-        fileHandler.setFormatter(logFormatter)
-        getLogger().addHandler(fileHandler)
+        timestamp = datetime.datetime.now().strftime('%y%m%d%H%M%S')
+        logFormatter = Formatter('%(asctime)s.%(msecs)03d %(message)s', datefmt='%H:%M:%S')
+        path = str(Path.home()) + '/.local/share/pmachines/logs/evt/'
+        if not exists(path):
+            makedirs(path)
+        lpath = path + 'evt_%s.log' % timestamp
+        fileHandler = FileHandler(lpath)
+        fileHandler.setFormatter(logFormatter)
+        getLogger().addHandler(fileHandler)
 
         info('test idx: %s' % idx)
         self._offset = offset
 
         info('test idx: %s' % idx)
         self._offset = offset
index a3ccb5e1d16dcbf6127c24a4d266a0014a4057c1..c1ce61ccefb4a9e9460acd72e8381098781b3fff 100644 (file)
@@ -11,7 +11,7 @@ from time import sleep
 from os import system, remove, environ
 from os.path import exists, basename, join
 from glob import glob
 from os import system, remove, environ
 from os.path import exists, basename, join
 from glob import glob
-from subprocess import PIPE, Popen
+from subprocess import PIPE, Popen, STDOUT
 from panda3d.core import Filename
 from ya2.build.build import exec_cmd, _branch, _version
 
 from panda3d.core import Filename
 from ya2.build.build import exec_cmd, _branch, _version
 
@@ -84,11 +84,11 @@ class FunctionalTests(TestCase):
             sleep(8)
             info('launching ' + app_cmd)
             print('launching ' + app_cmd)
             sleep(8)
             info('launching ' + app_cmd)
             print('launching ' + app_cmd)
-            p_app = Popen(app_cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
+            p_app = Popen(app_cmd, shell=True, stderr=STDOUT, universal_newlines=True)
             sleep(30)
             info('launching ' + test_cmd)
             print('launching ' + test_cmd)
             sleep(30)
             info('launching ' + test_cmd)
             print('launching ' + test_cmd)
-            p_test = Popen(test_cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
+            p_test = Popen(test_cmd, shell=True, stderr=STDOUT, universal_newlines=True
             p_app_out, p_app_err = p_app.communicate()
             t_out, t_err = p_test.communicate()
             info('output (%s): %s' % (app_cmd, p_app_out))
             p_app_out, p_app_err = p_app.communicate()
             t_out, t_err = p_test.communicate()
             info('output (%s): %s' % (app_cmd, p_app_out))
index 7330b90e0b3c2624a0f81162366693a537d46b8b..2761867bcc08a57c8102cce61e7e3303ef0b39d8 100755 (executable)
@@ -118,7 +118,7 @@ class LogManager:
         list(map(self.log, self.__messages))
 
     def __write_observed_version(self):
         list(map(self.log, self.__messages))
 
     def __write_observed_version(self):
-        info(f'writing {LogicsTools.appdata_path}/{self.__appname}/observed_version.txt')
+        info(f'writing {LogicsTools.appdata_path}/{self.__app_name}/observed_version.txt')
         with open(LogicsTools.appdata_path + '/pmachines/observed_version.txt', 'w') as f:
             f.write(self.build_version)
 
         with open(LogicsTools.appdata_path + '/pmachines/observed_version.txt', 'w') as f:
             f.write(self.build_version)