summaryrefslogtreecommitdiff
path: root/src/port/resource/importers/ScriptFactory.cpp
blob: ed661efd820fa76ed1025196304a17a6db12ea67 (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
#include "ScriptFactory.h"
#include "../type/Script.h"
#include "spdlog/spdlog.h"
#include "ResourceUtil.h"

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

    auto script = std::make_shared<Script>(file->InitData);
    auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);

    auto size = reader->ReadUInt32();

    for (uint32_t i = 0; i < size; i++) {
        script->mScripts.push_back(LoadChild<uint16_t*>(reader->ReadUInt64()));
    }

    return script;
}
} // namespace LUS