ya2 · news · projects · code · about

version in json files
authorFlavio Calva <f.calva@gmail.com>
Tue, 20 Sep 2022 18:04:05 +0000 (19:04 +0100)
committerFlavio Calva <f.calva@gmail.com>
Tue, 20 Sep 2022 18:04:05 +0000 (19:04 +0100)
16 files changed:
assets/scenes/basketball.json [new file with mode: 0644]
assets/scenes/box.json [new file with mode: 0644]
assets/scenes/domino.json [new file with mode: 0644]
assets/scenes/domino_box.json [new file with mode: 0644]
assets/scenes/domino_box_basketball.json [new file with mode: 0644]
assets/scenes/teeter_domino_box_basketball.json [new file with mode: 0644]
assets/scenes/teeter_tooter.json [new file with mode: 0644]
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
prj.org

diff --git a/assets/scenes/basketball.json b/assets/scenes/basketball.json
new file mode 100644 (file)
index 0000000..aca901b
--- /dev/null
@@ -0,0 +1 @@
+{"version": "220914"}
diff --git a/assets/scenes/box.json b/assets/scenes/box.json
new file mode 100644 (file)
index 0000000..aca901b
--- /dev/null
@@ -0,0 +1 @@
+{"version": "220914"}
diff --git a/assets/scenes/domino.json b/assets/scenes/domino.json
new file mode 100644 (file)
index 0000000..aca901b
--- /dev/null
@@ -0,0 +1 @@
+{"version": "220914"}
diff --git a/assets/scenes/domino_box.json b/assets/scenes/domino_box.json
new file mode 100644 (file)
index 0000000..aca901b
--- /dev/null
@@ -0,0 +1 @@
+{"version": "220914"}
diff --git a/assets/scenes/domino_box_basketball.json b/assets/scenes/domino_box_basketball.json
new file mode 100644 (file)
index 0000000..aca901b
--- /dev/null
@@ -0,0 +1 @@
+{"version": "220914"}
diff --git a/assets/scenes/teeter_domino_box_basketball.json b/assets/scenes/teeter_domino_box_basketball.json
new file mode 100644 (file)
index 0000000..aca901b
--- /dev/null
@@ -0,0 +1 @@
+{"version": "220914"}
diff --git a/assets/scenes/teeter_tooter.json b/assets/scenes/teeter_tooter.json
new file mode 100644 (file)
index 0000000..aca901b
--- /dev/null
@@ -0,0 +1 @@
+{"version": "220914"}
index 6029d720c98ddf9558ce6ca94b0b0e63e9bbc350..31660ece45ebdf563fcafc44ecca778d4310a68b 100644 (file)
@@ -1,6 +1,7 @@
 from os.path import exists
 from os import makedirs
 from logging import info
+from json import loads
 from panda3d.core import AmbientLight, Texture, TextPropertiesManager, \
     TextNode, Spotlight, PerspectiveLens, BitMask32, NodePath
 from panda3d.bullet import BulletPlaneShape, BulletGhostNode
@@ -21,6 +22,7 @@ from ya2.p3d.p3d import LibP3d
 class Scene(DirectObject):
 
     scenes_done = []
+    json = {}
 
     def __init__(self, world, exit_cb, auto_close_instr, dbg_items, reload_cb, scenes, pos_mgr, testing, mouse_coords, persistent):
         super().__init__()
@@ -64,9 +66,16 @@ class Scene(DirectObject):
     def name():
         return ''
 
+    @classmethod
+    def version(cls):
+        if not cls.json:
+            with open(cls.filename) as f:
+                cls.json = loads(f.read())
+        return cls.json['version']
+
     @classmethod
     def is_done(cls):
-        return bool([(name, version) for name, version in cls.scenes_done if cls.__name__ == name and cls.version == version])
+        return bool([(name, version) for name, version in cls.scenes_done if cls.__name__ == name and cls.version() == version])
 
     def _instr_txt(self):
         return ''
@@ -495,7 +504,7 @@ class Scene(DirectObject):
         self._pos_mgr.register('close_instructions', LibP3d.wdg_pos(btn))
 
     def _set_win(self):
