comparison src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/transaction/DefaultJungleTreeEditor.cs @ 0:dec15de2c6ff

first commit
author Kazuma
date Tue, 21 Jun 2016 17:11:12 +0900
parents
children 4d08270a61c8 02b2ab7bffe6
comparison
equal deleted inserted replaced
-1:000000000000 0:dec15de2c6ff
1 using UnityEngine;
2 using System.Collections.Generic;
3
4 public class DefaultJungleTreeEditor : JungleTreeEditor {
5
6 private TransactionManager txManager;
7 private TreeNode root;
8 private TreeEditor editor;
9 private TreeOperationLog log;
10
11 public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor)
12 : this(_root, _txManager, _editor, new DefaultTreeOperationLog())
13 {
14 }
15
16
17
18 public DefaultJungleTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log)
19 {
20 this.root = newNode;
21 this.txManager = _txManager;
22 this.editor = _editor;
23 this.log = _log;
24 }
25
26
27
28 private Either<Error,JungleTreeEditor> _edit(NodePath _path,NodeEditor _e)
29 {
30 Either<Error, LoggingNode> either = editor.edit (root, _path, _e);
31 if (either.isA ()) {
32 return DefaultEither<Error, JungleTreeEditor>.newA (either.a ());
33 }
34
35 LoggingNode newLogging = either.b ();
36 OperationLog newLog = newLogging.getOperationLog ();
37 TreeNode newNode = newLogging.getWrap ();
38
39 // 無名クラスが書けてない
40 IterableConverter<TreeOperation,NodeOperation>.Converter<TreeOperation, NodeOperation> converter = new InnerConverter (_path);
41
42
43 IEnumerable<TreeOperation> iterable = new IterableConverter<TreeOperation, NodeOperation> (newLog, converter);
44 DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog (iterable, newLog.length ());
45 TreeOperationLog newTreeOpLog = log.append (treeOperationLog);
46
47 JungleTreeEditor newEditor = new DefaultJungleTreeEditor (newNode, txManager, editor, newTreeOpLog);
48 return DefaultEither<Error, JungleTreeEditor>.newB (newEditor);
49
50 }
51
52
53 public Either<Error, JungleTreeEditor> replaceNewRootNode() {
54 replaceRootNodeAt appendChildAt = new replaceRootNodeAt ();
55 return _edit (new DefaultNodePath(), appendChildAt);
56 }
57
58 public Either<Error, JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) {
59 AppendChildAt appendChildAt = new AppendChildAt (_pos);
60 return _edit (_path, appendChildAt);
61 }
62
63 public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) {
64 DeleteChildAt deleteChildAt = new DeleteChildAt(_pos);
65 return _edit(_path,deleteChildAt);
66 }
67
68 public Either<Error, JungleTreeEditor> putAttribute(NodePath _path, string _key, GameObject _value) {
69 PutAttribute putAttribute = new PutAttribute (_key, _value);
70 return _edit (_path, putAttribute);
71 }
72
73 public Either<Error, JungleTreeEditor> deleteAttribute(NodePath _path, string _key) {
74 DeleteAttribute deleteAttribute = new DeleteAttribute (_key);
75 return _edit (_path, deleteAttribute);
76 }
77
78 public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor) {
79 return _edit(_path,_editor);
80 }
81
82 public Either<Error,JungleTreeEditor> success() {
83 Either<Error,TransactionManager> either = txManager.commit(root,log);
84 if(either.isA()){
85 return DefaultEither<Error, JungleTreeEditor>.newA(either.a());
86 }
87
88 TransactionManager newTxManager = either.b();
89 JungleTreeEditor newTreeEditor = new DefaultJungleTreeEditor(root,newTxManager,editor);
90
91 return DefaultEither<Error, JungleTreeEditor>.newB(newTreeEditor);
92 }
93
94 public Either<Error, JungleTreeEditor> flushSuccess() {
95 return success();
96 }
97
98 public class InnerConverter : IterableConverter<TreeOperation,NodeOperation>.Converter<TreeOperation,NodeOperation>{
99
100 NodePath path;
101
102 public InnerConverter(NodePath _path) {
103 path = _path;
104 }
105
106
107 public TreeOperation conv(NodeOperation _b){
108 return new DefaultTreeOperation(path,_b);
109 }
110 }
111 }