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.graphics.drawable.Drawable;
|
27
|
import android.widget.ImageButton;
|
28
|
import android.widget.ImageView;
|
29
|
|
30
|
import org.distorted.dmesh.ObjectMesh;
|
31
|
import org.distorted.jsons.ObjectJson;
|
32
|
import org.distorted.objectlib.json.JsonWriter;
|
33
|
import org.distorted.objectlib.main.ObjectType;
|
34
|
import org.distorted.patterns.RubikPatternList;
|
35
|
|
36
|
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
|
37
|
|
38
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39
|
|
40
|
public class RubikObject
|
41
|
{
|
42
|
private final String mName;
|
43
|
private final int mNumScramble;
|
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
|
private Drawable mIconD;
|
52
|
|
53
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
|
55
|
RubikObject(ObjectType type)
|
56
|
{
|
57
|
int ordinal= type.ordinal();
|
58
|
|
59
|
mName = type.name();
|
60
|
mNumScramble = type.getNumScramble();
|
61
|
|
62
|
mIconID = type.getIconID();
|
63
|
mJsonID = ObjectJson.getObjectJsonID(ordinal);
|
64
|
mMeshID = ObjectMesh.getMeshID(ordinal);
|
65
|
mExtrasID = ObjectJson.getExtrasJsonID(ordinal);
|
66
|
|
67
|
int patternOrdinal = RubikPatternList.getOrdinal(ordinal);
|
68
|
mPatterns = RubikPatternList.getPatterns(patternOrdinal);
|
69
|
|
70
|
mMeshState = MESH_NICE;
|
71
|
mExtrasOrdinal = -1;
|
72
|
|
73
|
mObjectMinor = JsonWriter.VERSION_OBJECT_MINOR;
|
74
|
mExtrasMinor = JsonWriter.VERSION_EXTRAS_MINOR;
|
75
|
|
76
|
mIconD = null;
|
77
|
}
|
78
|
/*
|
79
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80
|
|
81
|
RubikObject(RubikObjectList.DownloadedObject object)
|
82
|
{
|
83
|
mName = object.shortName;
|
84
|
mMeshID = 0;
|
85
|
mPatterns = null;
|
86
|
mMeshState = MESH_NICE;
|
87
|
mExtrasOrdinal = -1;
|
88
|
|
89
|
|
90
|
|
91
|
mNumScramble = type.getNumScramble();
|
92
|
mObjectMinor = ?
|
93
|
mExtrasMinor = ?
|
94
|
mIconID = type.getIconID();
|
95
|
mJsonID = ObjectJson.getObjectJsonID(mOrdinal);
|
96
|
mExtrasID = ObjectJson.getExtrasJsonID(mOrdinal);
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
|
101
|
public void updateObject(RubikObjectList.DownloadedObject object)
|
102
|
{
|
103
|
|
104
|
}
|
105
|
*/
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
private void createIconDrawable(Activity act)
|
109
|
{
|
110
|
mIconD = act.getDrawable(mIconID);
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
public void setExtrasOrdinal(int ordinal)
|
116
|
{
|
117
|
mExtrasOrdinal = ordinal;
|
118
|
}
|
119
|
|
120
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121
|
|
122
|
public int getExtrasOrdinal()
|
123
|
{
|
124
|
return mExtrasOrdinal;
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
public void setMeshState(int state)
|
130
|
{
|
131
|
mMeshState = state;
|
132
|
}
|
133
|
|
134
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135
|
|
136
|
public int getMeshState()
|
137
|
{
|
138
|
return mMeshState;
|
139
|
}
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
// PUBLIC API
|
143
|
|
144
|
public String getName()
|
145
|
{
|
146
|
return mName;
|
147
|
}
|
148
|
|
149
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150
|
|
151
|
public int getNumScramble()
|
152
|
{
|
153
|
return mNumScramble;
|
154
|
}
|
155
|
|
156
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
157
|
|
158
|
public int getObjectMinor()
|
159
|
{
|
160
|
return mObjectMinor;
|
161
|
}
|
162
|
|
163
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164
|
|
165
|
public int getExtrasMinor()
|
166
|
{
|
167
|
return mExtrasMinor;
|
168
|
}
|
169
|
|
170
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171
|
|
172
|
public void setIconTo(Activity act,ImageButton button)
|
173
|
{
|
174
|
if( mIconD==null ) createIconDrawable(act);
|
175
|
button.setBackground(mIconD);
|
176
|
}
|
177
|
|
178
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
179
|
|
180
|
public void setIconTo(Activity act,ImageView view)
|
181
|
{
|
182
|
if( mIconD==null ) createIconDrawable(act);
|
183
|
view.setImageDrawable(mIconD);
|
184
|
}
|
185
|
|
186
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187
|
|
188
|
public InputStream getObjectStream(Activity act)
|
189
|
{
|
190
|
if( mJsonID!=0 )
|
191
|
{
|
192
|
Resources res = act.getResources();
|
193
|
return res.openRawResource(mJsonID);
|
194
|
}
|
195
|
return null;
|
196
|
}
|
197
|
|
198
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199
|
|
200
|
public InputStream getMeshStream(Activity act)
|
201
|
{
|
202
|
if( mMeshID!=0 )
|
203
|
{
|
204
|
Resources res = act.getResources();
|
205
|
return res.openRawResource(mMeshID);
|
206
|
}
|
207
|
return null;
|
208
|
}
|
209
|
|
210
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
211
|
|
212
|
public InputStream getExtrasStream(Activity act)
|
213
|
{
|
214
|
if( mExtrasID!=0 )
|
215
|
{
|
216
|
Resources res = act.getResources();
|
217
|
return res.openRawResource(mExtrasID);
|
218
|
}
|
219
|
return null;
|
220
|
}
|
221
|
|
222
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
223
|
|
224
|
public boolean hasExtras()
|
225
|
{
|
226
|
return mExtrasID!=0;
|
227
|
}
|
228
|
|
229
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
230
|
|
231
|
public String[][] getPatterns()
|
232
|
{
|
233
|
return mPatterns;
|
234
|
}
|
235
|
}
|