summaryrefslogtreecommitdiffhomepage
path: root/loader/impl.hpp
blob: a6916ceb0cc6fb98feceb05e8a59b1b19bcbe47f (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include "loader/loader.hpp"
#include <memory>
#include <vector>
#include <unordered_map>
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/StringView.h>
#include <Corrade/Containers/StringStlHash.h>
#include <Corrade/Utility/Resource.h>
#include <Corrade/PluginManager/PluginManager.h>
#include <Magnum/Trade/AbstractImporter.h>

namespace floormat { struct anim_def; }

namespace floormat::loader_detail {

struct loader_impl final : loader_
{
    Optional<Utility::Resource> shader_res;
    Optional<PluginManager::Manager<Trade::AbstractImporter>> importer_plugins;
    Containers::Pointer<Trade::AbstractImporter> image_importer;
    Containers::Pointer<Trade::AbstractImporter> tga_importer;

    std::unordered_map<String, std::shared_ptr<struct tile_atlas>> tile_atlas_map;
    std::unordered_map<String, std::shared_ptr<struct anim_atlas>> anim_atlas_map;
    std::vector<String> anim_atlases;

    std::vector<serialized_scenery> sceneries_array;
    std::unordered_map<StringView, const serialized_scenery*> sceneries_map;

    StringView shader(StringView filename) override;
    Trade::ImageData2D texture(StringView prefix, StringView filename);
    std::shared_ptr<struct tile_atlas> tile_atlas(StringView filename, Vector2ub size) override;
    ArrayView<String> anim_atlas_list() override;
    std::shared_ptr<struct anim_atlas> anim_atlas(StringView name, StringView dir) override;
    const std::vector<serialized_scenery>& sceneries() override;
    const scenery_proto& scenery(StringView name) override;

    void get_anim_atlas_list();

    static void set_application_working_directory();
    static anim_def deserialize_anim(StringView filename);
    static void system_init();
    static bool chdir(StringView pathname);
    [[nodiscard]] static bool check_atlas_name(StringView name);
    void ensure_plugins();

    explicit loader_impl();
    ~loader_impl() override;
};

} // namespace floormat::loader_detail