|
@@ -1,13 +1,17 @@
|
|
|
package app.mar.game;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.util.Log;
|
|
|
|
|
|
+import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
import app.mar.utils.files.JSONAssetsManager;
|
|
|
import min3d.core.Object3d;
|
|
@@ -31,19 +35,79 @@ public class Resource implements Serializable {
|
|
|
protected int mStage;
|
|
|
protected String mType = ""; //3D Image Audio Video
|
|
|
protected String mTitle= ""; //3D Image Audio Video
|
|
|
+ private static JSONObject mRessourcesList = null;
|
|
|
+ public static ArrayList<String> mNotFound = new ArrayList<>();
|
|
|
+ protected String mFile = null;
|
|
|
+
|
|
|
+ public String getFile() {
|
|
|
+ if(mFile!=null)
|
|
|
+ return mFile;
|
|
|
+ return mName;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isFile() {
|
|
|
+ return mFile!=null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void initResourceList(Activity act)
|
|
|
+ {
|
|
|
+ if(mRessourcesList!=null) return;
|
|
|
+ Game.logv( "Chargement de la liste des ressources...");
|
|
|
+ JSONObject obj = JSONAssetsManager.load(act, "ressources.res");
|
|
|
+ if(obj==null)
|
|
|
+ {
|
|
|
+ Game.logw("Attention il n'existe pas de fichier pour la liste des ressrouecs");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mRessourcesList=obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static JSONObject getRessourceDataFromList(String name)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ if(mRessourcesList!=null)
|
|
|
+ return mRessourcesList.getJSONObject(name);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ Game.logw("Impossiblle de trouver la ressource '"+name+"' dans la liste des ressources");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void logNotFound()
|
|
|
+ {
|
|
|
+ Log.e("LoadingRes", "Liste des ressources non-trouvées:");
|
|
|
+ for(int i=0; i<mNotFound.size(); i++)
|
|
|
+ Log.e("LoadingRes", "\t'"+mNotFound.get(i)+"'");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void setNotFound(String name)
|
|
|
+ {
|
|
|
+ for(int i=0; i< mNotFound.size(); i++)
|
|
|
+ if(mNotFound.get(i).compareTo(name)==0) return;
|
|
|
+ mNotFound.add(name);
|
|
|
+ }
|
|
|
|
|
|
protected void loadResourceData(Activity act)
|
|
|
{
|
|
|
- Log.w("-----", "Loading resource '"+mName+"'");
|
|
|
+ initResourceList(act);
|
|
|
+ Game.logv( "--- Chargement de la ressource '"+mName+"' --- ");
|
|
|
JSONObject obj = JSONAssetsManager.load(act, mName+"_res");
|
|
|
if(obj==null) obj = JSONAssetsManager.load(act, mName+".res");
|
|
|
+ if(obj==null) obj = getRessourceDataFromList(mName);
|
|
|
+ if(obj == null)
|
|
|
+ {
|
|
|
+ Game.loge("\tLa ressource '"+mName+"' est introuvable.");
|
|
|
+ setNotFound(mName);
|
|
|
+ Game.fail();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
//mandatory
|
|
|
try {
|
|
|
mType = obj.getString("type");
|
|
|
} catch(JSONException e)
|
|
|
{
|
|
|
- Log.e("-----", "Enable to load resource '"+mName+"'");
|
|
|
+ Game.loge("\tLa ressource '"+mName+"' n'a pas d'attribut 'type' valide (String)");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
@@ -62,6 +126,13 @@ public class Resource implements Serializable {
|
|
|
} catch (JSONException e) {
|
|
|
}
|
|
|
|
|
|
+ try{
|
|
|
+ mFile = obj.getString("file");
|
|
|
+ }catch (JSONException e)
|
|
|
+ {
|
|
|
+ mFile=null;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
try {
|
|
|
mPosition.x = (float) obj.getJSONArray("position").getDouble(0);
|
|
@@ -87,6 +158,10 @@ public class Resource implements Serializable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public boolean hasFile(){
|
|
|
+ return mFile!=null;
|
|
|
+ }
|
|
|
+
|
|
|
public void loadModel(Activity context)
|
|
|
{
|
|
|
get3DModel(context);
|