|
| 1 | +# Migrating from Geode v3.x to v4.0 |
| 2 | + |
| 3 | +## Changes to `Result` |
| 4 | +* Result type has been rewritten from scratch, and it is now shared with many parts of the Geode codebase (Geode itself, TulipHook and matjson). |
| 5 | +* Many methods removed or renamed: |
| 6 | + * `value()` -> `unwrap()` |
| 7 | + * `expect(str, fmt args...)` -> Use `mapErr` along with `fmt::format` |
| 8 | + * Snake case methods renamed to camel case |
| 9 | +* Universal `GEODE_UNWRAP(res)` and `GEODE_UNWRAP_INTO(value, res)` macros |
| 10 | + * These macros were already previously available, but this is just a reminder that they can help a lot when dealing with results. |
| 11 | + * If you only ever expect to build your code with **clang**, you can use the `GEODE_UNWRAP` macro like so, for convenience: |
| 12 | + ```cpp |
| 13 | + Result<int> getInt(); |
| 14 | + |
| 15 | + Result<int> foo(int extra) { |
| 16 | + // This will not compile on MSVC |
| 17 | + int value = GEODE_UNWRAP(getInt()) + extra; |
| 18 | + return Ok(value); |
| 19 | + } |
| 20 | + ``` |
| 21 | + |
| 22 | +## Changes to the Geode Settings API |
| 23 | +* Settings v2 has been removed, V3 suffix from classes are now aliased |
| 24 | +* Code that already used SettingsV3 should still work |
| 25 | + |
| 26 | +## Changes to `geode::Layout` |
| 27 | +* No longer in cocos2d namespace |
| 28 | + * Can now be found in `Geode/ui/Layout.hpp` |
| 29 | + |
| 30 | +## Changes to `matjson` |
| 31 | +[Link to the full docs](https://github.com/geode-sdk/json) |
| 32 | +* Entire library rewritten to use `geode::Result` |
| 33 | + * See result section for tips on how to use Geode's Result class |
| 34 | +* Methods are now camel case to fit with rest of Geode's codebase |
| 35 | + * `is_string` -> `isString` |
| 36 | + * `as_string` -> `asString` |
| 37 | + * etc.. |
| 38 | +* `matjson::Object` has been removed, now you can just iterate directly off a Value (same for arrays!) |
| 39 | + ```cpp |
| 40 | + matjson::Value someObject = ...; |
| 41 | + for (auto& [key, value] : someObject) { |
| 42 | + log::debug("{}: {}", key, value); |
| 43 | + } |
| 44 | + |
| 45 | + matjson::Value someArray = ...; |
| 46 | + for (auto& value : someArray) { |
| 47 | + log::debug("{}", value); |
| 48 | + } |
| 49 | + ``` |
| 50 | +* Use `matjson::makeObject` for making objects inline now: |
| 51 | + ```cpp |
| 52 | + matjson::Value obj = matjson::makeObject({ |
| 53 | + { "key", 123 }, |
| 54 | + { "another-key": "another value!" } |
| 55 | + }); |
| 56 | + ``` |
| 57 | +* Accessing missing properties with `Value::operator[]` will now return a null value instead of throwing an exception |
| 58 | +* Serialization methods have been changed: |
| 59 | + * `T from_json(matjson::Value const&)` -> `Result<T> fromJson(matjson::Value const&)` |
| 60 | + * `matjson::Value to_json(T const& value)` -> `matjson::Value toJson(T const& value)` |
| 61 | + * `is_json` is no longer used, instead just return an error in `fromJson` |
| 62 | +* `bool Value::is<T>()` removed |
| 63 | +* `#include <matjson/stl_serialize.hpp>` -> `#include <matjson/std.hpp>` |
| 64 | +* Added new experimental `<matjson/reflect.hpp>` header, uses [qlibs/reflect](https://github.com/qlibs/reflect) to (de)serialize aggregate structs |
| 65 | + * Behavior might change in the future, so use with caution |
0 commit comments