Project

General

Profile

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

magiccube / src / main / java / org / distorted / magic / RubikSettingsEnum.java @ ce0c7ca8

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.magic;
21

    
22
import android.content.SharedPreferences;
23

    
24
import org.distorted.effect.ScrambleEffect;
25
import org.distorted.effect.SizeChangeEffect;
26
import org.distorted.effect.SolveEffect;
27

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

    
30
enum RubikSettingsEnum
31
  {
32
  SIZECHANGE  (  20, 1, R.string.sizechange_effect),
33
  SOLVE       (  20, 1, R.string.solve_effect      ),
34
  SCRAMBLE    ( 100, 1, R.string.scramble_effect   );
35

    
36
  public static final int LENGTH = values().length;
37
  private final int mDefaultPos, mDefaultType;
38
  private int mCurrentPos, mCurrentType;
39
  private int mText;
40

    
41
  private static final RubikSettingsEnum[] enums;  // copy the values() to a local variable so that we
42
                                                   // don't have to keep recreating the array every time
43
  static
44
    {
45
    int i=0;
46

    
47
    enums= new RubikSettingsEnum[LENGTH];
48

    
49
    for(RubikSettingsEnum name: RubikSettingsEnum.values())
50
      {
51
      enums[i] = name;
52
      i++;
53
      }
54
    }
55

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

    
58
  RubikSettingsEnum( int dPos, int dType, int text )
59
    {
60
    mDefaultPos  = mCurrentPos = dPos;
61
    mDefaultType = mCurrentType= dType;
62
    mText        = text;
63
    }
64

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

    
67
  int getText()
68
    {
69
    return mText;
70
    }
71

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

    
74
  int getCurrentPos()
75
    {
76
    return mCurrentPos;
77
    }
78

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

    
81
  int getCurrentType()
82
    {
83
    return mCurrentType;
84
    }
85

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

    
88
  void setCurrentPos(int pos)
89
    {
90
    mCurrentPos = pos;
91
    }
92

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

    
95
  void setCurrentType(int type)
96
    {
97
    mCurrentType = type;
98
    }
99

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

    
102
  void savePreferences(SharedPreferences.Editor editor)
103
    {
104
    String name = name();
105

    
106
    editor.putInt(name+"_Pos" , mCurrentPos );
107
    editor.putInt(name+"_Type", mCurrentType);
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  void restorePreferences(SharedPreferences preferences)
113
    {
114
    String name = name();
115

    
116
    mCurrentPos  = preferences.getInt(name+"_Pos" , mDefaultPos );
117
    mCurrentType = preferences.getInt(name+"_Type", mDefaultType);
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  static RubikSettingsEnum getEnum(int ordinal)
123
    {
124
    return enums[ordinal];
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  static String[] getNames(int ordinal)
130
    {
131
    switch(ordinal)
132
      {
133
      case 0: return SizeChangeEffect.getNames();
134
      case 1: return SolveEffect.getNames();
135
      case 2: return ScrambleEffect.getNames();
136
      }
137

    
138
    return null;
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  static int translatePos(int pos)
144
     {
145
     return (pos/2)*100;
146
     }
147
  }
(6-6/7)