Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / RubikObject.java @ 314e9ff0

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 java.io.InputStream;
23

    
24
import android.app.Activity;
25
import android.content.res.Resources;
26
import android.widget.ImageButton;
27
import android.widget.ImageView;
28

    
29
import org.distorted.dmesh.ObjectMesh;
30
import org.distorted.jsons.ObjectJson;
31
import org.distorted.objectlib.json.JsonWriter;
32
import org.distorted.objectlib.main.ObjectType;
33
import org.distorted.patterns.RubikPatternList;
34

    
35
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
public class RubikObject
40
{
41
  private final String mName;
42
  private final int mNumScramble;
43
  private final int mOrdinal;
44
  private final int mJsonID, mMeshID, mExtrasID;
45
  private final int mIconID;
46
  private final String[][] mPatterns;
47
  private final int mObjectMinor, mExtrasMinor;
48

    
49
  private int mMeshState;
50
  private int mExtrasOrdinal;
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  RubikObject(ObjectType type)
55
    {
56
    mName        = type.name();
57
    mNumScramble = type.getNumScramble();
58
    mOrdinal     = type.ordinal();
59

    
60
    mIconID      = type.getIconID();
61
    mJsonID      = ObjectJson.getObjectJsonID(mOrdinal);
62
    mMeshID      = ObjectMesh.getMeshID(mOrdinal);
63
    mExtrasID    = ObjectJson.getExtrasJsonID(mOrdinal);
64

    
65
    int patternOrdinal  = RubikPatternList.getOrdinal(mOrdinal);
66
    mPatterns = RubikPatternList.getPatterns(patternOrdinal);
67

    
68
    mMeshState = MESH_NICE;
69
    mExtrasOrdinal = -1;
70

    
71
    mObjectMinor = JsonWriter.VERSION_OBJECT_MINOR;
72
    mExtrasMinor = JsonWriter.VERSION_EXTRAS_MINOR;
73
    }
74
/*
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  RubikObject(RubikObjectList.DownloadedObject object)
78
    {
79
    mName = object.shortName;
80

    
81
    mNumScramble = type.getNumScramble();
82
    mOrdinal     = type.ordinal();
83

    
84
    mObjectMinor = ?
85
    mExtrasMinor = ?
86

    
87
    mIconID      = type.getIconID();
88
    mJsonID      = ObjectJson.getObjectJsonID(mOrdinal);
89
    mExtrasID    = ObjectJson.getExtrasJsonID(mOrdinal);
90

    
91
    mMeshID   = 0;
92
    mPatterns = null;
93

    
94
    mMeshState = MESH_NICE;
95
    mExtrasOrdinal = -1;
96
    }
97

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

    
100
  public void updateObject(RubikObjectList.DownloadedObject object)
101
    {
102

    
103
    }
104
*/
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  public void setExtrasOrdinal(int ordinal)
108
    {
109
    mExtrasOrdinal = ordinal;
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  public int getExtrasOrdinal()
115
    {
116
    return mExtrasOrdinal;
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  public void setMeshState(int state)
122
    {
123
    mMeshState = state;
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  public int getMeshState()
129
    {
130
    return mMeshState;
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
// PUBLIC API
135

    
136
  public String getName()
137
    {
138
    return mName;
139
    }
140

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

    
143
  public int getNumScramble()
144
    {
145
    return mNumScramble;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  public int getOrdinal()
151
    {
152
    return mOrdinal;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public void setIconTo(ImageButton button)
158
    {
159
    button.setBackgroundResource(mIconID);
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  public void setIconTo(ImageView view)
165
    {
166
    view.setImageResource(mIconID);
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  public InputStream getObjectStream(Activity act)
172
    {
173
    if( mJsonID!=0 )
174
      {
175
      Resources res = act.getResources();
176
      return res.openRawResource(mJsonID);
177
      }
178
    return null;
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  public InputStream getMeshStream(Activity act)
184
    {
185
    if( mMeshID!=0 )
186
      {
187
      Resources res = act.getResources();
188
      return res.openRawResource(mMeshID);
189
      }
190
    return null;
191
    }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

    
195
  public InputStream getExtrasStream(Activity act)
196
    {
197
    if( mExtrasID!=0 )
198
      {
199
      Resources res = act.getResources();
200
      return res.openRawResource(mExtrasID);
201
      }
202
    return null;
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

    
207
  public boolean hasExtras()
208
    {
209
    return mExtrasID!=0;
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  public String[][] getPatterns()
215
    {
216
    return mPatterns;
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  public int getObjectMinor()
222
    {
223
    return mObjectMinor;
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
  public int getExtrasMinor()
229
    {
230
    return mExtrasMinor;
231
    }
232
}
(1-1/2)