/* * GDevelop Core * Copyright 2008-present Florian Rival (Florian.Rival@gmail.com). All rights * reserved. This project is released under the MIT License. */ #include "EventsFunctionsContainer.h" namespace gd { gd::EventsFunction &EventsFunctionsContainer::InsertNewEventsFunctionInFolder( const gd::String &name, gd::FunctionFolderOrFunction &functionFolderOrFunction, std::size_t position) { gd::EventsFunction &newlyCreatedFunction = InsertNew(name, GetEventsFunctionsCount()); functionFolderOrFunction.InsertFunction(&newlyCreatedFunction, position); return newlyCreatedFunction; } std::vector EventsFunctionsContainer::GetAllFunctionFolderOrFunction() const { std::vector results; std::function addChildrenOfFolder = [&](const FunctionFolderOrFunction &folder) { for (size_t i = 0; i < folder.GetChildrenCount(); ++i) { const auto &child = folder.GetChildAt(i); results.push_back(&child); if (child.IsFolder()) { addChildrenOfFolder(child); } } }; addChildrenOfFolder(*rootFolder); return results; } void EventsFunctionsContainer::AddMissingFunctionsInRootFolder() { for (std::size_t i = 0; i < GetEventsFunctionsCount(); ++i) { auto &function = GetEventsFunction(i); if (!rootFolder->HasFunctionNamed(function.GetName())) { gd::EventsFunction *groupSource = &function; // Groups were implicit for ActionWithOperator if (function.GetFunctionType() == gd::EventsFunction::ActionWithOperator) { const gd::String &getterName = function.GetGetterName(); if (HasEventsFunctionNamed(getterName)) { groupSource = &GetEventsFunction(getterName); } } const gd::String &group = groupSource->GetGroup(); auto &folder = !group.empty() ? rootFolder->GetOrCreateChildFolder(group) : *rootFolder; folder.InsertFunction(&function); } } } void EventsFunctionsContainer::SerializeFoldersTo( SerializerElement &element) const { rootFolder->SerializeTo(element); } void EventsFunctionsContainer::UnserializeFoldersFrom( const SerializerElement &element) { rootFolder->UnserializeFrom(element, *this); rootFolder->UpdateGroupNameOfAllFunctions(); } } // namespace gd