Skip to content

Commit 92c7d90

Browse files
committed
array hooray
1 parent b2cb7d6 commit 92c7d90

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

src/resource/factory/ArrayFactory.cpp

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
#include "resource/factory/ArrayFactory.h"
22
#include "resource/type/Array.h"
3+
#include "resource/readerbox/BinaryReaderBox.h"
34
#include "spdlog/spdlog.h"
45

56
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;
1513
}
1614

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.");
1918
return nullptr;
2019
}
2120

22-
factory->ParseFileBinary(reader, resource);
21+
auto array = std::make_shared<Array>(initData);
2322

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();
3024

3125
array->ArrayType = (ArrayResourceType)reader->ReadUInt32();
3226
array->ArrayCount = reader->ReadUInt32();
@@ -74,5 +68,7 @@ void ArrayFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::
7468
}
7569
}
7670
}
71+
72+
return array;
7773
}
7874
} // namespace LUS

src/resource/factory/ArrayFactory.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44
#include "resource/ResourceFactory.h"
55

66
namespace LUS {
7-
class ArrayFactory : public ResourceFactory {
7+
class ResourceFactoryBinaryArrayV0 : public ResourceFactory {
88
public:
99
std::shared_ptr<IResource> ReadResource(std::shared_ptr<ResourceInitData> initData,
10-
std::shared_ptr<BinaryReader> reader) override;
11-
};
12-
13-
class ArrayFactoryV0 : public ResourceVersionFactory {
14-
public:
15-
void ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) override;
10+
std::shared_ptr<ReaderBox> readerBox) override;
1611
};
1712
} // namespace LUS

0 commit comments

Comments
 (0)