diff --git a/core/src/fr/evolving/automata/Cell.java b/core/src/fr/evolving/automata/Cell.java index c43ec82..ee5955e 100644 --- a/core/src/fr/evolving/automata/Cell.java +++ b/core/src/fr/evolving/automata/Cell.java @@ -2,12 +2,13 @@ package fr.evolving.automata; import java.io.Serializable; -public class Cell implements Serializable { +public class Cell implements Serializable,Cloneable { public int Fiber; public boolean Copper; + public Transmuter Transmuter; + public transient int Copper_calc; public transient int Fiber_old; - public Transmuter Transmuter; public transient int Transmuter_calc; public transient int Transmuter_movex; public transient int Transmuter_movey; @@ -21,5 +22,13 @@ public class Cell implements Serializable { this.Transmuter_movex = 0; this.Transmuter_movey = 0; } - + + public Object clone() { + Cell result = new Cell(); + result.Copper=this.Copper; + result.Fiber=this.Fiber; + if (this.Transmuter!=null) + result.Transmuter=(Transmuter)this.Transmuter.clone(); + return result; + } } diff --git a/core/src/fr/evolving/automata/Grid.java b/core/src/fr/evolving/automata/Grid.java index 6d19483..7c8a4d9 100644 --- a/core/src/fr/evolving/automata/Grid.java +++ b/core/src/fr/evolving/automata/Grid.java @@ -7,7 +7,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.ObjectMap.Entry; -public class Grid implements Serializable { +public class Grid implements Serializable,Cloneable { public Cell[][] Cells; public Integer sizeX, sizeY; @@ -269,5 +269,13 @@ public class Grid implements Serializable { else return cell.Copper_calc; } + + public Object clone() { + Grid result = new Grid(this.sizeX,this.sizeY); + for (int x = 0; x < this.sizeX; x++) + for (int y = 0; y < this.sizeY; y++) + result.Cells[x][y] = (Cell)this.Cells[x][y].clone(); + return result; + } } diff --git a/core/src/fr/evolving/automata/Worlds.java b/core/src/fr/evolving/automata/Worlds.java index 030ac6f..e9bdb1d 100644 --- a/core/src/fr/evolving/automata/Worlds.java +++ b/core/src/fr/evolving/automata/Worlds.java @@ -166,14 +166,14 @@ public class Worlds extends Actor { ReadLastGrid(); if (usedlevel.Grid == null || force) { Gdx.app.debug(getClass().getSimpleName(), "Copie monde original."); - usedlevel.Grid = usedlevel.Grid_orig; + usedlevel.Grid = (Grid)usedlevel.Grid_orig.clone(); } else { - Gdx.app.debug(getClass().getSimpleName(), - "Récupération de la dernière grille."); - usedlevel.Grid.tiling_copper(); - usedlevel.Grid.tiling_transmuter(); + Gdx.app.debug(getClass().getSimpleName(),"Récupération de la dernière grille."); + ReadLastGrid(); } + usedlevel.Grid.tiling_copper(); + usedlevel.Grid.tiling_transmuter(); } public void setLevel(int alevel) { diff --git a/core/src/fr/evolving/screens/LevelScreen.java b/core/src/fr/evolving/screens/LevelScreen.java index 7fb1640..caf3d1c 100644 --- a/core/src/fr/evolving/screens/LevelScreen.java +++ b/core/src/fr/evolving/screens/LevelScreen.java @@ -201,7 +201,9 @@ public class LevelScreen implements Screen { } buttonLevels = null; buttonLevels = new ButtonLevel[10]; - for (Level level : worlds.getLevels()) { + Array levels=worlds.getLevels(); + if (levels!=null) + for (Level level : levels) { if (level != null) { if (level.Name.isEmpty()) level.Name=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-name]"); @@ -268,15 +270,17 @@ public class LevelScreen implements Screen { } if (worlds.getInformations()==null) selected=buttonLevels[0]; - selected.setChecked(true); - showlevel(selected); + if (selected!=null) { + selected.setChecked(true); + buttonPlay.setVisible(true); + TextDescriptive.setVisible(true); + showlevel(selected); + } Previous.setVisible(!worlds.isFirstWorld()); if (worlds.isDebug()) Next.setVisible(!worlds.isRealLastWorld()); else Next.setVisible(!worlds.isLastWorld()); - buttonPlay.setVisible(true); - TextDescriptive.setVisible(true); } else { Previous.setVisible(false); @@ -623,8 +627,9 @@ public class LevelScreen implements Screen { } public void showlevel(ButtonLevel button) { - Gdx.app.debug(getClass().getSimpleName(), "Reading button " - + button.level.Name); + if (button==null) + return; + Gdx.app.debug(getClass().getSimpleName(), "Reading button " + button.level.Name); TextDescriptive.setText(button.level.Description); if (button.level.Maxcycle < 99999 && button.level.Maxcycle > 0) { cycle.setText(String.valueOf(button.level.Maxcycle));