From 56ee3e943cd1aea61d9bd08965bb38f54a7b8489 Mon Sep 17 00:00:00 2001
From: Debucquoy <debucqquoy.anthony@gmail.com>
Date: Fri, 17 Feb 2023 17:02:34 +0100
Subject: [PATCH] wip: menu

---
 prototypes/saves_prototypes/parser.py | 64 ++++++++++++++++++++++-----
 prototypes/saves_prototypes/test.map  |  1 -
 2 files changed, 53 insertions(+), 12 deletions(-)
 delete mode 100644 prototypes/saves_prototypes/test.map

diff --git a/prototypes/saves_prototypes/parser.py b/prototypes/saves_prototypes/parser.py
index 6adf531..f08c2ae 100644
--- a/prototypes/saves_prototypes/parser.py
+++ b/prototypes/saves_prototypes/parser.py
@@ -1,11 +1,20 @@
+import os
+
 class MapNotSquareException(Exception):
-    pass
+    """
+    Matrix used is not a Square and cannot be interpretted as a piece
+    """
 
-class  PieceNotSquareException(Exception):
-    pass
+class PieceNotSquareException(Exception):
+    """
+    Matrix used is not a Square and cannot be interpretted as a piece
+    """
 
-class save_Parser:
-    def __init__(self, filename:str ):
+class SaveParser:
+    """
+    Parser for the game file
+    """
+    def __init__(self):
         self.filename = filename
         self.map_shape = [[0]]
         self.pieces = list()
@@ -41,7 +50,7 @@ class save_Parser:
         load the file and prepare to parse informations
         """
 
-    def save(self):
+    def save(self, filename):
         """
         save parsed info to the file
         """
@@ -54,12 +63,45 @@ class save_Parser:
             save_data +=len(piece).to_bytes(1, 'big')
             save_data += self.shape_to_bytes(piece)
         save_data += b'SME'
-        with open(self.filename, mode='bw') as file:
+        with open(filename, mode='bw') as file:
             file.write(save_data)
 
+def cls():
+    'clear the screen'
+    for _ in range(os.get_terminal_size()[1]):
+        print()
+
+def menu():
+    """draw a simple menu to test the SaveParser class"""
+
+    P = SaveParser()
+
+    print("1) define terrain")
+    print("2) add a piece")
+    print("3) show data")
+    print("4) save data")
+    print("5) load data")
+    item = input("Select an option :")
+    cls()
+    match item:
+        case 1:
+            pass
+        case 2:
+            pass
+        case 3:
+            pass
+        case 4:
+            filename = input('enter the file name (default: default.smap):')
+            filename = filename if filename else "default.smap"
+            P.save(filename)
+        case 5:
+            filename = input('enter the file name (default: default.smap):')
+            filename = filename if filename else "default.smap"
+            P.load(filename)
 if __name__ == "__main__":
-    p = save_Parser('test.map')
-    p.define_map([[1,0,1],[1,1,1], [1,0,0]])
-    p.add_piece([[0, 1],[0, 1]])
-    p.save()
+    cls()
+    # p = SaveParser('test.smap')
+    # p.define_map([[1,0,1],[1,1,1], [1,0,0]])
+    # p.add_piece([[0, 1],[0, 1]])
+    # p.save()
     # print(p.shape_to_bytes([[1,0,1],[1,1,1], [1,0,0]]))
diff --git a/prototypes/saves_prototypes/test.map b/prototypes/saves_prototypes/test.map
deleted file mode 100644
index fff7b49..0000000
--- a/prototypes/saves_prototypes/test.map
+++ /dev/null
@@ -1 +0,0 @@
-SMS|SME
\ No newline at end of file