Project

General

Profile

« Previous | Next » 

Revision fcf7320f

Added by Leszek Koltunski almost 3 years ago

Progress downloading objects and extras.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogTutorialView.java
70 70
    {
71 71
    super(act);
72 72

  
73
    InputStream jsonStream = RubikObjectList.getTutorialStream(position,act);
73
    InputStream jsonStream = RubikObjectList.getExtrasStream(position,act);
74 74
    String[][] tutorials=null;
75 75

  
76 76
    if( jsonStream!=null )
src/main/java/org/distorted/network/RubikNetwork.java
36 36
import androidx.fragment.app.FragmentActivity;
37 37

  
38 38
import org.distorted.library.main.DistortedLibrary;
39
import org.distorted.objectlib.json.JsonWriter;
39 40
import org.distorted.objects.RubikObjectList;
40 41

  
41 42
import static org.distorted.objects.RubikObjectList.MAX_LEVEL;
......
112 113
  private static String mVersion;
113 114
  private static String mDebug;
114 115
  private static int mNumObjects;
116
  private static RubikUpdates mUpdates;
115 117

  
116 118
///////////////////////////////////////////////////////////////////////////////////////////////////
117 119

  
......
122 124
    if( mCountry==null || newNum!=mNumObjects ) mCountry = new String[newNum][MAX_LEVEL][MAX_PLACES];
123 125
    if( mName==null    || newNum!=mNumObjects ) mName    = new String[newNum][MAX_LEVEL][MAX_PLACES];
124 126
    if( mTime==null    || newNum!=mNumObjects ) mTime    = new  float[newNum][MAX_LEVEL][MAX_PLACES];
125
    if( mPlaces==null  || newNum!=mNumObjects ) mPlaces  = new int[newNum][MAX_LEVEL];
127
    if( mPlaces==null  || newNum!=mNumObjects ) mPlaces  = new    int[newNum][MAX_LEVEL];
128

  
129
    if( mUpdates==null ) mUpdates = new RubikUpdates();
126 130

  
127 131
    mNumObjects = newNum;
128 132
    }
......
157 161

  
158 162
///////////////////////////////////////////////////////////////////////////////////////////////////
159 163

  
160
  private boolean fillValues()
164
  private boolean fillValuesNormal()
161 165
    {
162 166
    int begin=-1 ,end, len = mScores.length();
163 167
    String row;
......
380 384
      conn.setRequestMethod("GET");
381 385
      conn.connect();
382 386
      conn.getOutputStream().flush();
383
      conn.getInputStream();
387

  
388
      InputStream is = conn.getInputStream();
389
      BufferedReader r = new BufferedReader(new InputStreamReader(is));
390
      StringBuilder answer = new StringBuilder();
391

  
392
      for (String line; (line = r.readLine()) != null; )
393
        {
394
        answer.append(line).append('\n');
395
        }
396

  
397
      String updates = answer.toString();
398
      mUpdates.parse(updates);
384 399
      }
385 400
    catch( final Exception e )
386 401
      {
......
490 505
    String country = scores.getCountry();
491 506
    String renderer = DistortedLibrary.getDriverRenderer();
492 507
    String version  = DistortedLibrary.getDriverVersion();
508
    int objectAPI   = JsonWriter.VERSION_OBJECT_MAJOR;
509
    int tutorialAPI = JsonWriter.VERSION_EXTRAS_MAJOR;
493 510

  
494 511
    renderer = URLencode(renderer);
495 512
    version  = URLencode(version);
496 513

  
497
    String url="https://distorted.org/magic/cgi-bin/debugs.cgi";
498
    url += "?n="+name+"&r="+numRuns+"&p="+numPlay+"&c="+country+"&e="+mVersion+"d"+"&d="+renderer+"&v="+version;
514
    String url="https://distorted.org/magic/cgi-bin/debugs-new.cgi";
515
    url += "?n="+name+"&r="+numRuns+"&p="+numPlay+"&c="+country+"&e="+mVersion+"d";
516
    url += "&d="+renderer+"&v="+version+"&a="+objectAPI+"&b="+tutorialAPI;
499 517

  
500 518
    return url;
501 519
    }
