-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassetsloader.py
More file actions
32 lines (26 loc) · 1 KB
/
assetsloader.py
File metadata and controls
32 lines (26 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 31 13:55:52 2015
@author: chaddai
"""
import glob
import os.path
import pygame
from constants import *
def filename(path):
"""Nettoie un chemin pour ne garder que le nom du fichier, sans l'extension"""
base = os.path.basename(path)
(name, ext) = os.path.splitext(base)
return name
def load_asset(path, width, height):
"""Charge et réduit aux dimensions prescrites un fichier image pris en charge par pygame"""
image = pygame.image.load(path).convert_alpha()
image = pygame.transform.smoothscale(image, (width, height))
return image
def create_assets(im_dir):
"""Retourne un dictionnaire qui à chaque nom de fichier (sans l'extension)
associe l'image correspondante"""
# une liste de tous les fichiers d'extension .png dans le dossier im_dir
im_paths = glob.glob(os.path.join(im_dir, "*.png"))
assets_dict = {filename(path): load_asset(path, tilewidth, int(scale_factor * 171)) for path in im_paths}
return assets_dict