-        self.__persistent.save_scene(self.__class__.__name__, self.version)
+        self.__persistent.save_scene(self.__class__.__name__, self.version())
         loader.load_sfx('assets/audio/sfx/success.ogg').play()
         self._paused = True
         self.__store_state()
index 4d46a0da9a9931f16c116283b9885acad81010d0..c3f24938a4f2bf9233810df09a005c8d47a54ccf 100644 (file)
@@ -6,7 +6,7 @@ from pmachines.items.basketball import Basketball
 
 class SceneBasketBall(Scene):
 
-    version = '220914'
+    filename = 'assets/scenes/basketball.json'
 
     @staticmethod
     def name():
index 65dc738f4e70852da5ada3a3cacc94711d27ee05..6997fa22d0373d33f1602f7d2f7f1d643b8d27af 100644 (file)
@@ -5,7 +5,7 @@ from pmachines.items.shelf import Shelf
 
 class SceneBox(Scene):
 
-    version = '220914'
+    filename = 'assets/scenes/box.json'
 
     @staticmethod
     def name():
index 6450a62a7fddd76ff773be36377a4b1f4cf275c3..5467afd915a08e0a6cec442109842987959fb457 100644 (file)
@@ -5,7 +5,7 @@ from pmachines.items.domino import Domino, DownStrategy
 
 class SceneDomino(Scene):
 
-    version = '220914'
+    filename = 'assets/scenes/domino.json'
 
     @staticmethod
     def name():
index 41695bfada782f454c0103c554113885eea4307d..d8ed0131f1a7ba3f83d289557fbfe3b8e702e2dd 100644 (file)
@@ -6,7 +6,7 @@ from pmachines.items.domino import Domino, UpStrategy, DownStrategy
 
 class SceneDominoBox(Scene):
 
-    version = '220914'
+    filename = 'assets/scenes/domino_box.json'
 
     @staticmethod
     def name():
index 7f9e9a2f97cd2c299c10ee6a65d316e32ca18347..f45048bbe31fbe189700911cd1b3d04efa2a3153 100644 (file)
@@ -7,7 +7,7 @@ from pmachines.items.basketball import Basketball
 
 class SceneDominoBoxBasketball(Scene):
 
-    version = '220914'
+    filename = 'assets/scenes/domino_box_basketball.json'
 
     @staticmethod
     def name():
index 457e8c146d2c6bc910eda9eb657c17c64c9c175e..eeff1b448292768fcd6ef59b025a5d60340609cb 100644 (file)
@@ -8,7 +8,7 @@ from pmachines.items.teetertooter import TeeterTooter
 
 class SceneTeeterDominoBoxBasketball(Scene):
 
-    version = '220914'
+    filename = 'assets/scenes/domino_box_basketball.json'
 
     @staticmethod
     def name():
index 25b843155b2afaa889b3aa13da18621bdbb33f8a..7d2f9dd99c2765c7493023bf7abe275747271f98 100644 (file)
@@ -7,7 +7,7 @@ from pmachines.items.teetertooter import TeeterTooter
 
 class SceneTeeterTooter(Scene):
 
-    version = '220914'
+    filename = 'assets/scenes/teeter_tooter.json'
 
     @staticmethod
     def name():
diff --git a/prj.org b/prj.org
index 65f85b569939269d304f443f87527500656af8a1..9c574932ab5e1c02d48f158ca04d1984224229b9 100644 (file)
--- a/prj.org
+++ b/prj.org
@@ -3,8 +3,13 @@
 #+CATEGORY: pmachines
 #+TAGS: bug(b) calendar(c) waiting(w)
 
+* DOING bug: scene done, back to menu, the button is not transparent (it is transparent in the next session)
+* READY editor
+- [ ] move info to json (find_by_id)
+- [ ] create gui
+* BACKLOG teeter-tooter with constraints (real teeter tooter)
+* BACKLOG magnet, road cone, bucket
 * BACKLOG actions: rewind, prev, next
-* BACKLOG teeter-tooter with constraints (real teeter tooter), magnet, road cone, bucket
 * BACKLOG (when python 3.11) use toml in place of ini
 * BACKLOG (when panda3d provides it) android build (test with the emulator of android studio)
 * BACKLOG (when itch.io's client waiting works with wine) functional tests for windows-itch.io