From 4652a2170320e067946db03c8f767bd304a3a543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Mon, 27 Jun 2016 13:41:06 +0200 Subject: [PATCH] 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 --- core/src/fr/evolving/automata/Level.java | 2 + core/src/fr/evolving/automata/Worlds.java | 75 +++++++++++++++++-- core/src/fr/evolving/database/LocalBase.java | 18 ++--- core/src/fr/evolving/screens/LevelScreen.java | 40 +++------- 4 files changed, 89 insertions(+), 46 deletions(-) diff --git a/core/src/fr/evolving/automata/Level.java b/core/src/fr/evolving/automata/Level.java index 607b52c..14f6061 100644 --- a/core/src/fr/evolving/automata/Level.java +++ b/core/src/fr/evolving/automata/Level.java @@ -55,6 +55,7 @@ public class Level implements Serializable,Cloneable { this.Element = Element; this.rewards = Current; this.Victory_orig = Victory; + this.Victory = Victory; this.X = X; this.Y = Y; this.Tech = Tech; @@ -72,6 +73,7 @@ public class Level implements Serializable,Cloneable { this.Special = Special; this.Tuto = Tuto; this.Link = Link; + this.Locked=true; } public Object clone() { diff --git a/core/src/fr/evolving/automata/Worlds.java b/core/src/fr/evolving/automata/Worlds.java index b603a02..b25113b 100644 --- a/core/src/fr/evolving/automata/Worlds.java +++ b/core/src/fr/evolving/automata/Worlds.java @@ -22,6 +22,7 @@ public class Worlds extends Actor { private Level lastchange; public enum State {pause,simulating,notloaded,databasefailed}; + public enum LinkDelMethod {all,in,out,rebase}; public Worlds(String campaign) { name=campaign; @@ -193,17 +194,22 @@ public class Worlds extends Actor { usedlevel.Grid_orig = (Grid)usedlevel.Grid.clone(); } - public Level findLevel(int levelid) { + public Level findLevel(int worldid, int levelid) { if (state!=State.notloaded) - if (usedworld>=0) { - Array tempworld=getLevels(); - for(Level level:tempworld) - if (level.aLevel==levelid) - return level; + if (worldid>=0) { + Array tempworld=getLevels(worldid); + if (tempworld!=null) + for(Level level:tempworld) + if (level.aLevel==levelid) + return level; } return null; } + public Level findLevel(int levelid) { + return findLevel(usedworld, levelid); + } + public void setLevel(int levelid) { Level level=findLevel(levelid); if (level!=null) @@ -252,6 +258,63 @@ public class Worlds extends Actor { 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 links=new Array(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 links=new Array(); + Array templinks=new Array(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 alinks=new Array(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 links=new Array(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 links=new Array(button.level.Link); - 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(); - } + Gdx.app.debug("wirechem-LevelScreen", "Destruction des liens :"+selected.level.aLevel); + worlds.delLink(selected.level.aLevel, LinkDelMethod.rebase); } } }); @@ -937,7 +915,7 @@ public class LevelScreen implements Screen { } }); vertibar=new VerticalGroup(); - vertibar.setPosition(1600, AssetLoader.height-500); + vertibar.setPosition(1600, AssetLoader.height-100); vertibar.center(); vertibar.addActor(databaseSave); vertibar.space(20f);