Project

General

Profile

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

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

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

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

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

    
77
  private static final ObjectType[] objects;
78

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

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

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

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

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

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

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

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

    
114
    return -1;
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

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

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

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

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

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

    
148
    return mSmallIcon;
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

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

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

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

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