......
599 617

  
600 618
    if( mRunning )
601 619
      {
602
      receiveValues = fillValues();
620
      receiveValues = fillValuesNormal();
603 621
      mRunning = false;
604 622
      }
605 623

  
src/main/java/org/distorted/network/RubikUpdates.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.network;
21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
import org.distorted.objects.RubikObjectList;
25

  
26
import java.util.ArrayList;
27

  
28
public class RubikUpdates
29
{
30
  public static class UpdateInfo
31
    {
32
    public final String mObjectName;
33
    public final int mMinorVersion;
34

  
35
    public UpdateInfo(String name,int version)
36
      {
37
      mObjectName  = name;
38
      mMinorVersion= version;
39
      }
40
    }
41

  
42
  private String mUrl;
43
  private final ArrayList<UpdateInfo> mNewObjects;
44
  private final ArrayList<UpdateInfo> mNewExtras;
45
  private final ArrayList<UpdateInfo> mUpdObjects;
46
  private final ArrayList<UpdateInfo> mUpdExtras;
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
50
  public RubikUpdates()
51
    {
52
    mNewObjects = new ArrayList<>();
53
    mNewExtras  = new ArrayList<>();
54
    mUpdObjects = new ArrayList<>();
55
    mUpdExtras  = new ArrayList<>();
56
    }
57

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

  
60
  private String debug(ArrayList<UpdateInfo> list)
61
    {
62
    String ret = "";
63
    for( UpdateInfo info : list) ret += ("  "+info.mObjectName+" "+info.mMinorVersion);
64
    return ret;
65
    }
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
  private void parseLine(String[] elements)
70
    {
71
    String objName  = elements[0];
72
    String objMinor = elements[1];
73
    String extMinor = elements[2];
74
    int oMinor, eMinor;
75

  
76
    try { oMinor = Integer.parseInt(objMinor); }
77
    catch (NumberFormatException ex) { oMinor = -1; }
78
    try { eMinor = Integer.parseInt(extMinor); }
79
    catch (NumberFormatException ex) { eMinor = -1; }
80

  
81
    int objOrdinal = RubikObjectList.getOrdinal(objName.toUpperCase());
82

  
83
    if( oMinor>=0 )
84
      {
85
      if( objOrdinal>=0 )
86
        {
87
        int localObjectMinor = RubikObjectList.getLocalObjectMinor(objOrdinal);
88
        if( localObjectMinor>=0 && localObjectMinor<oMinor )
89
          {
90
          UpdateInfo info = new UpdateInfo(objName,oMinor);
91
          mUpdObjects.add(info);
92
          }
93
        }
94
      else
95
        {
96
        UpdateInfo info = new UpdateInfo(objName,oMinor);
97
        mNewObjects.add(info);
98
        }
99
      }
100

  
101
    if( eMinor>=0 )
102
      {
103
      if( objOrdinal>=0 )
104
        {
105
        int localExtrasMinor = RubikObjectList.getLocalExtrasMinor(objOrdinal);
106
        if( localExtrasMinor>=0 && localExtrasMinor<eMinor )
107
          {
108
          UpdateInfo info = new UpdateInfo(objName,eMinor);
109
          mUpdExtras.add(info);
110
          }
111
        }
112
      else
113
        {
114
        UpdateInfo info = new UpdateInfo(objName,eMinor);
115
        mNewExtras.add(info);
116
        }
117
      }
118
    }
119

  
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

  
122
  void parse(String updates)
123
    {
124
    android.util.Log.e("D", updates);
125

  
126
    mNewObjects.clear();
127
    mNewExtras.clear();
128
    mUpdObjects.clear();
129
    mUpdExtras.clear();
130

  
131
    String[] lines = updates.split("\n");
132
    int numLines = lines.length;
133

  
134
    if( numLines>=1 )
135
      {
136
      mUrl = lines[0];
137
      for(int line=1; line<numLines; line++)
138
        {
139
        String[] elements = lines[line].split(" ");
140
        if( elements.length>=3 ) parseLine(elements);
141
        }
142
      }
143

  
144
    android.util.Log.e("D", "url: "+mUrl);
145
    android.util.Log.e("D", "new objects: "+debug(mNewObjects));
146
    android.util.Log.e("D", "new extras : "+debug(mNewExtras ));
147
    android.util.Log.e("D", "upd objects: "+debug(mUpdObjects));
148
    android.util.Log.e("D", "upd extras : "+debug(mUpdExtras ));
149
    }
150

  
151
}
src/main/java/org/distorted/objects/RubikObject.java
21 21

  
22 22
import org.distorted.dmesh.ObjectMesh;
23 23
import org.distorted.jsons.ObjectJson;
24
import org.distorted.objectlib.json.JsonWriter;
24 25
import org.distorted.objectlib.main.ObjectType;
25 26
import org.distorted.patterns.RubikPatternList;
26 27

  
......
33 34
  private final String mName;
