fix: correction importante du bogue d'enregistrement sous android (execsql au lieu de rawqsql) ajout de la suppression dynamique des liens correction de bogues pour la duplication de mondes
This commit is contained in:
parent
f513cd3473
commit
4652a21703
|
@ -55,6 +55,7 @@ public class Level implements Serializable,Cloneable {
|
||||||
this.Element = Element;
|
this.Element = Element;
|
||||||
this.rewards = Current;
|
this.rewards = Current;
|
||||||
this.Victory_orig = Victory;
|
this.Victory_orig = Victory;
|
||||||
|
this.Victory = Victory;
|
||||||
this.X = X;
|
this.X = X;
|
||||||
this.Y = Y;
|
this.Y = Y;
|
||||||
this.Tech = Tech;
|
this.Tech = Tech;
|
||||||
|
@ -72,6 +73,7 @@ public class Level implements Serializable,Cloneable {
|
||||||
this.Special = Special;
|
this.Special = Special;
|
||||||
this.Tuto = Tuto;
|
this.Tuto = Tuto;
|
||||||
this.Link = Link;
|
this.Link = Link;
|
||||||
|
this.Locked=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class Worlds extends Actor {
|
||||||
private Level lastchange;
|
private Level lastchange;
|
||||||
|
|
||||||
public enum State {pause,simulating,notloaded,databasefailed};
|
public enum State {pause,simulating,notloaded,databasefailed};
|
||||||
|
public enum LinkDelMethod {all,in,out,rebase};
|
||||||
|
|
||||||
public Worlds(String campaign) {
|
public Worlds(String campaign) {
|
||||||
name=campaign;
|
name=campaign;
|
||||||
|
@ -193,10 +194,11 @@ public class Worlds extends Actor {
|
||||||
usedlevel.Grid_orig = (Grid)usedlevel.Grid.clone();
|
usedlevel.Grid_orig = (Grid)usedlevel.Grid.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Level findLevel(int levelid) {
|
public Level findLevel(int worldid, int levelid) {
|
||||||
if (state!=State.notloaded)
|
if (state!=State.notloaded)
|
||||||
if (usedworld>=0) {
|
if (worldid>=0) {
|
||||||
Array<Level> tempworld=getLevels();
|
Array<Level> tempworld=getLevels(worldid);
|
||||||
|
if (tempworld!=null)
|
||||||
for(Level level:tempworld)
|
for(Level level:tempworld)
|
||||||
if (level.aLevel==levelid)
|
if (level.aLevel==levelid)
|
||||||
return level;
|
return level;
|
||||||
|
@ -204,6 +206,10 @@ public class Worlds extends Actor {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Level findLevel(int levelid) {
|
||||||
|
return findLevel(usedworld, levelid);
|
||||||
|
}
|
||||||
|
|
||||||
public void setLevel(int levelid) {
|
public void setLevel(int levelid) {
|
||||||
Level level=findLevel(levelid);
|
Level level=findLevel(levelid);
|
||||||
if (level!=null)
|
if (level!=null)
|
||||||
|
@ -252,6 +258,63 @@ public class Worlds extends Actor {
|
||||||
return lastchange;
|
return lastchange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delLink(int levelid, LinkDelMethod atype) {
|
||||||
|
Level level = findLevel(levelid);
|
||||||
|
if (level!=null) {
|
||||||
|
if (atype==LinkDelMethod.all || atype==LinkDelMethod.out)
|
||||||
|
level.Link=new int[][] {};
|
||||||
|
if (atype==LinkDelMethod.all || atype==LinkDelMethod.in)
|
||||||
|
if (levels!=null)
|
||||||
|
for(Level alevel:levels)
|
||||||
|
if (alevel!=null) {
|
||||||
|
Array<int[]> links=new Array<int[]>(alevel.Link);
|
||||||
|
for(int[] link: links)
|
||||||
|
if (link.length==2 && link[0]==level.aWorld && link[1]==level.aLevel)
|
||||||
|
links.removeValue(link, true);
|
||||||
|
alevel.Link=links.toArray();
|
||||||
|
}
|
||||||
|
if (atype==LinkDelMethod.rebase) {
|
||||||
|
Array<int[]> links=new Array<int[]>();
|
||||||
|
Array<int[]> templinks=new Array<int[]>(level.Link);
|
||||||
|
for(int[] link: templinks) {
|
||||||
|
if (link.length==2) {
|
||||||
|
Level alevel = findLevel(link[0],link[1]);
|
||||||
|
if (alevel!=null)
|
||||||
|
links.add(new int[]{link[0],link[1],(int) alevel.X,(int) alevel.Y});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
level.Link=new int[][]{};
|
||||||
|
for(Level blevel:levels)
|
||||||
|
if (blevel!=null) {
|
||||||
|
Array<int[]> alinks=new Array<int[]>(blevel.Link);
|
||||||
|
for(int[] alink: alinks)
|
||||||
|
if (alink.length==2 && alink[0]==level.aWorld && alink[1]==level.aLevel) {
|
||||||
|
int distance=1000000000;
|
||||||
|
int choosedlevel[]=null;
|
||||||
|
for(int[] link: links) {
|
||||||
|
int distancetemp=(int)Math.sqrt((blevel.X-link[2])*(blevel.X-link[2])+(blevel.Y-link[3])*(blevel.Y-link[3]));
|
||||||
|
if (distancetemp<distance)
|
||||||
|
choosedlevel=link;
|
||||||
|
distance=distancetemp;
|
||||||
|
}
|
||||||
|
if (choosedlevel!=null) {
|
||||||
|
alink[0]=choosedlevel[0];
|
||||||
|
alink[1]=choosedlevel[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
links.removeValue(alink, true);
|
||||||
|
blevel.Link=alinks.toArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delLink(LinkDelMethod atype) {
|
||||||
|
delLink(usedlevel.aLevel, atype);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addLevel(Level level) {
|
public void addLevel(Level level) {
|
||||||
levels.add(level);
|
levels.add(level);
|
||||||
onchanged(level);
|
onchanged(level);
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class LocalBase extends Base {
|
||||||
dbHandler.openOrCreateDatabase();
|
dbHandler.openOrCreateDatabase();
|
||||||
} catch (SQLiteGdxException e) {
|
} catch (SQLiteGdxException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Gdx.app.log("wirechem-LocalBase", "Erreur à l'ouverture de la base");
|
Gdx.app.error("wirechem-LocalBase", "Erreur à l'ouverture de la base");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -140,7 +140,7 @@ public class LocalBase extends Base {
|
||||||
|
|
||||||
public boolean deleteCampaign(String description) {
|
public boolean deleteCampaign(String description) {
|
||||||
try {
|
try {
|
||||||
dbHandler.rawQuery("delete from worlds where desc='" + description
|
dbHandler.execSQL("delete from worlds where desc='" + description
|
||||||
+ "';");
|
+ "';");
|
||||||
} catch (SQLiteGdxException e) {
|
} catch (SQLiteGdxException e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -159,7 +159,7 @@ public class LocalBase extends Base {
|
||||||
bos.close();
|
bos.close();
|
||||||
byte[] bytes = bos.toByteArray();
|
byte[] bytes = bos.toByteArray();
|
||||||
encoded = Base64Coder.encodeLines(bytes);
|
encoded = Base64Coder.encodeLines(bytes);
|
||||||
dbHandler.rawQuery("replace into worlds (desc,object) values ('"
|
dbHandler.execSQL("replace into worlds (desc,object) values ('"
|
||||||
+ description + "','" + encoded + "');");
|
+ description + "','" + encoded + "');");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -185,7 +185,7 @@ public class LocalBase extends Base {
|
||||||
|
|
||||||
public boolean setLevelunlock(int user, int level) {
|
public boolean setLevelunlock(int user, int level) {
|
||||||
try {
|
try {
|
||||||
dbHandler.rawQuery("insert into locks (user,level) values (" + user
|
dbHandler.execSQL("insert into locks (user,level) values (" + user
|
||||||
+ "," + level + ");");
|
+ "," + level + ");");
|
||||||
} catch (SQLiteGdxException e) {
|
} catch (SQLiteGdxException e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -237,7 +237,7 @@ public class LocalBase extends Base {
|
||||||
byte[] bytes = bos.toByteArray();
|
byte[] bytes = bos.toByteArray();
|
||||||
encoded = Base64Coder.encodeLines(bytes);
|
encoded = Base64Coder.encodeLines(bytes);
|
||||||
dbHandler
|
dbHandler
|
||||||
.rawQuery("replace into transmuters (user,object) values ("
|
.execSQL("replace into transmuters (user,object) values ("
|
||||||
+ user + ",'" + encoded + "');");
|
+ user + ",'" + encoded + "');");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -262,7 +262,7 @@ public class LocalBase extends Base {
|
||||||
|
|
||||||
public boolean setResearchpoint(int user, int point) {
|
public boolean setResearchpoint(int user, int point) {
|
||||||
try {
|
try {
|
||||||
dbHandler.rawQuery("replace into research (user,value) values ("
|
dbHandler.execSQL("replace into research (user,value) values ("
|
||||||
+ user + "," + point + ");");
|
+ user + "," + point + ");");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -332,7 +332,7 @@ public class LocalBase extends Base {
|
||||||
bos.close();
|
bos.close();
|
||||||
byte[] bytes = bos.toByteArray();
|
byte[] bytes = bos.toByteArray();
|
||||||
encoded = Base64Coder.encodeLines(bytes);
|
encoded = Base64Coder.encodeLines(bytes);
|
||||||
dbHandler.rawQuery("insert into grids (user,level,object) values ("
|
dbHandler.execSQL("insert into grids (user,level,object) values ("
|
||||||
+ user + "," + level + ",'" + encoded + "');");
|
+ user + "," + level + ",'" + encoded + "');");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -352,12 +352,12 @@ public class LocalBase extends Base {
|
||||||
byte[] bytes = bos.toByteArray();
|
byte[] bytes = bos.toByteArray();
|
||||||
encoded = Base64Coder.encodeLines(bytes);
|
encoded = Base64Coder.encodeLines(bytes);
|
||||||
try {
|
try {
|
||||||
dbHandler.rawQuery("delete from grids where user=" + user
|
dbHandler.execSQL("delete from grids where user=" + user
|
||||||
+ " and level=" + level + " and tag='" + tag + "';");
|
+ " and level=" + level + " and tag='" + tag + "';");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
dbHandler
|
dbHandler
|
||||||
.rawQuery("insert into grids (user,level,tag,object) values ("
|
.execSQL("insert into grids (user,level,tag,object) values ("
|
||||||
+ user
|
+ user
|
||||||
+ ","
|
+ ","
|
||||||
+ level
|
+ level
|
||||||
|
|
|
@ -42,6 +42,7 @@ import fr.evolving.automata.Grid;
|
||||||
import fr.evolving.automata.Level;
|
import fr.evolving.automata.Level;
|
||||||
import fr.evolving.automata.Transmuter;
|
import fr.evolving.automata.Transmuter;
|
||||||
import fr.evolving.automata.Worlds;
|
import fr.evolving.automata.Worlds;
|
||||||
|
import fr.evolving.automata.Worlds.LinkDelMethod;
|
||||||
import fr.evolving.automata.Worlds.State;
|
import fr.evolving.automata.Worlds.State;
|
||||||
import fr.evolving.database.Base;
|
import fr.evolving.database.Base;
|
||||||
import fr.evolving.dialogs.WarningDialog;
|
import fr.evolving.dialogs.WarningDialog;
|
||||||
|
@ -187,7 +188,11 @@ public class LevelScreen implements Screen {
|
||||||
if (level.Name.isEmpty())
|
if (level.Name.isEmpty())
|
||||||
level.Name=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-name]");
|
level.Name=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-name]");
|
||||||
if (level.Description.isEmpty())
|
if (level.Description.isEmpty())
|
||||||
|
try {
|
||||||
level.Description=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-desc]");
|
level.Description=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-desc]");
|
||||||
|
}
|
||||||
|
catch (Exception E) {}
|
||||||
|
finally {level.Description="";}
|
||||||
ButtonLevel buttonlevel= new ButtonLevel(level, AssetLoader.ratio, true);
|
ButtonLevel buttonlevel= new ButtonLevel(level, AssetLoader.ratio, true);
|
||||||
buttonLevels.add(buttonlevel);
|
buttonLevels.add(buttonlevel);
|
||||||
if (worlds.isDebug()) buttonlevel.setDisabled(false);
|
if (worlds.isDebug()) buttonlevel.setDisabled(false);
|
||||||
|
@ -813,25 +818,6 @@ public class LevelScreen implements Screen {
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
if (selected!=null) {
|
if (selected!=null) {
|
||||||
for (int i=0;i<buttonLevels.size;i++) {
|
|
||||||
ButtonLevel button=buttonLevels.get(i);
|
|
||||||
Array<int[]> links=new Array<int[]>(button.level.Link);
|
|
||||||
for(int[] link: links)
|
|
||||||
if (link.length==2 && link[0]==selected.level.aWorld && link[1]==selected.level.aLevel)
|
|
||||||
{
|
|
||||||
if (i==buttonLevels.size-1)
|
|
||||||
links.removeValue(link, true);
|
|
||||||
else {
|
|
||||||
for (int j=i+1;j<buttonLevels.size;j++) {
|
|
||||||
if (buttonLevels.get(j)!=null) {
|
|
||||||
link[1]=j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
button.level.Link=links.toArray();
|
|
||||||
}
|
|
||||||
Gdx.app.debug("wirechem-LevelScreen", "Destruction du bouton :"+selected.level.aLevel);
|
Gdx.app.debug("wirechem-LevelScreen", "Destruction du bouton :"+selected.level.aLevel);
|
||||||
worlds.delLevel(selected.level.aLevel);
|
worlds.delLevel(selected.level.aLevel);
|
||||||
selectone();
|
selectone();
|
||||||
|
@ -844,16 +830,8 @@ public class LevelScreen implements Screen {
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
if (selected!=null) {
|
if (selected!=null) {
|
||||||
for (ButtonLevel button : buttonLevels) {
|
Gdx.app.debug("wirechem-LevelScreen", "Destruction des liens :"+selected.level.aLevel);
|
||||||
Array<int[]> links=new Array<int[]>(button.level.Link);
|
worlds.delLink(selected.level.aLevel, LinkDelMethod.rebase);
|
||||||
for(int[] link: links)
|
|
||||||
if (link.length==2 && link[0]==selected.level.aWorld && link[1]==selected.level.aLevel)
|
|
||||||
{
|
|
||||||
Gdx.app.debug("wirechem-LevelScreen", "Destruction du lien :"+selected.level.aLevel);
|
|
||||||
links.removeValue(link, true);
|
|
||||||
}
|
|
||||||
button.level.Link=links.toArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -937,7 +915,7 @@ public class LevelScreen implements Screen {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
vertibar=new VerticalGroup();
|
vertibar=new VerticalGroup();
|
||||||
vertibar.setPosition(1600, AssetLoader.height-500);
|
vertibar.setPosition(1600, AssetLoader.height-100);
|
||||||
vertibar.center();
|
vertibar.center();
|
||||||
vertibar.addActor(databaseSave);
|
vertibar.addActor(databaseSave);
|
||||||
vertibar.space(20f);
|
vertibar.space(20f);
|
||||||
|
|
Loading…
Reference in New Issue