载入中...
搜索中...
未找到
MapObjectContract.cpp
浏览该文件的文档.
22bool booleanMember(const eve::Value::Object& object, std::string_view name, bool fallback, bool& output) {
81 eve::DiagnosticCode::InvalidArgument, "property value is outside its enum", path, {}, "map.object-contract"));
86 eve::DiagnosticCode::TypeMismatch, "property must be an integer", path, {}, "map.object-contract"));
91 eve::DiagnosticCode::TypeMismatch, "property must be a finite number", path, {}, "map.object-contract"));
95 eve::DiagnosticCode::TypeMismatch, "property must be true or false", path, {}, "map.object-contract"));
98 eve::DiagnosticCode::Unsupported, "unsupported property kind", path, {}, "map.object-contract"));
102 eve::DiagnosticCode::InvalidArgument, "property is below its minimum", path, {}, "map.object-contract"));
105 eve::DiagnosticCode::InvalidArgument, "property exceeds its maximum", path, {}, "map.object-contract"));
111eve::Result<void> validateMapObjects(std::span<const MapObject> objects, std::string_view contractJson) {
116 eve::DiagnosticCode::TypeMismatch, "contract root must be an object", "$contract", {}, "map.object-contract"));
123 eve::DiagnosticCode::InvalidArgument, "unsupported contract schema", "$contract.schema", {}, "map.object-contract"));
126 eve::DiagnosticCode::UnknownVersion, "unsupported contract version", "$contract.version", {}, "map.object-contract"));
129 eve::DiagnosticCode::TypeMismatch, "types must be an array", "$contract.types", {}, "map.object-contract"));
135 eve::DiagnosticCode::TypeMismatch, "requireUniqueNames must be boolean", "$contract.requireUniqueNames", {}, "map.object-contract"));
138 eve::DiagnosticCode::TypeMismatch, "allowUnknownTypes must be boolean", "$contract.allowUnknownTypes", {}, "map.object-contract"));
145 eve::DiagnosticCode::TypeMismatch, "type rule must be an object", base, {}, "map.object-contract"));
149 eve::DiagnosticCode::InvalidArgument, "type must be a non-empty string", base + ".type", {}, "map.object-contract"));
151 if (!booleanMember(*definition, "allowUnknownProperties", false, typeRule.allowUnknownProperties))
153 eve::DiagnosticCode::TypeMismatch, "allowUnknownProperties must be boolean", base + ".allowUnknownProperties", {}, "map.object-contract"));
155 const auto* properties = propertiesValue ? propertiesValue->getIf<eve::Value::Array>() : nullptr;
158 eve::DiagnosticCode::TypeMismatch, "properties must be an array", base + ".properties", {}, "map.object-contract"));
165 eve::DiagnosticCode::TypeMismatch, "property rule must be an object", propertyPath, {}, "map.object-contract"));
170 eve::DiagnosticCode::InvalidArgument, "property name must be non-empty", propertyPath + ".name", {}, "map.object-contract"));
173 eve::DiagnosticCode::TypeMismatch, "property kind must be a string", propertyPath + ".kind", {}, "map.object-contract"));
177 eve::DiagnosticCode::TypeMismatch, "required must be boolean", propertyPath + ".required", {}, "map.object-contract"));
183 eve::DiagnosticCode::TypeMismatch, std::string(field) + " must be numeric", propertyPath + "." + std::string(field), {}, "map.object-contract"));
187 if (propertyRule.minimum && propertyRule.maximum && *propertyRule.minimum > *propertyRule.maximum)
189 eve::DiagnosticCode::InvalidArgument, "min must not exceed max", propertyPath, {}, "map.object-contract"));
194 eve::DiagnosticCode::TypeMismatch, "enum must be an array", propertyPath + ".enum", {}, "map.object-contract"));
198 eve::DiagnosticCode::TypeMismatch, "enum values must be strings", propertyPath + ".enum", {}, "map.object-contract"));
201 eve::DiagnosticCode::AlreadyExists, "duplicate enum value", propertyPath + ".enum", {}, "map.object-contract"));
206 eve::DiagnosticCode::AlreadyExists, "duplicate property rule", propertyPath + ".name", {}, "map.object-contract"));
211 eve::DiagnosticCode::AlreadyExists, "duplicate type rule", base + ".type", {}, "map.object-contract"));
221 eve::DiagnosticCode::InvalidArgument, "object geometry must be finite and non-negative", base, {}, "map.object-contract"));
224 eve::DiagnosticCode::Conflict, "object names must be unique, bounded, non-empty, and control-free", base + ".name", {}, "map.object-contract"));
229 eve::DiagnosticCode::Unsupported, "object type is not admitted", base + ".type", {}, "map.object-contract"));
237 eve::DiagnosticCode::NotFound, "required property is missing", base + ".properties." + name, {}, "map.object-contract"));
248 eve::DiagnosticCode::Unsupported, "property is not admitted", base + ".properties." + name, {}, "map.object-contract"));
Owning, renderer-independent dynamic values.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
const std::string & asString() const
Return the string payload; the caller must have checked the kind.
Definition Value.cpp:87
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
std::int64_t asInt() const
Return the Int64 payload; the caller must have checked the kind.
Definition Value.cpp:69
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:180
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:124
放置世界:格子占用(多通道)+ 地形语义 + 已放置建筑实例。 行为由 PlacementSystem 提供;本类暴露便于脚本绑定的薄封装方法。 坐标换算统一走 eve::grid(支持 rectang...
Definition PlacementWorld.h:19
eve::Result< void > validateMapObjects(std::span< const MapObject > objects, std::string_view contractJson)
Validate map objects against an owning JSON content contract.
Definition MapObjectContract.cpp:111
@ InvalidArgument
@ TypeMismatch
A stable reference resolved to a different canonical domain type.
@ NotFound
@ UnknownVersion
@ AlreadyExists
@ Unsupported
@ Conflict
A named, typed rectangle object from a Tiled objectgroup layer. Used by Map::setObjects / getObject* ...
Definition MapObject.h:13