package main.java.model;

import java.io.File;

import main.java.controller.Game;

public class SaveDAO extends CsvDAO {
	
	private ModelManager modelManager;
	
	public SaveDAO(File file, ModelManager mm)
	{
		super(file);
		modelManager = mm;
		System.out.println("Save file DAO created");
	}
	
	public void load()
	{
		System.out.println("Loading");
	}
	
	public void save()
	{
		System.out.println("Saving");
		//Piece[] pieces = modelManager.getPieces();
		Game game =  modelManager.getGame();
		
		Piece[] pieces = game.getGamePanel().getOrderedPieces();
		
		int debug = 0;
		for(Piece p : pieces)
		{
			System.out.println("Peice : " + ++debug + " id " + p.getId() + " orientation " + p.getOrientation() + " x:" + p.getPositionX() + " y:" +  p.getPositionY());
			for(Face f : p.getFaces())
			{
				System.out.println(" Face : " + f.getId() + " patern " + f.getPattern() + " " + f.getBgColor() + " " + f.getFgColor());
			}
		}
	}

}

@@ -35,15 +35,65 @@
 ava.
-io.File
+awt.List;%0Aimport java.io.File;%0Aimport java.util.ArrayList
 ;%0A%0Ai
@@ -391,24 +391,144 @@
 %22Loading%22);%0A
+%09%09//Read the CSV file%0A%09%09//Apply content to the game (create faces and pieces and so on%0A%09%09//Relaunch it with theses data%0A
 %09%7D%0A%09%0A%09public
@@ -729,57 +729,796 @@
 ;%0A%09%09
-%0A%09%09int debug = 0;%0A%09%09for(Piece p : pieces)%0A%09%09%7B%0A%09%09%09
+ArrayList%3CString%5B%5D%3E gameContent = new ArrayList%3CString%5B%5D%3E();%0A%0A%09%09int debug = 0;%0A%09%09for(Piece p : pieces)%0A%09%09%7B%0A%09%09%09//Piece ID, Piece Orient, F1 ID, F1 Pat, F1 bg, F1 FG, F2 ID, F2 pat... etc..%0A%09%09%09String%5B%5D pieceDesc = new String%5B18%5D;%0A%09%09%09%0A%09%09%09//Integer id = new Integer(p.getId());%0A%09%09%09%0A%09%09%09pieceDesc%5B0%5D = new Integer(p.getId()).toString();%0A%09%09%09pieceDesc%5B1%5D = new Integer(p.getOrientation()).toString();%0A%09%09%09for(int i = 0; i %3C 4; i++)%0A%09%09%09%7B%0A%09%09%09%09pieceDesc%5B2 + 0 + 4*i%5D = new Integer(p.getFaces()%5Bi%5D.getId()).toString();%0A%09%09%09%09pieceDesc%5B2 + 1 + 4*i%5D = p.getFaces()%5Bi%5D.getPattern();%0A%09%09%09%09pieceDesc%5B2 + 2 + 4*i%5D = p.getFaces()%5Bi%5D.getBgColor();%0A%09%09%09%09pieceDesc%5B2 + 3 + 4*i%5D = p.getFaces()%5Bi%5D.getFgColor();%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09for(String s : pieceDesc)%0A%09%09%09%09System.out.println(s);%0A%09%09%09%0A%09%09%09gameContent.add(pieceDesc);%0A%09%09%09/*
 Syst
@@ -1837,12 +1837,235 @@
 %09%09%09%7D
-%0A%09%09%7D
+*/%0A%09%09%09%0A%09%09%09%0A%09%09%7D%0A%09%09%0A%09%09this.writeLineFromArray(gameContent);%0A%09%09%0A%09%09//Get all information in text form%0A%09%09//create an Array%3CStrings%3E that represent the content of the CSV to write%0A%09%09//wite it with %0A%09%09//this.writeLineFromArray(array);
 %0A%09%7D%0A

write the complete content of the puzzle board to a file whenhitting the save button