<commit_before>#include <TGUI/TGUI.hpp>
#include <vili/Vili.hpp>

#include "System/Window.hpp"
#include <Editor/MapEditor.hpp>
#include <Modes/Game.hpp>
#include <Modes/Menu.hpp>
#include <Modes/Toolkit.hpp>
#include <System/Config.hpp>
#include <System/Loaders.hpp>
#include <System/Path.hpp>
#include <Utils/StringUtils.hpp>
#include <thread>

namespace obe::Modes
{
    void scrollPanel(tgui::Panel::Ptr panel, tgui::Scrollbar::Ptr scrollbar)
    {
        static int previousScrolbarValue = 0;
        const int distanceToMove =
            previousScrolbarValue - scrollbar->getValue();

        for (auto& widget : panel->getWidgets())
            widget->setPosition(widget->getPosition().x,
                                widget->getPosition().y + distanceToMove);

        previousScrolbarValue = scrollbar->getValue();
    }

    void chooseMapAddMaps(tgui::Panel::Ptr middlePanel,
                          tgui::Scrollbar::Ptr scrollbar,
                          tgui::Theme& baseTheme, std::string& currentMap)
    {
        int scrollBoxSize = 0;

        scrollbar->setLowValue(middlePanel->getSize().y);
        scrollbar->setMaximum(scrollBoxSize);

        middlePanel->removeAllWidgets();

        std::vector<std::string> allMapsTemp;
        System::Path("Data/Maps")
            .loadAll(System::Loaders::filePathLoader, allMapsTemp);
        std::vector<std::string> allMaps;
        for (int i = 0; i < allMapsTemp.size(); i++)
        {
            if (Utils::String::endsWith(allMapsTemp[i], ".map.vili"))
                allMaps.push_back(allMapsTemp[i]);
        }
        for (int i = 0; i < allMaps.size(); i++)
        {
            vili::ViliParser mapInfoParser;
            mapInfoParser.setQuickLookAttributes({"Meta"});
            System::Path("Data/Maps")
                .add(allMaps[i])
                .load(System::Loaders::dataLoader, mapInfoParser);
            const std::string filename = allMaps[i];
            std::string levelName = "???";

            if (mapInfoParser->contains(vili::NodeType::ComplexNode, "Meta"))
            {
                if (mapInfoParser.at("Meta").contains(vili::NodeType::DataNode,
                                                      "name"))
                    levelName = mapInfoParser.at("Meta")
                                    .getDataNode("name")
                                    .get<std::string>();
            }

            tgui::Button::Ptr selectMapButton = tgui::Button::create();
            selectMapButton->setText(
                levelName + " (" +
                filename.substr(0, allMapsTemp[i].size() - 9) + ")");
            selectMapButton->setRenderer(
                baseTheme.getRenderer("MapSelectButton"));
            selectMapButton->setSize("100%", "20%");
            selectMapButton->setPosition("0", i * selectMapButton->getSize().y);
            selectMapButton->connect(
                "pressed", [&currentMap, filename] { currentMap = filename; });
            middlePanel->add(selectMapButton);
            scrollBoxSize += selectMapButton->getSize().y - 1;
        }
        scrollbar->setLowValue(middlePanel->getSize().y);
        scrollbar->setMaximum(scrollBoxSize);
    }

