Project

General

Profile

Download (11.8 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectType.java @ b146015e

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objectlib.main;
21

    
22
import android.content.res.Resources;
23

    
24
import org.distorted.library.main.DistortedEffects;
25
import org.distorted.library.main.DistortedTexture;
26
import org.distorted.library.mesh.MeshSquare;
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.R;
31
import org.distorted.objectlib.objects.*;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
public enum ObjectType
36
  {
37
  CUBE_2 ( new int[] {2,2,2}      , 12, R.drawable.cube_2s, R.drawable.cube_2m, R.drawable.cube_2b, R.drawable.cube_2h),
38
  CUBE_3 ( new int[] {3,3,3}      , 17, R.drawable.cube_3s, R.drawable.cube_3m, R.drawable.cube_3b, R.drawable.cube_3h),
39
  CUBE_4 ( new int[] {4,4,4}      , 24, R.drawable.cube_4s, R.drawable.cube_4m, R.drawable.cube_4b, R.drawable.cube_4h),
40
  CUBE_5 ( new int[] {5,5,5}      , 28, R.drawable.cube_5s, R.drawable.cube_5m, R.drawable.cube_5b, R.drawable.cube_5h),
41
  JING_2 ( new int[] {2,2,2,2}    , 11, R.drawable.jing_2s, R.drawable.jing_2m, R.drawable.jing_2b, R.drawable.jing_2h),
42
  PYRA_3 ( new int[] {3,3,3,3}    , 10, R.drawable.pyra_3s, R.drawable.pyra_3m, R.drawable.pyra_3b, R.drawable.pyra_3h),
43
  PYRA_4 ( new int[] {4,4,4,4}    , 17, R.drawable.pyra_4s, R.drawable.pyra_4m, R.drawable.pyra_4b, R.drawable.pyra_4h),
44
  PYRA_5 ( new int[] {5,5,5,5}    , 23, R.drawable.pyra_5s, R.drawable.pyra_5m, R.drawable.pyra_5b, R.drawable.pyra_5h),
45
  KILO_3 ( new int[] {3,3,3,3,3,3}, 18, R.drawable.kilo_3s, R.drawable.kilo_3m, R.drawable.kilo_3b, R.drawable.kilo_3h),
46
  KILO_5 ( new int[] {5,5,5,5,5,5}, 33, R.drawable.kilo_5s, R.drawable.kilo_5m, R.drawable.kilo_5b, R.drawable.kilo_5h),
47
  MEGA_3 ( new int[] {3,3,3,3,3,3}, 21, R.drawable.mega_3s, R.drawable.mega_3m, R.drawable.mega_3b, R.drawable.mega_3h),
48
  MEGA_5 ( new int[] {5,5,5,5,5,5}, 37, R.drawable.mega_5s, R.drawable.mega_5m, R.drawable.mega_5b, R.drawable.mega_5h),
49
  ULTI_2 ( new int[] {2,2,2,2}    , 18, R.drawable.ulti_2s, R.drawable.ulti_2m, R.drawable.ulti_2b, R.drawable.ulti_2h),
50
  DIAM_2 ( new int[] {2,2,2,2}    , 12, R.drawable.diam_2s, R.drawable.diam_2m, R.drawable.diam_2b, R.drawable.diam_2h),
51
  DIAM_3 ( new int[] {3,3,3,3}    , 24, R.drawable.diam_3s, R.drawable.diam_3m, R.drawable.diam_3b, R.drawable.diam_3h),
52
  DIAM_4 ( new int[] {4,4,4,4}    , 32, R.drawable.diam_4s, R.drawable.diam_4m, R.drawable.diam_4b, R.drawable.diam_4h),
53
  DINO_3 ( new int[] {3,3,3,3}    , 10, R.drawable.dino_3s, R.drawable.dino_3m, R.drawable.dino_3b, R.drawable.dino_3h),
54
  DIN4_3 ( new int[] {3,3,3,3}    ,  7, R.drawable.din4_3s, R.drawable.din4_3m, R.drawable.din4_3b, R.drawable.din4_3h),
55
  REDI_3 ( new int[] {3,3,3,3}    , 16, R.drawable.redi_3s, R.drawable.redi_3m, R.drawable.redi_3b, R.drawable.redi_3h),
56
  HELI_3 ( new int[] {3,3,3,3,3,3}, 20, R.drawable.heli_3s, R.drawable.heli_3m, R.drawable.heli_3b, R.drawable.heli_3h),
57
  SKEW_2 ( new int[] {2,2,2,2}    , 11, R.drawable.skew_2s, R.drawable.skew_2m, R.drawable.skew_2b, R.drawable.skew_2h),
58
  SKEW_3 ( new int[] {3,3,3,3}    , 21, R.drawable.skew_3s, R.drawable.skew_3m, R.drawable.skew_3b, R.drawable.skew_3h),
59
  IVY_2  ( new int[] {2,2,2,2}    ,  8, R.drawable.ivy_2s , R.drawable.ivy_2m , R.drawable.ivy_2b , R.drawable.ivy_2h ),
60
  REX_3  ( new int[] {3,3,3,3}    , 19, R.drawable.rex_3s , R.drawable.rex_3m , R.drawable.rex_3b , R.drawable.rex_3h ),
61
  BAN1_3 ( new int[] {3,3,3}      , 16, R.drawable.ban1_3s, R.drawable.ban1_3m, R.drawable.ban1_3b, R.drawable.ban1_3h),
62
  BAN2_3 ( new int[] {3,3,3}      , 16, R.drawable.ban2_3s, R.drawable.ban2_3m, R.drawable.ban2_3b, R.drawable.ban2_3h),
63
  BAN3_3 ( new int[] {3,3,3}      , 16, R.drawable.ban3_3s, R.drawable.ban3_3m, R.drawable.ban3_3b, R.drawable.ban3_3h),
64
  BAN4_3 ( new int[] {3,3,3}      , 16, R.drawable.ban4_3s, R.drawable.ban4_3m, R.drawable.ban4_3b, R.drawable.ban4_3h),
65
  SQU1_3 ( new int[] {3,2,3}      , 24, R.drawable.squ1_3s, R.drawable.squ1_3m, R.drawable.squ1_3b, R.drawable.squ1_3h),
66
  SQU2_3 ( new int[] {3,2,3}      , 24, R.drawable.squ2_3s, R.drawable.squ2_3m, R.drawable.squ2_3b, R.drawable.squ2_3h),
67
  MIRR_2 ( new int[] {2,2,2}      , 12, R.drawable.mirr_2s, R.drawable.mirr_2m, R.drawable.mirr_2b, R.drawable.mirr_2h),
68
  MIRR_3 ( new int[] {3,3,3}      , 17, R.drawable.mirr_3s, R.drawable.mirr_3m, R.drawable.mirr_3b, R.drawable.mirr_3h),
69
  CU_323 ( new int[] {3,2,3}      , 15, R.drawable.cu_323s, R.drawable.cu_323m, R.drawable.cu_323b, R.drawable.cu_323h),
70
  CU_232 ( new int[] {2,3,2}      , 16, R.drawable.cu_232s, R.drawable.cu_232m, R.drawable.cu_232b, R.drawable.cu_232h),
71
  CU_343 ( new int[] {3,4,3}      , 23, R.drawable.cu_343s, R.drawable.cu_343m, R.drawable.cu_343b, R.drawable.cu_343h),
72
  ;
73

    
74
  public static final int NUM_OBJECTS = values().length;
75
  public static final int MAX_SCRAMBLE,MAX_OBJECT_SIZE;
76

    
77
  private final int[] mNumLayers;
78
  private final int mNumScrambles;
79
  private final int mSmallIcon, mMediumIcon, mBigIcon, mHugeIcon;
80

    
81
  private static final ObjectType[] objects;
82

    
83
  static
84
    {
85
    int i = 0;
86
    objects = new ObjectType[NUM_OBJECTS];
87
    int maxScramble= Integer.MIN_VALUE;
88
    int maxSize    = Integer.MIN_VALUE;
89

    
90
    for(ObjectType object: ObjectType.values())
91
      {
92
      objects[i++] = object;
93

    
94
      if( object.mNumScrambles> maxScramble ) maxScramble= object.mNumScrambles;
95

    
96
      int len = object.mNumLayers.length;
97

    
98
      for(int j=0; j<len; j++)
99
        if( object.mNumLayers[j]>maxSize ) maxSize = object.mNumLayers[j];
100
      }
101

    
102
    MAX_SCRAMBLE    = maxScramble;
103
    MAX_OBJECT_SIZE = maxSize;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public static ObjectType getObject(int ordinal)
109
    {
110
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public static int getOrdinal(String name)
116
    {
117
    for(int i=0; i<NUM_OBJECTS; i++)
118
      {
119
      if( objects[i].name().equals(name) ) return i;
120
      }
121

    
122
    return -1;
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
  ObjectType(int[] numLayers, int scrambles, int sIcon, int mIcon, int bIcon, int hIcon)
128
    {
129
    mNumLayers   = numLayers;
130
    mNumScrambles= scrambles;
131
    mSmallIcon   = sIcon;
132
    mMediumIcon  = mIcon;
133
    mBigIcon     = bIcon;
134
    mHugeIcon    = hIcon;
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  public int getNumScramble()
140
    {
141
    return mNumScrambles;
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  public int getIconID(int size)
147
    {
148
    switch(size)
149
      {
150
      case 0: return mSmallIcon;
151
      case 1: return mMediumIcon;
152
      case 2: return mBigIcon;
153
      case 3: return mHugeIcon;
154
      }
155

    
156
    return mSmallIcon;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public TwistyObject create(Static4D quat, Static3D move, Resources res, int surfaceW, int surfaceH)
162
    {
163
    DistortedTexture texture = new DistortedTexture();
164
    DistortedEffects effects = new DistortedEffects();
165
    MeshSquare mesh          = new MeshSquare(20,20);   // mesh of the node, not of the cubits
166

    
167
    int ord = ordinal();
168
    int[] numL= objects[ord].mNumLayers;
169

    
170
    switch(ord)
171
      {
172
      case  0:
173
      case  1:
174
      case  2:
175
      case  3: return new TwistyCuboid        (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
176
      case  4: return new TwistyJing          (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
177
      case  5:
178
      case  6:
179
      case  7: return new TwistyPyraminx      (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
180
      case  8:
181
      case  9: return new TwistyKilominx      (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
182
      case 10:
183
      case 11: return new TwistyMegaminx      (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
184
      case 12: return new TwistyUltimate      (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
185
      case 13:
186
      case 14:
187
      case 15: return new TwistyDiamond       (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
188
      case 16: return new TwistyDino6         (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
189
      case 17: return new TwistyDino4         (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
190
      case 18: return new TwistyRedi          (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
191
      case 19: return new TwistyHelicopter    (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
192
      case 20:
193
      case 21: return new TwistySkewb         (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
194
      case 22: return new TwistyIvy           (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
195
      case 23: return new TwistyRex           (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
196
      case 24: return new TwistyBandagedFused (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
197
      case 25: return new TwistyBandaged2Bar  (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
198
      case 26: return new TwistyBandaged3Plate(numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
199
      case 27: return new TwistyBandagedEvil  (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
200
      case 28: return new TwistySquare1       (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
201
      case 29: return new TwistySquare2       (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
202
      case 30:
203
      case 31: return new TwistyMirror        (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
204
      case 32:
205
      case 33:
206
      case 34: return new TwistyCuboid        (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
207
      }
208

    
209
    return null;
210
    }
211
  }
(10-10/16)