载入中...
搜索中...
未找到
EditorAssetDatabase.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cctype>
4#include <exception>
5#include <set>
6#include <utility>
7#include "common/Exception.h"
10#include "editor/EditorDock.h"
12
13// EditorAssetDatabase.cpp
14namespace eve::editor {
15namespace {
16
17bool containsInsensitive(std::string value, std::string text) {
18 auto lower = [](unsigned char character) { return static_cast<char>(std::tolower(character)); };
19 std::transform(value.begin(), value.end(), value.begin(), lower);
20 std::transform(text.begin(), text.end(), text.begin(), lower);
21 return value.find(text) != std::string::npos;
22}
23
24} // namespace
25
26Result<AssetRecord> MemoryAssetDatabase::publish(AssetRecord record, std::vector<AssetDependency> dependencies) {
27 if (record.guid.empty() || record.logicalUri.empty() || record.typeId.empty())
28 return eve::editing::failed<AssetRecord>(EditorStatus::Rejected, RuleId("editor.asset.invalid-record"),
29 "Asset GUID, logical URI and type are required");
30 const auto uriOwner = uriToGuid_.find(record.logicalUri);
31 if (uriOwner != uriToGuid_.end() && uriOwner->second != record.guid)
32 return eve::editing::failed<AssetRecord>(EditorStatus::Conflict, RuleId("editor.asset.uri-conflict"),
33 "Another asset already owns this logical URI");
34 for (const AssetDependency& dependency : dependencies) {
35 if (dependency.from != record.guid || dependency.to.empty())
36 return eve::editing::failed<AssetRecord>(EditorStatus::Rejected, RuleId("editor.asset.invalid-dependency"),
37 "Published dependencies must originate from the product asset");
38 }
40 const auto existing = records_.find(record.guid);
41 if (existing != records_.end() && existing->second.logicalUri != record.logicalUri)
42 uriToGuid_.erase(existing->second.logicalUri);
43 uriToGuid_.insert_or_assign(record.logicalUri, record.guid);
44 records_.insert_or_assign(record.guid, record);
45 std::erase_if(dependencies_, [&](const AssetDependency& dependency) { return dependency.from == record.guid; });
46 dependencies_.insert(dependencies_.end(), dependencies.begin(), dependencies.end());
47 ++generation_;
48 return eve::editing::applied<AssetRecord>(std::move(record));
49}
50
51Result<std::vector<AssetRecord>> MemoryAssetDatabase::publishBatch(std::vector<AssetPublication> publications) {
52 if (publications.empty())
53 return eve::editing::failed<std::vector<AssetRecord>>(EditorStatus::Rejected,
54 RuleId("editor.asset.empty-publication"),
55 "An asset publication batch must not be empty");
56 auto stagedRecords = records_;
57 auto stagedUris = uriToGuid_;
58 auto stagedDependencies = dependencies_;
59 std::vector<AssetRecord> published;
60 std::unordered_map<AssetGuid, bool, StrongEditorIdHash<AssetGuid>> batchGuids;
61 published.reserve(publications.size());
62 for (AssetPublication& publication : publications) {
63 AssetRecord& record = publication.record;
64 if (record.guid.empty() || record.logicalUri.empty() || record.typeId.empty())
65 return eve::editing::failed<std::vector<AssetRecord>>(EditorStatus::Rejected,
66 RuleId("editor.asset.invalid-record"),
67 "Asset GUID, logical URI and type are required");
68 if (!batchGuids.emplace(record.guid, true).second)
69 return eve::editing::failed<std::vector<AssetRecord>>(
70 EditorStatus::Conflict, RuleId("editor.asset.duplicate-batch-guid"),
71 "An asset publication batch contains a duplicate GUID");
72 const auto uriOwner = stagedUris.find(record.logicalUri);
73 if (uriOwner != stagedUris.end() && uriOwner->second != record.guid)
74 return eve::editing::failed<std::vector<AssetRecord>>(EditorStatus::Conflict,
75 RuleId("editor.asset.uri-conflict"),
76 "Another asset already owns this logical URI");
77 for (const AssetDependency& dependency : publication.dependencies) {
78 if (dependency.from != record.guid || dependency.to.empty())
79 return eve::editing::failed<std::vector<AssetRecord>>(
80 EditorStatus::Rejected, RuleId("editor.asset.invalid-dependency"),
81 "Published dependencies must originate from the product asset");
82 }
84 const auto existing = stagedRecords.find(record.guid);
85 if (existing != stagedRecords.end() && existing->second.logicalUri != record.logicalUri)
86 stagedUris.erase(existing->second.logicalUri);
87 stagedUris.insert_or_assign(record.logicalUri, record.guid);
88 stagedRecords.insert_or_assign(record.guid, record);
89 std::erase_if(stagedDependencies,
90 [&](const AssetDependency& dependency) { return dependency.from == record.guid; });
91 stagedDependencies.insert(stagedDependencies.end(), publication.dependencies.begin(),
92 publication.dependencies.end());
93 published.push_back(std::move(record));
94 }
95 records_ = std::move(stagedRecords);
96 uriToGuid_ = std::move(stagedUris);
97 dependencies_ = std::move(stagedDependencies);
98 ++generation_;
99 return eve::editing::applied<std::vector<AssetRecord>>(std::move(published));
100}
101
103 auto found = records_.find(guid);
104 if (found == records_.end())
105 return eve::editing::failed<AssetRecord>(EditorStatus::NotFound, RuleId("editor.asset.not-found"),
106 "Asset is not indexed: " + guid.value());
107 return eve::editing::applied<AssetRecord>(found->second);
108}
109
110Result<AssetRecord> MemoryAssetDatabase::findByUri(const std::string& logicalUri) const {
111 const auto guid = uriToGuid_.find(logicalUri);
112 if (guid != uriToGuid_.end()) return find(guid->second);
113 return eve::editing::failed<AssetRecord>(EditorStatus::NotFound, RuleId("editor.asset.not-found"),
114 "Asset URI is not indexed: " + logicalUri);
115}
116
118 std::size_t limit,
119 std::optional<std::uint64_t> generation) const {
120 if (generation && *generation != generation_)
121 return eve::editing::failed<AssetPage<AssetRecord>>(EditorStatus::Conflict, RuleId("editor.asset.page-expired"),
122 "Asset index changed while paging");
123 std::vector<AssetRecord> matches;
124 for (const auto& [guid, record] : records_) {
125 (void)guid;
126 if (query.status && record.status != *query.status) continue;
127 if (!query.typeIds.empty() &&
128 std::find(query.typeIds.begin(), query.typeIds.end(), record.typeId) == query.typeIds.end())
129 continue;
130 if (!query.pathPrefixes.empty()) {
131 bool prefix = false;
132 for (const std::string& candidate : query.pathPrefixes)
133 if (record.logicalUri.starts_with(candidate)) prefix = true;
134 if (!prefix) continue;
135 }
136 bool tags = true;
137 for (const std::string& tag : query.tagsAll)
138 if (std::find(record.tags.begin(), record.tags.end(), tag) == record.tags.end()) tags = false;
139 if (!tags) continue;
140 if (!query.text.empty() && !containsInsensitive(record.logicalUri, query.text) &&
141 !containsInsensitive(record.typeId, query.text))
142 continue;
143 matches.push_back(record);
144 }
145 std::sort(matches.begin(), matches.end(),
146 [](const AssetRecord& left, const AssetRecord& right) { return left.logicalUri < right.logicalUri; });
148 page.generation = generation_;
149 if (offset < matches.size()) {
150 const std::size_t end = std::min(matches.size(), offset + limit);
151 page.values.assign(matches.begin() + static_cast<std::ptrdiff_t>(offset),
152 matches.begin() + static_cast<std::ptrdiff_t>(end));
153 page.nextOffset = end;
154 page.hasMore = end < matches.size();
155 }
156 return eve::editing::applied<AssetPage<AssetRecord>>(std::move(page));
157}
158
159std::vector<AssetDependency> MemoryAssetDatabase::dependencies(const AssetGuid& guid, bool incoming) const {
160 std::vector<AssetDependency> result;
161 for (const AssetDependency& dependency : dependencies_)
162 if ((incoming && dependency.to == guid) || (!incoming && dependency.from == guid)) result.push_back(dependency);
163 return result;
164}
165
167 if (!database_)
168 return eve::editing::failed<AssetRecord>(EditorStatus::Failed, RuleId("editor.import.missing-database"),
169 "Import coordinator has no asset database");
170 if (product.record.sourceUri.empty() || product.record.importerId.empty())
171 return eve::editing::failed<AssetRecord>(EditorStatus::Rejected, RuleId("editor.import.invalid-product"),
172 "Import product requires source URI and importer identity");
173 return database_->publish(std::move(product.record), std::move(product.dependencies));
174}
175
176Result<ImportTicket> ImportCoordinator::begin(const AssetGuid& asset, std::string sourceHash, std::string importerId,
177 std::uint32_t importerVersion) {
178 if (asset.empty() || sourceHash.empty() || importerId.empty() || importerVersion == 0)
179 return eve::editing::failed<ImportTicket>(EditorStatus::Rejected, RuleId("editor.import.invalid-request"),
180 "Import request requires asset, source hash and versioned importer");
181 const std::uint64_t generation = ++generations_[asset];
182 return eve::editing::applied<ImportTicket>(
183 {asset, generation, std::move(sourceHash), std::move(importerId), importerVersion});
184}
185
187 if (!database_)
188 return eve::editing::failed<AssetRecord>(EditorStatus::Failed, RuleId("editor.import.missing-database"),
189 "Import coordinator has no asset database");
190 const auto generation = generations_.find(ticket.asset);
191 if (generation == generations_.end() || generation->second != ticket.generation)
192 return eve::editing::failed<AssetRecord>(EditorStatus::Conflict, RuleId("editor.import.stale-product"),
193 "Importer product was superseded by a newer source generation");
194 AssetRecord& record = product.record;
195 if (record.guid != ticket.asset || record.sourceHash != ticket.sourceHash ||
196 record.importerId != ticket.importerId || record.importerVersion != ticket.importerVersion)
197 return eve::editing::failed<AssetRecord>(EditorStatus::Conflict, RuleId("editor.import.ticket-mismatch"),
198 "Importer product identity does not match its request ticket");
199 if (record.sourceUri.empty() || record.logicalUri.empty() || record.typeId.empty())
200 return eve::editing::failed<AssetRecord>(EditorStatus::Rejected, RuleId("editor.import.incomplete-product"),
201 "Importer product lacks source, logical URI or asset type");
202 std::set<std::string> artifacts;
203 for (const std::string& artifact : record.artifacts)
204 if (artifact.empty() || !artifacts.insert(artifact).second)
205 return eve::editing::failed<AssetRecord>(EditorStatus::Rejected, RuleId("editor.import.invalid-artifact"),
206 "Importer artifacts must be unique and non-empty");
207 if (record.artifacts.empty())
208 return eve::editing::failed<AssetRecord>(EditorStatus::Rejected, RuleId("editor.import.missing-artifact"),
209 "Importer product must contain at least one published artifact");
210 if (std::any_of(record.diagnostics.begin(), record.diagnostics.end(), [](const EditorDiagnostic& diagnostic) {
211 return diagnostic.severity() == DiagnosticSeverity::Error ||
212 diagnostic.severity() == DiagnosticSeverity::Fatal;
213 }))
214 return eve::editing::failed<AssetRecord>(EditorStatus::Rejected, RuleId("editor.import.product-errors"),
215 "Importer product contains error diagnostics");
216 auto published = database_->publish(std::move(record), std::move(product.dependencies));
217 if (published.ok()) generations_.erase(ticket.asset);
218 return published;
219}
220
221} // namespace eve::editor
222
223// EditorCommandService.cpp
224namespace eve::editor {
225
226namespace {
227
228constexpr size_t kMaxPayloadDepth = 32;
229constexpr size_t kMaxPayloadElements = 100'000;
230
231} // namespace
232
233Result<EditorValue> EditorCommandService::error(EditorStatus status, const char* rule, std::string message) {
234 return eve::editing::failed<EditorValue>(status, RuleId(rule), std::move(message));
235}
236
237Result<void> EditorCommandService::checkExecutionPolicy(const CommandDescriptor& descriptor, const CommandId& id,
239 const HostProfile& profile) const {
240 if (!profile.allowsCommand(id))
241 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.command.profile-denied"),
242 "Command is unavailable in this host: " + id.value());
243 if (!profile.hasFeatures(descriptor.requiredFeatures))
244 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.command.feature-denied"),
245 "Command requires features unavailable in this host: " + id.value());
246 if (source == CommandSource::Automation && !descriptor.automationAllowed)
247 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.command.automation-denied"),
248 "Command is not available to automation: " + id.value());
249 if (!payload.isWithinLimits(kMaxPayloadDepth, kMaxPayloadElements, profile.maxPayloadBytes()))
250 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.command.payload-limit"),
251 "Command payload exceeds host limits: " + id.value());
252 return eve::editing::applied<void>();
253}
254
256 bool replace) {
257 if (!descriptor.id || descriptor.ownerModule.empty() || !handler)
258 return error(EditorStatus::Rejected, "editor.command.invalid-registration",
259 "Command id, owner module and handler are required");
260
261 auto it = std::find_if(commands_.begin(), commands_.end(),
262 [&](const Registration& entry) { return entry.descriptor.id == descriptor.id; });
263 if (it != commands_.end()) {
264 if (!replace || it->descriptor.ownerModule != descriptor.ownerModule)
265 return error(EditorStatus::Rejected, "editor.command.duplicate",
266 "Command is already registered: " + descriptor.id.value());
267 *it = {std::move(descriptor), std::move(handler), {}, {}, nextRegistrationGeneration_++};
268 } else {
269 commands_.push_back({std::move(descriptor), std::move(handler), {}, {}, nextRegistrationGeneration_++});
270 }
271 ++revision_;
272 return eve::editing::applied<EditorValue>(EditorValue{});
273}
274
276 EditorCommandPlanner planner,
277 EditorCommandPlanExecutor executor, bool replace) {
278 if (!descriptor.id || descriptor.ownerModule.empty() || !planner || !executor)
279 return error(EditorStatus::Rejected, "editor.command.invalid-registration",
280 "Command id, owner module, planner and executor are required");
281 auto it = std::find_if(commands_.begin(), commands_.end(),
282 [&](const Registration& entry) { return entry.descriptor.id == descriptor.id; });
283 if (it != commands_.end()) {
284 if (!replace || it->descriptor.ownerModule != descriptor.ownerModule)
285 return error(EditorStatus::Rejected, "editor.command.duplicate",
286 "Command is already registered: " + descriptor.id.value());
287 *it = {std::move(descriptor), {}, std::move(planner), std::move(executor), nextRegistrationGeneration_++};
288 } else {
289 commands_.push_back(
290 {std::move(descriptor), {}, std::move(planner), std::move(executor), nextRegistrationGeneration_++});
291 }
292 ++revision_;
293 return eve::editing::applied<EditorValue>(EditorValue{});
294}
295
296bool EditorCommandService::unregisterCommand(const CommandId& id, const std::string& ownerModule) {
297 auto it = std::find_if(commands_.begin(), commands_.end(), [&](const Registration& entry) {
298 return entry.descriptor.id == id && (ownerModule.empty() || entry.descriptor.ownerModule == ownerModule);
299 });
300 if (it == commands_.end()) return false;
301 commands_.erase(it);
302 ++revision_;
303 return true;
304}
305
306size_t EditorCommandService::unregisterOwner(const std::string& ownerModule) {
307 if (ownerModule.empty()) return 0;
308 const size_t before = commands_.size();
309 std::erase_if(commands_, [&](const Registration& entry) { return entry.descriptor.ownerModule == ownerModule; });
310 const size_t removed = before - commands_.size();
311 if (removed > 0) ++revision_;
312 return removed;
313}
314
316 if (commands_.empty()) return;
317 commands_.clear();
318 ++revision_;
319}
320
322 auto it = std::find_if(commands_.begin(), commands_.end(),
323 [&](const Registration& entry) { return entry.descriptor.id == id; });
324 return it == commands_.end() ? nullptr : &it->descriptor;
325}
326
328 const auto it = std::find_if(commands_.begin(), commands_.end(),
329 [&](const Registration& entry) { return entry.descriptor.id == id; });
330 return it != commands_.end() && static_cast<bool>(it->planner) && static_cast<bool>(it->planExecutor);
331}
332
333std::vector<CommandDescriptor> EditorCommandService::commands(const HostProfile& profile) const {
334 std::vector<CommandDescriptor> result;
335 result.reserve(commands_.size());
336 for (const auto& entry : commands_)
337 if (profile.allowsCommand(entry.descriptor.id) && profile.hasFeatures(entry.descriptor.requiredFeatures))
338 result.push_back(entry.descriptor);
339 return result;
340}
341
343 const EditorValue& payload) const {
344 auto it = std::find_if(commands_.begin(), commands_.end(),
345 [&](const Registration& entry) { return entry.descriptor.id == id; });
346 if (it == commands_.end())
347 return error(EditorStatus::NotFound, "editor.command.not-found", "Command is not registered: " + id.value());
348 if (!context.profile)
349 return error(EditorStatus::Failed, "editor.command.missing-profile", "Command context has no host profile");
350 if (auto policy = checkExecutionPolicy(it->descriptor, id, context.source, payload, *context.profile); !policy.ok())
351 return Result<EditorValue>::failure(std::move(policy).status());
352
353 if (!it->handler)
354 return error(EditorStatus::Unsupported, "editor.command.requires-plan",
355 "Command must be planned before it can be executed: " + id.value());
356 try {
357 return it->handler(context, payload);
358 } catch (const std::exception& exception) {
359 return error(EditorStatus::Failed, "editor.command.handler-exception",
360 "Command handler failed: " + std::string(exception.what()));
361 } catch (...) {
362 return error(EditorStatus::Failed, "editor.command.handler-exception",
363 "Command handler failed with an unknown exception");
364 }
365}
366
368 auto failure = [](EditorStatus status, const char* rule, std::string message) {
369 return eve::editing::failed<CommandPlan>(status, RuleId(rule), std::move(message));
370 };
371 auto it = std::find_if(commands_.begin(), commands_.end(),
372 [&](const Registration& entry) { return entry.descriptor.id == request.id; });
373 if (it == commands_.end())
374 return failure(EditorStatus::NotFound, "editor.command.not-found",
375 "Command is not registered: " + request.id.value());
376 if (auto policy = checkExecutionPolicy(it->descriptor, request.id, request.source, request.payload, profile);
377 !policy.ok())
378 return Result<CommandPlan>::failure(std::move(policy).status());
379 if (request.expectedRevision && *request.expectedRevision != request.context.targetRevision)
380 return failure(EditorStatus::Conflict, "editor.command.revision-conflict",
381 "Expected revision does not match the captured context");
382 if (!it->planner)
383 return failure(EditorStatus::Unsupported, "editor.command.planning-unsupported",
384 "Command does not provide a planning handler");
385 try {
386 Result<CommandPlan> result = it->planner(request);
387 if (result.ok()) {
388 result.value().command = request.id;
389 result.value().target = request.context.target;
390 result.value().baseRevision = request.context.targetRevision;
391 if (result.value().targetGeneration == 0)
392 result.value().targetGeneration = request.context.targetGeneration;
393 result.value().commandGeneration = it->generation;
394 result.value().plannedPayload = request.payload;
395 result.value().plannedSource = request.source;
396 if (result.value().id.empty())
397 result.value().id = PlanId(request.id.value() + ".plan." + std::to_string(++planSequence_));
398 }
399 return result;
400 } catch (const std::exception& exception) {
401 return failure(EditorStatus::Failed, "editor.command.planner-exception", exception.what());
402 } catch (...) {
403 return failure(EditorStatus::Failed, "editor.command.planner-exception",
404 "Command planner failed with an unknown exception");
405 }
406}
407
409 const HostProfile& profile) const {
410 auto failure = [](EditorStatus status, const char* rule, std::string message) {
411 return eve::editing::failed<TransactionReceipt>(status, RuleId(rule), std::move(message));
412 };
413 if (plan.id.empty() || plan.command != request.id || plan.target != request.context.target)
414 return failure(EditorStatus::Rejected, "editor.command.invalid-plan",
415 "Plan identity or target does not match the request");
416 if (plan.baseRevision != request.context.targetRevision)
417 return failure(EditorStatus::Conflict, "editor.command.stale-plan",
418 "Plan was produced for another target revision");
419 if (plan.targetGeneration != request.context.targetGeneration)
420 return failure(EditorStatus::Conflict, "editor.command.stale-target-generation",
421 "Plan was produced for another target lifetime");
422 if (request.expectedRevision && *request.expectedRevision != request.context.targetRevision)
423 return failure(EditorStatus::Conflict, "editor.command.revision-conflict",
424 "Expected revision does not match the captured context");
425 auto it = std::find_if(commands_.begin(), commands_.end(),
426 [&](const Registration& entry) { return entry.descriptor.id == request.id; });
427 if (it == commands_.end())
428 return failure(EditorStatus::NotFound, "editor.command.not-found",
429 "Command is not registered: " + request.id.value());
430 if (plan.commandGeneration != it->generation)
431 return failure(EditorStatus::Conflict, "editor.command.stale-registration",
432 "Command registration changed after planning");
433 if (auto policy = checkExecutionPolicy(it->descriptor, request.id, request.source, request.payload, profile);
434 !policy.ok())
435 return Result<TransactionReceipt>::failure(std::move(policy).status());
436 if (request.payload != plan.plannedPayload || request.source != plan.plannedSource)
437 return failure(EditorStatus::Rejected, "editor.command.plan-input-mismatch",
438 "Plan payload or source differs from the validated request");
439 if (!it->planExecutor)
440 return failure(EditorStatus::Unsupported, "editor.command.execution-unsupported",
441 "Command does not provide a plan executor");
442 try {
443 return it->planExecutor(request, plan);
444 } catch (const std::exception& exception) {
445 return failure(EditorStatus::Failed, "editor.command.executor-exception", exception.what());
446 } catch (...) {
447 return failure(EditorStatus::Failed, "editor.command.executor-exception",
448 "Command executor failed with an unknown exception");
449 }
450}
451
452} // namespace eve::editor
453
454// EditorDiagnostics.cpp
455namespace eve::editor {
456
458 rules_.emplace(RuleId("settlement.rules.document"),
459 RegisteredRule{"settlement", [](const ValidationRequest& request) {
460 if (request.subject != "settlement.rules") return std::vector<EditorDiagnostic>{};
461 const auto* json = request.value.getIf<std::string>();
462 if (json == nullptr)
463 return std::vector<EditorDiagnostic>{eve::editing::ruleDiagnostic(
464 eve::DiagnosticCode::TypeMismatch, RuleId("settlement.rules.document"),
465 DiagnosticSeverity::Error,
466 "Settlement rule document must be supplied as JSON text")};
467 auto inspected = settlement::SettlementRuleSet::fromJson(*json);
468 if (inspected) return std::vector<EditorDiagnostic>{};
469 return inspected.status().diagnostics();
470 }});
471}
472
474 if (owner.empty() || id.empty() || !rule)
475 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.validation.invalid-rule"),
476 "Validation owner, rule id and callback are required");
477 rules_.insert_or_assign(std::move(id), RegisteredRule{std::move(owner), std::move(rule)});
478 return eve::editing::applied<void>();
479}
480
481std::size_t EditorValidationService::unregisterOwner(const std::string& owner) {
482 return std::erase_if(rules_, [&](const auto& entry) { return entry.second.owner == owner; });
483}
484
485std::vector<EditorDiagnostic> EditorValidationService::validate(const ValidationRequest& request) const {
486 std::vector<EditorDiagnostic> diagnostics;
487 for (const auto& [id, registered] : rules_) {
488 (void)id;
489 auto current = registered.rule(request);
490 diagnostics.insert(diagnostics.end(), std::make_move_iterator(current.begin()),
491 std::make_move_iterator(current.end()));
492 }
493 return diagnostics;
494}
495
496void EditorDiagnosticService::publish(std::string source, std::vector<EditorDiagnostic> diagnostics) {
497 std::lock_guard lock(mutex_);
498 channels_.insert_or_assign(std::move(source), std::move(diagnostics));
499}
500
501void EditorDiagnosticService::clear(const std::string& source) {
502 std::lock_guard lock(mutex_);
503 channels_.erase(source);
504}
505
506std::vector<EditorDiagnostic> EditorDiagnosticService::snapshot() const {
507 std::lock_guard lock(mutex_);
508 std::vector<EditorDiagnostic> result;
509 for (const auto& [source, diagnostics] : channels_) {
510 (void)source;
511 result.insert(result.end(), diagnostics.begin(), diagnostics.end());
512 }
513 return result;
514}
515
516} // namespace eve::editor
517
518// EditorDock.cpp
519namespace eve::editor {
520
522 sizes_["left"] = 200.f;
523 sizes_["right"] = 280.f;
524 sizes_["top"] = 40.f;
525 sizes_["bottom"] = 24.f;
526}
527
528void EditorDock::setRegionSize(const std::string& region, float pixels) {
529 if (region != "left" && region != "right" && region != "top" && region != "bottom") {
530 throw Exception("EditorDock::setRegionSize: expected left|right|top|bottom");
531 }
532 if (pixels < 0.f) throw Exception("EditorDock::setRegionSize: size must be >= 0");
533 sizes_[region] = pixels;
534}
535
536float EditorDock::getRegionSize(const std::string& region) const { return sizeOf(region); }
537
538float EditorDock::sizeOf(const std::string& region) const {
539 auto it = sizes_.find(region);
540 return it == sizes_.end() ? 0.f : it->second;
541}
542
543void EditorDock::layout(float screenW, float screenH) {
544 if (screenW <= 0.f || screenH <= 0.f) {
545 throw Exception("EditorDock::layout: screen size must be > 0");
546 }
547 float left = sizeOf("left");
548 float right = sizeOf("right");
549 float top = sizeOf("top");
550 float bottom = sizeOf("bottom");
551 // Clamp so center remains non-negative
552 if (left + right > screenW) {
553 float s = screenW / (left + right);
554 left *= s;
555 right *= s;
556 }
557 if (top + bottom > screenH) {
558 float s = screenH / (top + bottom);
559 top *= s;
560 bottom *= s;
561 }
562
563 rects_["top"] = {0.f, 0.f, screenW, top};
564 rects_["bottom"] = {0.f, screenH - bottom, screenW, bottom};
565 rects_["left"] = {0.f, top, left, screenH - top - bottom};
566 rects_["right"] = {screenW - right, top, right, screenH - top - bottom};
567 rects_["center"] = {left, top, screenW - left - right, screenH - top - bottom};
568}
569
570const EditorDock::Rect* EditorDock::rectOf(const std::string& region) const {
571 auto it = rects_.find(region);
572 return it == rects_.end() ? nullptr : &it->second;
573}
574
575float EditorDock::getRegionX(const std::string& region) const {
576 const Rect* r = rectOf(region);
577 if (!r) throw Exception("EditorDock::getRegionX: call layout() first / unknown region");
578 return r->x;
579}
580float EditorDock::getRegionY(const std::string& region) const {
581 const Rect* r = rectOf(region);
582 if (!r) throw Exception("EditorDock::getRegionY: call layout() first / unknown region");
583 return r->y;
584}
585float EditorDock::getRegionW(const std::string& region) const {
586 const Rect* r = rectOf(region);
587 if (!r) throw Exception("EditorDock::getRegionW: call layout() first / unknown region");
588 return r->w;
589}
590float EditorDock::getRegionH(const std::string& region) const {
591 const Rect* r = rectOf(region);
592 if (!r) throw Exception("EditorDock::getRegionH: call layout() first / unknown region");
593 return r->h;
594}
595
596} // namespace eve::editor
Value::Object payload
std::string descriptor
const std::string & s
Generation generation
Definition ECS.cpp:40
ScriptComponentRecord record
Definition ECS.cpp:228
ScriptFieldRegion region
std::string message
const GltfImportRequest & request
wgpu::PopErrorScopeStatus status
double r
HexVec3 left
HexVec3 right
size_t offset
Poco::JSON::Object::Ptr result
HSQOBJECT handler
std::unordered_set< std::string > tags
const std::string * tag
std::shared_ptr< OceanGpuSpectrum > owner
std::string error
Definition Package.cpp:174
Object::Ptr value
uint8_t * pixels
bool found
int removed
std::string text
std::string_view source
size_t end
double current
Declarative, domain-neutral rules for buffs and gameplay effects.
int limit
Definition TreeMesh.cpp:166
const VegetationPresetContext & context
float bottom
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Move-only operation result carrying either a value or Status.
Definition Result.h:176
const T & value() const &
Borrow the value from a const lvalue after checking success.
Definition Result.h:339
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:313
const std::string & value() const noexcept
Returns the exact legacy or canonical compatibility spelling.
Definition Identity.h:365
bool empty() const noexcept
True when no compatibility spelling has been assigned.
Definition Identity.h:377
Deterministic owning value tree shared by authoring hosts.
size_t unregisterOwner(const std::string &ownerModule)
Remove every command registered by a module.
Result< EditorValue > execute(const CommandId &id, const CommandContext &context, const EditorValue &payload) const
Execute a command after payload and profile checks.
bool supportsPlanning(const CommandId &id) const
Return whether the registered command requires plan/commit execution.
const CommandDescriptor * find(const CommandId &id) const
Return command metadata or nullptr when it is not registered.
Result< EditorValue > registerCommand(CommandDescriptor descriptor, EditorCommandHandler handler, bool replace=false)
Register one command.
std::vector< CommandDescriptor > commands(const HostProfile &profile) const
Return descriptors visible to a host profile.
Result< EditorValue > registerPlannedCommand(CommandDescriptor descriptor, EditorCommandPlanner planner, EditorCommandPlanExecutor executor, bool replace=false)
Register a side-effect-free planner and explicit plan executor.
void clear()
Remove all registrations. Primarily useful for isolated tests.
Result< TransactionReceipt > executePlan(const CommandRequest &request, const CommandPlan &plan, const HostProfile &profile) const
Execute a plan only when its lifetime, registration, policy and input bindings remain valid.
Result< CommandPlan > plan(const CommandRequest &request, const HostProfile &profile) const
Produce a side-effect-free plan bound to the target, command generation, payload and source.
bool unregisterCommand(const CommandId &id, const std::string &ownerModule={})
Remove one command, optionally requiring a matching owner.
std::vector< EditorDiagnostic > snapshot() const
Return all channels in deterministic source order.
void clear(const std::string &source)
Clear one producer channel.
void publish(std::string source, std::vector< EditorDiagnostic > diagnostics)
Replace one producer's current diagnostics atomically.
float getRegionX(const std::string &region) const
Returns the region x.
void setRegionSize(const std::string &region, float pixels)
Sets the region size.
float getRegionY(const std::string &region) const
Returns the region y.
void layout(float screenW, float screenH)
Layout.
float getRegionW(const std::string &region) const
Returns the region w.
float getRegionH(const std::string &region) const
Returns the region h.
float getRegionSize(const std::string &region) const
Returns the region size.
std::function< std::vector< EditorDiagnostic >(const ValidationRequest &)> Rule
std::size_t unregisterOwner(const std::string &owner)
Remove every rule owned by an unloading extension.
Result< void > registerRule(std::string owner, RuleId id, Rule rule)
Register or replace a stable rule owned by an extension.
EditorValidationService()
Construct with built-in validation for canonical settlement rule documents.
std::vector< EditorDiagnostic > validate(const ValidationRequest &request) const
Execute all registered rules in deterministic rule-id order.
Upper capability boundary for one editor host.
bool hasFeatures(HostFeature required) const
True when features.
bool allowsCommand(const CommandId &id) const
Allows command.
Result< AssetRecord > publish(ImportProduct product)
Validate and publish a completed import product.
Result< ImportTicket > begin(const AssetGuid &asset, std::string sourceHash, std::string importerId, std::uint32_t importerVersion)
Start or supersede one asset import and return its immutable generation ticket.
Result< AssetRecord > find(const AssetGuid &guid) const
Find one asset by stable GUID.
Result< AssetRecord > findByUri(const std::string &logicalUri) const
Find one asset by logical content URI.
Result< AssetPage< AssetRecord > > query(const AssetQuery &query, std::size_t offset, std::size_t limit, std::optional< std::uint64_t > generation=std::nullopt) const
Query a deterministic page; stale generations return Conflict.
Result< std::vector< AssetRecord > > publishBatch(std::vector< AssetPublication > publications)
Validate and atomically publish an entire package projection as one index generation.
std::uint64_t generation() const
Return the monotonic index generation.
std::vector< AssetDependency > dependencies(const AssetGuid &guid, bool incoming=false) const
Query outgoing or incoming dependencies for one asset.
Result< AssetRecord > publish(AssetRecord record, std::vector< AssetDependency > dependencies={})
Atomically publish one validated record and its dependencies.
static eve::Result< SettlementRuleSet > fromJson(std::string_view json)
Decode and compile a strict versioned JSON rule document without mutating an existing rule set.
SQInteger top
Definition Snapshot.cpp:115
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build an owning common diagnostic carrying an open editing rule identity.
Result< T > failed(Status status, eve::DiagnosticCode code, RuleId rule, std::string message)
Construct a failed editing result with explicit status and diagnostic categories.
std::function< Result< TransactionReceipt >(const CommandRequest &, const CommandPlan &)> EditorCommandPlanExecutor
eve::editing::Value EditorValue
Compatibility alias for the UI-independent authoring value tree.
Definition EditorValue.h:8
eve::editing::PlanId PlanId
Definition EditorIds.h:35
eve::editing::CommandId CommandId
Definition EditorIds.h:30
std::function< Result< EditorValue >(const CommandContext &, const EditorValue &)> EditorCommandHandler
eve::editing::RuleId RuleId
Definition EditorIds.h:32
eve::editing::CommandSource CommandSource
Compatibility alias for the UI-independent authoring command source.
std::function< Result< CommandPlan >(const CommandRequest &)> EditorCommandPlanner
eve::StatusCode EditorStatus
Definition EditorResult.h:8
@ TypeMismatch
A stable reference resolved to a different canonical domain type.
StatusCode
Stable outcome category for an operation.
Definition Status.h:28
CommandPlan public API.
CommandRequest public API.
Directed dependency between two stable asset identities.
One page of values tied to an asset index generation.
One owning record/dependency unit staged for an atomic index generation.
Deterministic filter used by headless and UI asset queries.
Value snapshot stored by the editor asset index.
Immutable execution context captured for a synchronous command.
Presentation and execution metadata for a registered command.
Validated importer output staged before publishing to AssetDB.
std::vector< AssetDependency > dependencies
Generation-qualified import request used to reject stale worker products.
Context supplied to project- and document-level validation rules.