Project

General

Profile

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

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

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 mJsonID, mMeshID, mExtrasID;
44
  private final int mIconID;
45
  private final String[][] mPatterns;
46
  private final int mObjectMinor, mExtrasMinor;
47

    
48
  private int mMeshState;
49
  private int mExtrasOrdinal;
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  RubikObject(ObjectType type)
54
    {
55
    int ordinal= type.ordinal();
56

    
57
    mName        = type.name();
58
    mNumScramble = type.getNumScramble();
59

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

    
65
    int patternOrdinal  = RubikPatternList.getOrdinal(ordinal);
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
    mMeshID        = 0;
81
    mPatterns      = null;
82
    mMeshState     = MESH_NICE;
83
    mExtrasOrdinal = -1;
84

    
85

    
86

    
87
    mNumScramble = type.getNumScramble();
88
    mObjectMinor = ?
89
    mExtrasMinor = ?
90
    mIconID      = type.getIconID();
91
    mJsonID      = ObjectJson.getObjectJsonID(mOrdinal);
92
    mExtrasID    = ObjectJson.getExtrasJsonID(mOrdinal);
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  public void updateObject(RubikObjectList.DownloadedObject object)
98
    {
99

    
100
    }
101
*/
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  public void setExtrasOrdinal(int ordinal)
105
    {
106
    mExtrasOrdinal = ordinal;
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  public int getExtrasOrdinal()
112
    {
113
    return mExtrasOrdinal;
114
    }
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
    }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
// PUBLIC API
132

    
133
  public String getName()
134
    {
135
    return mName;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public int getNumScramble()
141
    {
142
    return mNumScramble;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  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
    {
163
    if( mJsonID!=0 )
164
      {
165
      Resources res = act.getResources();
166
      return res.openRawResource(mJsonID);
167
      }
168
    return null;
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

    
173
  public InputStream getMeshStream(Activity act)
174
    {
175
    if( mMeshID!=0 )
176
      {
177
      Resources res = act.getResources();
178
      return res.openRawResource(mMeshID);
179
      }
180
    return null;
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  public InputStream getExtrasStream(Activity act)
186
    {
187
    if( mExtrasID!=0 )
188
      {
189
      Resources res = act.getResources();
190
      return res.openRawResource(mExtrasID);
191
      }
192
    return null;
193
    }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
  public boolean hasExtras()
198
    {
199
    return mExtrasID!=0;
200
    }
201

    
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

    
204
  public String[][] getPatterns()
205
    {
206
    return mPatterns;
207
    }
208

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210

    
211
  public int getObjectMinor()
212
    {
213
    return mObjectMinor;
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  public int getExtrasMinor()
219
    {
220
    return mExtrasMinor;
221
    }
222
}
(1-1/2)