@@ -613,3 +613,93 @@ def __repr__(self) -> str:
613613
614614 def __len__ (self ) -> int :
615615 return len (self .maps )
616+
617+
618+ class ProceduralData (PyscrollDataAdapter ):
619+ """
620+ A concrete PyscrollDataAdapter subclass for generating simple, procedural
621+ maps on the fly. Used primarily for testing and demonstration.
622+
623+ Generates a map with three layers: [0: Ground, 1: Detail, 2: Overlay].
624+ """
625+
626+ _TILE_SIZE : Vector2DInt = (32 , 32 )
627+ _MAP_WIDTH : int = 40
628+ _MAP_HEIGHT : int = 30
629+ _LAYER_COUNT : int = 3
630+
631+ _GID_GRASS : int = 1
632+ _GID_WATER : int = 2
633+ _GID_ROCK : int = 3
634+ _GID_ALT_WATER : int = 999
635+
636+ def __init__ (self ) -> None :
637+ super ().__init__ ()
638+ self ._surfaces : dict [int , Surface ] = {}
639+ self ._create_surfaces ()
640+ self ._animated_tile : dict [tuple [int , int , int ], Any ] = {}
641+ self ._animation_map : dict [int , Any ] = {}
642+ self ._animation_queue : list [Any ] = []
643+ self ._tracked_gids : set [int ] = set ()
644+
645+ @property
646+ def tile_size (self ) -> Vector2DInt :
647+ return self ._TILE_SIZE
648+
649+ @property
650+ def map_size (self ) -> Vector2DInt :
651+ return (self ._MAP_WIDTH , self ._MAP_HEIGHT )
652+
653+ @property
654+ def visible_tile_layers (self ) -> list [int ]:
655+ return list (range (self ._LAYER_COUNT ))
656+
657+ def _create_surfaces (self ) -> None :
658+ """Create and store tile surfaces."""
659+ w , h = self .tile_size
660+
661+ def make_surface (color : str ) -> Surface :
662+ surf = Surface ((w , h ))
663+ surf .fill (pygame .Color (color ))
664+ return surf
665+
666+ self ._surfaces [self ._GID_GRASS ] = make_surface ("#799a46" )
667+ self ._surfaces [self ._GID_WATER ] = make_surface ("#4a82a6" )
668+ self ._surfaces [self ._GID_ROCK ] = make_surface ("#555555" )
669+ self ._surfaces [self ._GID_ALT_WATER ] = make_surface ("#62a2cc" )
670+
671+ def reload_data (self ) -> None :
672+ """No external data to reload."""
673+ pass
674+
675+ def _get_tile_image_by_id (self , id : int ) -> Optional [Surface ]:
676+ return self ._surfaces .get (id )
677+
678+ def _get_tile_gid (self , x : int , y : int , l : int ) -> Optional [int ]:
679+ if not self .is_on_map (x , y ):
680+ return None
681+
682+ if l == 0 :
683+ return self ._GID_GRASS if (x + y ) % 2 == 0 else self ._GID_WATER
684+ elif l == 1 :
685+ if x % 5 == 0 and y % 5 == 0 :
686+ return self ._GID_ROCK
687+ return None
688+
689+ def _get_tile_image (self , x : int , y : int , l : int ) -> Optional [Surface ]:
690+ gid = self ._get_tile_gid (x , y , l )
691+ return self ._surfaces .get (gid ) if gid is not None else None
692+
693+ def get_animations (self ) -> list [Any ]:
694+ """
695+ Demonstrates a simple animation: water alternates between two colors.
696+ """
697+ return [
698+ (
699+ self ._GID_WATER ,
700+ [
701+ (self ._GID_WATER , 500 ),
702+ (self ._GID_ALT_WATER , 500 ),
703+ ],
704+ )
705+ ]
0 commit comments