Project

General

Profile

« Previous | Next » 

Revision a7d8c3cd

Added by Leszek Koltunski about 3 years ago

Progress replacing the enum ObjetType with the class RubikObjectList.

View differences:

src/main/java/org/distorted/config/ConfigScreen.java
33 33
import android.widget.TextView;
34 34

  
35 35
import org.distorted.objectlib.main.ObjectControl;
36
import org.distorted.objectlib.main.ObjectType;
37 36

  
38 37
import org.distorted.helpers.TransparentImageButton;
39 38
import org.distorted.main.R;
40 39
import org.distorted.main.RubikActivity;
40
import org.distorted.objects.RubikObject;
41
import org.distorted.objects.RubikObjectList;
41 42

  
42 43
import static android.view.View.inflate;
43
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
44 44

  
45 45
///////////////////////////////////////////////////////////////////////////////////////////////////
46 46

  
......
97 97
      colSpecs[col] = GridLayout.spec(col);
98 98
      }
99 99

  
100
    for(int object = 0; object< NUM_OBJECTS; object++)
100
    int numObjects = RubikObjectList.getNumObjects();
101

  
102
    for(int object=0; object<numObjects; object++)
101 103
      {
102 104
      final int ordinal = object;
103
      ObjectType type = ObjectType.getObject(ordinal);
105
      RubikObject rubikObject = RubikObjectList.getObject(ordinal);
104 106
      int iconSize = RubikActivity.getDrawableSize();
105
      int icons = type.getIconID(iconSize);
107
      int icons = rubikObject.getIconID(iconSize);
106 108
      int row = object/NUM_COLUMNS;
107 109

  
108 110
      ImageButton button = new ImageButton(act);
......
115 117
          if( act.getControl().isUINotBlocked() && mObjectOrdinal!=ordinal )
116 118
            {
117 119
            mObjectOrdinal = ordinal;
118
            act.changeObject(type);
119
            mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,NUM_OBJECTS));
120
            act.changeObject(rubikObject);
121
            mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,numObjects));
120 122
            mPane.updatePane(act,mObjectOrdinal);
121 123
            }
122 124

  
......
234 236

  
235 237
///////////////////////////////////////////////////////////////////////////////////////////////////
236 238

  
237
  private void prevObject(ConfigActivity act)
239
  private void prevObject(ConfigActivity act, int numObjects)
238 240
    {
239 241
    mObjectOrdinal--;
240
    if( mObjectOrdinal<0 ) mObjectOrdinal=NUM_OBJECTS-1;
242
    if( mObjectOrdinal<0 ) mObjectOrdinal=numObjects-1;
241 243

  
242
    ObjectType type = ObjectType.getObject(mObjectOrdinal);
243
    act.changeObject(type);
244
    RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
245
    act.changeObject(object);
244 246

  
245 247
    mPane.updatePane(act,mObjectOrdinal);
246 248
    }
247 249

  
248 250
///////////////////////////////////////////////////////////////////////////////////////////////////
249 251

  
250
  private void nextObject(ConfigActivity act)
252
  private void nextObject(ConfigActivity act, int numObjects)
251 253
    {
252 254
    mObjectOrdinal++;
253
    if( mObjectOrdinal>=NUM_OBJECTS ) mObjectOrdinal=0;
255
    if( mObjectOrdinal>=numObjects ) mObjectOrdinal=0;
254 256

  
255
    ObjectType type = ObjectType.getObject(mObjectOrdinal);
256
    act.changeObject(type);
257
    RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
258
    act.changeObject(object);
257 259

  
258 260
    mPane.updatePane(act,mObjectOrdinal);
259 261
    }
......
271 273
      @Override
272 274
      public void onClick(View v)
273 275
        {
274
        prevObject(act);
275
        mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,NUM_OBJECTS));
276
        int numObjects = RubikObjectList.getNumObjects();
277
        prevObject(act,numObjects);
278
        mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,numObjects));
276 279
        }
277 280
      });
278 281
    }
......
290 293
      @Override
291 294
      public void onClick(View v)
292 295
        {
293
        nextObject(act);
294
        mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,NUM_OBJECTS));
296
        int numObjects = RubikObjectList.getNumObjects();
297
        nextObject(act,numObjects);
298
        mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,numObjects));
295 299
        }
296 300
      });
