Chira Engine
A customizable MIT-licensed game engine.
FilesystemResourceProvider.h
1 #pragma once
2 
3 #include <utility/String.h>
4 #include "IResourceProvider.h"
5 
6 namespace chira {
7 
8 const std::string FILESYSTEM_ROOT_FOLDER = "resources";
9 const std::string FILESYSTEM_PROVIDER_NAME = "file";
10 
12 public:
13  explicit FilesystemResourceProvider(std::string path_, bool isPathAbsolute = false, const std::string& name_ = FILESYSTEM_PROVIDER_NAME);
14  [[nodiscard]] bool hasResource(std::string_view name) const override;
15  void compileResource(std::string_view name, Resource* resource) const override;
16  [[nodiscard]] std::string_view getPath() const {
17  return this->path;
18  }
19  [[nodiscard]] bool isAbsolute() const {
20  return this->absolute;
21  }
22  [[nodiscard]] std::string getFolder() const;
23  [[nodiscard]] std::string getLocalResourceAbsolutePath(const std::string& identifier) const;
24 
26  static void nixifyPath(std::string& path);
29  static std::string getResourceIdentifier(std::string_view absolutePath);
33  static std::string getResourceFolderPath(std::string_view absolutePath);
35  static std::string getResourceAbsolutePath(const std::string& identifier);
36 
37  static constexpr inline short FILEPATH_MAX_LENGTH = 1024;
38 private:
39  std::string path;
40  bool absolute;
41 };
42 
43 } // namespace chira
static std::string getResourceIdentifier(std::string_view absolutePath)
Takes an absolute path of a resource file and converts it to a resource identifier.
static void nixifyPath(std::string &path)
Converts all backslashes in a string to forward slashes.
static std::string getResourceAbsolutePath(const std::string &identifier)
Takes a resource identifier and returns the full absolute path, if it exists.
static std::string getResourceFolderPath(std::string_view absolutePath)
Takes an absolute path of a resource folder and converts it to a valid input path for a FilesystemRes...
A chunk of data, usually a file. Is typically cached and shared.
Definition: Resource.h:19