|
1 | 1 | #include "resource/factory/ArrayFactory.h"
|
2 | 2 | #include "resource/type/Array.h"
|
| 3 | +#include "resource/readerbox/BinaryReaderBox.h" |
3 | 4 | #include "spdlog/spdlog.h"
|
4 | 5 |
|
5 | 6 | namespace LUS {
|
6 |
| -std::shared_ptr<IResource> ArrayFactory::ReadResource(std::shared_ptr<ResourceInitData> initData, |
7 |
| - std::shared_ptr<BinaryReader> reader) { |
8 |
| - auto resource = std::make_shared<Array>(initData); |
9 |
| - std::shared_ptr<ResourceVersionFactory> factory = nullptr; |
10 |
| - |
11 |
| - switch (resource->GetInitData()->ResourceVersion) { |
12 |
| - case 0: |
13 |
| - factory = std::make_shared<ArrayFactoryV0>(); |
14 |
| - break; |
| 7 | +std::shared_ptr<IResource> ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr<ResourceInitData> initData, |
| 8 | + std::shared_ptr<ReaderBox> readerBox) { |
| 9 | + auto binaryReaderBox = std::dynamic_pointer_cast<BinaryReaderBox>(readerBox); |
| 10 | + if (binaryReaderBox == nullptr) { |
| 11 | + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); |
| 12 | + return nullptr; |
15 | 13 | }
|
16 | 14 |
|
17 |
| - if (factory == nullptr) { |
18 |
| - SPDLOG_ERROR("Failed to load Array with version {}", resource->GetInitData()->ResourceVersion); |
| 15 | + auto reader = binaryReaderBox->GetReader(); |
| 16 | + if (reader == nullptr) { |
| 17 | + SPDLOG_ERROR("null reader in box."); |
19 | 18 | return nullptr;
|
20 | 19 | }
|
21 | 20 |
|
22 |
| - factory->ParseFileBinary(reader, resource); |
| 21 | + auto array = std::make_shared<Array>(initData); |
23 | 22 |
|
24 |
| - return resource; |
25 |
| -} |
26 |
| - |
27 |
| -void ArrayFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) { |
28 |
| - std::shared_ptr<Array> array = std::static_pointer_cast<Array>(resource); |
29 |
| - ResourceVersionFactory::ParseFileBinary(reader, array); |
| 23 | + uint32_t dataSize = reader->ReadUInt32(); |
30 | 24 |
|
31 | 25 | array->ArrayType = (ArrayResourceType)reader->ReadUInt32();
|
32 | 26 | array->ArrayCount = reader->ReadUInt32();
|
@@ -74,5 +68,7 @@ void ArrayFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::
|
74 | 68 | }
|
75 | 69 | }
|
76 | 70 | }
|
| 71 | + |
| 72 | + return array; |
77 | 73 | }
|
78 | 74 | } // namespace LUS
|
0 commit comments