34 |
34 |
public enum Type
|
35 |
35 |
{
|
36 |
36 |
NONE (ScrambleEffectNone.class ),
|
|
37 |
ROTATIONS (ScrambleEffectRotations.class ),
|
37 |
38 |
;
|
38 |
39 |
|
39 |
40 |
final Class<? extends ScrambleEffect> effect;
|
... | ... | |
45 |
46 |
}
|
46 |
47 |
|
47 |
48 |
private static int NUM_EFFECTS = Type.values().length;
|
48 |
|
private static final int NUM_PHASES = 2;
|
49 |
49 |
private static final int FAKE_EFFECT_ID = -3;
|
50 |
50 |
private static final Type[] types;
|
51 |
51 |
|
... | ... | |
62 |
62 |
|
63 |
63 |
private EffectListener mListener;
|
64 |
64 |
private int mDuration;
|
65 |
|
private int mEffectReturned;
|
66 |
|
private int[] mCubeEffectNumber, mNodeEffectNumber;
|
67 |
|
private int mPhase;
|
|
65 |
private int[] mEffectReturned;
|
68 |
66 |
private RubikCube mCube;
|
69 |
67 |
private DistortedScreen mScreen;
|
70 |
68 |
|
|
69 |
static final int EFFECT_FLAVOUR_BASE = 0;
|
|
70 |
static final int EFFECT_FLAVOUR_PLUGIN= 1;
|
|
71 |
static final int NUM_EFFECT_FLAVOURS = 2;
|
|
72 |
|
71 |
73 |
Effect[][] mNodeEffects;
|
72 |
74 |
int[][] mNodeEffectPosition;
|
73 |
75 |
Effect[][] mCubeEffects;
|
74 |
76 |
int[][] mCubeEffectPosition;
|
|
77 |
int[] mCubeEffectNumber, mNodeEffectNumber;
|
75 |
78 |
|
76 |
79 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77 |
80 |
|
78 |
81 |
ScrambleEffect()
|
79 |
82 |
{
|
80 |
|
mPhase = 0;
|
81 |
|
|
82 |
|
mCubeEffectNumber = new int[NUM_PHASES];
|
83 |
|
mNodeEffectNumber = new int[NUM_PHASES];
|
84 |
|
mCubeEffectPosition = new int[NUM_PHASES][];
|
85 |
|
mNodeEffectPosition = new int[NUM_PHASES][];
|
86 |
|
mCubeEffects = new Effect[NUM_PHASES][];
|
87 |
|
mNodeEffects = new Effect[NUM_PHASES][];
|
|
83 |
mEffectReturned = new int[NUM_EFFECT_FLAVOURS];
|
|
84 |
mCubeEffectNumber = new int[NUM_EFFECT_FLAVOURS];
|
|
85 |
mNodeEffectNumber = new int[NUM_EFFECT_FLAVOURS];
|
|
86 |
mCubeEffectPosition = new int[NUM_EFFECT_FLAVOURS][];
|
|
87 |
mNodeEffectPosition = new int[NUM_EFFECT_FLAVOURS][];
|
|
88 |
mCubeEffects = new Effect[NUM_EFFECT_FLAVOURS][];
|
|
89 |
mNodeEffects = new Effect[NUM_EFFECT_FLAVOURS][];
|
88 |
90 |
}
|
89 |
91 |
|
90 |
92 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
117 |
119 |
|
118 |
120 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119 |
121 |
|
120 |
|
abstract void createEffectsPhase0(int duration);
|
121 |
|
abstract void createEffectsPhase1(int duration);
|
|
122 |
abstract void createEffects(int duration);
|
|
123 |
abstract void effectFinishedPlugin(final long effectID);
|
122 |
124 |
|
123 |
125 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124 |
|
|
125 |
|
public void effectFinished(final long effectID)
|
|
126 |
// TODO
|
|
127 |
private void createBaseEffects(int duration, int numScrambles)
|
126 |
128 |
{
|
127 |
|
int total = mCubeEffectNumber[mPhase]+mNodeEffectNumber[mPhase];
|
|
129 |
mCubeEffectNumber[EFFECT_FLAVOUR_BASE] = 0;
|
|
130 |
mNodeEffectNumber[EFFECT_FLAVOUR_BASE] = 0;
|
|
131 |
}
|
128 |
132 |
|
129 |
|
for(int i=0; i<mCubeEffectNumber[mPhase]; i++)
|
130 |
|
{
|
131 |
|
long id = mCubeEffects[mPhase][i].getID();
|
|
133 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
134 |
// TODO
|
132 |
135 |
|
133 |
|
if( effectID == id )
|
134 |
|
{
|
135 |
|
if( ++mEffectReturned == total ) effectAction(mPhase);
|
136 |
|
mCube.remove(id);
|
137 |
|
return;
|
138 |
|
}
|
139 |
|
}
|
140 |
|
for(int i=0; i<mNodeEffectNumber[mPhase]; i++)
|
141 |
|
{
|
142 |
|
long id = mNodeEffects[mPhase][i].getID();
|
|
136 |
private void effectFinishedBase(final long effectID)
|
|
137 |
{
|
143 |
138 |
|
144 |
|
if( effectID == id )
|
145 |
|
{
|
146 |
|
if( ++mEffectReturned == total ) effectAction(mPhase);
|
147 |
|
mCube.getEffects().abortById(id);
|
148 |
|
return;
|
149 |
|
}
|
150 |
|
}
|
151 |
139 |
}
|
152 |
140 |
|
153 |
141 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
154 |
142 |
|
155 |
|
private void effectAction(int phase)
|
|
143 |
public void effectFinished(final long effectID)
|
156 |
144 |
{
|
157 |
|
switch(phase)
|
|
145 |
for(int flavour=0; flavour<NUM_EFFECT_FLAVOURS; flavour++)
|
158 |
146 |
{
|
159 |
|
case 0: mEffectReturned = 0;
|
160 |
|
mPhase = 1;
|
161 |
|
mCube.unscramble();
|
162 |
|
createEffectsPhase1(mDuration);
|
163 |
|
assignEffects(mPhase);
|
164 |
|
break;
|
165 |
|
case 1: mListener.effectFinished(FAKE_EFFECT_ID);
|
166 |
|
break;
|
|
147 |
for(int i=0; i<mCubeEffectNumber[flavour]; i++)
|
|
148 |
{
|
|
149 |
long id = mCubeEffects[flavour][i].getID();
|
|
150 |
|
|
151 |
if( effectID == id )
|
|
152 |
{
|
|
153 |
mEffectReturned[flavour]++;
|
|
154 |
|
|
155 |
switch(flavour)
|
|
156 |
{
|
|
157 |
case EFFECT_FLAVOUR_BASE : effectFinishedBase( effectID); break;
|
|
158 |
case EFFECT_FLAVOUR_PLUGIN: effectFinishedPlugin(effectID); break;
|
|
159 |
}
|
|
160 |
|
|
161 |
if( mEffectReturned[flavour] == mCubeEffectNumber[flavour]+mNodeEffectNumber[flavour] )
|
|
162 |
{
|
|
163 |
disassignEffects(flavour);
|
|
164 |
}
|
|
165 |
|
|
166 |
return;
|
|
167 |
}
|
|
168 |
}
|
|
169 |
for(int i=0; i<mNodeEffectNumber[flavour]; i++)
|
|
170 |
{
|
|
171 |
long id = mNodeEffects[flavour][i].getID();
|
|
172 |
|
|
173 |
if( effectID == id )
|
|
174 |
{
|
|
175 |
mEffectReturned[flavour]++;
|
|
176 |
|
|
177 |
switch(flavour)
|
|
178 |
{
|
|
179 |
case EFFECT_FLAVOUR_BASE : effectFinishedBase( effectID); break;
|
|
180 |
case EFFECT_FLAVOUR_PLUGIN: effectFinishedPlugin(effectID); break;
|
|
181 |
}
|
|
182 |
|
|
183 |
if( mEffectReturned[flavour] == mCubeEffectNumber[flavour]+mNodeEffectNumber[flavour] )
|
|
184 |
{
|
|
185 |
disassignEffects(flavour);
|
|
186 |
}
|
|
187 |
|
|
188 |
return;
|
|
189 |
}
|
|
190 |
}
|
167 |
191 |
}
|
168 |
192 |
}
|
169 |
193 |
|
... | ... | |
176 |
200 |
mListener = listener;
|
177 |
201 |
mDuration = duration;
|
178 |
202 |
|
179 |
|
createEffectsPhase0(mDuration);
|
180 |
|
assignEffects(mPhase);
|
|
203 |
createBaseEffects(mDuration, numScrambles);
|
|
204 |
assignEffects(EFFECT_FLAVOUR_BASE);
|
|
205 |
|
|
206 |
createEffects(mDuration);
|
|
207 |
|
|
208 |
if( mCubeEffectNumber[EFFECT_FLAVOUR_PLUGIN]==0 && mNodeEffectNumber[EFFECT_FLAVOUR_PLUGIN]==0 )
|
|
209 |
{
|
|
210 |
throw new RuntimeException("Cube and Node Plugin Effects not created!");
|
|
211 |
}
|
|
212 |
|
|
213 |
assignEffects(EFFECT_FLAVOUR_PLUGIN);
|
181 |
214 |
|
182 |
215 |
return FAKE_EFFECT_ID;
|
183 |
216 |
}
|
184 |
217 |
|
185 |
218 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
186 |
219 |
|
187 |
|
private void assignEffects(int phase)
|
|
220 |
private void assignEffects(int flavour)
|
188 |
221 |
{
|
189 |
|
mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0;
|
190 |
|
mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0;
|
|
222 |
for(int i=0; i<mCubeEffectNumber[flavour]; i++)
|
|
223 |
{
|
|
224 |
android.util.Log.e("scramble", "applying cube effect "+mCubeEffects[flavour][i].getName());
|
|
225 |
|
|
226 |
mCube.apply(mCubeEffects[flavour][i],mCubeEffectPosition[flavour][i]);
|
|
227 |
mCubeEffects[flavour][i].notifyWhenFinished(this);
|
|
228 |
}
|
|
229 |
|
|
230 |
DistortedEffects nodeEffects = mCube.getEffects();
|
191 |
231 |
|
192 |
|
if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 )
|
|
232 |
for(int i=0; i<mNodeEffectNumber[flavour]; i++)
|
193 |
233 |
{
|
194 |
|
throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!");
|
|
234 |
nodeEffects.apply(mNodeEffects[flavour][i],mNodeEffectPosition[flavour][i]);
|
|
235 |
mNodeEffects[flavour][i].notifyWhenFinished(this);
|
195 |
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196 |
240 |
|
197 |
|
for(int i=0; i<mCubeEffectNumber[phase]; i++)
|
|
241 |
private void disassignEffects(int flavour)
|
|
242 |
{
|
|
243 |
for(int i=0; i<mCubeEffectNumber[flavour]; i++)
|
198 |
244 |
{
|
199 |
|
mCube.apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
|
200 |
|
mCubeEffects[phase][i].notifyWhenFinished(this);
|
|
245 |
android.util.Log.e("scramble", "removing cube effect "+mCubeEffects[flavour][i].getName());
|
|
246 |
|
|
247 |
mCube.remove(mCubeEffects[flavour][i].getID());
|
201 |
248 |
}
|
202 |
249 |
|
203 |
250 |
DistortedEffects nodeEffects = mCube.getEffects();
|
204 |
251 |
|
205 |
|
for(int i=0; i<mNodeEffectNumber[phase]; i++)
|
|
252 |
for(int i=0; i<mNodeEffectNumber[flavour]; i++)
|
|
253 |
{
|
|
254 |
nodeEffects.abortById(mNodeEffects[flavour][i].getID());
|
|
255 |
}
|
|
256 |
|
|
257 |
if( flavour==EFFECT_FLAVOUR_PLUGIN )
|
206 |
258 |
{
|
207 |
|
nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]);
|
208 |
|
mNodeEffects[phase][i].notifyWhenFinished(this);
|
|
259 |
mListener.effectFinished(FAKE_EFFECT_ID);
|
209 |
260 |
}
|
210 |
261 |
}
|
211 |
262 |
|
Progress with ScrambleEffects