297 301
    }
298 302

  
299 303
///////////////////////////////////////////////////////////////////////////////////////////////////
300 304

  
301
  private void setupTextView(final ConfigActivity act, final float width)
305
  private void setupTextView(final ConfigActivity act, final float width, int numObjects)
302 306
    {
303 307
    int padding = (int)(width*RubikActivity.PADDING);
304 308
    int margin  = (int)(width*RubikActivity.MARGIN);
......
314 318
    mMovesText.setPadding(padding,0,padding,0);
315 319
    mMovesText.setGravity(Gravity.CENTER);
316 320
    mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
317
    mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,NUM_OBJECTS));
321
    mMovesText.setText(act.getString(R.string.mo_placeholder,mObjectOrdinal+1,numObjects));
318 322
    }
319 323

  
320 324
///////////////////////////////////////////////////////////////////////////////////////////////////
321 325

  
322 326
  void onAttachedToWindow(final ConfigActivity act, final int objectOrdinal)
323 327
    {
328
    int numObjects = RubikObjectList.getNumObjects();
324 329
    int width = act.getScreenWidthInPixels();
325 330
    mBarHeight = act.getHeightBar();
326 331
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
327 332

  
328
    mRowCount = (NUM_OBJECTS + NUM_COLUMNS-1) / NUM_COLUMNS;
333
    mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
329 334
    mColCount = NUM_COLUMNS;
330 335

  
331 336
    mObjectOrdinal = objectOrdinal;
......
344 349
    setupObjectButton(act,width);
345 350
    setupPrevButton(act);
346 351
    setupNextButton(act);
347
    setupTextView(act,width);
352
    setupTextView(act,width,numObjects);
348 353
    setupBackButton(act);
349 354

  
350 355
    layoutLeft.addView(mObjectButton);
src/main/java/org/distorted/config/ConfigScreenPane.java
24 24
import android.widget.LinearLayout;
25 25
import android.widget.RadioButton;
26 26
import android.widget.RadioGroup;
27
import android.widget.RelativeLayout;
28 27
import android.widget.TextView;
29 28

  
30 29
import org.distorted.jsons.ObjectJson;
31 30
import org.distorted.main.R;
32 31
import org.distorted.objectlib.json.JsonReader;
33
import org.distorted.objectlib.main.ObjectType;
32
import org.distorted.objects.RubikObject;
33
import org.distorted.objects.RubikObjectList;
34 34

  
35 35
import java.io.InputStream;
36 36

  
......
90 90

  
91 91
    mObjectOrdinal = objectOrdinal;
92 92

  
93
    ObjectType type = ObjectType.getObject(objectOrdinal);
94
    InputStream stream = ObjectJson.getStream(type,act);
93
    RubikObject object = RubikObjectList.getObject(objectOrdinal);
94
    int jsonID = object.getJsonID();
95
    InputStream stream = ObjectJson.getStream(jsonID,act);
95 96
    mReader.parseJsonFileMetadata(stream);
96 97

  
97 98
    String name = mReader.getObjectName();
src/main/java/org/distorted/network/RubikNetwork.java
34 34
import androidx.fragment.app.FragmentActivity;
35 35

  
36 36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.objectlib.main.ObjectType;
37
import org.distorted.objects.RubikObject;
38
import org.distorted.objects.RubikObjectList;
38 39

  
39 40
import static org.distorted.screens.RubikScreenPlay.MAX_LEVEL;
40
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
41 41

  
42 42
///////////////////////////////////////////////////////////////////////////////////////////////////
43 43

  
......
108 108
  private static int mMode = IDLE;
109 109
  private static Receiver mReceiver;
110 110
  private static String mVersion;
111
  private static int mNumObjects;
111 112

  
112 113
///////////////////////////////////////////////////////////////////////////////////////////////////
113 114

  
114 115
  private static void initializeStatics()
115 116
    {
116
    if( mCountry==null ) mCountry = new String[NUM_OBJECTS][MAX_LEVEL][MAX_PLACES];
117
    if( mName==null    ) mName    = new String[NUM_OBJECTS][MAX_LEVEL][MAX_PLACES];
118
    if( mTime==null    ) mTime    = new  float[NUM_OBJECTS][MAX_LEVEL][MAX_PLACES];
119
    if( mPlaces==null  ) mPlaces  = new int[NUM_OBJECTS][MAX_LEVEL];
117
    int newNum = RubikObjectList.getNumObjects();
118

  
119
    if( mCountry==null || newNum!=mNumObjects ) mCountry = new String[newNum][MAX_LEVEL][MAX_PLACES];
120
    if( mName==null    || newNum!=mNumObjects ) mName    = new String[newNum][MAX_LEVEL][MAX_PLACES];
121
    if( mTime==null    || newNum!=mNumObjects ) mTime    = new  float[newNum][MAX_LEVEL][MAX_PLACES];
122
    if( mPlaces==null  || newNum!=mNumObjects ) mPlaces  = new int[newNum][MAX_LEVEL];
123

  
124
    mNumObjects = newNum;
120 125
    }
121 126

  
122 127
///////////////////////////////////////////////////////////////////////////////////////////////////
......
165 170
      return false;
166 171
      }
