ya2 · news · projects · code · about

json: start items
authorFlavio Calva <f.calva@gmail.com>
Thu, 22 Sep 2022 18:54:36 +0000 (19:54 +0100)
committerFlavio Calva <f.calva@gmail.com>
Thu, 22 Sep 2022 18:54:36 +0000 (19:54 +0100)
15 files changed:
assets/scenes/basketball.json
assets/scenes/box.json
assets/scenes/domino.json
assets/scenes/domino_box.json
assets/scenes/domino_box_basketball.json
assets/scenes/teeter_domino_box_basketball.json
assets/scenes/teeter_tooter.json
pmachines/scene.py
pmachines/scenes/scene_basketball.py
pmachines/scenes/scene_box.py
pmachines/scenes/scene_domino.py
pmachines/scenes/scene_domino_box.py
pmachines/scenes/scene_domino_box_basketball.py
pmachines/scenes/scene_teeter_domino_box_basketball.py
pmachines/scenes/scene_teeter_tooter.py

index 918214ea0039886568f53458357193b31ac930dc..f8bc9e57c0673c8d1775f802dc3b32f60d25f7b8 100644 (file)
@@ -8,4 +8,7 @@
         {"id": "drag_stop_0",
          "position": [-0.42, 1.03]},
         {"id": "drag_stop_1",
-         "position": [-4.19, 4.66]}]}}
+         "position": [-4.19, 4.66]}]},
+ "start_items": [
+     {"class": "Basketball",
+      "count": 1}]}
index bb366a2bacc9daa50d93d83e8d1e9f4db440f289..54b0e650a38c911711970ba6b3699be7a9af31db 100644 (file)
@@ -11,4 +11,8 @@
          "position": [0.42, -2.18]},
         {"id": "drag_stop_2",
          "position": [0.35, -1.06]}
-     ]}}
+     ]},
+ "start_items": [
+     {"class": "Box",
+      "count": 3}]
+}
index ebd3fd67b34f530fa406f7fe13ceeff5ebd58fae..bdd34c0da62970b58b4325eff5af80d8e6ece553 100644 (file)
@@ -16,4 +16,7 @@
         {"id": "drag_stop_3",
          "position": [-1.05, 0.4]}
      ]
- }}
+ },
+ "start_items": [
+     {"class": "Domino",
+      "count": 2}]}
index fd1971eb21c3ec0f7635cf56212cdbf8095afaae..d3c60e805dc7e8963afb880d0eb0624b5b47247e 100644 (file)
@@ -11,4 +11,8 @@
          "position": [3.21, 0.33]},
         {"id": "drag_stop_2",
          "position": [2.16, 1.87]}
-     ]}}
+     ]},
+ "start_items": [
+     {"class": "Box",
+      "count": 2,
+      "mass": 5}]}
index d5e0af3c6a5320644a8ed2b5fac22ccb4e1bff55..ba396584f0f3a63a44b5b084e04684a97188efcd 100644 (file)
          "position": [-0.28, -0.85]},
         {"id": "drag_stop_4",
          "position": [-0.42, -0.85]}
-     ]}}
+     ]},
+ "start_items": [
+     {"class": "Box",
+      "count": 1,
+      "mass": 5},
+     {"class": "Domino",
+      "count": 1}]}
index c0c9c4b2b14654b9375d3bc759b181133015c942..91d36cfa63e3f9ffebc0adacbafd7f01f15f6065 100644 (file)
@@ -13,4 +13,9 @@
          "position": [-6.77, 4.66]},
         {"id": "drag_stop_2",
          "position": [-6.77, 4.24]}
-     ]}}
+     ]},
+ "start_items": [
+     {"class": "Box",
+      "count": 2,
+      "mass": 3,
+      "friction": 1}]}
index c2db52026e3d2555e4a3b8faab1d56bb57a39259..244c097a1d5b54dab3c3f11d75a0ee5d8512f3b1 100644 (file)
@@ -13,4 +13,9 @@
          "position": [-2.3, 3.75]},
         {"id": "drag_stop_2",
          "position": [-2.5, 3.66]}
-     ]}}
+     ]},
+ "start_items": [
+     {"class": "Box",
+      "count": 1,
+      "mass": 3,
+      "friction": 1}]}
index b77cf6f53395dcbab9e5087d20051f08ba665259..083f145713f001c9cb3114b7342fd87be6cfd82e 100644 (file)
@@ -14,6 +14,9 @@ from direct.interval.IntervalGlobal import Sequence, Func
 from direct.interval.LerpInterval import LerpFunctionInterval
 from pmachines.items.background import Background
 from pmachines.gui.sidepanel import SidePanel
+from pmachines.items.box import Box
+from pmachines.items.basketball import Basketball
+from pmachines.items.domino import Domino
 from ya2.utils.cursor import MouseCursor
 from ya2.p3d.gfx import P3dGfxMgr
 from ya2.p3d.p3d import LibP3d
@@ -83,6 +86,29 @@ class Scene(DirectObject):
     def _set_items(self):
         self.items = []
         self._test_items = []
