载入中...
搜索中...
未找到
MapObjectContract.cpp
浏览该文件的文档.
23bool booleanMember(const eve::Value::Object& object, std::string_view name, bool fallback, bool& output) {
83 eve::DiagnosticCode::InvalidArgument, "property value is outside its enum", path, {}, "map.object-contract"));
88 eve::DiagnosticCode::TypeMismatch, "property must be an integer", path, {}, "map.object-contract"));
93 eve::DiagnosticCode::TypeMismatch, "property must be a finite number", path, {}, "map.object-contract"));
97 eve::DiagnosticCode::TypeMismatch, "property must be true or false", path, {}, "map.object-contract"));
100 eve::DiagnosticCode::Unsupported, "unsupported property kind", path, {}, "map.object-contract"));
104 eve::DiagnosticCode::InvalidArgument, "property is below its minimum", path, {}, "map.object-contract"));
107 eve::DiagnosticCode::InvalidArgument, "property exceeds its maximum", path, {}, "map.object-contract"));
113eve::Result<void> validateMapObjects(std::span<const MapObject> objects, std::string_view contractJson) {
118 eve::DiagnosticCode::TypeMismatch, "contract root must be an object", "$contract", {}, "map.object-contract"));
132 "unsupported contract version; expected version:1 with types:[{type,properties:[{name,kind}]}]",
137 eve::DiagnosticCode::TypeMismatch, "types must be an array of {type,properties:[{name,kind}]} rules",
144 eve::DiagnosticCode::TypeMismatch, "requireUniqueNames must be boolean", "$contract.requireUniqueNames", {}, "map.object-contract"));
147 eve::DiagnosticCode::TypeMismatch, "allowUnknownTypes must be boolean", "$contract.allowUnknownTypes", {}, "map.object-contract"));
154 eve::DiagnosticCode::TypeMismatch, "type rule must be an object", base, {}, "map.object-contract"));
158 eve::DiagnosticCode::InvalidArgument, "type must be a non-empty string", base + ".type", {}, "map.object-contract"));
160 if (!booleanMember(*definition, "allowUnknownProperties", false, typeRule.allowUnknownProperties))
162 eve::DiagnosticCode::TypeMismatch, "allowUnknownProperties must be boolean", base + ".allowUnknownProperties", {}, "map.object-contract"));
164 const auto* properties = propertiesValue ? propertiesValue->getIf<eve::Value::Array>() : nullptr;
167 eve::DiagnosticCode::TypeMismatch, "properties must be an array", base + ".properties", {}, "map.object-contract"));
174 eve::DiagnosticCode::TypeMismatch, "property rule must be an object", propertyPath, {}, "map.object-contract"));
179 eve::DiagnosticCode::InvalidArgument, "property name must be non-empty", propertyPath + ".name", {}, "map.object-contract"));
182 eve::DiagnosticCode::TypeMismatch, "property kind must be a string", propertyPath + ".kind", {}, "map.object-contract"));
186 eve::DiagnosticCode::TypeMismatch, "required must be boolean", propertyPath + ".required", {}, "map.object-contract"));
192 eve::DiagnosticCode::TypeMismatch, std::string(field) + " must be numeric", propertyPath + "." + std::string(field), {}, "map.object-contract"));
196 if (propertyRule.minimum && propertyRule.maximum && *propertyRule.minimum > *propertyRule.maximum)
198 eve::DiagnosticCode::InvalidArgument, "min must not exceed max", propertyPath, {}, "map.object-contract"));
203 eve::DiagnosticCode::TypeMismatch, "enum must be an array", propertyPath + ".enum", {}, "map.object-contract"));
207 eve::DiagnosticCode::TypeMismatch, "enum values must be strings", propertyPath + ".enum", {}, "map.object-contract"));
210 eve::DiagnosticCode::AlreadyExists, "duplicate enum value", propertyPath + ".enum", {}, "map.object-contract"));
215 eve::DiagnosticCode::AlreadyExists, "duplicate property rule", propertyPath + ".name", {}, "map.object-contract"));
220 eve::DiagnosticCode::AlreadyExists, "duplicate type rule", base + ".type", {}, "map.object-contract"));
230 eve::DiagnosticCode::InvalidArgument, "object geometry must be finite and non-negative", base, {}, "map.object-contract"));
233 eve::DiagnosticCode::Conflict, "object names must be unique, bounded, non-empty, and control-free", base + ".name", {}, "map.object-contract"));
238 eve::DiagnosticCode::Unsupported, "object type is not admitted", base + ".type", {}, "map.object-contract"));
246 eve::DiagnosticCode::NotFound, "required property is missing", base + ".properties." + name, {}, "map.object-contract"));
257 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={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
const std::string & asString() const
Return the string payload; the caller must have checked the kind.
Definition Value.cpp:207
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:244
Result< double > numericValue(const Value &value)
Read an Integer or Number as an owning double without applying domain validation.
Definition EditingValue.cpp:8
放置世界:格子占用(多通道)+ 地形语义 + 已放置建筑实例。 行为由 PlacementSystem 提供;本类暴露便于脚本绑定的薄封装方法。 坐标换算统一走 eve::grid(支持 rectang...
Definition ArchSpaceTileMapProjector.h:10
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:113
@ InvalidArgument
@ TypeMismatch
A stable reference resolved to a different canonical domain type.
@ NotFound
@ UnknownVersion
@ AlreadyExists
@ Unsupported
@ Conflict
Result< bool > readBoolValue(const Value &value)
Read a Bool without coercing integers, strings or other kinds.
Definition Value.cpp:50
Result< double > readNumericDoubleValue(const Value &value)
Read an Int64 or Double as a double without imposing a finite-value policy.
Definition Value.cpp:74
A named, typed rectangle object from a Tiled objectgroup layer. Used by Map::setObjects / getObject* ...
Definition MapObject.h:13