载入中...
搜索中...
未找到
EditCommand.cpp
浏览该文件的文档.
2
3#include <utility>
4
5namespace eve::editor {
6
9bool IntFieldEditCommand::record(int x, int y, int after) {
10 auto *field = target_ ? target_->query<IIntFieldTarget>() : nullptr;
11 if (!field || !field->containsCell(x, y)) return false;
12 for (auto &change : changes_) {
13 if (change.x == x && change.y == y) { change.after = after; return true; }
14 }
15 const int before = field->readInt(x, y);
16 if (before == after) return false;
17 changes_.push_back({x, y, before, after});
18 dirty_.include(x, y);
19 return true;
20}
22 auto *field = target_ ? target_->query<IIntFieldTarget>() : nullptr;
23 if (!field || changes_.empty()) return false;
24 for (std::size_t i = 0; i < changes_.size(); ++i) {
25 if (field->writeInt(changes_[i].x, changes_[i].y, changes_[i].after) == FieldWriteStatus::Rejected) {
26 while (i > 0) {
27 --i;
28 (void)field->writeInt(changes_[i].x, changes_[i].y, changes_[i].before);
29 }
30 return false;
31 }
32 }
33 return true;
34}
36 auto *field = target_ ? target_->query<IIntFieldTarget>() : nullptr;
37 if (!field) return;
38 for (auto it = changes_.rbegin(); it != changes_.rend(); ++it) (void)field->writeInt(it->x, it->y, it->before);
39}
40std::unique_ptr<IEditCommand> IntFieldEditCommand::clone() const {
41 return std::make_unique<IntFieldEditCommand>(*this);
42}
44 auto *later = dynamic_cast<const IntFieldEditCommand *>(&laterBase);
45 if (!later || later->target_ != target_) return false;
46 for (const auto &incoming : later->changes_) {
47 bool merged = false;
48 for (auto &current : changes_) {
49 if (current.x == incoming.x && current.y == incoming.y) {
50 current.after = incoming.after;
51 merged = true;
52 break;
53 }
54 }
55 if (!merged) changes_.push_back(incoming);
56 }
57 dirty_.include(later->dirty_);
58 return true;
59}
60
63bool ScalarFieldEditCommand::record(int x, int y, float after) {
64 auto *field = target_ ? target_->query<IScalarFieldTarget>() : nullptr;
65 if (!field || !field->containsCell(x, y)) return false;
66 for (auto &change : changes_) {
67 if (change.x == x && change.y == y) { change.after = after; return true; }
68 }
69 const float before = field->readScalar(x, y);
70 if (before == after) return false;
71 changes_.push_back({x, y, before, after});
72 dirty_.include(x, y);
73 return true;
74}
76 auto *field = target_ ? target_->query<IScalarFieldTarget>() : nullptr;
77 if (!field || changes_.empty()) return false;
78 for (std::size_t i = 0; i < changes_.size(); ++i) {
79 if (field->writeScalar(changes_[i].x, changes_[i].y, changes_[i].after) == FieldWriteStatus::Rejected) {
80 while (i > 0) {
81 --i;
82 (void)field->writeScalar(changes_[i].x, changes_[i].y, changes_[i].before);
83 }
84 return false;
85 }
86 }
87 return true;
88}
90 auto *field = target_ ? target_->query<IScalarFieldTarget>() : nullptr;
91 if (!field) return;
92 for (auto it = changes_.rbegin(); it != changes_.rend(); ++it)
93 static_cast<void>(field->writeScalar(it->x, it->y, it->before));
94}
95std::unique_ptr<IEditCommand> ScalarFieldEditCommand::clone() const {
96 return std::make_unique<ScalarFieldEditCommand>(*this);
97}
99 auto *later = dynamic_cast<const ScalarFieldEditCommand *>(&laterBase);
100 if (!later || later->target_ != target_) return false;
101 for (const auto &incoming : later->changes_) {
102 bool merged = false;
103 for (auto &current : changes_) {
104 if (current.x == incoming.x && current.y == incoming.y) {
105 current.after = incoming.after;
106 merged = true;
107 break;
108 }
109 }
110 if (!merged) changes_.push_back(incoming);
111 }
112 dirty_.include(later->dirty_);
113 return true;
114}
115
116} // namespace eve::editor
LogicalId target
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
std::string name
double current
IEditableTarget public API.
IIntFieldTarget public API.
IScalarFieldTarget public API.
Reversible unit accepted by the editor transaction manager.
Definition EditCommand.h:14
Reversible edits to any target exposing IIntFieldTarget.
Definition EditCommand.h:46
IntFieldEditCommand(std::string name, IEditableTarget *target)
Int field edit command.
std::unique_ptr< IEditCommand > clone() const override
Deep copy. @ownership Caller deletes.
void revert() override
Revert.
bool record(int x, int y, int after)
Record.
bool apply() override
Applies .
bool mergeWith(const IEditCommand &later) override
Merge with.
Reversible edits to any target exposing IScalarFieldTarget.
Definition EditCommand.h:77
std::unique_ptr< IEditCommand > clone() const override
Deep copy. @ownership Caller deletes.
bool mergeWith(const IEditCommand &later) override
Merge with.
ScalarFieldEditCommand(std::string name, IEditableTarget *target)
Scalar field edit command.
bool apply() override
Applies .
bool record(int x, int y, float after)
Record.
void include(int x, int y)
Include.