Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / RubikObject.java @ eb985085

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