@@ -417,6 +417,8 @@ def remove(self) -> int:
417417 Returns:
418418 int: error code *(number 0 if everything went right)*
419419 """
420+
421+ global CUR_DB
420422
421423 if not self .search ():
422424 return handle_error (49 , "This database is not being used by DoomMapGuesser in any way." )
@@ -518,35 +520,58 @@ def verify(self) -> int:
518520 return handle_error (19 , "HELL_KEEP should be a string in format:\n GAME///EPISODE///MAP" )
519521
520522 # [!?] Rule 3.2: Game, episode and map are valid
521- if self ._DB .get (w_list [0 ], None ) is None :
523+ if self ._DB [ 'struct' ] .get (w_list [0 ], None ) is None :
522524 self ._DB = {}
523525 return handle_error (19 , "WARRENS is pointing to an invalid game." )
524526
525- if self ._DB [w_list [0 ]].get (w_list [1 ], None ) is None :
527+ if self ._DB ['struct' ][ w_list [0 ]].get (w_list [1 ], None ) is None :
526528 self ._DB = {}
527529 return handle_error (19 , f"WARRENS is poiting to an invalid episode inside of game { w_list [0 ]} " )
528530
529- if self ._DB [w_list [0 ]][w_list [1 ]].get (w_list [2 ], None ) is None :
531+ if self ._DB ['struct' ][ w_list [0 ]][w_list [1 ]].get (w_list [2 ], None ) is None :
530532 self ._DB = {}
531533 return handle_error (19 , f"WARRENS is poiting to an invalid map inside of game { w_list [0 ]} , episode { w_list [1 ]} " )
532534
533535 # --
534536
535- if self ._DB .get (w_list [0 ], None ) is None :
537+ if self ._DB [ 'struct' ] .get (w_list [0 ], None ) is None :
536538 self ._DB = {}
537539 return handle_error (19 , "HELL_KEEP is pointing to an invalid game." )
538540
539- if self ._DB [w_list [0 ]].get (w_list [1 ], None ) is None :
541+ if self ._DB ['struct' ][ w_list [0 ]].get (w_list [1 ], None ) is None :
540542 self ._DB = {}
541543 return handle_error (19 , f"HELL_KEEP is poiting to an invalid episode inside of game { w_list [0 ]} " )
542544
543- if self ._DB [w_list [0 ]][w_list [1 ]].get (w_list [2 ], None ) is None :
545+ if self ._DB ['struct' ][ w_list [0 ]][w_list [1 ]].get (w_list [2 ], None ) is None :
544546 self ._DB = {}
545547 return handle_error (19 , f"HELL_KEEP is poiting to an invalid map inside of game { w_list [0 ]} , episode { w_list [1 ]} " )
546548
547549 return 0 # [i] it cool
548550 # [!] NOTE: it's possible a database has wrong images - however, images are tested at the time they are generated
549551
552+ def generate (self ) -> list [str ]:
553+ """
554+ # Database.generate
555+
556+ ## Alias
557+ - **Database.gen**
558+
559+ Returns:
560+ list[str]: a list of 3 generated choices in order - Game, Episode, Map
561+ """
562+
563+ choices : list [str ] = [
564+ random .choice (self ._DB ['struct' ])
565+ ]
566+
567+ choices .append (random .choice (self ._DB ['struct' ][choices [0 ]]))
568+ choices .append (random .choice (self ._DB ['struct' ][choices [0 ]][choices [1 ]]))
569+ # [<] no need to append the details, that can be done manually after
570+
571+ return choices .copy ()
572+
573+ gen = generate
574+
550575 @property
551576 def database (self ) -> dict | None :
552577 """
@@ -561,6 +586,26 @@ def database(self) -> dict | None:
561586
562587 return self ._DB
563588
589+ @property
590+ def structure (self ) -> dict | None :
591+ """
592+ # Database.structure
593+
594+ ## Alias
595+ - **Database.struct**
596+ - **Database.database['struct']**
597+
598+ Returns:
599+ dict: the inner game/ep./map structure in the database *(None means the database hasn't been obtained or is invalid)*
600+ """
601+
602+ if not self ._DB :
603+ return None
604+
605+ return self ._DB ['struct' ]
606+
607+ struct : property = structure
608+
564609 @property
565610 def index (self ) -> int | None :
566611 """
@@ -600,7 +645,7 @@ def __setitem__(self, item, value) -> None:
600645 self ._DB [item ] = value
601646
602647
603- def add_database (source : str , * _ , index : int | None = None ):
648+ def add_database (source : str , * _ , index : int | None = None ) -> Database | bool :
604649 new_database = Database (source )
605650 new_database .get ()
606651
@@ -629,7 +674,15 @@ def add_database(source: str, *_, index: int | None = None):
629674
630675
631676def generate_new_screenshot () -> int :
632-
677+ TODO = '''
678+ here are the plans:
679+ - get the generated details
680+ - handle them according to the exclusion rule
681+ - save the details in a global variable, as well as their placeholders
682+ - and then we got good stuff!!!
683+ '''
684+
685+ del TODO
633686
634687 return handle_error (11 , "Not Implemented." )
635688
0 commit comments