载入中...
搜索中...
未找到
BuildingAssemblyTarget.cpp
浏览该文件的文档.
7 std::string id;
8 std::reference_wrapper<building::PlacementWorld> world;
9 std::unique_ptr<building::PlacementWorld> owned;
11};
13 : state_(std::make_unique<State>(State{std::move(id), world, {}, {}})) {}
14BuildingAssemblyTarget::~BuildingAssemblyTarget() = default;
15editing::TargetId BuildingAssemblyTarget::targetId() const { return editing::TargetId(state_->id); }
16editing::TargetDescriptor BuildingAssemblyTarget::describe() const {
17 return {targetId(), "building.assembly", revision(), false, {}};
18}
19editing::Result<editing::DomainOperation> BuildingAssemblyTarget::makeOperation(
20 building::PreparedAssembly prepared) const {
21 auto candidate = state_->world.get().cloneState();
22 auto committed = building::AssemblyService::commit(*candidate, std::move(prepared));
24 auto receipt = std::move(committed).takeValue();
26 op.target = targetId();
27 op.type = "building.assembly.exchange.v1";
28 op.inverseType = op.type;
29 op.hasInverse = true;
30 op.payload = editing::toEditingValue(Value::Object{{"expected", receipt.before}, {"desired", receipt.after}});
32 Value::Object{{"expected", std::move(receipt.after)}, {"desired", std::move(receipt.before)}});
33 op.affectedObjects.push_back({targetId(), receipt.assembly.format(), 0});
35}
36editing::Result<void> BuildingAssemblyTarget::applyDomainOperation(const editing::DomainOperation& op) {
37 if (op.target != targetId() || op.type != "building.assembly.exchange.v1")
39 Diagnostic::error(DiagnosticCode::Unsupported, "Wrong house operation target/type"));
41 auto expected = value.find("expected"), desired = value.find("desired");
42 if (!expected || !desired)
44 Diagnostic::error(DiagnosticCode::InvalidArgument, "Missing house state endpoints"));
45 auto result = building::AssemblyService::applyReceipt(state_->world.get(), *expected, *desired);
46 if (result.ok()) markDirty();
47 return result;
48}
49std::unique_ptr<editing::IDomainOperationTarget> BuildingAssemblyTarget::cloneDomainState() const {
50 auto before = building::AssemblyService::snapshotWorld(state_->world.get());
51 if (!before.ok()) return {};
52 auto world = state_->world.get().cloneState();
53 auto copy = std::make_unique<BuildingAssemblyTarget>(state_->id, *world);
54 copy->state_->owned = std::move(world);
55 copy->state_->expected = std::move(before).takeValue();
56 copy->setRevision(revision());
57 return copy;
58}
59editing::Result<void> BuildingAssemblyTarget::commitDomainState(
60 std::unique_ptr<editing::IDomainOperationTarget> candidate) {
61 auto* c = dynamic_cast<BuildingAssemblyTarget*>(candidate.get());
62 if (!c || !c->state_->owned || c->targetId() != targetId())
64 Diagnostic::error(DiagnosticCode::Conflict, "Invalid house staging target"));
65 auto desired = building::AssemblyService::snapshotWorld(*c->state_->owned);
66 if (!desired.ok()) return editing::Result<void>::failure(desired.status());
67 auto result = building::AssemblyService::applyReceipt(state_->world.get(), c->state_->expected, desired.value());
68 if (result.ok()) markDirty();
69 return result;
70}
71} // namespace eve::building_editing
std::uint64_t revision
bool committed
std::int32_t c
std::string id
Poco::JSON::Object::Ptr result
std::uint32_t targetId
Object::Ptr value
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:313
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
static Result< AssemblyReceipt > commit(PlacementWorld &world, PreparedAssembly token)
Consume a prepared operation if world and definition preconditions still match. @cost Compares owning...
static Result< Value > snapshotWorld(const PlacementWorld &world)
Capture the complete logical world, including grid, terrain, curves and assemblies....
static Result< void > applyReceipt(PlacementWorld &world, const Value &expected, const Value &desired)
Apply a receipt endpoint only when the current world matches the expected endpoint....
格子型建筑放置世界(脚本可直接操作)。
Move-only proof of a fully validated house operation. @ownership Owns its candidate; destruction canc...
Whole-house transaction target sharing the canonical runtime world state. @ownership Borrows a world;...
BuildingAssemblyTarget(std::string id, building::PlacementWorld &world)
Bind a host-owned world that outlives this target. @cost One small state allocation per target.
eve::Value toPresentationValue(const Value &value)
To presentation value.
StrongId< TargetIdTag > TargetId
Definition EditingIds.h:57
Value toEditingValue(const eve::Value &value)
To editing value.
std::reference_wrapper< building::PlacementWorld > world
std::unique_ptr< building::PlacementWorld > owned
DomainOperation public API.
std::vector< ObjectRefValue > affectedObjects
Stable discovery metadata exposed by every editable target.