34 35
  private final int mNumScramble;
35 36
  private final int mOrdinal;
36
  private final int mJsonID, mMeshID, mTutorialsID;
37
  private final int mJsonID, mMeshID, mExtrasID;
37 38
  private final int mIconID;
38 39
  private final String[][] mPatterns;
39 40

  
40 41
  private int mMeshState;
41
  private int mTutorialOrdinal;
42
  private int mExtrasOrdinal;
43
  private int mObjectMinor, mExtrasMinor;
42 44

  
43 45
///////////////////////////////////////////////////////////////////////////////////////////////////
44 46

  
......
50 52
    mOrdinal     = type.ordinal();
51 53
    mJsonID      = ObjectJson.getObjectJsonID(mOrdinal);
52 54
    mMeshID      = ObjectMesh.getMeshID(mOrdinal);
53
    mTutorialsID = ObjectJson.getTutorialJsonID(mOrdinal);
55
    mExtrasID    = ObjectJson.getExtrasJsonID(mOrdinal);
54 56

  
55 57
    int patternOrdinal  = RubikPatternList.getOrdinal(mOrdinal);
56 58
    mPatterns = RubikPatternList.getPatterns(patternOrdinal);
57 59

  
58 60
    mMeshState = MESH_NICE;
59
    mTutorialOrdinal = -1;
61
    mExtrasOrdinal = -1;
62

  
63
    mObjectMinor = JsonWriter.VERSION_OBJECT_MINOR;
64
    mExtrasMinor = JsonWriter.VERSION_EXTRAS_MINOR;
60 65
    }
61 66

  
62 67
///////////////////////////////////////////////////////////////////////////////////////////////////
63 68

  
64
  public void setTutorialOrdinal(int ordinal)
69
  public void setExtrasOrdinal(int ordinal)
65 70
    {
66
    mTutorialOrdinal = ordinal;
71
    mExtrasOrdinal = ordinal;
67 72
    }
68 73

  
69 74
///////////////////////////////////////////////////////////////////////////////////////////////////
70 75

  
71
  public int getTutorialOrdinal()
76
  public int getExtrasOrdinal()
72 77
    {
73
    return mTutorialOrdinal;
78
    return mExtrasOrdinal;
74 79
    }
75 80

  
76 81
///////////////////////////////////////////////////////////////////////////////////////////////////
......
132 137

  
133 138
///////////////////////////////////////////////////////////////////////////////////////////////////
134 139

  
135
  public int getTutorialJsonID()
140
  public int getExtrasJsonID()
136 141
    {
137
    return mTutorialsID;
142
    return mExtrasID;
138 143
    }
139 144

  
140 145
///////////////////////////////////////////////////////////////////////////////////////////////////
......
143 148
    {
144 149
    return mPatterns;
145 150
    }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

  
154
  public int getObjectMinor()
155
    {
156
    return mObjectMinor;
157
    }
158

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

  
161
  public int getExtrasMinor()
162
    {
163
    return mExtrasMinor;
164
    }
146 165
}
src/main/java/org/distorted/objects/RubikObjectList.java
45 45

  
46 46
  private static RubikObjectList mType;
47 47
  private static int mNumObjects;
48
  private static int mNumTutorials;
48
  private static int mNumExtras;
49 49
  private static ArrayList<RubikObject> mObjects;
50 50
  private static int mObject = DEF_OBJECT;
