summaryrefslogtreecommitdiff
path: root/src/port/resource/importers/SkeletonFactory.cpp
blob: c09543ee725051f960bb46605e060d8bfc0e2bf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "SkeletonFactory.h"

#include "../type/Skeleton.h"
#include "spdlog/spdlog.h"
#include "ResourceUtil.h"

namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinarySkeletonV0::ReadResource(std::shared_ptr<Ship::File> file,
                                                                               std::shared_ptr<Ship::ResourceInitData> initData) {
    if (!FileHasValidFormatAndReader(file, initData)) {
        return nullptr;
    }

    auto skel = std::make_shared<Skeleton>(initData);
    auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);

    auto count = reader->ReadUInt32();
    for(size_t i = 0; i < count; i++) {
        skel->mLimbs.push_back(LoadChild<LimbData*>(reader->ReadUInt64()));
    }
    skel->mLimbs.push_back(nullptr);

    return skel;
}
} // namespace LUS