changeset 11:cf20add31466

change putAttribute -> use fmap.
author Kazuma Takeda
date Sat, 28 Jan 2017 19:15:44 +0900
parents 3fefb9f9025d
children b55d586dd4eb
files Assets/Application/Scripts/Item.cs Assets/Application/Scripts/Player.cs Assets/Application/Scripts/StageManager.cs Assets/Application/Scripts/Test/SaveDataTest.cs obj/Debug/Assembly-CSharp.dll obj/Debug/Assembly-CSharp.dll.mdb
diffstat 6 files changed, 52 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/Assets/Application/Scripts/Item.cs	Fri Jan 20 07:30:26 2017 +0900
+++ b/Assets/Application/Scripts/Item.cs	Sat Jan 28 19:15:44 2017 +0900
@@ -47,6 +47,7 @@
 
 	public void Delete() {
 		if (nowBroken == 0) {
+			DeleteTreeNode ();
 			Destroy (this.gameObject);
 			return;
 		}
@@ -54,6 +55,24 @@
 		nowBroken -= 1;
 	}
 
+	public void DeleteTreeNode () {
+		jungle = SaveDataTest.jungle;
+		JungleTree tree      = jungle.getTreeByName ("SceneTree");
+		JungleTreeEditor edt = tree.getTreeEditor ();
+
+		NodePath root        = new DefaultNodePath ();
+		NodePath stagePath   = root.add (1);
+
+		Either<Error, JungleTreeEditor> e = edt.deleteChildAt (stagePath, indexID);
+		if (e.isA ()) {
+			print ("[Error] Try again!");
+			SetCreateTreeNode ();
+		}
+		edt = e.b ();
+		edt.commit ();
+	}
+
+
 	public void SetCreateTreeNode () {
 		jungle = SaveDataTest.jungle;
 		JungleTree tree      = jungle.getTreeByName ("SceneTree");
--- a/Assets/Application/Scripts/Player.cs	Fri Jan 20 07:30:26 2017 +0900
+++ b/Assets/Application/Scripts/Player.cs	Sat Jan 28 19:15:44 2017 +0900
@@ -124,8 +124,10 @@
 		JungleTreeEditor edt = tree.getTreeEditor ();
 
 		NodePath playerpath = new DefaultNodePath ().add (0);
-		edt = edt.putAttribute (playerpath, "HP", Encoding.UTF8.GetBytes (HP.ToString())).b();
-		edt = edt.commit ().b();
+		Either<Error, JungleTreeEditor> e = edt.putAttribute (playerpath, this);
+		// e.fmap (edt.commit ());
+
+
 	}
 
 }
--- a/Assets/Application/Scripts/StageManager.cs	Fri Jan 20 07:30:26 2017 +0900
+++ b/Assets/Application/Scripts/StageManager.cs	Sat Jan 28 19:15:44 2017 +0900
@@ -8,19 +8,19 @@
 
 	private float _maxHeight = 10;
 
-	//パーリンノイズを使ったマップか
+	// パーリンノイズを使ったマップか
 	[SerializeField]
 	private bool _isPerlinNoiseMap = true;
 
-	//起伏の激しさ
+	// 起伏の激しさ
 	[SerializeField]
 	private float _relief = 15f;
 
-	//Y座標を滑らかにするか(小数点以下をそのままにする)
+	// Y座標を滑らかにするか(小数点以下をそのままにする)
 	[SerializeField]
 	private bool _isSmoothness = false;
 
-	//マップの大きさ
+	// マップの大きさ
 	[SerializeField]
 	private float _mapSize = 1f;
 
@@ -85,14 +85,11 @@
 		TreeNode item_node = getItem (box_node, ItemID);
 
 		attr = item_node.getAttributes ();
-		string subType = attr.getString ("Type");
-		string broken = attr.getString ("Broken");
-		string itemID = attr.getString ("ID");
-		string color_code = attr.getString ("Color");
+		ItemInfo iteminfo = attr.get<ItemInfo> ("ItemInfo");
 
 		GameObject item = Resources.Load<GameObject> ("Prefabs/" + type + "/Box");
 		GameObject obj = Instantiate (item);
