|
@@ -99,15 +99,46 @@ public class cubeWorker {
|
99
|
99
|
// Misc. Methods
|
100
|
100
|
// --------------------
|
101
|
101
|
|
102
|
|
- private void sortAnimationList() {
|
103
|
|
- Collections.sort(animations);
|
|
102
|
+ // Returns a number that is below the size of the animations list and not used as order
|
|
103
|
+ // If a order is higher or equal to the size of the list, it tries to assign a hole found to this
|
|
104
|
+ // Returns -1 if there is no hole
|
|
105
|
+ private int holeInAnimationList() {
|
|
106
|
+ int s = animations.size();
|
|
107
|
+ byte[] result = new byte[s];
|
|
108
|
+ int hole = -1;
|
|
109
|
+ int fix = -1;
|
|
110
|
+ for (int i = 0; i < s; i++) {
|
|
111
|
+ result[i] = 0;
|
|
112
|
+ }
|
|
113
|
+ for (int i = 0; i < s; i++) {
|
|
114
|
+ int order = animations.get(i).getOrder();
|
|
115
|
+ if (order >= s) {
|
|
116
|
+ // Houston, we have a problem...
|
|
117
|
+ fix = i;
|
|
118
|
+ }
|
|
119
|
+ result[order] = 1;
|
|
120
|
+ }
|
|
121
|
+ for (int i = 0; i < s; i++) {
|
|
122
|
+ if (result[i] == 0) {
|
|
123
|
+ hole = i;
|
|
124
|
+ break;
|
|
125
|
+ }
|
|
126
|
+ }
|
|
127
|
+ if ((hole != -1) && (fix != 1)) {
|
|
128
|
+ animations.get(fix).setOrder(hole);
|
|
129
|
+ return holeInAnimationList();
|
|
130
|
+ }
|
|
131
|
+ return hole;
|
104
|
132
|
}
|
105
|
133
|
|
106
|
|
- // return true if damaged and fixed partially
|
|
134
|
+ // return true if damaged and to be sorted
|
107
|
135
|
private boolean checkAnimationList() {
|
108
|
136
|
for (int i = 0; i < animations.size(); i++) {
|
109
|
137
|
if (animations.get(i).getOrder() != i) {
|
110
|
|
- animations.get(i).setOrder(animations.size());
|
|
138
|
+ int h = holeInAnimationList();
|
|
139
|
+ if (h != -1) {
|
|
140
|
+ animations.get(i).setOrder(h);
|
|
141
|
+ }
|
111
|
142
|
return true;
|
112
|
143
|
}
|
113
|
144
|
}
|
|
@@ -122,7 +153,7 @@ public class cubeWorker {
|
122
|
153
|
*/
|
123
|
154
|
public int numOfAnimations() {
|
124
|
155
|
while(checkAnimationList()) {
|
125
|
|
- sortAnimationList();
|
|
156
|
+ Collections.sort(animations);
|
126
|
157
|
}
|
127
|
158
|
return animations.size();
|
128
|
159
|
}
|
|
@@ -151,7 +182,7 @@ public class cubeWorker {
|
151
|
182
|
// --------------------
|
152
|
183
|
|
153
|
184
|
/**
|
154
|
|
- * Add an animation.
|
|
185
|
+ * Add an animation. It has an initial empty frame
|
155
|
186
|
*
|
156
|
187
|
* @return Index of new animation, or -1 if not enough space remaining.
|
157
|
188
|
*/
|
|
@@ -163,6 +194,8 @@ public class cubeWorker {
|
163
|
194
|
int s = animations.size();
|
164
|
195
|
animations.add(s, new Animation());
|
165
|
196
|
animations.get(s).setName("Animation " + animations.size());
|
|
197
|
+ animations.get(s).add(0, new AFrame());
|
|
198
|
+ animations.get(s).get(0).setName("Frame 1");
|
166
|
199
|
return s;
|
167
|
200
|
}
|
168
|
201
|
}
|