Skip to content

Commit 04b5410

Browse files
committed
add initial migration guide
1 parent 45000aa commit 04b5410

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tutorials/migrate-v5.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Migrating from Geode v4.x to v5.0
2+
3+
## Changes to `Popup`
4+
5+
`geode::Popup` is no longer templated, and instead accepts its own arguments in `Popup::init` (which also replaces `initAnchored`). It now uses the pattern similar to any other node. For example the following code:
6+
7+
```cpp
8+
class MyPopup : public Popup<int> {
9+
public:
10+
static MyPopup* create(int value) {
11+
auto popup = new MyPopup;
12+
if (popup->initAnchored(320.f, 160.f, value)) {
13+
popup->autorelease();
14+
return ret;
15+
}
16+
delete ret;
17+
return nullptr;
18+
}
19+
20+
protected:
21+
bool setup(int value) override {
22+
auto node = CCLabelBMFont::create("Hi", "bigFont.fnt");
23+
this->addChild(node);
24+
25+
return true;
26+
}
27+
};
28+
```
29+
30+
Should be refactored to this:
31+
32+
```cpp
33+
class MyPopup : public Popup {
34+
public:
35+
static MyPopup* create(int value) {
36+
auto popup = new MyPopup;
37+
if (popup->init(value)) {
38+
popup->autorelease();
39+
return ret;
40+
}
41+
delete ret;
42+
return nullptr;
43+
}
44+
45+
protected:
46+
bool init(int value) {
47+
if (!Popup::init(320.f, 160.f))
48+
return false;
49+
50+
auto node = CCLabelBMFont::create("Hi", "bigFont.fnt");
51+
this->addChild(node);
52+
53+
return true;
54+
}
55+
};
56+
```
57+
58+
## Changes to `std::function` arguments
59+
60+
Almost all parts of geode that accepted a `std::function` (such as `queueInMainThread`, `TextInput::setCallback`, etc.) have been changed to use `geode::Function` instead. The primary difference is that a `geode::Function` cannot be copied, only moved. Most proper usages should still compile and work properly, but if you have errors that are related to `std::function`, try adding `std::move`s or making sure to explicitly use `geode::Function` everywhere.
61+
62+
## Changes to string arguments
63+
64+
A ton of functions that accepted `std::string_view`, `std::string` or `std::string const&` have been written uncarefully and inefficiently before, which v5 aimed to fix. For many cases, you don't need to change anything, but conversion between string types isn't always possible, so this might break some code. This applies to return values as well, certain commonly used functions like `CCNode::getID` have been changed to return `geode::ZStringView`, which is a type that attempts to be API-compatible with `string_view`, while keeping a guarantee of null termination. Here are some examples of code that breaks and how to fix it:
65+
66+
TODO

0 commit comments

Comments
 (0)