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