Project

General

Profile

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

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

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.s_cube_2, R.drawable.m_cube_2, R.drawable.b_cube_2, R.drawable.h_cube_2),
38
  CUBE_3 ( new int[] {3,3,3}      , 17, R.drawable.s_cube_3, R.drawable.m_cube_3, R.drawable.b_cube_3, R.drawable.h_cube_3),
39
  CUBE_4 ( new int[] {4,4,4}      , 24, R.drawable.s_cube_4, R.drawable.m_cube_4, R.drawable.b_cube_4, R.drawable.h_cube_4),
40
  CUBE_5 ( new int[] {5,5,5}      , 28, R.drawable.s_cube_5, R.drawable.m_cube_5, R.drawable.b_cube_5, R.drawable.h_cube_5),
41
  JING_2 ( new int[] {2,2,2,2}    , 11, R.drawable.s_jing_2, R.drawable.m_jing_2, R.drawable.b_jing_2, R.drawable.h_jing_2),
42
  PYRA_3 ( new int[] {3,3,3,3}    , 10, R.drawable.s_pyra_3, R.drawable.m_pyra_3, R.drawable.b_pyra_3, R.drawable.h_pyra_3),
43
  PYRA_4 ( new int[] {4,4,4,4}    , 17, R.drawable.s_pyra_4, R.drawable.m_pyra_4, R.drawable.b_pyra_4, R.drawable.h_pyra_4),
44
  PYRA_5 ( new int[] {5,5,5,5}    , 23, R.drawable.s_pyra_5, R.drawable.m_pyra_5, R.drawable.b_pyra_5, R.drawable.h_pyra_5),
45
  KILO_3 ( new int[] {3,3,3,3,3,3}, 18, R.drawable.s_kilo_3, R.drawable.m_kilo_3, R.drawable.b_kilo_3, R.drawable.h_kilo_3),
46
  KILO_5 ( new int[] {5,5,5,5,5,5}, 33, R.drawable.s_kilo_5, R.drawable.m_kilo_5, R.drawable.b_kilo_5, R.drawable.h_kilo_5),
47
  MEGA_3 ( new int[] {3,3,3,3,3,3}, 21, R.drawable.s_mega_3, R.drawable.m_mega_3, R.drawable.b_mega_3, R.drawable.h_mega_3),
48
  MEGA_5 ( new int[] {5,5,5,5,5,5}, 37, R.drawable.s_mega_5, R.drawable.m_mega_5, R.drawable.b_mega_5, R.drawable.h_mega_5),
49
  ULTI_2 ( new int[] {2,2,2,2}    , 18, R.drawable.s_ulti_2, R.drawable.m_ulti_2, R.drawable.b_ulti_2, R.drawable.h_ulti_2),
50
  DIAM_2 ( new int[] {2,2,2,2}    , 12, R.drawable.s_diam_2, R.drawable.m_diam_2, R.drawable.b_diam_2, R.drawable.h_diam_2),
51
  DIAM_3 ( new int[] {3,3,3,3}    , 24, R.drawable.s_diam_3, R.drawable.m_diam_3, R.drawable.b_diam_3, R.drawable.h_diam_3),
52
  DIAM_4 ( new int[] {4,4,4,4}    , 32, R.drawable.s_diam_4, R.drawable.m_diam_4, R.drawable.b_diam_4, R.drawable.h_diam_4),
53
  DINO_3 ( new int[] {3,3,3,3}    , 10, R.drawable.s_dino_3, R.drawable.m_dino_3, R.drawable.b_dino_3, R.drawable.h_dino_3),
54
  DIN4_3 ( new int[] {3,3,3,3}    ,  7, R.drawable.s_din4_3, R.drawable.m_din4_3, R.drawable.b_din4_3, R.drawable.h_din4_3),
55
  REDI_3 ( new int[] {3,3,3,3}    , 16, R.drawable.s_redi_3, R.drawable.m_redi_3, R.drawable.b_redi_3, R.drawable.h_redi_3),
56
  HELI_3 ( new int[] {3,3,3,3,3,3}, 20, R.drawable.s_heli_3, R.drawable.m_heli_3, R.drawable.b_heli_3, R.drawable.h_heli_3),
57
  SKEW_2 ( new int[] {2,2,2,2}    , 11, R.drawable.s_skew_2, R.drawable.m_skew_2, R.drawable.b_skew_2, R.drawable.h_skew_2),
58
  SKEW_3 ( new int[] {3,3,3,3}    , 21, R.drawable.s_skew_3, R.drawable.m_skew_3, R.drawable.b_skew_3, R.drawable.h_skew_3),
59
  IVY_2  ( new int[] {2,2,2,2}    ,  8, R.drawable.s_ivy_2 , R.drawable.m_ivy_2 , R.drawable.b_ivy_2 , R.drawable.h_ivy_2 ),
60
  REX_3  ( new int[] {3,3,3,3}    , 19, R.drawable.s_rex_3 , R.drawable.m_rex_3 , R.drawable.b_rex_3 , R.drawable.h_rex_3 ),
61
  BAN1_3 ( new int[] {3,3,3}      , 16, R.drawable.s_ban1_3, R.drawable.m_ban1_3, R.drawable.b_ban1_3, R.drawable.h_ban1_3),
62
  BAN2_3 ( new int[] {3,3,3}      , 16, R.drawable.s_ban2_3, R.drawable.m_ban2_3, R.drawable.b_ban2_3, R.drawable.h_ban2_3),
63
  BAN3_3 ( new int[] {3,3,3}      , 16, R.drawable.s_ban3_3, R.drawable.m_ban3_3, R.drawable.b_ban3_3, R.drawable.h_ban3_3),
64
  BAN4_3 ( new int[] {3,3,3}      , 16, R.drawable.s_ban4_3, R.drawable.m_ban4_3, R.drawable.b_ban4_3, R.drawable.h_ban4_3),
65
  SQU1_3 ( new int[] {3,2,3}      , 24, R.drawable.s_squ1_3, R.drawable.m_squ1_3, R.drawable.b_squ1_3, R.drawable.h_squ1_3),
66
  SQU2_3 ( new int[] {3,2,3}      , 24, R.drawable.s_squ2_3, R.drawable.m_squ2_3, R.drawable.b_squ2_3, R.drawable.h_squ2_3),
67
  MIRR_2 ( new int[] {2,2,2}      , 12, R.drawable.s_mirr_2, R.drawable.m_mirr_2, R.drawable.b_mirr_2, R.drawable.h_mirr_2),
68
  MIRR_3 ( new int[] {3,3,3}      , 17, R.drawable.s_mirr_3, R.drawable.m_mirr_3, R.drawable.b_mirr_3, R.drawable.h_mirr_3),
69

    
70
  CU_223 ( new int[] {2,3,2}      , 16, R.drawable.s_cube_2, R.drawable.m_cube_2, R.drawable.b_cube_2, R.drawable.h_cube_2),
71
  CU_334 ( new int[] {3,4,3}      , 20, R.drawable.s_cube_3, R.drawable.m_cube_3, R.drawable.b_cube_3, R.drawable.h_cube_3),
72
  CU_122 ( new int[] {1,2,2}      , 20, R.drawable.s_cube_3, R.drawable.m_cube_3, R.drawable.b_cube_3, R.drawable.h_cube_3),
73
  CU_321 ( new int[] {3,2,1}      , 20, R.drawable.s_cube_3, R.drawable.m_cube_3, R.drawable.b_cube_3, R.drawable.h_cube_3),
74
  CU_111 ( new int[] {1,1,1}      , 20, R.drawable.s_cube_3, R.drawable.m_cube_3, R.drawable.b_cube_3, R.drawable.h_cube_3),
75
  CU_141 ( new int[] {1,4,1}      , 20, R.drawable.s_cube_3, R.drawable.m_cube_3, R.drawable.b_cube_3, R.drawable.h_cube_3),
76

    
77
  ;
78

    
79
  public static final int NUM_OBJECTS = values().length;
80
  public static final int MAX_SCRAMBLE,MAX_OBJECT_SIZE;
81

    
82
  private final int[] mNumLayers;
83
  private final int mNumScrambles;
84
  private final int mSmallIcon, mMediumIcon, mBigIcon, mHugeIcon;
85

    
86
  private static final ObjectType[] objects;
87

    
88
  static
89
    {
90
    int i = 0;
91
    objects = new ObjectType[NUM_OBJECTS];
92
    int maxScramble= Integer.MIN_VALUE;
93
    int maxSize    = Integer.MIN_VALUE;
94

    
95
    for(ObjectType object: ObjectType.values())
96
      {
97
      objects[i++] = object;
98

    
99
      if( object.mNumScrambles> maxScramble ) maxScramble= object.mNumScrambles;
100

    
101
      int len = object.mNumLayers.length;
102

    
103
      for(int j=0; j<len; j++)
104
        if( object.mNumLayers[j]>maxSize ) maxSize = object.mNumLayers[j];
105
      }
106

    
107
    MAX_SCRAMBLE    = maxScramble;
108
    MAX_OBJECT_SIZE = maxSize;
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  public static ObjectType getObject(int ordinal)
114
    {
115
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  public static int getOrdinal(String name)
121
    {
122
    for(int i=0; i<NUM_OBJECTS; i++)
123
      {
124
      if( objects[i].name().equals(name) ) return i;
125
      }
126

    
127
    return -1;
128
    }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
  public static int getNumScramble(int ordinal)
133
    {
134
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal].mNumScrambles : 0;
135
    }
136

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

    
139
  ObjectType(int[] numLayers, int scrambles, int sIcon, int mIcon, int bIcon, int hIcon)
140
    {
141
    mNumLayers   = numLayers;
142
    mNumScrambles= scrambles;
143
    mSmallIcon   = sIcon;
144
    mMediumIcon  = mIcon;
145
    mBigIcon     = bIcon;
146
    mHugeIcon    = hIcon;
147
    }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

    
151
  public int getIconID(int size)
152
    {
153
    switch(size)
154
      {
155
      case 0: return mSmallIcon;
156
      case 1: return mMediumIcon;
157
      case 2: return mBigIcon;
158
      case 3: return mHugeIcon;
159
      }
160

    
161
    return mSmallIcon;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  public TwistyObject create(Static4D quat, Static3D move, Resources res, int surfaceW, int surfaceH)
167
    {
168
    DistortedTexture texture = new DistortedTexture();
169
    DistortedEffects effects = new DistortedEffects();
170
    MeshSquare mesh          = new MeshSquare(20,20);   // mesh of the node, not of the cubits
171

    
172
    int ord = ordinal();
173
    int[] numL= objects[ord].mNumLayers;
174

    
175
    switch(ord)
176
      {
177
      case 32:
178
      case 33:
179
      case 34:
180
      case 35:
181
      case 36:
182
      case 37:
183

    
184
      case  0:
185
      case  1:
186
      case  2:
187
      case  3: return new TwistyCube          (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
188
      case  4: return new TwistyJing          (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
189
      case  5:
190
      case  6:
191
      case  7: return new TwistyPyraminx      (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
192
      case  8:
193
      case  9: return new TwistyKilominx      (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
194
      case 10:
195
      case 11: return new TwistyMegaminx      (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
196
      case 12: return new TwistyUltimate      (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
197
      case 13:
198
      case 14:
199
      case 15: return new TwistyDiamond       (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
200
      case 16: return new TwistyDino6         (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
201
      case 17: return new TwistyDino4         (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
202
      case 18: return new TwistyRedi          (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
203
      case 19: return new TwistyHelicopter    (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
204
      case 20:
205
      case 21: return new TwistySkewb         (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
206
      case 22: return new TwistyIvy           (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
207
      case 23: return new TwistyRex           (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
208
      case 24: return new TwistyBandagedFused (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
209
      case 25: return new TwistyBandaged2Bar  (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
210
      case 26: return new TwistyBandaged3Plate(numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
211
      case 27: return new TwistyBandagedEvil  (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
212
      case 28: return new TwistySquare1       (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
213
      case 29: return new TwistySquare2       (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
214
      case 30:
215
      case 31: return new TwistyMirror        (numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
216
      }
217

    
218
    return null;
219
    }
220
  }
(9-9/15)