0
|
1 using UnityEngine;
|
|
2 using System.Collections;
|
7
|
3 using JungleDB;
|
0
|
4
|
|
5 public class SaveData : MonoBehaviour {
|
|
6
|
|
7 public static SaveData Instance;
|
|
8
|
4
|
9 private Jungle mainScene ;
|
|
10 private JungleTree mainTree;
|
|
11 private JungleTreeEditor TreeEditor;
|
|
12 private TreeNode node;
|
8
|
13 // private NodePath root;
|
0
|
14 // Use this for initialization
|
|
15 void Awake () {
|
|
16 if (Instance == null) {
|
|
17 Instance = this;
|
|
18 }
|
|
19 }
|
4
|
20
|
|
21 private void Start () {
|
|
22 JungleStart ();
|
8
|
23 // root = new DefaultNodePath ();
|
|
24 // InterfaceTraverser t = new InterfaceTraverser (root, false);
|
4
|
25 }
|
|
26
|
|
27 private void JungleStart () {
|
|
28 Debug.Log ("[Jungle] Start ...");
|
|
29 mainScene = new DefaultJungle(null, "Main", new DefaultTreeEditor(new DefaultTraverser()));
|
|
30 }
|
|
31
|
|
32 public void CreateTree (string name) {
|
5
|
33 mainScene.createNewTree (name);
|
|
34 mainTree = mainScene.getTreeByName (name);
|
4
|
35 Debug.Log ("[Jungle] Create " + name + " Tree");
|
|
36 EditorMode ();
|
|
37 }
|
|
38
|
|
39 public void EditorMode () {
|
|
40 TreeEditor = mainTree.getTreeEditor ();
|
|
41 Debug.Log ("[Jungle] Editor Mode" + TreeEditor.ToString());
|
|
42 }
|
|
43
|
5
|
44 public void createTree (int pos, NodePath path, string key, byte[] value) {
|
|
45 Either<Error, JungleTreeEditor> either = TreeEditor.addNewChildAt(path, pos);
|
4
|
46 if (either.isA ()) {
|
5
|
47 Debug.LogError ("[Error]" + either.a ());
|
4
|
48 } else {
|
5
|
49 TreeEditor = either.b ();
|
|
50 Either<Error, JungleTreeEditor> eitherput = TreeEditor.putAttribute (path.add(pos), key, value);
|
|
51 if (eitherput.isA ()) {
|
|
52 Debug.LogError ("[Error]" + eitherput.a());
|
|
53 } else {
|
|
54 Debug.Log ("[Success]");
|
|
55 TreeEditor = eitherput.b ();
|
|
56 }
|
4
|
57 }
|
|
58 }
|
|
59
|
5
|
60 // public void PutAttribute (NodePath path, string key, byte[] value) {
|
|
61 // Either<Error, JungleTreeEditor> either = TreeEditor.putAttribute (path, key, value);
|
|
62 // if (either.isA ()) {
|
|
63 // Debug.LogError ("[Error]" + either.a());
|
|
64 // } else {
|
|
65 // Debug.Log ("[Success]");
|
|
66 // either.b ();
|
|
67 // }
|
|
68 // }
|
|
69
|
4
|
70 public void GetAttribute (NodePath path, string key) {
|
5
|
71 Either<Error, TreeNode> either = mainTree.getNodeOfPath (path);
|
|
72 if (either.isA ()) {
|
|
73 Debug.LogError ("[Error]");
|
|
74 } else {
|
|
75 node = either.b ();
|
|
76 print (key);
|
10
|
77 object target = node.getAttributes ().get (key);
|
|
78 print (target);
|
5
|
79 }
|
4
|
80 }
|
|
81
|
|
82 public void Push() {
|
7
|
83 Either<Error, JungleTreeEditor> r = TreeEditor.commit();
|
5
|
84 if (r.isA ()) {
|
4
|
85 Debug.LogError ("[Error]");
|
|
86 } else {
|
|
87 Debug.Log ("[Success]");
|
|
88 TreeEditor = r.b ();
|
|
89 }
|
|
90 }
|
0
|
91 }
|