167 172

  
168
    for(int i=0; i<NUM_OBJECTS; i++)
173
    for(int i=0; i<mNumObjects; i++)
169 174
      for(int j=0; j<MAX_LEVEL; j++)
170 175
        {
171 176
        mPlaces[i][j] = 0;
......
204 209

  
205 210
    if( s5>s4 && s4>s3 && s3>s2 && s2>s1 && s1>0 )
206 211
      {
207
      int object = ObjectType.getOrdinal( row.substring(0,s1) );
212
      int object = RubikObjectList.getOrdinal( row.substring(0,s1) );
208 213

  
209
      if( object>=0 && object<NUM_OBJECTS )
214
      if( object>=0 && object<mNumObjects )
210 215
        {
211 216
        int level      = Integer.parseInt( row.substring(s1+1,s2) );
212 217
        String name    = row.substring(s2+1, s3);
......
463 468
  private static String getObjectList()
464 469
    {
465 470
    StringBuilder list = new StringBuilder();
466
    ObjectType[] objects = ObjectType.values();
467 471

  
468
    for(int i=0; i<NUM_OBJECTS; i++)
472
    for(int i=0; i<mNumObjects; i++)
469 473
      {
470
      if( i>0 ) list.append(',');
471
      list.append(objects[i].name());
474
      RubikObject object = RubikObjectList.getObject(i);
475

  
476
      if( object!=null )
477
        {
478
        if( i>0 ) list.append(',');
479
        list.append(object.getName());
480
        }
472 481
      }
473 482

  
474 483
    return list.toString();
src/main/java/org/distorted/network/RubikScores.java
19 19

  
20 20
package org.distorted.network;
21 21

  
22
import java.util.HashMap;
22 23
import java.util.UUID;
23 24

  
24 25
import android.content.Context;
......
27 28

  
28 29
import com.google.firebase.crashlytics.FirebaseCrashlytics;
29 30

  
30
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
31 31
import static org.distorted.screens.RubikScreenPlay.MAX_LEVEL;
32

  
33
import org.distorted.objectlib.main.ObjectType;
34

  
35 32
import org.distorted.main.BuildConfig;
33
import org.distorted.objects.RubikObject;
34
import org.distorted.objects.RubikObjectList;
36 35

  
37 36
///////////////////////////////////////////////////////////////////////////////////////////////////
38 37
// hold my own scores, and some other statistics.
39 38

  
40 39
public class RubikScores
41 40
  {
41
  public static final int MULT = 1000000;
42 42
  public static final long NO_RECORD = Long.MAX_VALUE;
43 43
  private static RubikScores mThis;
44 44

  
45
  private final long[][] mRecords;
46
  private final int [][] mSubmitted;
47

  
48 45
  private String mName, mCountry;
49 46
  private boolean mNameIsVerified;
50 47
  private int mNumRuns;
......
52 49
  private int mNumWins;
53 50
  private int mDeviceID;
54 51

  
52
  private static class MapValue
53
    {
54
    long record;
55
    boolean submitted;
56

  
57
    MapValue(long rec,int sub)
58
      {
59
      record    = rec;
60
      submitted = sub!=0;
61
      }
62
    }
63

  
64
  private final HashMap<Integer,MapValue> mMap;
65

  
55 66
///////////////////////////////////////////////////////////////////////////////////////////////////
56 67

  
57 68
  private RubikScores()
58 69
    {
59
    mRecords   = new long[NUM_OBJECTS][MAX_LEVEL];
60
    mSubmitted = new int [NUM_OBJECTS][MAX_LEVEL];
61

  
62
    for(int object=0; object<NUM_OBJECTS; object++)
63
      for(int level=0; level<MAX_LEVEL; level++)
64
        {
65
        mRecords[object][level]   = NO_RECORD;
66
        mSubmitted[object][level] = 0;
67
        }
70
    mMap = new HashMap<>();
68 71

  
69 72
    mName = "";
70 73
    mCountry = "un";
......
77 80
    mNumWins =  0;
78 81
    }
79 82

  
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

  
85
  private int mapKey(int object,int level)
86
    {
87
    return object*MULT + level;
88
    }
89

  
80 90
///////////////////////////////////////////////////////////////////////////////////////////////////
81 91

  
82 92
  private int privateGetDeviceID()
......
103 113
    {
104 114
    mNameIsVerified = true;
105 115

  
106
    for(int object=0; object<NUM_OBJECTS; object++)
107
      for(int level=0; level<MAX_LEVEL; level++)
108
        {
109
        mSubmitted[object][level]=1;
110
        }
116
    for(int key: mMap.keySet())
117
      {
118
      MapValue value = mMap.get(key);
119
      if( value!=null ) value.submitted = true;
120
      }
111 121
    }
112 122

  
113 123
///////////////////////////////////////////////////////////////////////////////////////////////////
......
121 131

  
122 132
  synchronized boolean thereAreUnsubmittedRecords()
123 133
    {
124
    for(int object=0; object<NUM_OBJECTS; object++)
125
      for(int level=0; level<MAX_LEVEL; level++)
126
        {
127
        if( mSubmitted[object][level]==0 && mRecords[object][level]<NO_RECORD ) return true;
128
        }
134
    for(int key: mMap.keySet())
135
      {
136
      MapValue value = mMap.get(key);
137
      if( value!=null && !value.submitted && value.record<NO_RECORD) return true;
138
      }
129 139

  
130 140
    return false;
131 141
    }
......
139 149
    StringBuilder builderTim = new StringBuilder();
140 150
    boolean first = true;
141 151

  
142
    for(int object=0; object<NUM_OBJECTS; object++)
152
    for(int key: mMap.keySet())
143 153
      {
144
      String name = ObjectType.getObject(object).name();
154
      MapValue value = mMap.get(key);
145 155

  
146
      for(int level=0; level<MAX_LEVEL; level++)
156
      if( value!=null && !value.submitted && value.record<NO_RECORD)
147 157
        {
148
        if( mSubmitted[object][level]==0 && mRecords[object][level]<NO_RECORD )
158
        if( !first )
149 159
          {
150
          if( !first )
151
            {
152
            builderObj.append(',');
153
            builderLvl.append(',');
154
            builderTim.append(',');
155
            }
156
          first=false;
160
          builderObj.append(',');
161
          builderLvl.append(',');
162
          builderTim.append(',');
163
          }
164
        first=false;
157 165

  
158
          builderObj.append(name);
159
          builderLvl.append(level);
160
          builderTim.append(mRecords[object][level]);
166
        RubikObject object = RubikObjectList.getObject(key/MULT);
167

  
168
        if( object!=null )
169
          {
170
          builderObj.append(object.getName());
171
          builderLvl.append(key%MULT);
172
          builderTim.append(value.record);
161 173
          }
162 174
        }
163 175
      }
......
167 179

  
168 180
///////////////////////////////////////////////////////////////////////////////////////////////////
169 181
// Public API
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

  
172
  public synchronized long getRecord(int obj, int level)
173
    {
174
    return (obj>=0 && obj<NUM_OBJECTS && level>=0 && level<MAX_LEVEL) ? mRecords[obj][level] : -1;
175
    }
176

  
177 182
///////////////////////////////////////////////////////////////////////////////////////////////////
178 183

  
179 184
  public boolean isVerified()
......
240 245

  
241 246
///////////////////////////////////////////////////////////////////////////////////////////////////
242 247

  
243
  public synchronized boolean isSolved(int obj, int level)
248
  public synchronized boolean setRecord(int object, int level, long record)
249
    {
250
    int key = mapKey(object,level)-1; // -1 - historical reasons; previous versions saved it like this.
251
    MapValue oldValue = mMap.get(key);
252

  
253
    if( oldValue==null )
254
      {
255
      MapValue value = new MapValue(record,0);
256
      mMap.put(key,value);
257
      return true;
258
      }
259

  
260
    long oldRecord = oldValue.record;
261

  
262
    if( oldRecord>record)
263
      {
264
      MapValue value = new MapValue(record,0);
265
      mMap.put(key,value);
266
      return true;
267
      }
268

  
269
    return false;
270
    }
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272

  
273
  public synchronized long getRecord(int object, int level)
274
    {
275
    int key = mapKey(object,level);
276
    MapValue value = mMap.get(key);
277
    return value!=null ? value.record : NO_RECORD;
278
    }
279

  
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

  
282
  public synchronized boolean isSolved(int object, int level)
244 283
    {
245
    return obj>=0 && obj<NUM_OBJECTS && level>=0 && level<MAX_LEVEL && mRecords[obj][level]<NO_RECORD;
284
    int key = mapKey(object,level);
285
    MapValue value = mMap.get(key);
286
    return value!=null && value.record<NO_RECORD;
246 287
    }
247 288

  
248 289
///////////////////////////////////////////////////////////////////////////////////////////////////
......
289 330

  
290 331
  public synchronized void savePreferences(SharedPreferences.Editor editor)
291 332
    {
333
    int numObjects = RubikObjectList.getNumObjects();
292 334
    StringBuilder builder = new StringBuilder();
293
    String name;
294 335

  
295 336
    for(int level=0; level<MAX_LEVEL; level++)
296 337
      {
297 338
      builder.setLength(0);
298 339

  
299
      for(int object=0; object<NUM_OBJECTS; object++)
340
      for(int object=0; object<numObjects; object++)
300 341
        {
301
        name = ObjectType.getObject(object).name();
302
        builder.append(name);
303
        builder.append("=");
304
        builder.append(mRecords[object][level]);
305
        builder.append(",");
306
        builder.append(mSubmitted[object][level]);
307
        builder.append(" ");
342
        int key = mapKey(object,level);
343
        RubikObject obj = RubikObjectList.getObject(object);
344
        MapValue value = mMap.get(key);
345

  
346
        if( obj!=null && value!=null && value.record<NO_RECORD )
347
          {
348
          builder.append(obj.getName());
349
          builder.append("=");
350
          builder.append(value.record);
351
          builder.append(",");
352
          builder.append(value.submitted ? 1:0 );
353
          builder.append(" ");
354
          }
308 355
        }
309 356

  
310 357
      editor.putString("scores_record"+level, builder.toString());
......
326 373
    int start, end, equals, comma, object, subm;
327 374
    long time;
328 375
    boolean thereWasError = false;
376
    int numObjects = RubikObjectList.getNumObjects();
329 377

  
330 378
    for(int level=0; level<MAX_LEVEL; level++)
331 379
      {
......
350 398
          timeStr = subStr.substring(equals+1,comma);
351 399
          submStr = subStr.substring(comma+1);
352 400

  
353
          object = ObjectType.getOrdinal(nameStr);
401
          object = RubikObjectList.getOrdinal(nameStr);
354 402

  
355
          if( object>=0 && object< NUM_OBJECTS )
403
          if( object>=0 && object<numObjects )
356 404
            {
357 405
            time = Long.parseLong(timeStr);
358 406
            subm = Integer.parseInt(submStr);
359 407

  
360 408
            if( subm>=0 && subm<=1 )
361 409
              {
362
              mRecords  [object][level] = time;
363
              mSubmitted[object][level] = subm;
410
              MapValue value = new MapValue(time,subm);
411
              int key = mapKey(object,level);
412
              mMap.put(key,value);
364 413
              }
365 414
            else
366 415
              {
......
405 454
      crashlytics.recordException(ex);
406 455
      }
407 456
    }
408

  
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

  
411
  public synchronized boolean setRecord(int object, int level, long timeTaken)
412
    {
413
    if( object>=0 && object<NUM_OBJECTS && level>=1 && level<=MAX_LEVEL && mRecords[object][level-1]>timeTaken )
414
      {
415
      mRecords  [object][level-1] = timeTaken;
416
      mSubmitted[object][level-1] = 0;
417
      return true;
418
      }
419

  
420
    return false;
421
    }
422 457
  }
src/main/java/org/distorted/objects/RubikObject.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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.objects;
21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
import org.distorted.dmesh.ObjectMesh;
25
import org.distorted.jsons.ObjectJson;
26
import org.distorted.objectlib.main.ObjectType;
27
import org.distorted.patterns.RubikPatternList;
28

  
29
public class RubikObject
30
{
31
  private static final int NUM = 4;
32

  
33
  private final String mName;
34
  private final int mNumScramble;
35
  private final int mOrdinal;
36
  private final int mJsonID, mMeshID;
37
  private final int[] mIconID;
38
  private final String[][] mPatterns;
39

  
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

  
42
  RubikObject(int ordinal, ObjectType type)
43
    {
44
    mIconID = new int[NUM];
45
    for(int i=0; i<NUM; i++) mIconID[i] = type.getIconID(i);
46

  
47
    mName        = type.name();
48
    mNumScramble = type.getNumScramble();
49
    mOrdinal     = ordinal;
50
    mJsonID      = ObjectJson.getJsonID(type);
51
    mMeshID      = ObjectMesh.getMeshID(type);
52

  
53
    int patternOrdinal  = RubikPatternList.getOrdinal(type);
54
    mPatterns = RubikPatternList.getPatterns(patternOrdinal);
55
    }
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
// PUBLIC API
59

  
60
  public String getName()
61
    {
62
    return mName;
63
    }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  public int getIconID(int size)
68
    {
69
    return size>=0 && size<NUM ? mIconID[size] : 0;
70
    }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
  public int getNumScramble()
75
    {
76
    return mNumScramble;
77
    }
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

  
81
  public int getOrdinal()
82
    {
83
    return mOrdinal;
84
    }
85

  
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

  
88
  public int getJsonID()
89
    {
90
    return mJsonID;
91
    }
92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

  
95
  public int getMeshID()
96
    {
97
    return mMeshID;
98
    }
99

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

  
102
  public String[][] getPatterns()
103
    {
104
    return mPatterns;
105
    }
106
}
src/main/java/org/distorted/objects/RubikObjectList.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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.objects;
21

  
22
import org.distorted.objectlib.main.ObjectType;
23

  
24
import java.util.ArrayList;
25
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
public class RubikObjectList
30
{
31
  private static RubikObjectList mType;
32
  private static int mNumObjects;
33
  private static ArrayList<RubikObject> mObjects;
34

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
  private RubikObjectList()
38
    {
39
    mNumObjects = 0;
40
    mObjects = new ArrayList<>();
41

  
42
    createBuiltinObjects();
43
    }
44

  
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

  
47
  private void createBuiltinObjects()
48
    {
49
    for(int i=0; i<NUM_OBJECTS; i++)
50
      {
51
      ObjectType type = ObjectType.getObject(i);
52
      RubikObject obj = new RubikObject(i,type);
53
      mObjects.add(obj);
54
      mNumObjects++;
55
      }
56
    }
57

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59
// PUBLIC API
60

  
61
  public static RubikObject getObject(int ordinal)
62
    {
63
    if( mType==null ) mType = new RubikObjectList();
64
    return ordinal>=0 && ordinal<mNumObjects ? mObjects.get(ordinal) : null;
65
    }
66

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

  
69
  public static int getNumObjects()
70
    {
71
    if( mType==null ) mType = new RubikObjectList();
72
    return mNumObjects;
73
    }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

  
77
  public static int getOrdinal(String name)
78
    {
79
    if( mType==null ) mType = new RubikObjectList();
80

  
81
    for(int i=0; i<mNumObjects; i++)
82
      {
83
      RubikObject obj = mObjects.get(i);
84

  
85
      if( obj.getName().equals(name) ) return i;
86
      }
87

  
88
    return -1;
89
    }
90
}
src/main/java/org/distorted/patterns/RubikPatternList.java
55 55

  
56 56
///////////////////////////////////////////////////////////////////////////////////////////////////
57 57

  
58
  static String[][] getPatterns(int ordinal)
58
  public static String[][] getPatterns(int ordinal)
59 59
    {
60
    return objects[ordinal].mPatterns;
60
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal].mPatterns : null;
61 61
    }
62 62

  
63 63
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff