载入中...
搜索中...
未找到
LevelFormat.cpp
浏览该文件的文档.
66eve::Value::Object extraFields(const eve::Value& value, std::initializer_list<const char*> known) {
79void readProperties(eve::json::Value v, const eve::Value* owned, std::unordered_map<std::string, std::string>& out,
95 if (p.getString("type", "string") == "string" && p.get("value").isString() && p.keys().size() == 3)
104eve::Value propertyValue(const std::unordered_map<std::string, std::string>& properties, const Object& extras,
130 for (const auto& [key, value] : std::map<std::string, std::string>(properties.begin(), properties.end()))
161 eve::Result<std::unique_ptr<LevelDocument>> read(const std::string& s) const override { return readJson(s, false); }
162 eve::Result<std::string> write(const LevelDocument& d) const override { return writeJson(d, false); }
171 const auto fail = [](const std::string& message, eve::DiagnosticCode code = eve::DiagnosticCode::Unsupported) {
179 (r.getString("format") != "eve.level" || (version && (!version->isInt64() || version->asInt() != 1))))
182 if (r.getBool("infinite", false)) return fail("Infinite maps are not yet editable by LevelDocument");
191 if (w < 1 || h < 1 || int64_t(w) * h > 16 * 1024 * 1024 || !std::isfinite(tw) || !std::isfinite(th) ||
195 "map dimensions must be positive, finite and within the 16M-cell budget", {}, {}, "editor.level"));
205 {"format", "version", "type", "width", "height", "tilewidth", "tileheight", "orientation", "layers"});
217 if (!validId(owned.value().find("layers")->at(i), tiled) || !validProperties(v.get("properties")) ||
220 return fail("Invalid layer identity, properties or presentation", eve::DiagnosticCode::ParseError);
222 return fail("Chunked or encoded tile layers require the runtime importer; editing is not supported");
225 int li = obj ? out->addObjectLayer(v.getString("name")) : out->addTileLayer(v.getString("name"));
229 if (!layerIds.insert(l->id).second) return fail("Duplicate layer id", eve::DiagnosticCode::ParseError);
238 readProperties(v.get("properties"), owned.value().find("layers")->at(i).find("properties"), l->properties,
245 if (!q.isObject()) return fail("Map object must be an object", eve::DiagnosticCode::ParseError);
267 readProperties(q.get("properties"), ownedObject.find("properties"), ob->properties, ob->extensions);
272 return fail("Tile data must contain exactly width * height GIDs", eve::DiagnosticCode::ParseError);
303 for (const auto& object : layer.objects) nextObject = std::max(nextObject, numericId(object.id) + 1);
309 tiled ? eve::Value(numericId(layer.id) ? numericId(layer.id) : nextLayer++) : eve::Value(layer.id);
380 eve::DiagnosticCode::InvalidArgument, "level format must not be null", {}, {}, "editor.level"));
413eve::Result<std::string> LevelFormatRegistry::encode(const std::string& id, const LevelDocument& d) const {
425 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "cannot open level", p, {}, "editor.level"));
432eve::Result<void> LevelFormatRegistry::save(const std::string& p, const LevelDocument& d, const std::string& id) const {
445 staging += ".save-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()) + "-" +
465 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "cannot write level", p, {}, "editor.level"));
471 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "failed while writing level", p, {}, "editor.level"));
473 if (!MoveFileExW(temporary.c_str(), destination.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH))
475 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "cannot replace level file", p, {}, "editor.level"));
480 eve::DiagnosticCode::Failed, "cannot replace level file: " + error.message(), p, {}, "editor.level"));
Share string attribute map operations through the Windows Foundation DLL.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
void expect(std::string_view message) const
Require success for a void operation.
Definition Result.h:582
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
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
static Document parse(const std::string &text, std::string *error=nullptr)
Parse.
Definition Json.cpp:623
Format-neutral, editable top-down level model.
Definition LevelDocument.h:61
static const Object & extensions(const LevelDocument &document)
Definition LevelFormat.cpp:149
static Object & extensions(LevelDocument &document)
Definition LevelFormat.cpp:148
eve::Result< std::unique_ptr< LevelDocument > > load(const std::string &path, const std::string &format={}) const
Loads .
Definition LevelFormat.cpp:420
eve::Result< void > registerFormat(std::unique_ptr< LevelFormat > format)
Registers format.
Definition LevelFormat.cpp:377
eve::Result< void > save(const std::string &path, const LevelDocument &level, const std::string &format={}) const
Encode then atomically replace a file; failures preserve an existing destination.
Definition LevelFormat.cpp:432
std::string detect(const std::string &path, const std::string &text) const
Detect.
Definition LevelFormat.cpp:397
eve::Result< std::string > encode(const std::string &format, const LevelDocument &level) const
Encode.
Definition LevelFormat.cpp:413
eve::Result< std::unique_ptr< LevelDocument > > decode(const std::string &format, const std::string &text) const
Decode.
Definition LevelFormat.cpp:405
Result< T > fail(std::string message, DiagnosticCode code=DiagnosticCode::InvalidArgument)
Definition BuildingAssemblyInternal.h:35
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:27
void keys(const Value &value, std::initializer_list< const char * > names)
Definition OceanCodecInternal.h:8
Result< std::string > stringify(const eve::Value &value)
Serialize the canonical owning Value as deterministic compact JSON.
Definition Json.cpp:605
Definition Brush.cpp:10
@ InvalidArgument
@ NotFound
@ Unsupported
@ Failed
@ ParseError
@ Applied
@ Object
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24
enum EVENGINE_API_FOUNDATION Array
OT_ARRAY (editable via Runtime array APIs / ReflectedPropertyModel).
Definition Runtime.h:120
Definition Container.h:602