//
// Created by Dan Crosby on 11/27/22.
//

#include "SettingsLoader.hpp"

#include "src/main/cpp/net/eagle0/common/FilesystemUtils.hpp"
#include "src/main/cpp/net/eagle0/common/TsvParser.hpp"
#include "src/main/cpp/net/eagle0/shardok/util/BattalionTypeRegistrar.hpp"

namespace shardok {

auto SettingsLoader::LoadSettings() -> shared_ptr<GameSettings> {
    auto gameSettings = std::make_shared<GameSettings>();
    auto setter = gameSettings->GetSetter();

    BattalionTypeRegistrar::RegisterBattalionTypes(setter);

    TsvParser parser;
    const string settingsPath = FilesystemUtils::StaticShardokFilesDirectory() + "settings.tsv";
    const string settingsTsv = string(byte_vector::FromPath(settingsPath));
    const auto valuesAndTypes = parser.ParseColumnEntryTsv(settingsTsv);
    setter.SetFromTypesAndValues(valuesAndTypes[1], valuesAndTypes[0]);

    return gameSettings;
}

}  // namespace shardok
