Exemple #1
0
    public static NodeData CreateRoot(MapSaveStateSerializable saveState)
    {
        NodeData toReturn = new NodeData(null, saveState);

        toReturn.isRoot   = true;
        toReturn.nbChild  = 0;
        toReturn.depth    = 0;
        toReturn.isAMerge = false;
        return(toReturn);
    }
Exemple #2
0
    public static NodeData CreateMergeNode(NodeData into, NodeData from)
    {
        MapSaveStateSerializable saveState = new MapSaveStateSerializable(into, from);
        NodeData toReturn = new NodeData(null, saveState);

        toReturn.parent      = from.depth > into.depth ? from : into;
        toReturn.mergeOrigin = from.depth > into.depth ? into : from;
        toReturn.depth       = Mathf.Max(into.depth, from.depth) + 1;
        toReturn.nbChild     = 0;
        toReturn.isAMerge    = true;
        toReturn.parent.nbChild++;
        return(toReturn);
    }
Exemple #3
0
    public MapSaveStateSerializable(MapSaveStateSerializable saveState)
    {
        this.xSize  = saveState.xSize;
        this.ySize  = saveState.ySize;
        this.isDead = false;
        int size = saveState.xSize * saveState.ySize;

        tiles = new TileData[saveState.tiles.Length];
        for (int i = 0; i < saveState.tiles.Length; i++)
        {
            tiles[i] = saveState.tiles[i];
        }
    }
Exemple #4
0
    // Use this for initialization
    public static MapSaveState CreateFromSerialized(MapSaveStateSerializable serialized)
    {
        //MapSaveState toReturn = Create(serialized.xSize, serialized.ySize);
        MapSaveState toReturn = Instantiate(original).GetComponent <MapSaveState>();

        toReturn.xSize  = serialized.xSize;
        toReturn.ySize  = serialized.ySize;
        toReturn.isDead = false;
        toReturn.tiles  = new TileData[toReturn.xSize, toReturn.ySize];

        for (int i = 0; i < serialized.tiles.Length; i++)
        {
            toReturn.tiles[i % toReturn.xSize, i / toReturn.xSize] = serialized.tiles[i].GetCopy();
        }
        toReturn.serializable = serialized;
        toReturn.LinkTilesWithData();
        return(toReturn);
    }
Exemple #5
0
 public NodeData(NodeData parent, MapSaveStateSerializable saveState = null)
 {
     this.parent  = parent;
     this.nbChild = 0;
     if (parent != null)
     {
         this.depth = parent.depth + 1;
         parent.nbChild++;
     }
     if (saveState == null)
     {
         this.saveState = new MapSaveStateSerializable(parent.saveState);
     }
     else
     {
         this.saveState = saveState;
     }
     this.isRoot   = false;
     this.isAMerge = false;
 }
Exemple #6
0
 string MapToJSON(MapSaveStateSerializable obj)
 { // Save object to JSON string
     return(JsonUtility.ToJson(obj));
 }