feat: ajout d'un gestionnaire de base de donnée databasemanager auquel on peut ajouter des bases différentes selon le modèle base, amélioration du code base/sqlite, ajout de la gestion des sauvegarde/restauration des grilles avec une nouvelle fenêtre.
This commit is contained in:
parent
d85c5316ba
commit
57505ead12
|
@ -53,7 +53,10 @@ import fr.evolving.automata.Positiver_I;
|
||||||
import fr.evolving.automata.Positiver_II;
|
import fr.evolving.automata.Positiver_II;
|
||||||
import fr.evolving.automata.Positiver_III;
|
import fr.evolving.automata.Positiver_III;
|
||||||
import fr.evolving.automata.Transmuter;
|
import fr.evolving.automata.Transmuter;
|
||||||
|
import fr.evolving.database.DatabaseManager;
|
||||||
import fr.evolving.database.LocalBase;
|
import fr.evolving.database.LocalBase;
|
||||||
|
import fr.evolving.database.SqlBase;
|
||||||
|
import fr.evolving.database.Base.datatype;
|
||||||
import fr.evolving.screens.GameScreen;
|
import fr.evolving.screens.GameScreen;
|
||||||
|
|
||||||
public class AssetLoader {
|
public class AssetLoader {
|
||||||
|
@ -81,6 +84,7 @@ public class AssetLoader {
|
||||||
public static TooltipManager Tooltipmanager;
|
public static TooltipManager Tooltipmanager;
|
||||||
public static I18NBundle french,usa,language;
|
public static I18NBundle french,usa,language;
|
||||||
public static TextureFilter quality;
|
public static TextureFilter quality;
|
||||||
|
public static DatabaseManager Datahandler;
|
||||||
|
|
||||||
public static void loadall() {
|
public static void loadall() {
|
||||||
TextureLoader.TextureParameter params = new TextureLoader.TextureParameter();
|
TextureLoader.TextureParameter params = new TextureLoader.TextureParameter();
|
||||||
|
@ -195,6 +199,13 @@ public class AssetLoader {
|
||||||
else
|
else
|
||||||
language=usa;
|
language=usa;
|
||||||
I18NBundle.setExceptionOnMissingKey(true);
|
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) {
|
public static Transmuter getTransmuter(String Name) {
|
||||||
|
|
|
@ -10,6 +10,9 @@ public abstract class Base {
|
||||||
public enum datatype{statdata,userdata,gamedata}
|
public enum datatype{statdata,userdata,gamedata}
|
||||||
|
|
||||||
public Base(datatype model,String param) {
|
public Base(datatype model,String param) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Base() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Gestion type Gamebase
|
//Gestion type Gamebase
|
||||||
|
|
|
@ -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<Class<?>> 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<Class<?>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,6 +26,8 @@ public class LocalBase extends Base {
|
||||||
private String creation;
|
private String creation;
|
||||||
|
|
||||||
//Contructeur de la base de donnée
|
//Contructeur de la base de donnée
|
||||||
|
public LocalBase(){
|
||||||
|
}
|
||||||
|
|
||||||
public LocalBase(datatype model,String param) {
|
public LocalBase(datatype model,String param) {
|
||||||
super(model,param);
|
super(model,param);
|
||||||
|
@ -260,7 +262,7 @@ public class LocalBase extends Base {
|
||||||
public Array<String> getGrids(int user, int level){
|
public Array<String> getGrids(int user, int level){
|
||||||
DatabaseCursor cursor=null;
|
DatabaseCursor cursor=null;
|
||||||
try {
|
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) {
|
} catch (SQLiteGdxException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.ImageButton;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton;
|
import com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
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.SelectBox;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
|
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||||
|
@ -88,7 +90,7 @@ public class GameScreen implements Screen {
|
||||||
private GameRenderer Renderer;
|
private GameRenderer Renderer;
|
||||||
private float runTime;
|
private float runTime;
|
||||||
public Level level;
|
public Level level;
|
||||||
private Window winOptions;
|
private Window winOptions,winSave;
|
||||||
private ImageButton[] Barre;
|
private ImageButton[] Barre;
|
||||||
private CheckBox SetSound,SetVsynch,SetFullscreen,SetAnimation,Settuto,Setdebog,Setrefresh;
|
private CheckBox SetSound,SetVsynch,SetFullscreen,SetAnimation,Settuto,Setdebog,Setrefresh;
|
||||||
private Slider SetEffectvolume,SetMusicvolume;
|
private Slider SetEffectvolume,SetMusicvolume;
|
||||||
|
@ -96,6 +98,7 @@ public class GameScreen implements Screen {
|
||||||
private SelectBox<resolutions> selResolution;
|
private SelectBox<resolutions> selResolution;
|
||||||
private SelectBox<quality> selTexturequal;
|
private SelectBox<quality> selTexturequal;
|
||||||
private SelectBox<adaptation> selAdaptscreen;
|
private SelectBox<adaptation> 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 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 cycle,temp,nrj,rayon,cout,tech,research,info_cout,info_tech,info_research,info_activation;
|
||||||
private ImageTextButton[] Barre2;
|
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");
|
Gdx.app.debug(getClass().getSimpleName(),"Création de la fenêtre d'option");
|
||||||
Table Optiontable=Createoption();
|
Table Optiontable=Createoption();
|
||||||
stage.addActor(winOptions);
|
stage.addActor(winOptions);
|
||||||
|
Table Savetable=Createsaving();
|
||||||
|
stage.addActor(winSave);
|
||||||
Gdx.app.log("*****","Affichage du niveau.");
|
Gdx.app.log("*****","Affichage du niveau.");
|
||||||
for (int i=0;i<Barre2.length;i++)
|
for (int i=0;i<Barre2.length;i++)
|
||||||
table2.addActor(Barre2[i]);
|
table2.addActor(Barre2[i]);
|
||||||
|
@ -695,19 +700,10 @@ public class GameScreen implements Screen {
|
||||||
menu.EraseMenuTransmuterSurtile();
|
menu.EraseMenuTransmuterSurtile();
|
||||||
hideInfo();
|
hideInfo();
|
||||||
if (caller.getName()=="run") {
|
if (caller.getName()=="run") {
|
||||||
LocalBase test2=new LocalBase(datatype.userdata,"local:test.db");
|
|
||||||
test2.setGrid(0,0, level.Grid);
|
|
||||||
}
|
}
|
||||||
else if (caller.getName()=="stop") {
|
else if (caller.getName()=="stop") {
|
||||||
LocalBase test2=new LocalBase(datatype.userdata,"local:test.db");
|
|
||||||
level.Grid=test2.getGrid(0,0,0);
|
|
||||||
level.Grid.tiling_transmuter();
|
|
||||||
level.Grid.tiling_copper();
|
|
||||||
map.redraw(53);
|
|
||||||
}
|
}
|
||||||
else if (caller.getName()=="speed") {
|
else if (caller.getName()=="speed") {
|
||||||
LocalBase test2=new LocalBase(datatype.userdata,"local:test.db");
|
|
||||||
test2.setGrid(0,5, level.Grid);
|
|
||||||
}
|
}
|
||||||
else if (caller.getName()=="move") {
|
else if (caller.getName()=="move") {
|
||||||
selected=caller;
|
selected=caller;
|
||||||
|
@ -726,16 +722,14 @@ public class GameScreen implements Screen {
|
||||||
if (count>=2) map.initzoom();
|
if (count>=2) map.initzoom();
|
||||||
}
|
}
|
||||||
else if (caller.getName()=="raz") {
|
else if (caller.getName()=="raz") {
|
||||||
LocalBase test2=new LocalBase(datatype.userdata,"local:test.db");
|
winOptions.setVisible(false);
|
||||||
level.Grid=test2.getGrid(0,0, 1);
|
winSave.setVisible(!winSave.isVisible());
|
||||||
level.Grid.tiling_transmuter();
|
if (winSave.isVisible())
|
||||||
level.Grid.tiling_copper();
|
readsaved();
|
||||||
map.redraw(53);
|
|
||||||
}
|
}
|
||||||
else if (caller.getName()=="save") {
|
else if (caller.getName()=="save") {
|
||||||
LocalBase test2=new LocalBase(datatype.userdata,"local:test.db");
|
AssetLoader.Datahandler.user().setGrid(0, level.aLevel, level.Grid);
|
||||||
for(String tester :test2.getGrids(0,0))
|
readsaved();
|
||||||
Gdx.app.debug("test",tester);
|
|
||||||
}
|
}
|
||||||
else if (caller.getName()=="levels") {
|
else if (caller.getName()=="levels") {
|
||||||
Gdx.app.debug("Barre","Affichage des niveaux.");
|
Gdx.app.debug("Barre","Affichage des niveaux.");
|
||||||
|
@ -788,6 +782,7 @@ public class GameScreen implements Screen {
|
||||||
}
|
}
|
||||||
else if (caller.getName()=="settings") {
|
else if (caller.getName()=="settings") {
|
||||||
winOptions.setVisible(!winOptions.isVisible());
|
winOptions.setVisible(!winOptions.isVisible());
|
||||||
|
winSave.setVisible(false);
|
||||||
if (winOptions.isVisible())
|
if (winOptions.isVisible())
|
||||||
readpref();
|
readpref();
|
||||||
}
|
}
|
||||||
|
@ -921,6 +916,39 @@ public class GameScreen implements Screen {
|
||||||
stage.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() {
|
public Table Createoption() {
|
||||||
winOptions = new Window("Options", AssetLoader.Skin_ui);
|
winOptions = new Window("Options", AssetLoader.Skin_ui);
|
||||||
winOptions.add(SettingsVideo()).row();
|
winOptions.add(SettingsVideo()).row();
|
||||||
|
|
|
@ -41,7 +41,9 @@ import fr.evolving.automata.Level;
|
||||||
import fr.evolving.automata.Transmuter;
|
import fr.evolving.automata.Transmuter;
|
||||||
import fr.evolving.database.Base;
|
import fr.evolving.database.Base;
|
||||||
import fr.evolving.database.Base.datatype;
|
import fr.evolving.database.Base.datatype;
|
||||||
|
import fr.evolving.database.DatabaseManager;
|
||||||
import fr.evolving.database.LocalBase;
|
import fr.evolving.database.LocalBase;
|
||||||
|
import fr.evolving.database.SqlBase;
|
||||||
import fr.evolving.effects.Laser;
|
import fr.evolving.effects.Laser;
|
||||||
|
|
||||||
public class LevelScreen implements Screen {
|
public class LevelScreen implements Screen {
|
||||||
|
@ -64,6 +66,7 @@ public class LevelScreen implements Screen {
|
||||||
private Objectives Victory;
|
private Objectives Victory;
|
||||||
public ButtonLevel selected;
|
public ButtonLevel selected;
|
||||||
|
|
||||||
|
|
||||||
public int getMaxWorld() {
|
public int getMaxWorld() {
|
||||||
int max=0;
|
int max=0;
|
||||||
for (Level level :thelevels)
|
for (Level level :thelevels)
|
||||||
|
@ -267,31 +270,11 @@ public class LevelScreen implements Screen {
|
||||||
//menu();
|
//menu();
|
||||||
//Gdx.app.debug(getClass().getSimpleName(),"Création des boutons de niveau.");
|
//Gdx.app.debug(getClass().getSimpleName(),"Création des boutons de niveau.");
|
||||||
//thelevels= SaveObject.initObject();
|
//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=null;
|
||||||
thelevels=test.getworld("test pour voir").toArray();
|
thelevels=AssetLoader.Datahandler.game().getworld("test pour voir").toArray();
|
||||||
test.getworld("test pour voire");
|
|
||||||
//thelevels[0].Name="anus vivant";
|
|
||||||
//test.setworld(thelevels, "test pour voir");
|
|
||||||
//test.deleteworld("pop");
|
|
||||||
loadWorld(world);
|
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<Transmuter> retest=test.getTransmuters(0);
|
|
||||||
Gdx.app.debug("research",String.valueOf(test.getResearchpoint(0)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue