# HG changeset patch # User Kazuma Takeda # Date 1485598544 -32400 # Node ID cf20add314666fbcf6ec29f2ea6a9d9809a23e9d # Parent 3fefb9f9025de0d35cb5d3c14d54f6ba04476cf7 change putAttribute -> use fmap. diff -r 3fefb9f9025d -r cf20add31466 Assets/Application/Scripts/Item.cs --- 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 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"); diff -r 3fefb9f9025d -r cf20add31466 Assets/Application/Scripts/Player.cs --- 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 e = edt.putAttribute (playerpath, this); + // e.fmap (edt.commit ()); + + } } diff -r 3fefb9f9025d -r cf20add31466 Assets/Application/Scripts/StageManager.cs --- 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"); GameObject item = Resources.Load ("Prefabs/" + type + "/Box"); GameObject obj = Instantiate (item); - obj.GetComponent ().SetItem (Convert.ToInt32 (broken), subType, itemID, TotalIndex, color_code); + obj.GetComponent ().SetItem (iteminfo ,TotalIndex); obj.transform.position = new Vector3 (v.x, v.y, v.z); obj.transform.SetParent (baseStage.transform); obj.GetComponent ().SetCreateTreeNode (); diff -r 3fefb9f9025d -r cf20add31466 Assets/Application/Scripts/Test/SaveDataTest.cs --- 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 e = edt.putAttribute (rootPath, "TreeName", "Item"); - edt = edt.addNewChildAt (rootPath, 0).b (); - edt = edt.putAttribute ("Category", "Box").b (); + System.Func 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 infoList = new Default.List (); + 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 (); diff -r 3fefb9f9025d -r cf20add31466 obj/Debug/Assembly-CSharp.dll Binary file obj/Debug/Assembly-CSharp.dll has changed diff -r 3fefb9f9025d -r cf20add31466 obj/Debug/Assembly-CSharp.dll.mdb Binary file obj/Debug/Assembly-CSharp.dll.mdb has changed