Browse Source

Menu working with Folder API!

Thomas Buck 10 years ago
parent
commit
89a9fbbded
3 changed files with 11 additions and 11 deletions
  1. 1
    1
      ChangeLog.md
  2. 0
    1
      src/Menu.cpp
  3. 10
    9
      src/utils/Folder.cpp

+ 1
- 1
ChangeLog.md View File

@@ -4,7 +4,7 @@
4 4
 
5 5
     [ 20140808 ]
6 6
     * Added unit test for file-system utils
7
-    * Moving Menu to Folder/File API
7
+    * Moved Menu to Folder/File API
8 8
 
9 9
     [ 20140807 ]
10 10
     * Script parser successfully loading level scripts

+ 0
- 1
src/Menu.cpp View File

@@ -136,7 +136,6 @@ void Menu::display() {
136 136
 
137 137
 void Menu::play() {
138 138
     char *tmp = bufferString("load %s", mapFolder->getRecursiveItemName(mCursor).c_str());
139
-    getConsole().print("%s", tmp);
140 139
     if (getOpenRaider().command(tmp) == 0) {
141 140
         setVisible(false);
142 141
     } else {

+ 10
- 9
src/utils/Folder.cpp View File

@@ -99,18 +99,15 @@ Folder &Folder::getFolder(unsigned long i) {
99 99
 
100 100
 unsigned long Folder::countRecursiveItems() {
101 101
     unsigned long count = fileCount();
102
-
103
-    for (unsigned long i = 0; i < folderCount(); i++) {
102
+    for (unsigned long i = 0; i < folderCount(); i++)
104 103
         count += getFolder(i).countRecursiveItems();
105
-    }
106
-
107 104
     return count;
108 105
 }
109 106
 
110 107
 void Folder::executeRemoveRecursiveItems(std::function<bool (File &f)> func) {
111 108
     for (unsigned long i = 0; i < fileCount(); i++) {
112 109
         if (func(getFile(i))) {
113
-            files.erase(files.begin() + (long)i);
110
+            files.erase(files.begin() + (long)i--);
114 111
         }
115 112
     }
116 113
 
@@ -124,11 +121,13 @@ std::string Folder::getRecursiveItemName(unsigned long i) {
124 121
     if (i < fileCount()) {
125 122
         return getFile(i).getName();
126 123
     } else {
124
+        unsigned long count = fileCount();
127 125
         for (unsigned long n = 0; n < folderCount(); n++) {
128
-            if ((i - fileCount()) < getFolder(n).countRecursiveItems()) {
126
+            if ((i - count) < getFolder(n).countRecursiveItems()) {
129 127
                 return getFolder(n).getName() + '/'
130
-                    + getFolder(n).getRecursiveItemName(i - fileCount());
128
+                    + getFolder(n).getRecursiveItemName(i - count);
131 129
             }
130
+            count += getFolder(n).countRecursiveItems();
132 131
         }
133 132
     }
134 133
 
@@ -142,10 +141,12 @@ File &Folder::getRecursiveItem(unsigned long i) {
142 141
     if (i < fileCount()) {
143 142
         return getFile(i);
144 143
     } else {
144
+        unsigned long count = fileCount();
145 145
         for (unsigned long n = 0; n < folderCount(); n++) {
146
-            if ((i - fileCount()) < getFolder(n).countRecursiveItems()) {
147
-                return getFolder(n).getRecursiveItem(i - fileCount());
146
+            if ((i - count) < getFolder(n).countRecursiveItems()) {
147
+                return getFolder(n).getRecursiveItem(i - count);
148 148
             }
149
+            count += getFolder(n).countRecursiveItems();
149 150
         }
150 151
     }
151 152
 

Loading…
Cancel
Save