Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

Commit f29bfa2

Browse files
committed
Fixes
1 parent 4bb9c69 commit f29bfa2

3 files changed

Lines changed: 78 additions & 25 deletions

File tree

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
# 1.0.1
2+
- Fix batch node issues
3+
- Fix path issues
4+
15
# 1.0.0
26
- Initial Release.

mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "4.7.0",
2+
"geode": "4.9.0",
33
"gd": {
44
"win": "2.2074",
55
"android": "2.2074",
@@ -8,7 +8,7 @@
88
},
99
"id": "alphalaneous.alphas_reference_image",
1010
"name": "Alpha's Reference Image",
11-
"version": "v1.0.0",
11+
"version": "v1.0.1",
1212
"developer": "Alphalaneous",
1313
"description": "Add Reference Images to the Editor",
1414
"dependencies": {

src/main.cpp

Lines changed: 72 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class $modify(MyCustomizeObjectLayer, CustomizeObjectLayer) {
3131
auto fields = m_fields.self();
3232
if (auto textObject = typeinfo_cast<TextGameObject*>(m_targetObject)) {
3333
auto pair = splitIntoPair(textObject->m_text);
34-
if (pair.first == "image") {
34+
if (pair.first == "image" || pair.first == "image2") {
3535
fields->m_isImageObject = true;
3636
if (!m_textButton) return;
3737
if (auto spr = m_textButton->getChildByType<ButtonSprite*>(0)) {
@@ -54,7 +54,7 @@ class $modify(MyCustomizeObjectLayer, CustomizeObjectLayer) {
5454
if (!*result) return;
5555
auto path = result->unwrap();
5656
if (auto textObject = typeinfo_cast<TextGameObject*>(m_targetObject)) {
57-
textObject->updateTextObject("image:" + utils::string::pathToString(path), false);
57+
textObject->updateTextObject("image2:" + utils::base64::encode(utils::string::pathToString(path)), false);
5858
}
5959
});
6060
} else {
@@ -103,7 +103,6 @@ class $modify(MyTextGameObject, TextGameObject) {
103103
}
104104

105105
void setAttributes() {
106-
log::info("set attr");
107106
auto fields = m_fields.self();
108107
if (auto node = getChildByID("error-node"_spr)) {
109108
node->removeFromParent();
@@ -118,33 +117,83 @@ class $modify(MyTextGameObject, TextGameObject) {
118117
}
119118

120119
void setupCustomSprite() {
121-
auto fields = m_fields.self();
122-
if (fields->m_spr) fields->m_spr->removeFromParent();
120+
auto pair = splitIntoPair(m_text);
121+
122+
if (pair.first == "image") {
123+
if (!setupInitial(pair.second)) return;
124+
setupImageBackwardsCompat(pair.second);
125+
}
126+
else if (pair.first == "image2") {
127+
if (!setupInitial(pair.second)) return;
128+
setupImage(pair.second);
129+
}
130+
}
131+
132+
bool setupInitial(const std::string& path) {
123133
if (LevelEditorLayer::get()) {
124134
m_hasSpecialChild = true;
125135
}
126-
127-
if (auto node = getChildByID("error-node"_spr)) {
128-
node->removeFromParent();
136+
if (!LevelEditorLayer::get()) {
137+
updateTextObject("[Path Hidden, Delete Object Before Upload!]", false);
138+
return false;
129139
}
130-
131-
auto pair = splitIntoPair(m_text);
132-
if (pair.first == "image") {
133-
if (!LevelEditorLayer::get()) {
134-
updateTextObject("[Path Hidden, Delete Object Before Upload!]", false);
135-
return;
136-
}
137-
else {
138-
for (auto child : CCArrayExt<CCNode*>(getChildren())) {
139-
child->setVisible(false);
140-
}
140+
else {
141+
for (auto child : CCArrayExt<CCNode*>(getChildren())) {
142+
child->setVisible(false);
141143
}
142144
}
143-
else return;
145+
146+
if (path.empty()) return false;
147+
return true;
148+
}
149+
150+
151+
void setupImage(const std::string& path) {
152+
auto fields = m_fields.self();
153+
if (fields->m_spr) fields->m_spr->removeFromParent();
154+
155+
auto decodedRes = utils::base64::decodeString(path);
156+
if (!decodedRes) return;
157+
158+
auto u16Res = utils::string::utf8ToUtf16(decodedRes.unwrap());
159+
if (!u16Res) return;
160+
161+
std::filesystem::path decoded = u16Res.unwrap();
144162

145-
if (pair.second.empty()) return;
163+
log::info("decoded: {}", decoded);
164+
165+
if (std::filesystem::exists(decoded) && !std::filesystem::is_directory(decoded)) {
166+
167+
auto fields = m_fields.self();
168+
fields->m_spr = LazySprite::create({60, 60}, true);
169+
fields->m_spr->setZOrder(1);
170+
fields->m_spr->setPosition(getContentSize()/2);
171+
addChild(fields->m_spr);
146172

147-
auto path = std::filesystem::path(pair.second);
173+
fields->m_spr->setLoadCallback([this](Result<> res) {
174+
if (res) setAttributes();
175+
else {
176+
for (auto child : CCArrayExt<CCNode*>(getChildren())) {
177+
child->setVisible(true);
178+
}
179+
auto fields = m_fields.self();
180+
fields->m_spr->removeFromParent();
181+
fields->m_spr = nullptr;
182+
onImageFail();
183+
}
184+
});
185+
186+
fields->m_spr->loadFromFile(decoded, LazySprite::Format::kFmtUnKnown, true);
187+
}
188+
else {
189+
onImageFail();
190+
}
191+
}
192+
193+
void setupImageBackwardsCompat(const std::string& path) {
194+
auto fields = m_fields.self();
195+
if (fields->m_spr) fields->m_spr->removeFromParent();
196+
148197
if (std::filesystem::exists(path) && !std::filesystem::is_directory(path)) {
149198

150199
auto fields = m_fields.self();
@@ -221,7 +270,7 @@ class $modify(MyEditorUI, EditorUI) {
221270
posX = localPosAR.x;
222271
posY = localPosAR.y - m_toolbarHeight/2;
223272
}
224-
std::string obj = fmt::format("1,914,2,{},3,{},31,{}", posX, posY, utils::base64::encode("image:" + utils::string::pathToString(path)));
273+
std::string obj = fmt::format("1,914,2,{},3,{},31,{}", posX, posY, utils::base64::encode("image2:" + utils::base64::encode(utils::string::pathToString(path))));
225274
pasteObjects(obj, true, true);
226275
updateButtons();
227276
updateObjectInfoLabel();

0 commit comments

Comments
 (0)