pneuma-pygame/utils/resource_loader.py

43 lines
1.1 KiB
Python
Raw Normal View History

2023-06-14 12:15:05 +00:00
import pygame
from csv import reader
import os
2023-06-14 12:15:05 +00:00
2023-11-14 21:44:43 +00:00
2023-06-14 12:15:05 +00:00
def import_csv_layout(path):
script_dir = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(script_dir,
'..',
'assets',
path)
2023-06-14 12:15:05 +00:00
terrain_map = []
with open(path) as level_map:
2023-11-14 21:44:43 +00:00
layout = reader(level_map, delimiter=',')
2023-06-14 12:15:05 +00:00
for row in layout:
terrain_map.append(list(row))
return terrain_map
2023-11-14 21:44:43 +00:00
2023-06-14 12:15:05 +00:00
def import_folder(path):
script_dir = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(script_dir,
'..',
'assets',
path)
2023-06-14 12:15:05 +00:00
surface_list = []
2023-11-14 21:44:43 +00:00
for _, __, img_files in os.walk(path):
2023-06-14 12:15:05 +00:00
for image in img_files:
full_path = os.path.join(path, image)
2023-06-14 12:15:05 +00:00
image_surf = pygame.image.load(full_path).convert_alpha()
2023-06-14 12:15:05 +00:00
surface_list.append(image_surf)
return surface_list
def import_assets(path):
script_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(script_dir,
'..',
'assets', path)