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

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

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

    auto size = reader->ReadUInt32();

    for (uint32_t i = 0; i < size * 2; i++) {
        cmds->mCommands.push_back(reader->ReadUInt16());
    }

    return cmds;
}
} // namespace LUS