20
|
1 using System.Collections;
|
|
2 using System.Collections.Generic;
|
|
3 using System;
|
|
4 using UnityEngine;
|
|
5
|
|
6 namespace JungleDB {
|
|
7 public class DefaultJungle : Jungle {
|
|
8 private Journal journal;
|
|
9 private TreeMap <string, JungleTree> trees;
|
|
10 private string uuid;
|
|
11 private TreeEditor editor;
|
|
12
|
|
13 public void Start(){
|
|
14 DefaultJungle j = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser()));
|
|
15 JungleTree t = j.createNewTree ("fuga");
|
|
16
|
|
17 JungleTreeEditor e1 = t.getTreeEditor ();
|
|
18
|
|
19 DefaultNodePath root = new DefaultNodePath ();
|
|
20 Either<Error, JungleTreeEditor> either = e1.addNewChildAt (root, 0);
|
|
21 e1 = either.b();
|
|
22 either = e1.addNewChildAt (root.add (0), 0);
|
|
23 e1 = either.b ();
|
|
24 e1.commit ();
|
|
25 }
|
|
26
|
|
27 public DefaultJungle(Journal journal, string uuid, TreeEditor editor){
|
|
28 this.journal = new NullJournal();
|
|
29 this.trees = new TreeMap <string, JungleTree>();
|
|
30 this.uuid = uuid;
|
|
31 this.editor = editor;
|
|
32 }
|
|
33
|
|
34 public JungleTree getTreeByName(string name) {
|
|
35
|
|
36 JungleTree jungle_tree = trees.get(name);
|
|
37 if (jungle_tree != null) {
|
|
38 return jungle_tree;
|
|
39 } else {
|
|
40 Debug.Log ("そのTreeは無いようですね。");
|
|
41 return null;
|
|
42 }
|
|
43 }
|
|
44
|
|
45 public JungleTree createNewTree(string name) {
|
|
46 ChangeList list = new InnerChangeList(uuid,name);
|
|
47 DefaultTreeNode root = new DefaultTreeNode ();
|
|
48 InterfaceTraverser traverser = new InterfaceTraverser (root, true);
|
|
49 TreeContext tc = new DefaultTreeContext (root, null, list, uuid, name, 0, traverser);
|
|
50 JungleTree newTree = new DefaultJungleTree (tc, uuid, journal.getWriter (), editor);
|
|
51 if (newTree != null) {
|
|
52 trees = trees.put (name, newTree);
|
|
53 } else {
|
|
54 Debug.Log ("こんばんは、nullです。");
|
|
55 }
|
|
56 return newTree;
|
|
57 }
|
|
58
|
|
59 public class InnerChangeList : ChangeList {
|
|
60
|
|
61 string uuid;
|
|
62 string name;
|
|
63
|
|
64
|
|
65 IEnumerator IEnumerable.GetEnumerator()
|
|
66 {
|
|
67 return this.GetEnumerator();
|
|
68 }
|
|
69
|
|
70 public IEnumerator<TreeOperation> GetEnumerator()
|
|
71 {
|
|
72 return iterator ();
|
|
73 }
|
|
74
|
|
75 // construct
|
|
76 public InnerChangeList(string _uuid, string _name) {
|
|
77 this.uuid = _uuid;
|
|
78 this.name = _name;
|
|
79 }
|
|
80
|
|
81 public IEnumerator<TreeOperation> iterator() {
|
|
82 List<TreeOperation> nil = new List<TreeOperation>();
|
|
83 return nil.iterator();
|
|
84 }
|
|
85
|
|
86 public string uuids() {
|
|
87 return uuid;
|
|
88 }
|
|
89
|
|
90 public string getTreeName() {
|
|
91 return name;
|
|
92 }
|
|
93
|
|
94 public TreeOperationLog getLog() {
|
|
95 return new DefaultTreeOperationLog();
|
|
96 }
|
|
97 }
|
|
98 }
|
|
99 } |