@@ -49,25 +49,12 @@ class BlockContainer {
49
49
bool trySetBlockData (const Position& positionOfBlock, block_data_t data);
50
50
// Sets the data value to a block at position. Returns if block found. Pass a Difference* to read the what changes were made.
51
51
template <class T , unsigned int index>
52
- bool trySetBlockDataValue (const Position& positionOfBlock, T value) {
53
- Block* block = getBlock (positionOfBlock);
54
- if (!block) return false ;
55
- block->setDataValue <T, index >(value);
56
- return true ;
57
- }
52
+ bool trySetBlockDataValue (const Position& positionOfBlock, T value);
58
53
// Sets the data to a block at position. Returns if successful. Pass a Difference* to read the what changes were made.
59
54
bool trySetBlockData (const Position& positionOfBlock, block_data_t data, Difference* difference);
60
55
// Sets the data value to a block at position. Returns if block found. Pass a Difference* to read the what changes were made.
61
56
template <class T , unsigned int index>
62
- bool trySetBlockDataValue (const Position& positionOfBlock, T value, Difference* difference) {
63
- Block* block = getBlock (positionOfBlock);
64
- if (!block) return false ;
65
- block_data_t oldData = block->getRawData ();
66
- block->setDataValue <T, index >(value);
67
- block_data_t newData = block->getRawData ();
68
- if (oldData != newData) difference->addSetData (positionOfBlock, newData, oldData);
69
- return true ;
70
- }
57
+ bool trySetBlockDataValue (const Position& positionOfBlock, T value, Difference* difference);
71
58
72
59
/* ----------- connections ----------- */
73
60
// -- getters --
@@ -97,21 +84,7 @@ class BlockContainer {
97
84
const_iterator end () const { return blocks.end (); }
98
85
99
86
/* Difference Getter */
100
- Difference getCreationDifference () const {
101
- Difference difference;
102
- for (auto iter : blocks) {
103
- difference.addPlacedBlock (iter.second .getPosition (), iter.second .getRotation (), iter.second .type ());
104
- }
105
- for (auto iter : blocks) {
106
- for (connection_end_id_t id = 0 ; id <= iter.second .getConnectionContainer ().getMaxConnectionId (); id++) {
107
- if (iter.second .isConnectionInput (id)) continue ;
108
- for (auto connectionIter : iter.second .getConnectionContainer ().getConnections (id)) {
109
- difference.addCreatedConnection (iter.second .getConnectionPosition (id).first , getBlock (connectionIter.getBlockId ())->getConnectionPosition (connectionIter.getConnectionId ()).first );
110
- }
111
- }
112
- }
113
- return difference;
114
- }
87
+ Difference getCreationDifference () const ;
115
88
116
89
private:
117
90
inline Block* getBlock (const Position& position);
@@ -149,4 +122,23 @@ inline const Block* BlockContainer::getBlock(block_id_t blockId) const {
149
122
return (iter == blocks.end ()) ? nullptr : &iter->second ;
150
123
}
151
124
125
+ template <class T , unsigned int index>
126
+ bool BlockContainer::trySetBlockDataValue (const Position& positionOfBlock, T value) {
127
+ Block* block = getBlock (positionOfBlock);
128
+ if (!block) return false ;
129
+ block->setDataValue <T, index >(value);
130
+ return true ;
131
+ }
132
+
133
+ template <class T , unsigned int index>
134
+ bool BlockContainer::trySetBlockDataValue (const Position& positionOfBlock, T value, Difference* difference) {
135
+ Block* block = getBlock (positionOfBlock);
136
+ if (!block) return false ;
137
+ block_data_t oldData = block->getRawData ();
138
+ block->setDataValue <T, index >(value);
139
+ block_data_t newData = block->getRawData ();
140
+ if (oldData != newData) difference->addSetData (positionOfBlock, newData, oldData);
141
+ return true ;
142
+ }
143
+
152
144
#endif /* blockContainer_h */
0 commit comments