MCPcopy Create free account
hub / github.com/ddnet/ddnet / SortImages

Method SortImages

src/game/editor/mapitems/map.cpp:980–1014  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

978}
979
980std::vector<int> CEditorMap::SortImages()
981{
982 static const auto &&s_ImageNameComparator = [](const std::shared_ptr<CEditorImage> &pLhs, const std::shared_ptr<CEditorImage> &pRhs) {
983 return str_comp(pLhs->m_aName, pRhs->m_aName) < 0;
984 };
985 if(std::is_sorted(m_vpImages.begin(), m_vpImages.end(), s_ImageNameComparator))
986 {
987 return std::vector<int>();
988 }
989
990 const std::vector<std::shared_ptr<CEditorImage>> vpTemp = m_vpImages;
991 std::vector<int> vSortedIndex;
992 vSortedIndex.resize(vpTemp.size());
993
994 std::sort(m_vpImages.begin(), m_vpImages.end(), s_ImageNameComparator);
995 for(size_t OldIndex = 0; OldIndex < vpTemp.size(); OldIndex++)
996 {
997 for(size_t NewIndex = 0; NewIndex < m_vpImages.size(); NewIndex++)
998 {
999 if(vpTemp[OldIndex] == m_vpImages[NewIndex])
1000 {
1001 vSortedIndex[OldIndex] = NewIndex;
1002 break;
1003 }
1004 }
1005 }
1006 ModifyImageIndex([vSortedIndex](int *pIndex) {
1007 if(*pIndex >= 0)
1008 {
1009 *pIndex = vSortedIndex[*pIndex];
1010 }
1011 });
1012
1013 return vSortedIndex;
1014}
1015
1016std::shared_ptr<CEditorSound> CEditorMap::SelectedSound() const
1017{

Callers 3

ReplaceImageMethod · 0.80
AddImageMethod · 0.80
AddTileArtMethod · 0.80

Calls 3

str_compFunction · 0.85
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected