Project

General

Profile

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

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

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.Static4D;
28

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

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
public enum ObjectType
35
  {
36
  CUBE_2 ( 2, 12, R.drawable.small_cube2, R.drawable.medium_cube2, R.drawable.big_cube2, R.drawable.huge_cube2),
37
  CUBE_3 ( 3, 17, R.drawable.small_cube3, R.drawable.medium_cube3, R.drawable.big_cube3, R.drawable.huge_cube3),
38
  CUBE_4 ( 4, 24, R.drawable.small_cube4, R.drawable.medium_cube4, R.drawable.big_cube4, R.drawable.huge_cube4),
39
  CUBE_5 ( 5, 28, R.drawable.small_cube5, R.drawable.medium_cube5, R.drawable.big_cube5, R.drawable.huge_cube5),
40
  JING_2 ( 2, 11, R.drawable.small_jing2, R.drawable.medium_jing2, R.drawable.big_jing2, R.drawable.huge_jing2),
41
  PYRA_3 ( 3, 10, R.drawable.small_pyra3, R.drawable.medium_pyra3, R.drawable.big_pyra3, R.drawable.huge_pyra3),
42
  PYRA_4 ( 4, 17, R.drawable.small_pyra4, R.drawable.medium_pyra4, R.drawable.big_pyra4, R.drawable.huge_pyra4),
43
  PYRA_5 ( 5, 23, R.drawable.small_pyra5, R.drawable.medium_pyra5, R.drawable.big_pyra5, R.drawable.huge_pyra5),
44
  KILO_3 ( 3, 18, R.drawable.small_kilo3, R.drawable.medium_kilo3, R.drawable.big_kilo3, R.drawable.huge_kilo3),
45
  KILO_5 ( 5, 33, R.drawable.small_kilo5, R.drawable.medium_kilo5, R.drawable.big_kilo5, R.drawable.huge_kilo5),
46
  MEGA_3 ( 3, 21, R.drawable.small_mega3, R.drawable.medium_mega3, R.drawable.big_mega3, R.drawable.huge_mega3),
47
  MEGA_5 ( 5, 37, R.drawable.small_mega5, R.drawable.medium_mega5, R.drawable.big_mega5, R.drawable.huge_mega5),
48
  ULTI_2 ( 2, 18, R.drawable.small_ulti , R.drawable.medium_ulti , R.drawable.big_ulti , R.drawable.huge_ulti ),
49
  DIAM_2 ( 2, 12, R.drawable.small_diam2, R.drawable.medium_diam2, R.drawable.big_diam2, R.drawable.huge_diam2),
50
  DIAM_3 ( 3, 24, R.drawable.small_diam3, R.drawable.medium_diam3, R.drawable.big_diam3, R.drawable.huge_diam3),
51
  DIAM_4 ( 4, 32, R.drawable.small_diam4, R.drawable.medium_diam4, R.drawable.big_diam4, R.drawable.huge_diam4),
52
  DINO_3 ( 3, 10, R.drawable.small_dino , R.drawable.medium_dino , R.drawable.big_dino , R.drawable.huge_dino ),
53
  DIN4_3 ( 3,  7, R.drawable.small_din4 , R.drawable.medium_din4 , R.drawable.big_din4 , R.drawable.huge_din4 ),
54
  REDI_3 ( 3, 16, R.drawable.small_redi , R.drawable.medium_redi , R.drawable.big_redi , R.drawable.huge_redi ),
55
  HELI_3 ( 3, 20, R.drawable.small_heli , R.drawable.medium_heli , R.drawable.big_heli , R.drawable.huge_heli ),
56
  SKEW_2 ( 2, 11, R.drawable.small_skew2, R.drawable.medium_skew2, R.drawable.big_skew2, R.drawable.huge_skew2),
57
  SKEW_3 ( 3, 21, R.drawable.small_skew3, R.drawable.medium_skew3, R.drawable.big_skew3, R.drawable.huge_skew3),
58
  IVY_2  ( 2,  8, R.drawable.small_ivy  , R.drawable.medium_ivy  , R.drawable.big_ivy  , R.drawable.huge_ivy  ),
59
  REX_3  ( 3, 19, R.drawable.small_rex  , R.drawable.medium_rex  , R.drawable.big_rex  , R.drawable.huge_rex  ),
60
  BAN1_3 ( 3, 16, R.drawable.small_ban1 , R.drawable.medium_ban1 , R.drawable.big_ban1 , R.drawable.huge_ban1 ),
61
  BAN2_3 ( 3, 16, R.drawable.small_ban2 , R.drawable.medium_ban2 , R.drawable.big_ban2 , R.drawable.huge_ban2 ),
62
  BAN3_3 ( 3, 16, R.drawable.small_ban3 , R.drawable.medium_ban3 , R.drawable.big_ban3 , R.drawable.huge_ban3 ),
63
  BAN4_3 ( 3, 16, R.drawable.small_ban4 , R.drawable.medium_ban4 , R.drawable.big_ban4 , R.drawable.huge_ban4 ),
64
  SQU1_3 ( 3, 24, R.drawable.small_squa1, R.drawable.medium_squa1, R.drawable.big_squa1, R.drawable.huge_squa1),
65
  SQU2_3 ( 3, 24, R.drawable.small_squa2, R.drawable.medium_squa2, R.drawable.big_squa2, R.drawable.huge_squa2),
66
  MIRR_2 ( 2, 12, R.drawable.small_mirr2, R.drawable.medium_mirr2, R.drawable.big_mirr2, R.drawable.huge_mirr2),
67
  MIRR_3 ( 3, 17, R.drawable.small_mirr3, R.drawable.medium_mirr3, R.drawable.big_mirr3, R.drawable.huge_mirr3),
68
  ;
69

    
70
  public static final int NUM_OBJECTS = values().length;
71
  public static final int MAX_SCRAMBLE,MAX_OBJECT_SIZE;
72

    
73
  private final int mSize, mNumScrambles;
74
  private final int mSmallIcon, mMediumIcon, mBigIcon, mHugeIcon;
75

    
76
  private static final ObjectType[] objects;
77

    
78
  static
79
    {
80
    int i = 0;
81
    objects = new ObjectType[NUM_OBJECTS];
82
    int maxScramble= Integer.MIN_VALUE;
83
    int maxSize    = Integer.MIN_VALUE;
84

    
85
    for(ObjectType object: ObjectType.values())
86
      {
87
      objects[i++] = object;
88

    
89
      if( object.mNumScrambles> maxScramble ) maxScramble= object.mNumScrambles;
90
      if( object.mSize        > maxSize     ) maxSize    = object.mSize;
91
      }
92

    
93
    MAX_SCRAMBLE    = maxScramble;
94
    MAX_OBJECT_SIZE = maxSize;
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
  public static ObjectType getObject(int ordinal)
100
    {
101
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  public static int getOrdinal(String name)
107
    {
108
    for(int i=0; i<NUM_OBJECTS; i++)
109
      {
110
      if( objects[i].name().equals(name) ) return i;
111
      }
112

    
113
    return -1;
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  public static int getNumScramble(int ordinal)
119
    {
120
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal].mNumScrambles : 0;
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
  ObjectType(int size, int scrambles, int sIcon, int mIcon, int bIcon, int hIcon)
126
    {
127
    mSize        = size;
128
    mNumScrambles= scrambles;
129
    mSmallIcon   = sIcon;
130
    mMediumIcon  = mIcon;
131
    mBigIcon     = bIcon;
132
    mHugeIcon    = hIcon;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  public int getIconID(int size)
138
    {
139
    switch(size)
140
      {
141
      case 0: return mSmallIcon;
142
      case 1: return mMediumIcon;
143
      case 2: return mBigIcon;
144
      case 3: return mHugeIcon;
145
      }
146

    
147
    return mSmallIcon;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  public TwistyObject create(Static4D quat, Resources res, int scrWidth)
153
    {
154
    DistortedTexture texture = new DistortedTexture();
155
    DistortedEffects effects = new DistortedEffects();
156
    MeshSquare mesh          = new MeshSquare(20,20);   // mesh of the node, not of the cubits
157

    
158
    int ord = ordinal();
159
    int size= objects[ord].mSize;
160

    
161
    switch(ord)
162
      {
163
      case  0:
164
      case  1:
165
      case  2:
166
      case  3: return new TwistyCube          (size, quat, texture, mesh, effects, res, scrWidth);
167
      case  4: return new TwistyJing          (size, quat, texture, mesh, effects, res, scrWidth);
168
      case  5:
169
      case  6:
170
      case  7: return new TwistyPyraminx      (size, quat, texture, mesh, effects, res, scrWidth);
171
      case  8:
172
      case  9: return new TwistyKilominx      (size, quat, texture, mesh, effects, res, scrWidth);
173
      case 10:
174
      case 11: return new TwistyMegaminx      (size, quat, texture, mesh, effects, res, scrWidth);
175
      case 12: return new TwistyUltimate      (size, quat, texture, mesh, effects, res, scrWidth);
176
      case 13:
177
      case 14:
178
      case 15: return new TwistyDiamond       (size, quat, texture, mesh, effects, res, scrWidth);
179
      case 16: return new TwistyDino6         (size, quat, texture, mesh, effects, res, scrWidth);
180
      case 17: return new TwistyDino4         (size, quat, texture, mesh, effects, res, scrWidth);
181
      case 18: return new TwistyRedi          (size, quat, texture, mesh, effects, res, scrWidth);
182
      case 19: return new TwistyHelicopter    (size, quat, texture, mesh, effects, res, scrWidth);
183
      case 20:
184
      case 21: return new TwistySkewb         (size, quat, texture, mesh, effects, res, scrWidth);
185
      case 22: return new TwistyIvy           (size, quat, texture, mesh, effects, res, scrWidth);
186
      case 23: return new TwistyRex           (size, quat, texture, mesh, effects, res, scrWidth);
187
      case 24: return new TwistyBandagedFused (size, quat, texture, mesh, effects, res, scrWidth);
188
      case 25: return new TwistyBandaged2Bar  (size, quat, texture, mesh, effects, res, scrWidth);
189
      case 26: return new TwistyBandaged3Plate(size, quat, texture, mesh, effects, res, scrWidth);
190
      case 27: return new TwistyBandagedEvil  (size, quat, texture, mesh, effects, res, scrWidth);
191
      case 28: return new TwistySquare1       (size, quat, texture, mesh, effects, res, scrWidth);
192
      case 29: return new TwistySquare2       (size, quat, texture, mesh, effects, res, scrWidth);
193
      case 30:
194
      case 31: return new TwistyMirror        (size, quat, texture, mesh, effects, res, scrWidth);
195
      }
196

    
197
    return null;
198
    }
199
  }
(9-9/15)