Skip to content

Commit 045a37c

Browse files
2.208 update (#71)
* Switch to geode::Function in a lot of places * use pathToString instead of .string()
1 parent 6c9e0b9 commit 045a37c

10 files changed

Lines changed: 41 additions & 48 deletions

include/TextureLoader.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ inline std::vector<Pack> getAvailablePacks() GEODE_EVENT_EXPORT_NORES(&getAvaila
3535
inline std::vector<Pack> getAppliedPacks() GEODE_EVENT_EXPORT_NORES(&getAppliedPacks, ());
3636

3737
}
38+
39+
#undef MY_MOD_ID

src/DragThingy.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <utility>
44

5-
bool DragThingy::init(std::function<void()> onClick, std::function<void(CCPoint)> onMove, std::function<void()> onRelease) {
5+
bool DragThingy::init(Function<void()> onClick, Function<void(CCPoint)> onMove, Function<void()> onRelease) {
66
if (!CCLayer::init()) return false;
77

88
m_onClick = std::move(onClick);
@@ -38,12 +38,12 @@ void DragThingy::ccTouchEnded(CCTouch* touch, CCEvent*) {
3838
m_onRelease();
3939
}
4040

41-
DragThingy* DragThingy::create(std::function<void()> onClick, std::function<void(CCPoint)> onMove, std::function<void()> onRelease) {
42-
auto ret = new DragThingy;
41+
DragThingy* DragThingy::create(Function<void()> onClick, Function<void(CCPoint)> onMove, Function<void()> onRelease) {
42+
auto ret = new DragThingy();
4343
if (ret->init(std::move(onClick), std::move(onMove), std::move(onRelease))) {
4444
ret->autorelease();
4545
return ret;
4646
}
47-
CC_SAFE_DELETE(ret);
47+
delete ret;
4848
return nullptr;
4949
}

src/DragThingy.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ using namespace geode::prelude;
66

77
class DragThingy : public CCLayer {
88
protected:
9-
std::function<void()> m_onClick;
10-
std::function<void(CCPoint)> m_onMove;
11-
std::function<void()> m_onRelease;
9+
Function<void()> m_onClick;
10+
Function<void(CCPoint)> m_onMove;
11+
Function<void()> m_onRelease;
1212

13-
bool init(std::function<void()> onClick, std::function<void(CCPoint)> onMove, std::function<void()> onRelease);
13+
bool init(Function<void()> onClick, Function<void(CCPoint)> onMove, Function<void()> onRelease);
1414

1515
bool ccTouchBegan(CCTouch* touch, CCEvent*) override;
1616
void ccTouchMoved(CCTouch* touch, CCEvent*) override;
1717
void ccTouchEnded(CCTouch* touch, CCEvent*) override;
1818

1919
public:
20-
static DragThingy* create(std::function<void()> onClick, std::function<void(CCPoint)> onMove, std::function<void()> onRelease);
20+
static DragThingy* create(Function<void()> onClick, Function<void(CCPoint)> onMove, Function<void()> onRelease);
2121
};

src/Pack.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ std::filesystem::path Pack::getResourcesPath() const {
5050
std::string Pack::getID() const {
5151
return m_info.has_value() ?
5252
m_info.value().m_id :
53-
m_path.filename().string();
53+
string::pathToString(m_path.filename());
5454
}
5555

5656
std::string Pack::getDisplayName() const {
5757
return m_info.has_value() ?
5858
m_info.value().m_name :
59-
m_path.filename().string();
59+
string::pathToString(m_path.filename());
6060
}
6161

6262
std::optional<PackInfo> Pack::getInfo() const {
@@ -66,7 +66,7 @@ std::optional<PackInfo> Pack::getInfo() const {
6666
Result<> Pack::apply() {
6767
CCFileUtils::get()->addTexturePack(CCTexturePack {
6868
.m_id = this->getID(),
69-
.m_paths = { this->getResourcesPath().string() }
69+
.m_paths = { string::pathToString(this->getResourcesPath()) }
7070
});
7171
return Ok();
7272
}
@@ -105,7 +105,7 @@ Result<> Pack::extract() {
105105
// this method is only for zips and stuff
106106
if (std::filesystem::is_directory(m_path)) return Ok();
107107

108-
auto const fileExt = m_path.extension().string();
108+
auto const fileExt = string::pathToString(m_path.extension());
109109
// TODO: we dont support rar, lol
110110
if (fileExt != ".zip" && fileExt != ".apk") {
111111
return Err("Expected zip or apk");
@@ -153,7 +153,7 @@ Result<> Pack::extract() {
153153
std::optional<std::filesystem::path> Pack::findResourcesPath(std::filesystem::path targetPath) {
154154
// Packs are often distributed in weird ways, this code tries to find where the resources actually are..
155155

156-
if (m_path.extension().string() == ".apk") {
156+
if (string::pathToString(m_path.extension()) == ".apk") {
157157
// resources can only be in one place! very easy
158158
return m_unzippedPath / "assets";
159159
}
@@ -183,8 +183,8 @@ std::optional<std::filesystem::path> Pack::findResourcesPath(std::filesystem::pa
183183
if (!file.is_regular_file()) continue;
184184

185185
auto const path = file.path();
186-
auto const name = path.stem().string();
187-
auto const ext = path.extension().string();
186+
auto const name = string::pathToString(path.stem());
187+
auto const ext = string::pathToString(path.extension());
188188

189189
if (ext == ".plist") {
190190
return targetPath;
@@ -219,14 +219,6 @@ Pack::~Pack() {
219219
}
220220

221221
Result<std::shared_ptr<Pack>> Pack::from(std::filesystem::path const& dir) {
222-
#ifdef GEODE_IS_WINDOWS
223-
try {
224-
(void) dir.filename().string();
225-
} catch(const std::exception& e) {
226-
return Err("Invalid path");
227-
}
228-
#endif
229-
230222
if (!std::filesystem::exists(dir)) {
231223
return Err("Path does not exist");
232224
}

src/PackInfoPopup.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
class WackyBypassFont : public CCLabelBMFont {
77
protected:
88
void setFntFile(std::filesystem::path fnt) {
9-
auto conf = FNTConfigLoadFile(fnt.string().c_str());
10-
m_sFntFile = fnt.string();
9+
auto fntString = string::pathToString(fnt);
10+
auto conf = FNTConfigLoadFile(fntString.c_str());
11+
m_sFntFile = fntString;
1112
if (!conf) {
1213
log::error("!conf ?????");
1314
return;
@@ -16,7 +17,7 @@ class WackyBypassFont : public CCLabelBMFont {
1617
if (m_pConfiguration)
1718
m_pConfiguration->release();
1819
m_pConfiguration = conf;
19-
conf->m_sAtlasName = fnt.replace_extension("png").string();
20+
conf->m_sAtlasName = string::pathToString(fnt.replace_extension("png"));
2021

2122
this->setTexture(
2223
CCTextureCache::sharedTextureCache()->addImage(conf->getAtlasName(), false)
@@ -52,7 +53,7 @@ std::filesystem::path PackInfoPopup::getPathInPack(const char* filename) const {
5253

5354
auto fname = std::filesystem::path(filename);
5455
fname.replace_filename(
55-
fname.stem().string() + suffix + fname.extension().string()
56+
string::pathToString(fname.stem()) + suffix + string::pathToString(fname.extension())
5657
);
5758

5859
if (std::filesystem::exists(m_pack->getResourcesPath() / fname)) {
@@ -62,8 +63,10 @@ std::filesystem::path PackInfoPopup::getPathInPack(const char* filename) const {
6263
}
6364
}
6465

65-
bool PackInfoPopup::init() {
66-
if (!Popup::init(320.f, 200.f, this->getPathInPack("GJ_square01.png").string().c_str())) return false;
66+
bool PackInfoPopup::init(const std::shared_ptr<Pack>& pack) {
67+
if (!Popup::init(320.f, 200.f, string::pathToString(this->getPathInPack("GJ_square01.png")).c_str())) return false;
68+
69+
m_pack = pack;
6770

6871
auto title = WackyBypassFont::create(
6972
m_pack->getDisplayName().c_str(),
@@ -96,8 +99,8 @@ bool PackInfoPopup::init() {
9699
auto defaultBtnSize =
97100
defaultBtnLabel->getScaledContentSize() + CCSize { 20.f, 15.f };
98101

99-
auto defaultBtnSpr = CCScale9Sprite::create(
100-
this->getPathInPack("GJ_button_01.png").string().c_str(),
102+
auto defaultBtnSpr = NineSlice::create(
103+
string::pathToString(this->getPathInPack("GJ_button_01.png")),
101104
{ 0, 0, 40, 40 }
102105
);
103106
defaultBtnSpr->setContentSize(defaultBtnSize);
@@ -123,8 +126,8 @@ bool PackInfoPopup::init() {
123126
auto altBtnSize =
124127
altBtnLabel->getScaledContentSize() + CCSize { 20.f, 15.f };
125128

126-
auto altBtnSpr = CCScale9Sprite::create(
127-
this->getPathInPack("GJ_button_02.png").string().c_str(),
129+
auto altBtnSpr = NineSlice::create(
130+
string::pathToString(this->getPathInPack("GJ_button_02.png")),
128131
{ 0, 0, 40, 40 }
129132
);
130133
altBtnSpr->setContentSize(altBtnSize);
@@ -144,8 +147,7 @@ bool PackInfoPopup::init() {
144147

145148
PackInfoPopup* PackInfoPopup::create(const std::shared_ptr<Pack>& pack) {
146149
auto ret = new PackInfoPopup;
147-
ret->m_pack = pack;
148-
if (ret->init()) {
150+
if (ret->init(pack)) {
149151
ret->autorelease();
150152
return ret;
151153
}

src/PackInfoPopup.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class PackInfoPopup : public Popup {
99
protected:
1010
std::shared_ptr<Pack> m_pack;
1111

12-
bool init();
12+
bool init(const std::shared_ptr<Pack>& pack);
1313

1414
std::filesystem::path getPathInPack(const char* filename) const;
1515
public:

src/PackManager.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "Pack.hpp"
4-
#include <unordered_map>
54
#include <Geode/utils/cocos.hpp>
65

76
enum class PackListType {

src/PackNode.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "PackNode.hpp"
22
#include <Geode/binding/CCMenuItemToggler.hpp>
33
#include <Geode/ui/LazySprite.hpp>
4-
#include "PackManager.hpp"
54
#include "PackSelectPopup.hpp"
65
#include "PackInfoPopup.hpp"
76
#include "DragThingy.hpp"
@@ -125,10 +124,10 @@ bool PackNode::init(
125124

126125
this->addChild(dragHandle);
127126

128-
m_draggingBg = CCScale9Sprite::create(
127+
m_draggingBg = NineSlice::create(
129128
"square02b_001.png"
130129
);
131-
m_draggingBg->setCapInsets({10, 10, 50, 50});
130+
m_draggingBg->setInsets({10, 10, 10, 10});
132131
m_draggingBg->setColor({ 0, 0, 0 });
133132
m_draggingBg->setOpacity(90);
134133
m_draggingBg->setContentSize(this->getContentSize());
@@ -152,11 +151,11 @@ PackNode* PackNode::create(
152151
const std::shared_ptr<Pack>& pack,
153152
float width
154153
) {
155-
auto ret = new PackNode;
154+
auto ret = new PackNode();
156155
if (ret->init(layer, pack, width)) {
157156
ret->autorelease();
158157
return ret;
159158
}
160-
CC_SAFE_DELETE(ret);
159+
delete ret;
161160
return nullptr;
162161
}

src/PackNode.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
44
#include "Pack.hpp"
5-
#include <functional>
65

76
using namespace geode::prelude;
87

@@ -12,7 +11,7 @@ class PackNode : public CCNode {
1211
protected:
1312
PackSelectPopup* m_layer;
1413
std::shared_ptr<Pack> m_pack;
15-
CCScale9Sprite* m_draggingBg;
14+
NineSlice* m_draggingBg;
1615

1716
bool init(
1817
PackSelectPopup* layer,

src/PackSelectPopup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ bool PackSelectPopup::init() {
105105
availableTitle->setID("available-text");
106106
m_mainLayer->addChild(availableTitle);
107107

108-
auto availableListBG = CCScale9Sprite::create(
108+
auto availableListBG = NineSlice::create(
109109
"square02b_001.png", { 0, 0, 80, 80 }
110110
);
111111
availableListBG->setColor({ 0, 0, 0 });
@@ -139,7 +139,7 @@ bool PackSelectPopup::init() {
139139
appliedTitle->setID("applied-text");
140140
m_mainLayer->addChild(appliedTitle);
141141

142-
auto appliedListBG = CCScale9Sprite::create(
142+
auto appliedListBG = NineSlice::create(
143143
"square02b_001.png", { 0, 0, 80, 80 }
144144
);
145145
appliedListBG->setColor({ 0, 0, 0 });
@@ -389,6 +389,6 @@ PackSelectPopup* PackSelectPopup::create() {
389389
ret->autorelease();
390390
return ret;
391391
}
392-
CC_SAFE_DELETE(ret);
392+
delete ret;
393393
return nullptr;
394394
}

0 commit comments

Comments
 (0)