1 |
4a79e563
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2023 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.objectlib.bandaged;
|
11 |
|
|
|
12 |
|
|
import org.distorted.library.main.DistortedScreen;
|
13 |
|
|
|
14 |
|
|
import java.lang.reflect.Constructor;
|
15 |
|
|
import java.lang.reflect.InvocationTargetException;
|
16 |
|
|
|
17 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
18 |
|
|
|
19 |
|
|
public enum LocallyBandagedList
|
20 |
|
|
{
|
21 |
b5db1f7a
|
leszek
|
CUBOID ( BandagedObjectCuboid.class , 3, 1, 7 ),
|
22 |
|
|
PYRAMINX ( BandagedObjectPyraminx.class , 1, 1, 7 ),
|
23 |
|
|
MEGAMINX ( BandagedObjectMegaminx.class , 1, 2, 5 ),
|
24 |
|
|
OCTAHEDRON ( BandagedObjectOctahedron.class, 1, 2, 4 ),
|
25 |
1e2e00d5
|
leszek
|
SKEWB ( BandagedObjectSkewb.class , 1, 2, 3 ),
|
26 |
4a79e563
|
leszek
|
;
|
27 |
|
|
|
28 |
|
|
private final Class<? extends BandagedObject> mClass;
|
29 |
|
|
private final int mDimension;
|
30 |
|
|
private final int mMaxSupportedSize;
|
31 |
5c825988
|
leszek
|
private final int mMinSupportedSize;
|
32 |
4a79e563
|
leszek
|
|
33 |
|
|
public static final int NUM_OBJECTS = values().length;
|
34 |
|
|
private static final LocallyBandagedList[] objects;
|
35 |
|
|
|
36 |
|
|
static
|
37 |
|
|
{
|
38 |
|
|
objects = new LocallyBandagedList[NUM_OBJECTS];
|
39 |
|
|
int i=0;
|
40 |
|
|
for(LocallyBandagedList object: LocallyBandagedList.values()) objects[i++] = object;
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44 |
|
|
|
45 |
5c825988
|
leszek
|
LocallyBandagedList(Class<? extends BandagedObject> clazz, int dimension, int min, int max)
|
46 |
4a79e563
|
leszek
|
{
|
47 |
|
|
mDimension = dimension;
|
48 |
5c825988
|
leszek
|
mMinSupportedSize = min;
|
49 |
4a79e563
|
leszek
|
mMaxSupportedSize = max;
|
50 |
|
|
mClass = clazz;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
// PUBLIC API
|
55 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56 |
|
|
|
57 |
|
|
public static int getDimension(int ordinal)
|
58 |
|
|
{
|
59 |
|
|
return (ordinal>=0 && ordinal<NUM_OBJECTS) ? objects[ordinal].mDimension : -1;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
|
|
|
64 |
|
|
public static int getMaxSupported(int ordinal)
|
65 |
|
|
{
|
66 |
|
|
return (ordinal>=0 && ordinal<NUM_OBJECTS) ? objects[ordinal].mMaxSupportedSize : -1;
|
67 |
|
|
}
|
68 |
|
|
|
69 |
5c825988
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
public static int getMinSupported(int ordinal)
|
72 |
|
|
{
|
73 |
|
|
return (ordinal>=0 && ordinal<NUM_OBJECTS) ? objects[ordinal].mMinSupportedSize : -1;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
4a79e563
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77 |
|
|
|
78 |
|
|
public static BandagedObject create(int ordinal, DistortedScreen screen)
|
79 |
|
|
{
|
80 |
|
|
if( ordinal>=NUM_OBJECTS || ordinal<0 ) ordinal = 0;
|
81 |
|
|
|
82 |
|
|
Class<? extends BandagedObject> clazz = objects[ordinal].mClass;
|
83 |
|
|
|
84 |
|
|
try
|
85 |
|
|
{
|
86 |
|
|
Constructor<?>[] cons = clazz.getConstructors();
|
87 |
|
|
|
88 |
|
|
if( cons.length==1 )
|
89 |
|
|
{
|
90 |
6377eed5
|
leszek
|
int minSize = objects[ordinal].mMinSupportedSize;
|
91 |
|
|
int maxSize = objects[ordinal].mMaxSupportedSize;
|
92 |
|
|
Object[] parameters = new Object[] { screen,minSize,maxSize };
|
93 |
4a79e563
|
leszek
|
return (BandagedObject)cons[0].newInstance(parameters);
|
94 |
|
|
}
|
95 |
|
|
else
|
96 |
|
|
{
|
97 |
|
|
android.util.Log.e("ObjectList", "ERROR! number of BandagedObject constructors="+cons.length);
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
catch(IllegalAccessException iae)
|
101 |
|
|
{
|
102 |
|
|
android.util.Log.e("ObjectList", "Illegal Access Exception: "+iae.getMessage());
|
103 |
|
|
}
|
104 |
|
|
catch(InstantiationException ie)
|
105 |
|
|
{
|
106 |
|
|
android.util.Log.e("ObjectList", "Instantiation Exception: "+ie.getMessage());
|
107 |
|
|
}
|
108 |
|
|
catch(InvocationTargetException ite)
|
109 |
|
|
{
|
110 |
|
|
android.util.Log.e("ObjectList", "Invocation Target Exception: "+ite.getMessage());
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
return null;
|
114 |
|
|
}
|
115 |
|
|
}
|