Project

General

Profile

Download (5.76 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / object / RubikObjectList.java @ 4888e97c

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.object;
21

    
22
import org.distorted.library.main.DistortedEffects;
23
import org.distorted.library.main.DistortedTexture;
24
import org.distorted.library.mesh.MeshRectangles;
25
import org.distorted.library.type.Static4D;
26
import org.distorted.magic.R;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public enum RubikObjectList
31
  {
32
  CUBE     ( new int[] {2,3,4},
33
             new int[] {R.drawable.cube2,R.drawable.cube3,R.drawable.cube4},
34
             new RubikCubeMovement() ),
35
  PYRAMINX ( new int[] {3,4},
36
             new int[] {R.drawable.pyra3,R.drawable.pyra4},
37
             new RubikPyraminxMovement() ),
38
  ;
39

    
40
  public static final int NUM_OBJECTS = values().length;
41
  public static final int MAX_SIZE;
42

    
43
  private final int[] mObjectSizes, mIconIDs;
44
  final RubikObjectMovement mObjectMovementClass;
45
  private static final RubikObjectList[] objects;
46
  private static int mNumAll;
47

    
48
  static
49
    {
50
    mNumAll = 0;
51
    int size, i = 0;
52
    objects = new RubikObjectList[NUM_OBJECTS];
53
    int maxsize = Integer.MIN_VALUE;
54

    
55
    for(RubikObjectList object: RubikObjectList.values())
56
      {
57
      objects[i] = object;
58
      i++;
59
      size = object.mObjectSizes.length;
60
      mNumAll += size;
61
      if( size> maxsize ) maxsize = size;
62
      }
63

    
64
    MAX_SIZE = maxsize;
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  public static RubikObjectList getObject(int ordinal)
70
    {
71
    return objects[ordinal];
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  public static int pack(int object, int size)
77
    {
78
    int ret = 0;
79
    for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length;
80

    
81
    return ret+size;
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  public static int unpackSize(int number)
87
    {
88
    int num;
89

    
90
    for(int i=0; i<NUM_OBJECTS; i++)
91
      {
92
      num = objects[i].mObjectSizes.length;
93
      if( number<num ) return number;
94
      number -= num;
95
      }
96

    
97
    return -1;
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
  public static int unpackObject(int number)
103
    {
104
    int num;
105

    
106
    for(int i=0; i<NUM_OBJECTS; i++)
107
      {
108
      num = objects[i].mObjectSizes.length;
109
      if( number<num ) return i;
110
      number -= num;
111
      }
112

    
113
    return -1;
114
    }
115

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

    
118
  public static int getTotal()
119
    {
120
    return mNumAll;
121
    }
122

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

    
125
  RubikObjectList(int[] sizes, int[] iconIDs, RubikObjectMovement movement)
126
    {
127
    mObjectSizes= sizes;
128
    mIconIDs    = iconIDs;
129
    mObjectMovementClass = movement;
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  public int[] getIconIDs()
135
    {
136
    return mIconIDs;
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  public int[] getSizes()
142
    {
143
    return mObjectSizes;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  public RubikObject create(int size, Static4D quatCur, Static4D quatAcc)
149
    {
150
    DistortedTexture texture = new DistortedTexture();
151
    DistortedEffects effects = new DistortedEffects();
152
    MeshRectangles mesh      = new MeshRectangles(20,20);   // mesh of the node, not of the cubits
153

    
154
    switch(ordinal())
155
      {
156
      case 0: return new RubikCube    (size, quatCur, quatAcc, texture, mesh, effects);
157
      case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects);
158
      }
159

    
160
    return null;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  public RubikObjectMovement getObjectMovementClass()
166
    {
167
    return mObjectMovementClass;
168
    }
169
  }
(5-5/8)