| 89 | |
| 90 | template<typename PluginType = Plugin> |
| 91 | Array<PluginType*> SortPlugins(Array<PluginType*> plugins, MClass* pluginLoadOrderAttribute, MField* typeField) |
| 92 | { |
| 93 | // Sort plugins |
| 94 | Array<PluginType*> newPlugins; |
| 95 | for (int i = 0; i < plugins.Count(); i++) |
| 96 | { |
| 97 | PluginType* plugin = plugins[i]; |
| 98 | int32 insertIndex = -1; |
| 99 | for (int j = 0; j < newPlugins.Count(); j++) |
| 100 | { |
| 101 | // Get first instance where a game plugin needs another one before it |
| 102 | auto attribute = newPlugins[j]->GetClass()->GetAttribute(pluginLoadOrderAttribute); |
| 103 | if (attribute == nullptr || MCore::Object::GetClass(attribute) != pluginLoadOrderAttribute) |
| 104 | continue; |
| 105 | |
| 106 | // Check if attribute references a valid class |
| 107 | MTypeObject* refType = nullptr; |
| 108 | typeField->GetValue(attribute, &refType); |
| 109 | if (refType == nullptr) |
| 110 | continue; |
| 111 | |
| 112 | MType* type = INTERNAL_TYPE_OBJECT_GET(refType); |
| 113 | if (type == nullptr) |
| 114 | continue; |
| 115 | MClass* typeClass = MCore::Type::GetClass(type); |
| 116 | |
| 117 | if (plugin->GetClass() == typeClass) |
| 118 | { |
| 119 | insertIndex = j; |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | if (insertIndex == -1) |
| 124 | newPlugins.Add(plugin); |
| 125 | else |
| 126 | newPlugins.Insert(insertIndex, plugin); |
| 127 | } |
| 128 | return newPlugins; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | using namespace PluginManagerImpl; |
no test coverage detected