    void createLevel(tgui::EditBox::Ptr input)
    {
        const std::string newLevelName = input->getText();
        if (newLevelName != "")
        {
            if (!Utils::File::fileExists(System::Path("Data/Maps")
                                             .add(newLevelName + ".map.vili")
                                             .getPath(0)
                                             .toString()))
            {
                Debug::Log->info(
                    "<Menu:createLevel> Creating new Map file : '{0}'",
                    newLevelName);<commit_msg>fix display of maps list<commit_after>#include <TGUI/TGUI.hpp>
#include <vili/Vili.hpp>

#include "System/Window.hpp"
#include <Editor/MapEditor.hpp>
#include <Modes/Game.hpp>
#include <Modes/Menu.hpp>
#include <Modes/Toolkit.hpp>
#include <System/Config.hpp>
#include <System/Loaders.hpp>
#include <System/Path.hpp>
#include <Utils/StringUtils.hpp>
#include <thread>

namespace obe::Modes
{
    void scrollPanel(tgui::Panel::Ptr panel, tgui::Scrollbar::Ptr scrollbar)
    {
        static int previousScrolbarValue = 0;
        const int distanceToMove =
            previousScrolbarValue - scrollbar->getValue();

        for (auto& widget : panel->getWidgets())
            widget->setPosition(widget->getPosition().x,
                                widget->getPosition().y + distanceToMove);

        previousScrolbarValue = scrollbar->getValue();
    }

    void chooseMapAddMaps(tgui::Panel::Ptr middlePanel,
                          tgui::Scrollbar::Ptr scrollbar,
                          tgui::Theme& baseTheme, std::string& currentMap)
    {
        int scrollBoxSize = 0;

        scrollbar->setLowValue(middlePanel->getSize().y);
        scrollbar->setMaximum(scrollBoxSize);

        middlePanel->removeAllWidgets();

        std::vector<std::string> allMapsTemp;
        System::Path("Data/Maps")
            .loadAll(System::Loaders::filePathLoader, allMapsTemp);
        std::vector<std::string> allMaps;
        for (int i = 0; i < allMapsTemp.size(); i++)
        {
            if (Utils::String::endsWith(allMapsTemp[i], ".map.vili"))
                allMaps.push_back(allMapsTemp[i]);
        }
        for (int i = 0; i < allMaps.size(); i++)
        {
            vili::ViliParser mapInfoParser;
            mapInfoParser.setQuickLookAttributes({"Meta"});
            System::Path("Data/Maps")
                .add(allMaps[i])
                .load(System::Loaders::dataLoader, mapInfoParser);
            const std::string filename = allMaps[i];
            std::string levelName = "???";

            if (mapInfoParser->contains(vili::NodeType::ComplexNode, "Meta"))
            {
                if (mapInfoParser.at("Meta").contains(vili::NodeType::DataNode,
                                                      "name"))
                    levelName = mapInfoParser.at("Meta")
                                    .getDataNode("name")
                                    .get<std::string>();
            }

            tgui::Button::Ptr selectMapButton = tgui::Button::create();
            middlePanel->add(selectMapButton);
            selectMapButton->setText(
                levelName + " (" +
                filename.substr(0, allMapsTemp[i].size() - 9) + ")");
            selectMapButton->setRenderer(
                baseTheme.getRenderer("MapSelectButton"));
            selectMapButton->setSize("100%", "20%");
            selectMapButton->setPosition("0", i * selectMapButton->getSize().y);
            selectMapButton->connect(
                "pressed", [&currentMap, filename] { currentMap = filename; });
            scrollBoxSize += selectMapButton->getSize().y - 1;
        }
        scrollbar->setLowValue(middlePanel->getSize().y);
        scrollbar->setMaximum(scrollBoxSize);
    }

    void createLevel(tgui::EditBox::Ptr input)
    {
        const std::string newLevelName = input->getText();
        if (newLevelName != "")
        {
            if (!Utils::File::fileExists(System::Path("Data/Maps")
                                             .add(newLevelName + ".map.vili")
                                             .getPath(0)
                                             .toString()))
            {
                Debug::Log->info(
                    "<Menu:createLevel> Creating new Map file : '{0}'",
                    newLevelName);
{'fraction_non_alphanumeric': 0.13764969074878272, 'fraction_numerical': 0.0039478878799842085, 'mean_word_length': 1.8711749149981112, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5249732', 'n_tokens_mistral': 2119, 'n_tokens_neox': 2048, 'n_words': 327}