diff --git a/core/src/fr/evolving/assets/AssetLoader.java b/core/src/fr/evolving/assets/AssetLoader.java index df53a7c..8626cc9 100644 --- a/core/src/fr/evolving/assets/AssetLoader.java +++ b/core/src/fr/evolving/assets/AssetLoader.java @@ -53,7 +53,10 @@ import fr.evolving.automata.Positiver_I; import fr.evolving.automata.Positiver_II; import fr.evolving.automata.Positiver_III; import fr.evolving.automata.Transmuter; +import fr.evolving.database.DatabaseManager; import fr.evolving.database.LocalBase; +import fr.evolving.database.SqlBase; +import fr.evolving.database.Base.datatype; import fr.evolving.screens.GameScreen; public class AssetLoader { @@ -81,6 +84,7 @@ public class AssetLoader { public static TooltipManager Tooltipmanager; public static I18NBundle french,usa,language; public static TextureFilter quality; + public static DatabaseManager Datahandler; public static void loadall() { TextureLoader.TextureParameter params = new TextureLoader.TextureParameter(); @@ -195,6 +199,13 @@ public class AssetLoader { else language=usa; I18NBundle.setExceptionOnMissingKey(true); + Gdx.app.debug("AssetLoader","Mise en place de la base de donnée"); + Datahandler= new DatabaseManager(); + Datahandler.RegisterBackend(LocalBase.class); + Datahandler.RegisterBackend(SqlBase.class); + Datahandler.Attach(datatype.userdata, "local:test.db"); + Datahandler.Attach(datatype.statdata, "local:test.db"); + Datahandler.Attach(datatype.gamedata, "local:test.db"); } public static Transmuter getTransmuter(String Name) { diff --git a/core/src/fr/evolving/database/Base.java b/core/src/fr/evolving/database/Base.java index e288c1e..a6aa36a 100644 --- a/core/src/fr/evolving/database/Base.java +++ b/core/src/fr/evolving/database/Base.java @@ -10,6 +10,9 @@ public abstract class Base { public enum datatype{statdata,userdata,gamedata} public Base(datatype model,String param) { + } + + public Base() { } //Gestion type Gamebase diff --git a/core/src/fr/evolving/database/DatabaseManager.java b/core/src/fr/evolving/database/DatabaseManager.java new file mode 100644 index 0000000..b1e8161 --- /dev/null +++ b/core/src/fr/evolving/database/DatabaseManager.java @@ -0,0 +1,71 @@ +package fr.evolving.database; + +import java.lang.reflect.InvocationTargetException; + +import com.badlogic.gdx.utils.Array; + +public class DatabaseManager { + private static Base[] bases; + private static Array> backends; + + public Base user(){ + return bases[Base.datatype.userdata.ordinal()]; + } + + public Base stat(){ + return bases[Base.datatype.statdata.ordinal()]; + } + + public Base game(){ + return bases[Base.datatype.gamedata.ordinal()]; + } + + public DatabaseManager(){ + bases=new Base[3]; + backends=new Array>(); + } + + public void CloseAll() { + for(Base base:bases) + base.Close(); + } + + public boolean Attach(Base.datatype model, String Url) { + if (bases[model.ordinal()]!=null) + return false; + Base backend=getBackend(model,Url); + if (backend!=null) { + bases[model.ordinal()]=backend; + return true; + } + else + return false; + } + + public Base getBackend(Base.datatype model, String Url) { + String Type=Url.split(":")[0]; + Class[] cArg = new Class[2]; + cArg[0] = Base.datatype.class; + cArg[1] = String.class; + for(Class classe:backends) { + Base back; + try { + back = (Base) classe.getDeclaredConstructor(cArg).newInstance(model,Url); + if (back.getprefix().equals(Type)) + return back; + } catch (InstantiationException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return null; + + } + + public void RegisterBackend(Class classe) { + backends.add(classe); + } + +} diff --git a/core/src/fr/evolving/database/LocalBase.java b/core/src/fr/evolving/database/LocalBase.java index 5e36d14..7751c65 100644 --- a/core/src/fr/evolving/database/LocalBase.java +++ b/core/src/fr/evolving/database/LocalBase.java @@ -26,6 +26,8 @@ public class LocalBase extends Base { private String creation; //Contructeur de la base de donnée + public LocalBase(){ + } public LocalBase(datatype model,String param) { super(model,param); @@ -260,7 +262,7 @@ public class LocalBase extends Base { public Array getGrids(int user, int level){ DatabaseCursor cursor=null; try { - cursor = dbHandler.rawQuery("select date from grids order by date desc;"); + cursor = dbHandler.rawQuery("select date from grids where level="+level+" and user="+user+" order by date desc;"); } catch (SQLiteGdxException e) { return null; } diff --git a/core/src/fr/evolving/screens/GameScreen.java b/core/src/fr/evolving/screens/GameScreen.java index eab59fb..db22a2b 100644 --- a/core/src/fr/evolving/screens/GameScreen.java +++ b/core/src/fr/evolving/screens/GameScreen.java @@ -39,6 +39,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; import com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton; import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.List; +import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.SelectBox; import com.badlogic.gdx.scenes.scene2d.ui.Slider; import com.badlogic.gdx.scenes.scene2d.ui.Table; @@ -88,7 +90,7 @@ public class GameScreen implements Screen { private GameRenderer Renderer; private float runTime; public Level level; - private Window winOptions; + private Window winOptions,winSave; private ImageButton[] Barre; private CheckBox SetSound,SetVsynch,SetFullscreen,SetAnimation,Settuto,Setdebog,Setrefresh; private Slider SetEffectvolume,SetMusicvolume; @@ -96,6 +98,7 @@ public class GameScreen implements Screen { private SelectBox selResolution; private SelectBox selTexturequal; private SelectBox selAdaptscreen; + private List selSaved; private ImageButton Setflag,info_up_nrj,info_up_temp,info_up_rayon,info_up_cycle,info_up_nrjval,info_up_tempval,info_up_rayonval,info_up_cycleval,SetFlag; private ImageTextButton cycle,temp,nrj,rayon,cout,tech,research,info_cout,info_tech,info_research,info_activation; private ImageTextButton[] Barre2; @@ -645,6 +648,8 @@ public class GameScreen implements Screen { Gdx.app.debug(getClass().getSimpleName(),"Création de la fenêtre d'option"); Table Optiontable=Createoption(); stage.addActor(winOptions); + Table Savetable=Createsaving(); + stage.addActor(winSave); Gdx.app.log("*****","Affichage du niveau."); for (int i=0;i=2) map.initzoom(); } else if (caller.getName()=="raz") { - LocalBase test2=new LocalBase(datatype.userdata,"local:test.db"); - level.Grid=test2.getGrid(0,0, 1); - level.Grid.tiling_transmuter(); - level.Grid.tiling_copper(); - map.redraw(53); + winOptions.setVisible(false); + winSave.setVisible(!winSave.isVisible()); + if (winSave.isVisible()) + readsaved(); } else if (caller.getName()=="save") { - LocalBase test2=new LocalBase(datatype.userdata,"local:test.db"); - for(String tester :test2.getGrids(0,0)) - Gdx.app.debug("test",tester); + AssetLoader.Datahandler.user().setGrid(0, level.aLevel, level.Grid); + readsaved(); } else if (caller.getName()=="levels") { Gdx.app.debug("Barre","Affichage des niveaux."); @@ -788,6 +782,7 @@ public class GameScreen implements Screen { } else if (caller.getName()=="settings") { winOptions.setVisible(!winOptions.isVisible()); + winSave.setVisible(false); if (winOptions.isVisible()) readpref(); } @@ -920,6 +915,39 @@ public class GameScreen implements Screen { public void dispose() { stage.dispose(); } + + public Table Createsaving() { + winSave = new Window("Saved grids", AssetLoader.Skin_ui); + winSave.add(savingPanel()).row(); + winSave.setColor(1, 1, 1, 0.8f); + winSave.setVisible(false); + winSave.pack(); + winSave.setBounds(50, 100, 250, 450); + return winSave; + } + + private Table savingPanel() { + Table table = new Table(); + table.pad(10, 10, 0, 10); + selSaved = new List(AssetLoader.Skin_ui); + selSaved.addListener(new ClickListener(){ + public void clicked(InputEvent event, float x, float y) { + if (this.getTapCount()>1) + level.Grid=AssetLoader.Datahandler.user().getGrid(0, level.aLevel, selSaved.getSelectedIndex()); + level.Grid.tiling_copper(); + level.Grid.tiling_transmuter(); + map.redraw(53); + } + }); + ScrollPane scroll=new ScrollPane(selSaved); + table.add(scroll).width(250).height(440).row(); + return table; + } + + public void readsaved() { + selSaved.setItems(AssetLoader.Datahandler.user().getGrids(0, level.aLevel)); + + } public Table Createoption() { winOptions = new Window("Options", AssetLoader.Skin_ui); diff --git a/core/src/fr/evolving/screens/LevelScreen.java b/core/src/fr/evolving/screens/LevelScreen.java index 105c414..5117a7a 100644 --- a/core/src/fr/evolving/screens/LevelScreen.java +++ b/core/src/fr/evolving/screens/LevelScreen.java @@ -41,7 +41,9 @@ import fr.evolving.automata.Level; import fr.evolving.automata.Transmuter; import fr.evolving.database.Base; import fr.evolving.database.Base.datatype; +import fr.evolving.database.DatabaseManager; import fr.evolving.database.LocalBase; +import fr.evolving.database.SqlBase; import fr.evolving.effects.Laser; public class LevelScreen implements Screen { @@ -63,6 +65,7 @@ public class LevelScreen implements Screen { public int world; private Objectives Victory; public ButtonLevel selected; + public int getMaxWorld() { int max=0; @@ -267,31 +270,11 @@ public class LevelScreen implements Screen { //menu(); //Gdx.app.debug(getClass().getSimpleName(),"Création des boutons de niveau."); //thelevels= SaveObject.initObject(); - //loadWorld(world); - LocalBase test=new LocalBase(datatype.gamedata,"local:test.db"); - //for(String tester :test.getworlds()) - // Gdx.app.debug("test",tester); - //test.setworld(thelevels, "test pour voir"); - //thelevels=null; - thelevels=test.getworld("test pour voir").toArray(); - test.getworld("test pour voire"); - //thelevels[0].Name="anus vivant"; - //test.setworld(thelevels, "test pour voir"); - //test.deleteworld("pop"); + thelevels=null; + thelevels=AssetLoader.Datahandler.game().getworld("test pour voir").toArray(); loadWorld(world); - - LocalBase test2=new LocalBase(datatype.userdata,"local:test.db"); - test.setlevelunlock(0, 1); - Gdx.app.debug("lock",String.valueOf(test.getlevellock(0, 1))); - Gdx.app.debug("lock",String.valueOf(test.getlevellock(110, 1))); - Gdx.app.debug("research",String.valueOf(test.getResearchpoint(0))); - test.setResearchpoint(0, 5000); - Gdx.app.debug("research",String.valueOf(test.getResearchpoint(0))); - test.setTransmuters(0, AssetLoader.allTransmuter); - Array retest=test.getTransmuters(0); - Gdx.app.debug("research",String.valueOf(test.getResearchpoint(0))); } @Override