def _screen_from_json(json_data: Any, sprites: Dict[str, Sprite]) -> Screen: background_data = json_data.get("background") background_color = None background_tilemap = None if background_data: background_color = background_data.get("background_color") tilemap_data = background_data.get("background_tilemap") if tilemap_data: background_tilemap = Tilemap(tilemap_id=tilemap_data["tilemap_id"], rect_uv=Rect.from_list( tilemap_data["tilemap_uv"])) screen_elements = [] if json_data.get("elements"): screen_elements = [ ScreenElement(position=Point.from_list(data["position"]), sprite=sprites.get(data.get("sprite_ref")), text=data.get("text")) for data in json_data["elements"] ] menu_position = None menu_scrollbar_rect = None if json_data.get("menu"): menu_data = json_data["menu"] menu_position = \ Point.from_list(menu_data["position"]) if menu_data.get("position") else None menu_scrollbar_rect = \ Rect.from_list(menu_data["scrollbar_rect"]) if menu_data.get("scrollbar_rect") else None return Screen(background_color=background_color, background_tilemap=background_tilemap, elements=tuple(screen_elements), menu_position=menu_position, menu_scrollbar_rect=menu_scrollbar_rect)
def create_level_templates(json_data: Any, sprite_packs: Dict[str, SpritePack]) \ -> Tuple[LevelTemplate, ...]: """Create level templates from metadata. :param json_data: input JSON containing level template metadata :param sprite_packs: collection of available sprite packs :return: collection of level templates """ return tuple([ LevelTemplate.from_level_num( level_num=level_num, tileset_index=data["tileset"], draw_offset=Point.from_list(data["draw_offset"]), sprite_packs=LevelSpritePacks( robot_sprite_pack=sprite_packs[data["robot_sprite_pack_ref"]], crate_sprite_pack=sprite_packs[data["crate_sprite_pack_ref"]])) for level_num, data in enumerate(json_data) ])
def create_gui_consts(json_data: Any, sprites: Dict[str, Sprite]) -> GuiConsts: """Create Gui constants from metadata. :param json_data: input JSON containing Gui constants :param sprites: collection of available sprites :return: Gui constants """ return GuiConsts(gui_positions=tuple([ Point.from_list(json_data["positions"][pos.resource_name]) for pos in list(GuiPosition) ]), gui_colors=tuple([ int(json_data["colors"][color.resource_name]) for color in list(GuiColor) ]), gui_sprites=tuple([ sprites[json_data["sprites"][sprite.resource_name]] for sprite in list(GuiSprite) ]))