51 51

  
......
66 66

  
67 67
  private RubikObjectList()
68 68
    {
69
    mNumObjects   = 0;
70
    mNumTutorials = 0;
69
    mNumObjects= 0;
70
    mNumExtras = 0;
71 71

  
72 72
    mObjects = new ArrayList<>();
73 73

  
......
85 85
      mObjects.add(obj);
86 86
      mNumObjects++;
87 87

  
88
      if( obj.getTutorialJsonID()!=0 )
88
      if( obj.getExtrasJsonID()!=0 )
89 89
        {
90
        obj.setTutorialOrdinal(mNumTutorials);
91
        mNumTutorials++;
90
        obj.setExtrasOrdinal(mNumExtras);
91
        mNumExtras++;
92 92
        }
93 93
      }
94 94
    }
......
242 242
    return -1;
243 243
    }
244 244

  
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

  
247
  public static int getNumExtrasObjects()
248
    {
249
    return mNumExtras;
250
    }
251

  
245 252
///////////////////////////////////////////////////////////////////////////////////////////////////
246 253

  
247 254
  public static int getNumTutorialObjects()
248 255
    {
249
    return mNumTutorials;
256
    return mNumExtras;
250 257
    }
251 258

  
252 259
///////////////////////////////////////////////////////////////////////////////////////////////////
253 260

  
254
  public static InputStream getTutorialStream(int tutorialOrdinal, Activity act)
261
  public static InputStream getExtrasStream(int extrasOrdinal, Activity act)
255 262
    {
256
    int objectOrdinal = getObjectOrdinal(tutorialOrdinal);
263
    int objectOrdinal = getObjectOrdinal(extrasOrdinal);
257 264
    RubikObject object= getObject(objectOrdinal);
258 265

  
259 266
    if( object!=null )
260 267
      {
261
      int jsonID = object.getTutorialJsonID();
262
      return ObjectJson.getTutorialStream(jsonID,act);
268
      int jsonID = object.getExtrasJsonID();
269
      return ObjectJson.getExtrasStream(jsonID,act);
263 270
      }
264 271

  
265 272
    return null;
......
267 274

  
268 275
///////////////////////////////////////////////////////////////////////////////////////////////////
269 276

  
270
  public static int getObjectOrdinal(int tutorialOrdinal)
277
  public static int getObjectOrdinal(int extrasOrdinal)
271 278
    {
272
    for(int i=tutorialOrdinal; i<mNumObjects; i++)
279
    for(int i=extrasOrdinal; i<mNumObjects; i++)
273 280
      {
274 281
      RubikObject object = getObject(i);
275
      int tutOrd = object!=null ? object.getTutorialOrdinal() : -1;
276
      if( tutOrd==tutorialOrdinal ) return i;
282
      int extOrd = object!=null ? object.getExtrasOrdinal() : -1;
283
      if( extOrd==extrasOrdinal ) return i;
277 284
      }
278 285

  
279 286
    return -1;
280 287
    }
281 288

  
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

  
291
  public static int getExtrasOrdinal(int objectOrdinal)
292
    {
293
    RubikObject object = getObject(objectOrdinal);
294
    return object!=null ? object.getExtrasOrdinal() : -1;
295
    }
296

  
282 297
///////////////////////////////////////////////////////////////////////////////////////////////////
283 298

  
284 299
  public static int getTutorialOrdinal(int objectOrdinal)
285 300
    {
286 301
    RubikObject object = getObject(objectOrdinal);
287
    return object!=null ? object.getTutorialOrdinal() : -1;
302
    return object!=null ? object.getExtrasOrdinal() : -1;
303
    }
304

  
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

  
307
  public static int getLocalObjectMinor(int objectOrdinal)
308
    {
309
    RubikObject object = getObject(objectOrdinal);
310
    return object!=null ? object.getObjectMinor() : -1;
311
    }
312

  
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

  
315
  public static int getLocalExtrasMinor(int objectOrdinal)
316
    {
317
    RubikObject object = getObject(objectOrdinal);
318
    return object!=null ? object.getExtrasMinor() : -1;
288 319
    }
289 320
}

Also available in: Unified diff