-		obj.GetComponent<Item> ().SetItem (Convert.ToInt32 (broken), subType, itemID, TotalIndex, color_code);
+		obj.GetComponent<Item> ().SetItem (iteminfo ,TotalIndex);
 		obj.transform.position = new Vector3 (v.x, v.y, v.z);
 		obj.transform.SetParent (baseStage.transform);
 		obj.GetComponent<Item> ().SetCreateTreeNode ();
--- a/Assets/Application/Scripts/Test/SaveDataTest.cs	Fri Jan 20 07:30:26 2017 +0900
+++ b/Assets/Application/Scripts/Test/SaveDataTest.cs	Sat Jan 28 19:15:44 2017 +0900
@@ -4,6 +4,7 @@
 using UnityEngine.SceneManagement;
 using JungleDB;
 using System.Text;
+using Default = System.Collections.Generic;
 
 public class SaveDataTest : MonoBehaviour {
 
@@ -111,33 +112,35 @@
 		JungleTree tree = jungle.createNewTree ("ItemTree");
 		JungleTreeEditor edt = tree.getTreeEditor ();
 
-		edt = edt.putAttribute (rootPath, "TreeName", "Item").b ();
+
+		Either<Error, JungleTreeEditor> e = edt.putAttribute (rootPath, "TreeName", "Item");
 
-		edt = edt.addNewChildAt (rootPath, 0).b ();
-		edt = edt.putAttribute ("Category", "Box").b ();
+		System.Func<JungleTreeEditor, JungleTreeEditor> f =  (JungleTreeEditor arg) => {
+			edt = arg;
+			return edt;
+		};
 
-		edt = edt.addNewChildAt (rootPath, 1).b ();
-		edt = edt.putAttribute ("Category", "Food").b ();
+		e.fmap (f, edt.addNewChildAt (rootPath, 0));
+		e.fmap (f, edt.putAttribute ("Category", "Box"));
+
+		e.fmap (f, edt.addNewChildAt (rootPath, 1));
+		e.fmap (f, edt.putAttribute ("Category", "Food"));
 
 		NodePath path = rootPath.add(0);
 
-		edt = edt.addNewChildAt (path, 0).b ();
-
-		ItemInfo item_info = new ItemInfo (1, 2, "Grass", "#019540FF");
-		edt = edt.putAttribute (item_info).b ();
-
-		edt = edt.addNewChildAt (path, 1).b ();
-		item_info = new ItemInfo (2, 4, "Wood", "#7F3C01FF");
-		edt = edt.putAttribute (item_info).b ();
+		Default.List<ItemInfo> infoList = new Default.List<ItemInfo> ();
+		infoList.Add (new ItemInfo (1, 2, "Grass", "#019540FF"));
+		infoList.Add (new ItemInfo (2, 4, "Wood", "#7F3C01FF"));
+		infoList.Add (new ItemInfo (3, 1, "Sand", "#D4500EFF"));
+		infoList.Add (new ItemInfo (4, 5, "Water", "#2432ADFF"));
 
-		edt = edt.addNewChildAt (path, 2).b ();
-		item_info = new ItemInfo (3, 1, "Sand", "#D4500EFF");
-		edt = edt.putAttribute (item_info).b ();
+		int i = 0;
+		foreach (var info in infoList) {
+			e.fmap (f, edt.addNewChildAt (path, i));
+			e.fmap (f, edt.putAttribute (info));
+			i++;
+		}
 
-
-		edt = edt.addNewChildAt (path, 3).b ();
-		item_info = new ItemInfo (4, 5, "Water", "#2432ADFF");
-		edt = edt.putAttribute (item_info).b ();
 		edt.commit ();
 
 		StageManager.Instance.Init ();
Binary file obj/Debug/Assembly-CSharp.dll has changed
Binary file obj/Debug/Assembly-CSharp.dll.mdb has changed