+        if not self.__class__.json:
+            with open(self.__class__.filename) as f:
+                self.__class__.json = loads(f.read())
+        for item in self.__class__.json['start_items']:
+            args = {
+                'world': self._world,
+                'plane_node': self._mouse_plane_node,
+                'cb_inst': self.cb_inst,
+                'curr_bottom': self.current_bottom,
+                'repos': self.repos,
+                'count': item['count']}
+            if 'mass' in item:
+                args['mass'] = item['mass']
+            if 'friction' in item:
+                args['friction'] = item['friction']
+            self.items += [self.__code2class(item['class'])(**args)]
+
+    def __code2class(self, code):
+        return {
+            'Box': Box,
+            'Basketball': Basketball,
+            'Domino': Domino
+        }[code]
 
     def screenshot(self, task=None):
         tex = Texture('screenshot')
index e8a76a544c988145c967353601b53ac8fb5e97eb..34d8606ca84072f35fbda561f943b4fbaef841ed 100644 (file)
@@ -1,7 +1,6 @@
 from pmachines.scene import Scene
 from pmachines.items.shelf import Shelf
 from pmachines.items.domino import Domino, DownStrategy
-from pmachines.items.basketball import Basketball
 
 
 class SceneBasketBall(Scene):
@@ -13,9 +12,10 @@ class SceneBasketBall(Scene):
         return _('Basket ball')
 
     def _set_items(self):
+        super()._set_items()
         #self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=5, count=2)]
         #self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=9)]
-        self.items += [Basketball(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=1)]
+        #self.items += [Basketball(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=1)]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(-.56, 0, .21))]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(1.67, 0, .21))]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(-.56, 0, -1.45))]
index d86be97aa601b2cc0c6d5bd1893c94d6442bed88..bc8df3132915f4129212975eaae9b7337c92d6d7 100644 (file)
@@ -12,7 +12,8 @@ class SceneBox(Scene):
         return _('Box')
 
     def _set_items(self):
-        self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=3)]
+        super()._set_items()
+        # self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=3)]
         #self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=3)]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(.46, 0, -3.95))]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(4.43, 0, -3.95))]
index b5c87ad4d1d5249371ab756e0e433295b55980f3..26317c45f8bed0316d0746413ff64512231ca50c 100644 (file)
@@ -12,11 +12,12 @@ class SceneDomino(Scene):
         return _('Domino')
 
     def _set_items(self):
+        super()._set_items()
         #self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=3)]
         #self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=3)]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(-1.2, 0, -.6))]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(1.2, 0, -.6))]
-        self.items += [Domino(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=2)]
+        #self.items += [Domino(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=2)]
         self.items += [Domino(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, pos=(-1.14, 0, -.04))]
         self.items[-1].set_strategy(DownStrategy(self.items[-1]._np, 60))
         self.items += [Domino(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, pos=(-.49, 0, -.04))]
index 0d065a14da0846131d8c947ed7e91ae98f806e23..9ee68624304416ea9d4ed8e7209af93c80e73a00 100644 (file)
@@ -1,5 +1,4 @@
 from pmachines.scene import Scene
-from pmachines.items.box import Box
 from pmachines.items.shelf import Shelf
 from pmachines.items.domino import Domino, UpStrategy, DownStrategy
 
@@ -13,7 +12,8 @@ class SceneDominoBox(Scene):
         return _('Domino and box')
 
     def _set_items(self):
-        self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=5, count=2)]
+        super()._set_items()
+        #self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=5, count=2)]
         #self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=9)]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(-.56, 0, .21))]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(1.67, 0, .21))]
index c08ac3a8f9b88de1b9a7ddd1980716530d3a9fba..c4039894517ad97aacd97c747cd5a09ef9bc112c 100644 (file)
@@ -1,5 +1,4 @@
 from pmachines.scene import Scene
-from pmachines.items.box import Box
 from pmachines.items.shelf import Shelf
 from pmachines.items.domino import Domino, DownStrategy
 from pmachines.items.basketball import Basketball
@@ -14,8 +13,9 @@ class SceneDominoBoxBasketball(Scene):
         return _('Domino, box and basket ball')
 
     def _set_items(self):
-        self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=1, mass=5)]
-        self.items += [Domino(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=1)]
+        super()._set_items()
+        #self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=1, mass=5)]
+        #self.items += [Domino(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, count=1)]
         self.items += [Basketball(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, pos=(-.3, 1, 2.5))]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(-.56, 0, -1.45))]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(1.67, 0, -1.45))]
index a4e687edae5f31dbb0dde6c0d127d1db5464f89f..3a044521ffc2420ebb29be3bcd58d695331e6418 100644 (file)
@@ -15,7 +15,8 @@ class SceneTeeterDominoBoxBasketball(Scene):
         return _('Teeter tooter, domino, box and basket ball')
 
     def _set_items(self):
-        self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=3, count=2, friction=1)]
+        super()._set_items()
+        #self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=3, count=2, friction=1)]
         self.items += [Basketball(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, pos=(.98, 1, 1.02))]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(-6.24, 0, -1.45))]
         self.items += [TeeterTooter(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(-6.24, 0, -1.20))]
index 214826c2fdcb37d0013b1d0e645254abc4e809c6..b7074a0043e04de890c767041aa5d8b6a00384cd 100644 (file)
@@ -14,7 +14,8 @@ class SceneTeeterTooter(Scene):
         return _('Teeter tooter')
 
     def _set_items(self):
-        self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=3, count=1, friction=1)]
+        super()._set_items()
+        #self.items += [Box(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=3, count=1, friction=1)]
         #self.items += [TeeterTooter(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=5, count=2)]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(-2.76, 0, -1.45))]
         self.items += [Shelf(self._world, self._mouse_plane_node, self.cb_inst, self.current_bottom, self.repos, mass=0, pos=(-.56, 0, -1.45))]