This repository was archived by the owner on Mar 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +16
-18
lines changed Expand file tree Collapse file tree 3 files changed +16
-18
lines changed Original file line number Diff line number Diff line change 4
4
5
5
namespace tkge ::Assets
6
6
{
7
- class TextAsset final : public IAsset
7
+ class TextAsset final : public ICopyableAsset<TextAsset>
8
8
{
9
9
public:
10
- explicit TextAsset () = default;
11
- void Load (ReadonlyByteStream byteStream) override
12
- {
13
- const auto vData = byteStream.AsSpan <char >(0 , byteStream.GetStreamSize ());
14
- this ->_text = std::string{ vData.begin (), vData.end () };
15
- }
16
-
17
- [[nodiscard]] const std::string& text () const noexcept { return this ->_text ; }
18
- private:
19
- std::string _text;
10
+ explicit TextAsset (std::string filename) : ICopyableAsset(std::move(filename)) {}
11
+ [[nodiscard]] std::string ReadAllText () const ;
12
+ [[nodiscard]] std::string ReadAt (std::size_t position, std::size_t size) const ;
20
13
};
21
14
} // namespace tkge::Assets
Original file line number Diff line number Diff line change @@ -18,13 +18,7 @@ namespace tkge
18
18
19
19
for (const auto & path : paths)
20
20
{
21
- if (std::filesystem::exists (path / fileName))
22
- {
23
- auto asset = std::make_unique<T>();
24
- Assets::ReadonlyByteStream byteStream{(path / fileName).string ()};
25
- asset->Load (std::move (byteStream));
26
- return asset;
27
- }
21
+ if (std::filesystem::exists (path / fileName)) { return std::make_unique<T>((path / fileName).string ()); }
28
22
}
29
23
30
24
throw std::runtime_error (" Asset not found: " + fileName);
Original file line number Diff line number Diff line change 1
1
#include < tkge/Assets/TextAsset.hpp>
2
+ std::string tkge::Assets::TextAsset::ReadAllText () const
3
+ {
4
+ const auto vData = this ->byteStream ().AsSpan <char >(0 , this ->byteStream ().GetStreamSize ());
5
+ return std::string{vData.begin (), vData.end ()};
6
+ }
7
+
8
+ std::string tkge::Assets::TextAsset::ReadAt (std::size_t position, std::size_t size) const
9
+ {
10
+ const auto vData = this ->byteStream ().AsSpan <char >(position, size);
11
+ return std::string{vData.begin (), vData.end ()};
12
+ }
You can’t perform that action at this time.
0 commit comments