载入中...
搜索中...
未找到
EditorDocumentService.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <exception>
4#include <set>
5#include <utility>
10
11// EditorDocumentService.cpp
12namespace eve::editor {
13
14Result<StoredDocument> MemoryAtomicDocumentStore::read(const std::string& resourceUri) const {
15 auto found = documents_.find(resourceUri);
16 if (found == documents_.end())
17 return eve::editing::failed<StoredDocument>(EditorStatus::NotFound, RuleId("editor.document.store-not-found"),
18 "Document resource is not persisted: " + resourceUri);
19 return eve::editing::applied<StoredDocument>(found->second);
20}
21
23 Revision expectedRevision,
24 const std::string& expectedContentHash,
25 const EditorValue& content) {
26 auto found = documents_.find(resourceUri);
27 const Revision current = found == documents_.end() ? 0 : found->second.revision;
28 const std::string currentHash = found == documents_.end() ? std::string{} : found->second.contentHash;
29 if (current != expectedRevision || currentHash != expectedContentHash)
30 return eve::editing::failed<StoredDocument>(EditorStatus::Conflict, RuleId("editor.document.disk-conflict"),
31 "Document store revision changed before save");
33 stored.content = content;
34 stored.revision = current + 1;
35 stored.contentHash = editorValueContentHash(content);
36 documents_.insert_or_assign(resourceUri, stored);
37 return eve::editing::applied<StoredDocument>(std::move(stored));
38}
39
41 EditorValue initialContent) {
42 if (!store_ || key.asset.empty() || resourceUri.empty())
43 return error(EditorStatus::Rejected, "editor.document.invalid-open",
44 "Document store, asset identity and resource URI are required");
45 DocumentId id("document:" + key.asset.value());
46 if (open_.contains(id)) return eve::editing::applied<DocumentSnapshot>(open_.at(id).snapshot);
47
48 OpenDocument document;
49 document.snapshot.id = id;
50 document.snapshot.key = std::move(key);
51 document.snapshot.title = std::move(title);
52 document.snapshot.resourceUri = std::move(resourceUri);
53 document.snapshot.state = DocumentState::Ready;
54 Result<StoredDocument> stored = store_->read(document.snapshot.resourceUri);
55 if (stored.ok()) {
56 document.content = stored.value().content;
57 document.snapshot.revision.disk = stored.value().revision;
58 document.snapshot.revision.edit = stored.value().revision;
59 document.snapshot.revision.saved = stored.value().revision;
60 document.snapshot.diskContentHash = stored.value().contentHash;
61 } else if (stored.code() == EditorStatus::NotFound) {
62 document.content = std::move(initialContent);
63 } else {
64 return error(stored.code(), "editor.document.store-read", "Document store could not be read");
65 }
66 DocumentSnapshot snapshot = document.snapshot;
67 open_.emplace(id, std::move(document));
68 return eve::editing::applied<DocumentSnapshot>(std::move(snapshot));
69}
70
72 std::optional<Revision> expectedRevision) {
73 auto found = open_.find(document);
74 if (found == open_.end()) return error(EditorStatus::NotFound, "editor.document.not-open", "Document is not open");
75 if (expectedRevision && *expectedRevision != found->second.snapshot.revision.edit)
76 return error(EditorStatus::Conflict, "editor.document.edit-conflict",
77 "Document edit revision changed before mutation");
78 found->second.content = std::move(content);
79 ++found->second.snapshot.revision.edit;
80 found->second.snapshot.state = DocumentState::Ready;
81 return eve::editing::applied<DocumentSnapshot>(found->second.snapshot);
82}
83
85 auto found = open_.find(document);
86 if (found == open_.end())
87 return eve::editing::failed<SaveTicket>(EditorStatus::NotFound, RuleId("editor.document.not-open"),
88 "Document is not open");
89 SaveTicket ticket;
90 ticket.id = StableId(document.value() + ".save." + std::to_string(++ticketSequence_));
91 ticket.document = document;
92 ticket.capturedEditRevision = found->second.snapshot.revision.edit;
93 ticket.expectedDiskRevision = found->second.snapshot.revision.disk;
94 ticket.expectedContentHash = found->second.snapshot.diskContentHash;
95 pendingSaves_.emplace(ticket.id, PendingSave{ticket, found->second.content});
96 return eve::editing::applied<SaveTicket>(std::move(ticket));
97}
98
100 auto pending = pendingSaves_.find(ticket.id);
101 auto document = open_.find(ticket.document);
102 if (pending == pendingSaves_.end() || document == open_.end())
103 return error(EditorStatus::NotFound, "editor.document.save-ticket-not-found",
104 "Save ticket or document is no longer available");
105 document->second.snapshot.state = DocumentState::Saving;
107 store_->compareAndSwap(document->second.snapshot.resourceUri, ticket.expectedDiskRevision,
108 ticket.expectedContentHash, pending->second.content);
109 pendingSaves_.erase(pending);
110 if (!stored.ok()) {
111 document->second.snapshot.state =
112 stored.code() == EditorStatus::Conflict ? DocumentState::Conflict : DocumentState::Failed;
113 document->second.snapshot.diagnostics = stored.diagnostics();
115 }
116 document->second.snapshot.revision.disk = stored.value().revision;
117 document->second.snapshot.revision.saved = ticket.capturedEditRevision;
118 document->second.snapshot.diskContentHash = stored.value().contentHash;
119 document->second.snapshot.state = DocumentState::Ready;
120 document->second.snapshot.diagnostics.clear();
121 return eve::editing::applied<DocumentSnapshot>(document->second.snapshot);
122}
123
125 auto found = open_.find(document);
126 if (found == open_.end())
127 return eve::editing::failed<EditorValue>(EditorStatus::NotFound, RuleId("editor.document.not-open"),
128 "Document is not open");
129 return eve::editing::applied<EditorValue>(found->second.content);
130}
131
133 auto found = open_.find(document);
134 if (found == open_.end()) return error(EditorStatus::NotFound, "editor.document.not-open", "Document is not open");
135 return eve::editing::applied<DocumentSnapshot>(found->second.snapshot);
136}
137
138std::vector<DocumentSnapshot> DocumentService::documents() const {
139 std::vector<DocumentSnapshot> result;
140 result.reserve(open_.size());
141 for (const auto& [id, document] : open_) {
142 (void)id;
143 result.push_back(document.snapshot);
144 }
145 std::sort(result.begin(), result.end(),
146 [](const DocumentSnapshot& left, const DocumentSnapshot& right) { return left.id < right.id; });
147 return result;
148}
149
153
155 auto found = open_.find(document);
156 if (found == open_.end()) return error(EditorStatus::NotFound, "editor.document.not-open", "Document is not open");
157
158 Result<StoredDocument> stored = store_->read(found->second.snapshot.resourceUri);
159 if (!stored.ok()) {
160 const bool expectedMissing = stored.code() == EditorStatus::NotFound &&
161 found->second.snapshot.revision.disk == 0 &&
162 found->second.snapshot.diskContentHash.empty();
163 if (expectedMissing) return eve::editing::applied<DocumentSnapshot>(found->second.snapshot);
164 found->second.snapshot.state =
165 stored.code() == EditorStatus::NotFound || stored.code() == EditorStatus::Conflict ? DocumentState::Conflict
167 found->second.snapshot.diagnostics = stored.diagnostics();
168 if (found->second.snapshot.diagnostics.empty())
169 found->second.snapshot.diagnostics.push_back(
170 eve::editing::ruleDiagnostic(eve::DiagnosticCode::NotFound, RuleId("editor.document.external-missing"),
171 DiagnosticSeverity::Error, "Persisted document was removed externally"));
172 const EditorStatus status =
173 found->second.snapshot.state == DocumentState::Conflict ? EditorStatus::Conflict : stored.code();
174 return Result<DocumentSnapshot>::failure(eve::Status(status, found->second.snapshot.diagnostics));
175 }
176
177 const bool changed = stored.value().revision != found->second.snapshot.revision.disk ||
178 stored.value().contentHash != found->second.snapshot.diskContentHash;
179 if (!changed) {
180 if (found->second.snapshot.state == DocumentState::Conflict) {
181 found->second.snapshot.state = DocumentState::Ready;
182 found->second.snapshot.diagnostics.clear();
183 }
184 return eve::editing::applied<DocumentSnapshot>(found->second.snapshot);
185 }
186 if (found->second.snapshot.dirty()) {
187 found->second.snapshot.state = DocumentState::Conflict;
188 found->second.snapshot.diagnostics = {eve::editing::ruleDiagnostic(
189 eve::DiagnosticCode::Conflict, RuleId("editor.document.external-conflict"), DiagnosticSeverity::Error,
190 "Document changed on disk while the session has unsaved edits")};
192 eve::Status(EditorStatus::Conflict, found->second.snapshot.diagnostics));
193 }
194
195 if (validator) {
196 auto validated = validator(stored.value().content);
197 if (!validated.ok()) {
198 found->second.snapshot.state = DocumentState::Conflict;
199 found->second.snapshot.diagnostics = validated.diagnostics();
200 if (found->second.snapshot.diagnostics.empty())
201 found->second.snapshot.diagnostics.push_back(eve::editing::ruleDiagnostic(
202 eve::DiagnosticCode::InvalidArgument, RuleId("editor.document.external-invalid"),
203 DiagnosticSeverity::Error, "External document content failed domain validation"));
205 eve::Status(EditorStatus::Conflict, found->second.snapshot.diagnostics));
206 }
207 }
208
209 found->second.content = stored.value().content;
210 const Revision synchronizedEdit = std::max(found->second.snapshot.revision.edit + 1, stored.value().revision);
211 found->second.snapshot.revision.edit = synchronizedEdit;
212 found->second.snapshot.revision.saved = synchronizedEdit;
213 found->second.snapshot.revision.disk = stored.value().revision;
214 found->second.snapshot.diskContentHash = stored.value().contentHash;
215 found->second.snapshot.state = DocumentState::Ready;
216 found->second.snapshot.diagnostics.clear();
217 return eve::editing::applied<DocumentSnapshot>(found->second.snapshot);
218}
219
221 if (!open_.erase(document))
222 return eve::editing::failed<void>(EditorStatus::NotFound, RuleId("editor.document.not-open"),
223 "Document is not open");
224 std::erase_if(pendingSaves_, [&](const auto& entry) { return entry.second.ticket.document == document; });
225 return eve::editing::applied<void>();
226}
227
228Result<DocumentSnapshot> DocumentService::error(EditorStatus status, const char* rule, std::string message) {
229 return eve::editing::failed<DocumentSnapshot>(status, RuleId(rule), std::move(message));
230}
231
232} // namespace eve::editor
233
234// EditorEnvironmentBrowser.cpp
235namespace eve::editor {
236namespace {
237const EditorValue* field(const EditorValue& value, const char* key) {
238 const auto* object = value.getIf<EditorValue::Object>();
239 if (!object) return nullptr;
240 const auto found = object->find(key);
241 return found == object->end() ? nullptr : &found->second;
242}
243} // namespace
244
245Result<EnvironmentAssetCard> EnvironmentAssetBrowser::card(const AssetRecord& record) const {
246 EnvironmentAssetCard result;
247 result.asset = record.guid;
248 result.logicalUri = record.logicalUri;
249 result.status = record.status;
250 result.diagnostics = record.diagnostics;
251 if (!record.artifacts.empty()) result.previewArtifact = record.artifacts.front();
252 const auto* layoutEntry = field(record.metadata, "layout");
253 const auto* widthEntry = field(record.metadata, "width");
254 const auto* heightEntry = field(record.metadata, "height");
255 const auto* facesEntry = field(record.metadata, "faceCount");
256 const auto* layout = layoutEntry ? layoutEntry->getIf<std::string>() : nullptr;
257 const auto* width = widthEntry ? widthEntry->getIf<int64_t>() : nullptr;
258 const auto* height = heightEntry ? heightEntry->getIf<int64_t>() : nullptr;
259 const auto* faces = facesEntry ? facesEntry->getIf<int64_t>() : nullptr;
260 static const std::set<std::string> layouts{"cubemap", "horizontal-cross", "vertical-cross", "equirectangular"};
261 if (!layout || !layouts.contains(*layout) || !width || !height || *width <= 0 || *height <= 0) {
262 result.diagnostics.push_back(eve::editing::ruleDiagnostic(
263 eve::DiagnosticCode::InvalidArgument, RuleId("editor.environment.invalid-map-metadata"),
264 DiagnosticSeverity::Error, "Environment map requires supported layout and positive dimensions"));
265 } else {
266 result.layout = *layout;
267 result.width = static_cast<int>(*width);
268 result.height = static_cast<int>(*height);
269 result.faceCount = faces ? static_cast<int>(*faces) : (*layout == "cubemap" ? 6 : 1);
270 if (*layout == "cubemap" && result.faceCount != 6)
271 result.diagnostics.push_back(eve::editing::ruleDiagnostic(
272 eve::DiagnosticCode::InvalidArgument, RuleId("editor.environment.cubemap-face-count"),
273 DiagnosticSeverity::Error, "Cubemap assets require exactly six faces"));
274 if (*layout == "equirectangular" && *width != *height * 2)
275 result.diagnostics.push_back(eve::editing::ruleDiagnostic(
276 eve::DiagnosticCode::InvalidArgument, RuleId("editor.environment.equirectangular-aspect"),
277 DiagnosticSeverity::Warning, "Equirectangular maps normally use a 2:1 aspect ratio"));
278 }
279 if (record.artifacts.empty())
280 result.diagnostics.push_back(eve::editing::ruleDiagnostic(
281 eve::DiagnosticCode::PreconditionViolation, RuleId("editor.environment.missing-artifact"),
282 DiagnosticSeverity::Error, "Environment asset has no imported artifact"));
283 if (record.status != AssetStatus::Ready && record.status != AssetStatus::Warning)
284 result.diagnostics.push_back(eve::editing::ruleDiagnostic(
285 eve::DiagnosticCode::PreconditionViolation, RuleId("editor.environment.asset-not-ready"),
286 DiagnosticSeverity::Error, "Environment asset is not ready for preview or assignment"));
287 const bool error =
288 std::any_of(result.diagnostics.begin(), result.diagnostics.end(), [](const EditorDiagnostic& diagnostic) {
289 return diagnostic.severity() == DiagnosticSeverity::Error ||
290 diagnostic.severity() == DiagnosticSeverity::Fatal;
291 });
292 if (error) return Result<EnvironmentAssetCard>::failure(eve::Status(EditorStatus::Rejected, result.diagnostics));
293 return eve::editing::applied<EnvironmentAssetCard>(std::move(result));
294}
295
297 std::optional<std::uint64_t> generation) const {
298 if (!database_ || limit == 0)
299 return eve::editing::failed<EnvironmentAssetPage>(
300 EditorStatus::Rejected, RuleId("editor.environment.invalid-browser-query"),
301 "Environment browser requires AssetDB and positive page size");
303 filter.typeIds = {"cubemap", "image.cubemap", "environment-map"};
304 filter.text = std::move(text);
305 auto page = database_->query(filter, offset, limit, generation);
306 if (!page.ok()) return Result<EnvironmentAssetPage>::failure(page.status());
308 result.nextOffset = page.value().nextOffset;
309 result.hasMore = page.value().hasMore;
310 result.generation = page.value().generation;
311 for (const auto& record : page.value().values) {
312 auto value = card(record);
313 if (value.ok()) result.values.push_back(value.value());
314 }
315 return eve::editing::applied<EnvironmentAssetPage>(std::move(result));
316}
317
319 if (!database_ || asset.empty())
320 return eve::editing::failed<EnvironmentAssetCard>(EditorStatus::Rejected,
321 RuleId("editor.environment.invalid-selection"),
322 "Environment selection requires AssetDB and asset id");
323 auto found = database_->find(asset);
324 if (!found.ok()) return Result<EnvironmentAssetCard>::failure(found.status());
325 return card(found.value());
326}
327
328} // namespace eve::editor
329
330// EditorEventTimeline.cpp
331namespace eve::editor {
332namespace {
333
334std::size_t nodeCount(const EditorValue& value, std::size_t limit) {
335 std::size_t result = 1;
336 if (const auto* array = value.getIf<EditorValue::Array>()) {
337 for (const auto& child : *array) {
338 if (result > limit) break;
339 result += nodeCount(child, limit - std::min(result, limit));
340 }
341 } else if (const auto* object = value.getIf<EditorValue::Object>()) {
342 for (const auto& [key, child] : *object) {
343 (void)key;
344 if (result > limit) break;
345 result += nodeCount(child, limit - std::min(result, limit));
346 }
347 }
348 return result;
349}
350
351bool includes(const std::vector<std::string>& values, const std::string& value) {
352 return values.empty() || std::find(values.begin(), values.end(), value) != values.end();
353}
354
355int severityRank(DiagnosticSeverity severity) {
356 switch (severity) {
357 case DiagnosticSeverity::Info: return 0;
358 case DiagnosticSeverity::Warning: return 1;
359 case DiagnosticSeverity::Error: return 2;
360 case DiagnosticSeverity::Fatal: return 3;
361 }
362 return 0;
363}
364
365} // namespace
366
368 if (capacity == 0 || capacity > 1000000)
369 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.timeline.capacity"),
370 "Timeline capacity must be between 1 and 1,000,000");
371 capacity_ = capacity;
372 while (events_.size() > capacity_) {
373 events_.pop_front();
374 ++dropped_;
375 }
376 ++generation_;
377 return eve::editing::applied<void>();
378}
379
381 if (event.domain.empty() || event.type.empty() || maximumPayloadNodes == 0 ||
382 nodeCount(event.payload, maximumPayloadNodes) > maximumPayloadNodes)
383 return eve::editing::failed<std::uint64_t>(EditorStatus::Rejected, RuleId("editor.timeline.invalid-event"),
384 "Timeline event identity or payload budget is invalid");
385 if (event.sequence == 0)
386 event.sequence = nextSequence_++;
387 else {
388 if (event.sequence < nextSequence_)
389 return eve::editing::failed<std::uint64_t>(EditorStatus::Conflict, RuleId("editor.timeline.sequence"),
390 "Timeline event sequence is stale or duplicated");
391 nextSequence_ = event.sequence + 1;
392 }
393 const std::uint64_t sequence = event.sequence;
394 if (events_.size() == capacity_) {
395 events_.pop_front();
396 ++dropped_;
397 }
398 events_.push_back(std::move(event));
399 ++generation_;
400 return eve::editing::applied<std::uint64_t>(sequence);
401}
402
404 std::size_t limit,
405 std::optional<std::uint64_t> generation) const {
406 if (limit == 0 || limit > 10000)
407 return eve::editing::failed<EditorTimelinePage>(EditorStatus::Rejected, RuleId("editor.timeline.page-size"),
408 "Timeline page size must be between 1 and 10,000");
409 if (generation && *generation != generation_)
410 return eve::editing::failed<EditorTimelinePage>(
411 EditorStatus::Conflict, RuleId("editor.timeline.stale-generation"), "Timeline changed while paging");
412 std::vector<EditorTimelineEvent> matched;
413 for (const auto& event : events_) {
414 if (!includes(filter.domains, event.domain) || !includes(filter.types, event.type) ||
415 (!filter.source.empty() && event.source != filter.source) ||
416 (!filter.correlation.empty() && event.correlation != filter.correlation) ||
417 (filter.minimumSeverity && severityRank(event.severity) < severityRank(*filter.minimumSeverity)) ||
418 event.tick < filter.firstTick || (filter.lastTick > 0 && event.tick > filter.lastTick))
419 continue;
420 matched.push_back(event);
421 }
423 result.generation = generation_;
424 result.droppedEvents = dropped_;
425 const std::size_t begin = std::min(offset, matched.size());
426 const std::size_t end = std::min(begin + limit, matched.size());
427 result.values.assign(matched.begin() + static_cast<std::ptrdiff_t>(begin),
428 matched.begin() + static_cast<std::ptrdiff_t>(end));
429 result.nextOffset = end;
430 result.hasMore = end < matched.size();
431 return eve::editing::applied<EditorTimelinePage>(std::move(result));
432}
433
435 events_.clear();
436 ++generation_;
437}
438
439} // namespace eve::editor
440
441// EditorExtension.cpp
442namespace eve::editor {
443
445 if (!commands_)
446 return invalid("editor.extension.missing-command-service", "Extension registry has no command service");
447 const std::string owner = extension.ownerModule();
448 if (owner.empty()) return invalid("editor.extension.missing-owner", "Game editor extension owner is required");
449 if (std::any_of(commandVisibility_.begin(), commandVisibility_.end(),
450 [&](const CommandVisibility& command) { return command.ownerModule == owner; }) ||
451 std::any_of(tools_.begin(), tools_.end(),
452 [&](const ExtensionToolDescriptor& tool) { return tool.ownerModule == owner; }))
453 return invalid("editor.extension.duplicate-owner", "Game editor extension owner is already loaded");
454 activeOwner_ = owner;
455 try {
456 extension.registerEditor(*this);
457 } catch (const std::exception& exception) {
458 unload(owner);
459 activeOwner_.clear();
460 return invalid("editor.extension.exception", exception.what());
461 } catch (...) {
462 unload(owner);
463 activeOwner_.clear();
464 return invalid("editor.extension.exception", "Game editor extension threw an unknown exception");
465 }
466 activeOwner_.clear();
467 return eve::editing::applied<void>();
468}
469
470std::size_t EditorExtensionRegistry::unload(const std::string& ownerModule) {
471 std::size_t removed = commands_ ? commands_->unregisterOwner(ownerModule) : 0;
472 auto eraseOwner = [&](auto& values) {
473 const std::size_t before = values.size();
474 std::erase_if(values, [&](const auto& value) { return value.ownerModule == ownerModule; });
475 removed += before - values.size();
476 };
477 eraseOwner(commandVisibility_);
478 eraseOwner(tools_);
479 eraseOwner(palettes_);
480 eraseOwner(rules_);
481 return removed;
482}
483
485 const ExtensionAudience audience = audienceFor(profile);
486 for (const CommandVisibility& command : commandVisibility_)
487 if (hasAudience(command.audiences, audience)) profile.allowCommand(command.id);
488}
489
490std::vector<ExtensionToolDescriptor> EditorExtensionRegistry::tools(const HostProfile& profile) const {
491 std::vector<ExtensionToolDescriptor> result;
492 const ExtensionAudience audience = audienceFor(profile);
493 for (const ExtensionToolDescriptor& tool : tools_)
494 if (hasAudience(tool.audiences, audience)) result.push_back(tool);
495 return result;
496}
497
498std::vector<ExtensionPaletteDescriptor> EditorExtensionRegistry::palettes(const HostProfile& profile) const {
499 std::vector<ExtensionPaletteDescriptor> result;
500 const ExtensionAudience audience = audienceFor(profile);
501 for (const ExtensionPaletteDescriptor& palette : palettes_)
502 if (hasAudience(palette.audiences, audience)) result.push_back(palette);
503 return result;
504}
505
506std::vector<ExtensionRuleDescriptor> EditorExtensionRegistry::rules(const HostProfile& profile) const {
507 std::vector<ExtensionRuleDescriptor> result;
508 const ExtensionAudience audience = audienceFor(profile);
509 for (const ExtensionRuleDescriptor& rule : rules_)
510 if (hasAudience(rule.audiences, audience)) result.push_back(rule);
511 return result;
512}
513
515 ExtensionAudience audiences) {
516 if (activeOwner_.empty())
517 return eve::editing::failed<EditorValue>(EditorStatus::Rejected,
518 RuleId("editor.extension.registration-outside-load"),
519 "Commands may only be registered while loading an extension");
520 descriptor.ownerModule = activeOwner_;
522 if (result.ok()) commandVisibility_.push_back({descriptor.id, activeOwner_, audiences});
523 return result;
524}
525
527 if (activeOwner_.empty() || descriptor.id.empty())
528 return invalid("editor.extension.invalid-tool", "Tool registration requires an active owner and id");
529 if (std::any_of(tools_.begin(), tools_.end(),
530 [&](const ExtensionToolDescriptor& tool) { return tool.id == descriptor.id; }))
531 return invalid("editor.extension.duplicate-tool", "Tool id is already registered");
532 descriptor.ownerModule = activeOwner_;
533 tools_.push_back(std::move(descriptor));
534 return eve::editing::applied<void>();
535}
536
538 if (activeOwner_.empty() || descriptor.id.empty())
539 return invalid("editor.extension.invalid-palette", "Palette registration requires an active owner and id");
540 descriptor.ownerModule = activeOwner_;
541 palettes_.push_back(std::move(descriptor));
542 return eve::editing::applied<void>();
543}
544
546 if (activeOwner_.empty() || descriptor.id.empty())
547 return invalid("editor.extension.invalid-rule", "Rule registration requires an active owner and id");
548 descriptor.ownerModule = activeOwner_;
549 rules_.push_back(std::move(descriptor));
550 return eve::editing::applied<void>();
551}
552
553ExtensionAudience EditorExtensionRegistry::audienceFor(const HostProfile& profile) {
554 switch (profile.kind()) {
555 case HostKind::Developer: return ExtensionAudience::Developer;
556 case HostKind::RuntimeBuilder: return ExtensionAudience::Player;
557 case HostKind::RuntimeAdmin: return ExtensionAudience::Admin;
558 case HostKind::Automation: return ExtensionAudience::Automation;
559 }
561}
562
563Result<void> EditorExtensionRegistry::invalid(const char* rule, std::string message) {
564 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId(rule), std::move(message));
565}
566
567} // namespace eve::editor
std::string descriptor
std::vector< QuestEvent > pending
std::string title
bool changed
SQObjectPtr key
Definition ECS.cpp:155
Generation generation
Definition ECS.cpp:40
ScriptComponentRecord record
Definition ECS.cpp:228
std::vector< std::uint8_t > stored
Definition Evpack.cpp:171
std::string palette
std::string layout
std::string message
std::uint32_t capacity
wgpu::PopErrorScopeStatus status
HexVec3 left
HexVec3 right
std::uint32_t height
std::uint32_t width
size_t offset
std::string id
Poco::JSON::Object::Ptr result
Snapshot snapshot
HSQOBJECT handler
std::shared_ptr< OceanGpuSpectrum > owner
std::unique_ptr< gpgpu::Sequence > sequence
Definition OnnxGpgpu.cpp:43
std::string error
Definition Package.cpp:174
std::set< std::string > values
Object::Ptr value
bool found
int removed
std::string filter
std::string text
size_t begin
size_t end
double current
Json object
int limit
Definition TreeMesh.cpp:166
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Structured status and zero or more diagnostics for an operation.
Definition Status.h:70
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.
std::vector< Value > Array
std::map< std::string, Value > Object
std::function< Result< void >(const EditorValue &)> ContentValidator
Synchronous content validator borrowed only for one external reconciliation call.
Result< DocumentSnapshot > reconcileExternal(const DocumentId &document)
Reconcile one open document with the latest store value. Clean documents adopt external content; dirt...
Result< DocumentSnapshot > edit(const DocumentId &document, EditorValue content, std::optional< Revision > expectedRevision=std::nullopt)
Replace the working content using an optional expected edit revision.
Result< DocumentSnapshot > snapshot(const DocumentId &document) const
Return one metadata snapshot.
Result< DocumentSnapshot > executeSave(const SaveTicket &ticket)
Execute a captured save ticket without reading newer working content.
std::vector< DocumentSnapshot > documents() const
Return all open documents in stable id order.
Result< EditorValue > content(const DocumentId &document) const
Return the current working content snapshot.
Result< SaveTicket > requestSave(const DocumentId &document)
Capture an exact content/revision pair for a later CAS save.
Result< void > close(const DocumentId &document)
Close and discard in-memory state; persisted content is unchanged.
Result< DocumentSnapshot > open(DocumentKey key, std::string title, std::string resourceUri, EditorValue initialContent={})
Open an asset-backed document, loading existing persisted content when present.
size_t unregisterOwner(const std::string &ownerModule)
Remove every command registered by a module.
Result< EditorValue > registerCommand(CommandDescriptor descriptor, EditorCommandHandler handler, bool replace=false)
Register one command.
Result< EditorTimelinePage > query(const EditorTimelineQuery &filter, 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< void > setCapacity(std::size_t capacity)
Set retained event capacity; shrinking drops oldest events.
void clear()
Clear retained events while preserving the next sequence number.
std::uint64_t generation() const
Generation.
Result< std::uint64_t > append(EditorTimelineEvent event, std::size_t maximumPayloadNodes=10000)
Copy one event, assigning a monotonic sequence when it is zero.
Result< void > registerPalette(ExtensionPaletteDescriptor descriptor) override
Registers palette.
Result< void > load(IGameEditorExtension &extension)
Load one extension under its stable owner module.
std::vector< ExtensionToolDescriptor > tools(const HostProfile &profile) const
Return tool descriptors visible to a host.
Result< EditorValue > registerCommand(CommandDescriptor descriptor, EditorCommandHandler handler, ExtensionAudience audiences) override
Registers command.
std::vector< ExtensionRuleDescriptor > rules(const HostProfile &profile) const
Return validation descriptors visible to a host.
std::vector< ExtensionPaletteDescriptor > palettes(const HostProfile &profile) const
Return palette descriptors visible to a host.
std::size_t unload(const std::string &ownerModule)
Remove every component registered by an owner module.
Result< void > registerRule(ExtensionRuleDescriptor descriptor) override
Registers rule.
Result< void > registerTool(ExtensionToolDescriptor descriptor) override
Registers tool.
void configureProfile(HostProfile &profile) const
Add player/admin/automation extension commands to a deny-by-default profile.
Result< EnvironmentAssetPage > query(std::string text, std::size_t offset, std::size_t limit, std::optional< std::uint64_t > generation=std::nullopt) const
Query deterministic cards; stale index generations return Conflict.
Result< EnvironmentAssetCard > select(const AssetGuid &asset) const
Resolve a selected environment map and reject unusable import metadata.
Upper capability boundary for one editor host.
void allowCommand(CommandId id)
Allow command.
HostKind kind() const
Kind.
virtual Result< StoredDocument > read(const std::string &resourceUri) const =0
Read the latest value for a resource URI.
virtual Result< StoredDocument > compareAndSwap(const std::string &resourceUri, Revision expectedRevision, const std::string &expectedContentHash, const EditorValue &content)=0
Replace a value only when the expected disk revision still matches.
Entry point implemented by a gameplay module to inject editor behavior.
Result< AssetRecord > find(const AssetGuid &guid) const
Find one asset by stable GUID.
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< StoredDocument > read(const std::string &resourceUri) const override
Reads .
Result< StoredDocument > compareAndSwap(const std::string &resourceUri, Revision expectedRevision, const std::string &expectedContentHash, const EditorValue &content) override
Compare and swap.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build an owning common diagnostic carrying an open editing rule identity.
eve::editing::StableId StableId
Definition EditorIds.h:36
eve::editing::Value EditorValue
Compatibility alias for the UI-independent authoring value tree.
Definition EditorValue.h:8
constexpr bool hasAudience(ExtensionAudience value, ExtensionAudience audience)
True when audience.
std::function< Result< EditorValue >(const CommandContext &, const EditorValue &)> EditorCommandHandler
eve::Diagnostic EditorDiagnostic
eve::editing::RuleId RuleId
Definition EditorIds.h:32
eve::Severity DiagnosticSeverity
Definition EditorResult.h:9
ExtensionAudience
Host audiences to which a game-provided editor extension may be published.
eve::editing::Revision Revision
StatusCode
Stable outcome category for an operation.
Definition Status.h:28
Deterministic filter used by headless and UI asset queries.
std::vector< std::string > typeIds
Presentation and execution metadata for a registered command.
Stable document identity; paths are deliberately excluded.
Immutable document metadata snapshot.
Immutable normalized runtime event copied into the editor timeline.
Generation-qualified timeline query page.
Deterministic event filter used by headless and visual presenters.
Generation-qualified environment asset browser page.
Semantic palette that can place the same tool differently per audience.
Discoverable gameplay validation rule registered by a game extension.
Host-neutral metadata for a game-provided editor tool.
Immutable save request capturing one exact edit revision.
Value snapshot returned by an atomic document store.