> For the complete documentation index, see [llms.txt](https://redboard.gitbook.io/r-type-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://redboard.gitbook.io/r-type-1/client/loader.md).

# Loader

The `Loader` class is an essential component in your game's ECS (Entity-Component-System) architecture.\
It is responsible for efficiently loading, unloading, and managing game textures, making it an integral part of your game's resource management system.

The `Loader` class simplifies the resource management process by centralizing the loading and unloading of textures. It enhances the efficiency and maintainability of your game's ECS system by providing easy access to game assets.

### Constructors and Destructors

#### Constructor

The `Loader` class has a default constructor that initializes the loader.

```cpp
Loader::Loader()
```

#### Destructor

The destructor for `Loader` is responsible for cleaning up any resources it has loaded.

```cpp
Loader::~Loader()
```

### Enumerations

The `toLoad` enumeration represents the various types of resources that the loader can handle. It includes:

* `ParallaxFirstbkg` and `ParallaxSecondbkg` for parallax background textures.
* `Player_move1`, `Player_move2`, `Player_move3`, and `Player_move4` for player character movement animations.
* `Missile` for missile textures.
* `Monster1` for monster character textures.

### Methods

```cpp
void loadTexture(const std::string path, toLoad type)
```

This method allows you to load a texture from a file and associate it with a specific resource type.

* `path`: The file path to the texture you want to load.
* `type`: The type of resource you are loading.

```cpp
void unloadTexture(toLoad type)
```

Use this method to unload a previously loaded texture for a specific resource type.

* `type`: The type of resource you want to unload.

```cpp
const std::shared_ptr<sf::Texture> &getTexture(toLoad type) const
```

Retrieve a loaded texture associated with a particular resource type. This method returns a reference to the texture.

* `type`: The type of resource for which you want to retrieve the texture.

### Data Structures

The `Loader` class uses an `std::unordered_map` to efficiently store and manage the loaded textures. The textures are stored as shared pointers to `sf::Texture` objects, ensuring that they are properly managed and unallocated when necessary.

### Error Handling

The `getTexture` method performs error handling by throwing a `client::MyError` exception if the requested texture is not found. This ensures that you receive an appropriate error message when attempting to retrieve a missing texture.

**You will also find some method for the font**

```cpp
void loadFont(const std::string path, toLoad type);
void unloadFont(toLoad type);
const std::shared_ptr<sf::Font> &getFont(toLoad type) const;
```

As you may see through their names, theses methods can be used to load a font, unload it or even got it.&#x20;

**The biggest par of this class is this enum**

```cpp
enum toLoad {
    ParallaxFirstbkg,
    ParallaxSecondbkg,
    Player_move1, Player_move2, Player_move3, Player_move4,
    Missile,
    MissileRed,
    OrangeMissile,
    PurpleMissile,
    GreenMissile,
    Explosion1,
    Monster1,
    Monster2,
    Monster3,
    Monster4,
    Boss1,
    Boss2,
    Boss3,
    Boss4,
    CreateRoomButton,
    JoinRoomButton,
    QuitButton,
    LeaveGame,
    MatchListButton,
    LooserScreen,
    MenuScreen,
    ChatBox,
    BlackPixel,
    ScoreCoche,
    RedPixel,
    GreenPixel,
    BluePixel,
    CyanPixel,
    YellowPixel,
    PurplePixel,
    WhitePixel,
    Arial,
    PressStart2P,
    playerLifeOutline,
    playerLifeContent,
    Bonus,
    Bomb,
    Pod1,
    Pod2,
    Pod3,
    Laser
};
```

This enum contains all the things that the game has to load before to start a game. So, he load all of these things when the program's launch.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redboard.gitbook.io/r-type-1/client/loader.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
