Module: Bestguigui::Assets
- Defined in:
- lib/bestguigui/assets.rb
Overview
Cache mémoïsé pour les images/sons chargés depuis le disque — évite de recharger le même fichier à chaque fois qu'une entité qui l'utilise est recréée (ex: une nouvelle partie qui reconstruit tous ses objets).
Pas d'instance à créer ni à faire passer partout : ce sont des méthodes de module, appelables depuis n'importe où.
Bestguigui::Assets.image("gfx/snowball.png", retro: true)
Bestguigui::Assets.tiles("gfx/player.png", 128, 128, retro: true)
Bestguigui::Assets.sample("sfx/hit.mp3")
Bestguigui::Assets.song("sfx/theme.mp3")
Le cache est tenu par (chemin + options) : les mêmes arguments renvoient toujours le même objet déjà chargé.
Class Method Summary collapse
-
.clear ⇒ Object
Vide le cache — utile si tu changes vraiment de contenu (rare en jam), ou en tests.
- .image(path, **options) ⇒ Object
- .sample(path) ⇒ Object
- .song(path) ⇒ Object
- .tiles(path, tile_width, tile_height, **options) ⇒ Object
Class Method Details
.clear ⇒ Object
Vide le cache — utile si tu changes vraiment de contenu (rare en jam), ou en tests.
40 41 42 43 44 |
# File 'lib/bestguigui/assets.rb', line 40 def clear @images.clear @samples.clear @songs.clear end |
.image(path, **options) ⇒ Object
22 23 24 |
# File 'lib/bestguigui/assets.rb', line 22 def image(path, **) @images[[path, ]] ||= Gosu::Image.new(path, **) end |
.sample(path) ⇒ Object
30 31 32 |
# File 'lib/bestguigui/assets.rb', line 30 def sample(path) @samples[path] ||= Gosu::Sample.new(path) end |
.song(path) ⇒ Object
34 35 36 |
# File 'lib/bestguigui/assets.rb', line 34 def song(path) @songs[path] ||= Gosu::Song.new(path) end |
.tiles(path, tile_width, tile_height, **options) ⇒ Object
26 27 28 |
# File 'lib/bestguigui/assets.rb', line 26 def tiles(path, tile_width, tile_height, **) @images[[path, tile_width, tile_height, ]] ||= Gosu::Image.load_tiles(path, tile_width, tile_height, **) end |