package net.mgsx.game.examples.openworld.systems;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;

import net.mgsx.game.core.annotations.Asset;
import net.mgsx.game.core.annotations.Editable;
import net.mgsx.game.core.annotations.EditableSystem;
import net.mgsx.game.examples.openworld.ui.ConnectionView;
import net.mgsx.game.plugins.core.systems.HUDSystem;
import net.mgsx.game.services.gapi.GAPI;

@EditableSystem
public class OpenWorldHUDSystem extends HUDSystem
{
	@Asset("skins/game-skin.json")
	public Skin skin;
	
	private Table root;
	private Table view;
	private boolean hidden = true;
	
	@Override
	public void update(float deltaTime) {
		// XXX init GUI in update because of dependency injection
		if(root == null){
			root = new Table(skin);
			root.setFillParent(true);
			buildUI();
		}
		super.update(deltaTime);
	}
	
	@Editable
	public void toggle() 
	{
		if(hidden){
			getStage().addActor(root);
			hidden = false;
		}else{
			root.remove();
			hidden = true;
		}
	}

	private void buildUI() 
	{
		view = new ConnectionView(skin);
		
		root.clearChildren();
		root.add(view);
	}

	@Editable
	public void testSaveGame() {
		
		GAPI.service.saveGame("slot01.json", Gdx.files.local("kit-autosave.json"));
		
	}
	
	@Editable
	public void testLoadGames() {
		
		GAPI.service.listGames();
		
	}
	
	@Editable
	public void testCompleteAch() {
		
		GAPI.service.unlockAchievement("CgkI9ouoooEcEAIQAw");
		
	}
	@Editable
	public void testIncAch() {
		
		GAPI.service.incrementAchievement("CgkI9ouoooEcEAIQAg", 1);
		
	}
	@Editable
	public void testUpdateLead() {
		
		GAPI.service.submitScore("CgkI9ouoooEcEAIQBQ", 500L);
	}
	

}

@@ -470,16 +470,62 @@
 pi.GAPI;
+%0Aimport net.mgsx.game.services.gapi.SavedGame;
 %0A%0A@Edita
@@ -1254,32 +1254,49 @@
 veGame() %7B%0A%09%09%0A%09%09
+SavedGame game = 
 GAPI.service.sav
@@ -1296,30 +1296,79 @@
 ice.
-sav
+creat
 eGame(
-%22slot01.json%22
+);%0A%09%09game.name = %22slot01.json%22;%0A%09%09GAPI.service.saveGame(game
 , Gd
@@ -1404,19 +1404,16 @@
 son%22));%0A
-%09%09%0A
 %09%7D%0A%09%0A%09@E

migrate saved game usage