|
1 | 1 | #include "resource/factory/ArrayFactory.h"
|
2 | 2 | #include "resource/type/Array.h"
|
3 |
| -#include "resource/readerbox/BinaryReaderBox.h" |
4 | 3 | #include "spdlog/spdlog.h"
|
5 | 4 |
|
6 | 5 | namespace LUS {
|
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."); |
| 6 | +std::shared_ptr<IResource> ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr<File> file) { |
| 7 | + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { |
| 8 | + SPDLOG_ERROR("resource file format does not match factory format."); |
12 | 9 | return nullptr;
|
13 | 10 | }
|
14 | 11 |
|
15 |
| - auto reader = binaryReaderBox->GetReader(); |
16 |
| - if (reader == nullptr) { |
17 |
| - SPDLOG_ERROR("null reader in box."); |
| 12 | + if (file->Reader == nullptr) { |
| 13 | + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, |
| 14 | + file->InitData->Path); |
18 | 15 | return nullptr;
|
19 | 16 | }
|
20 | 17 |
|
21 |
| - auto array = std::make_shared<Array>(initData); |
| 18 | + auto array = std::make_shared<Array>(file->InitData); |
22 | 19 |
|
23 |
| - uint32_t dataSize = reader->ReadUInt32(); |
| 20 | + uint32_t dataSize = file->Reader->ReadUInt32(); |
24 | 21 |
|
25 |
| - array->ArrayType = (ArrayResourceType)reader->ReadUInt32(); |
26 |
| - array->ArrayCount = reader->ReadUInt32(); |
| 22 | + array->ArrayType = (ArrayResourceType)file->Reader->ReadUInt32(); |
| 23 | + array->ArrayCount = file->Reader->ReadUInt32(); |
27 | 24 |
|
28 | 25 | for (uint32_t i = 0; i < array->ArrayCount; i++) {
|
29 | 26 | if (array->ArrayType == ArrayResourceType::Vertex) {
|
30 | 27 | // OTRTODO: Implement Vertex arrays as just a vertex resource.
|
31 | 28 | Vtx data;
|
32 |
| - data.v.ob[0] = reader->ReadInt16(); |
33 |
| - data.v.ob[1] = reader->ReadInt16(); |
34 |
| - data.v.ob[2] = reader->ReadInt16(); |
35 |
| - data.v.flag = reader->ReadUInt16(); |
36 |
| - data.v.tc[0] = reader->ReadInt16(); |
37 |
| - data.v.tc[1] = reader->ReadInt16(); |
38 |
| - data.v.cn[0] = reader->ReadUByte(); |
39 |
| - data.v.cn[1] = reader->ReadUByte(); |
40 |
| - data.v.cn[2] = reader->ReadUByte(); |
41 |
| - data.v.cn[3] = reader->ReadUByte(); |
| 29 | + data.v.ob[0] = file->Reader->ReadInt16(); |
| 30 | + data.v.ob[1] = file->Reader->ReadInt16(); |
| 31 | + data.v.ob[2] = file->Reader->ReadInt16(); |
| 32 | + data.v.flag = file->Reader->ReadUInt16(); |
| 33 | + data.v.tc[0] = file->Reader->ReadInt16(); |
| 34 | + data.v.tc[1] = file->Reader->ReadInt16(); |
| 35 | + data.v.cn[0] = file->Reader->ReadUByte(); |
| 36 | + data.v.cn[1] = file->Reader->ReadUByte(); |
| 37 | + data.v.cn[2] = file->Reader->ReadUByte(); |
| 38 | + data.v.cn[3] = file->Reader->ReadUByte(); |
42 | 39 | array->Vertices.push_back(data);
|
43 | 40 | } else {
|
44 |
| - array->ArrayScalarType = (ScalarType)reader->ReadUInt32(); |
| 41 | + array->ArrayScalarType = (ScalarType)file->Reader->ReadUInt32(); |
45 | 42 |
|
46 | 43 | int iter = 1;
|
47 | 44 |
|
48 | 45 | if (array->ArrayType == ArrayResourceType::Vector) {
|
49 |
| - iter = reader->ReadUInt32(); |
| 46 | + iter = file->Reader->ReadUInt32(); |
50 | 47 | }
|
51 | 48 |
|
52 | 49 | for (int k = 0; k < iter; k++) {
|
53 | 50 | ScalarData data;
|
54 | 51 |
|
55 | 52 | switch (array->ArrayScalarType) {
|
56 | 53 | case ScalarType::ZSCALAR_S16:
|
57 |
| - data.s16 = reader->ReadInt16(); |
| 54 | + data.s16 = file->Reader->ReadInt16(); |
58 | 55 | break;
|
59 | 56 | case ScalarType::ZSCALAR_U16:
|
60 |
| - data.u16 = reader->ReadUInt16(); |
| 57 | + data.u16 = file->Reader->ReadUInt16(); |
61 | 58 | break;
|
62 | 59 | default:
|
63 | 60 | // OTRTODO: IMPLEMENT OTHER TYPES!
|
|
0 commit comments