Project

General

Profile

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

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

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