Consolidation? 0 ▲ ronjeffries.com 42 minutes ago · Tech · hide · 0 comments Hello, loves! If we were to combine our formerly three now two sprite lists into one, would we lose some duplicated code? I think we might. Let’s find out. There are two sprite-oriented collections that the Maker and View use: def __init__(self, dungeon): self.setup_assets() self.dungeon = dungeon self.pub_sub = dungeon.pub_sub self.keyed_sprites = KeyedSpriteList(arcade.SpriteList()) self.content_sprites_by_cell: dict[Cell, list[Sprite]] = defaultdict(list) self.setup() The KeyedSpriteList maintains a list of all sprites, which we draw all at once, and a list indexed by cell — or, I think, by content item — used to look up individual sprites. class KeyedSpriteList: def __init__(self, sprite_list): self.sprite_dict = dict() self.sprite_list = sprite_list def add(self, cell, sprite): self.sprite_dict[cell] = sprite self.sprite_list.append(sprite) def draw(self): self.sprite_list.draw() def __getitem__(self, cell): return self.sprite_dict[cell] The content_sprites_by_cell is a… No comments yet. Log in to reply on the Fediverse. Comments will appear here.