Revision 314e9ff0
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objects/RubikObject.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.objects; |
21 | 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 |
|
|
22 | 29 |
import org.distorted.dmesh.ObjectMesh; |
23 | 30 |
import org.distorted.jsons.ObjectJson; |
24 | 31 |
import org.distorted.objectlib.json.JsonWriter; |
... | ... | |
37 | 44 |
private final int mJsonID, mMeshID, mExtrasID; |
38 | 45 |
private final int mIconID; |
39 | 46 |
private final String[][] mPatterns; |
47 |
private final int mObjectMinor, mExtrasMinor; |
|
40 | 48 |
|
41 | 49 |
private int mMeshState; |
42 | 50 |
private int mExtrasOrdinal; |
43 |
private int mObjectMinor, mExtrasMinor; |
|
44 | 51 |
|
45 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 53 |
|
47 | 54 |
RubikObject(ObjectType type) |
48 | 55 |
{ |
49 |
mIconID = type.getIconID(); |
|
50 | 56 |
mName = type.name(); |
51 | 57 |
mNumScramble = type.getNumScramble(); |
52 | 58 |
mOrdinal = type.ordinal(); |
59 |
|
|
60 |
mIconID = type.getIconID(); |
|
53 | 61 |
mJsonID = ObjectJson.getObjectJsonID(mOrdinal); |
54 | 62 |
mMeshID = ObjectMesh.getMeshID(mOrdinal); |
55 | 63 |
mExtrasID = ObjectJson.getExtrasJsonID(mOrdinal); |
... | ... | |
63 | 71 |
mObjectMinor = JsonWriter.VERSION_OBJECT_MINOR; |
64 | 72 |
mExtrasMinor = JsonWriter.VERSION_EXTRAS_MINOR; |
65 | 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 |
} |
|
66 | 97 |
|
98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
|
|
100 |
public void updateObject(RubikObjectList.DownloadedObject object) |
|
101 |
{ |
|
102 |
|
|
103 |
} |
|
104 |
*/ |
|
67 | 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 106 |
|
69 | 107 |
public void setExtrasOrdinal(int ordinal) |
... | ... | |
116 | 154 |
|
117 | 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
118 | 156 |
|
119 |
public int getIconID() |
|
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) |
|
120 | 172 |
{ |
121 |
return mIconID; |
|
173 |
if( mJsonID!=0 ) |
|
174 |
{ |
|
175 |
Resources res = act.getResources(); |
|
176 |
return res.openRawResource(mJsonID); |
|
177 |
} |
|
178 |
return null; |
|
122 | 179 |
} |
123 | 180 |
|
124 | 181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
125 | 182 |
|
126 |
public int getJsonID()
|
|
183 |
public InputStream getMeshStream(Activity act)
|
|
127 | 184 |
{ |
128 |
return mJsonID; |
|
185 |
if( mMeshID!=0 ) |
|
186 |
{ |
|
187 |
Resources res = act.getResources(); |
|
188 |
return res.openRawResource(mMeshID); |
|
189 |
} |
|
190 |
return null; |
|
129 | 191 |
} |
130 | 192 |
|
131 | 193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
132 | 194 |
|
133 |
public int getMeshID()
|
|
195 |
public InputStream getExtrasStream(Activity act)
|
|
134 | 196 |
{ |
135 |
return mMeshID; |
|
197 |
if( mExtrasID!=0 ) |
|
198 |
{ |
|
199 |
Resources res = act.getResources(); |
|
200 |
return res.openRawResource(mExtrasID); |
|
201 |
} |
|
202 |
return null; |
|
136 | 203 |
} |
137 | 204 |
|
138 | 205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
139 | 206 |
|
140 |
public int getExtrasJsonID()
|
|
207 |
public boolean hasExtras()
|
|
141 | 208 |
{ |
142 |
return mExtrasID; |
|
209 |
return mExtrasID!=0;
|
|
143 | 210 |
} |
144 | 211 |
|
145 | 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Refactor RubikObject in preparation for creating RubikObjects from DownloadedObjects.