Skip to content

Commit

Permalink
port le share de gd
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Jun 15, 2024
1 parent 3174511 commit 97cb788
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
- name: Windows
os: windows-latest

# - name: macOS
# os: macos-latest
- name: macOS
os: macos-latest

- name: Android32
os: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.3.0)
cmake_minimum_required(VERSION 3.28.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Expand All @@ -19,4 +19,4 @@ endif()
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)

target_link_libraries(${PROJECT_NAME} geode-sdk)
setup_geode_mod(${PROJECT_NAME} EXTERNALS geode.node-ids:1.0.0)
setup_geode_mod(${PROJECT_NAME} EXTERNALS geode.node-ids:1.12.0)
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# v1.1.0

* Add support for importing/exporting lists as `.gmdl` files
* Allow importing multiple levels at once
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"geode": "2.0.0-beta.25",
"geode": "3.0.0-beta.1",
"gd": {
"android": "2.205",
"win": "2.204",
"mac": "2.200"
"android": "2.206",
"win": "2.206",
"mac": "2.206"
},
"version": "1.1.0",
"version": "1.2.0",
"id": "hjfod.gdshare",
"name": "GDShare",
"developer": "HJfod",
Expand All @@ -20,11 +20,11 @@
"dependencies": [
{
"id": "hjfod.gmd-api",
"version": "v1.0.1"
"version": "1.2.0"
},
{
"id": "geode.node-ids",
"version": "v1.0.0"
"version": "1.12.0"
}
]
}
126 changes: 93 additions & 33 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#include <Geode/Loader.hpp>
#include <Geode/utils/cocos.hpp>
#include <Geode/modify/LevelBrowserLayer.hpp>
#include <Geode/modify/LevelInfoLayer.hpp>
#include <Geode/modify/EditLevelLayer.hpp>
#include <Geode/modify/IDManager.hpp>
#include <Geode/modify/LevelListLayer.hpp>
#include <Geode/ui/Popup.hpp>
#include <hjfod.gmd-api/include/GMD.hpp>

Expand All @@ -15,30 +15,42 @@ static auto IMPORT_PICK_OPTIONS = file::FilePickOptions {
std::nullopt,
{
{
"Level Files",
{ "*.gmd2", "*.gmd", "*.lvl" }
},
{
"GMD Files",
{ "*.gmd2", "*.gmd" }
"GD Level Files",
{ "*.gmd", "*.gmdl" }
}
}
};

static Task<Result<ghc::filesystem::path>> promptExportLevel(GJGameLevel* level) {
template <class L>
static Task<Result<std::filesystem::path>> promptExportLevel(L* level) {
auto opts = IMPORT_PICK_OPTIONS;
opts.defaultPath = std::string(level->m_levelName) + ".gmd";
if constexpr (std::is_same_v<L, GJLevelList>) {
opts.defaultPath = level->m_listName + ".gmdl";
}
else {
opts.defaultPath = level->m_levelName + ".gmd";
}
return file::pick(file::PickMode::SaveFile, opts);
}
static void onExportFilePick(GJGameLevel* level, typename Task<Result<ghc::filesystem::path>>::Event* event) {
template <class L>
static void onExportFilePick(L* level, typename Task<Result<std::filesystem::path>>::Event* event) {
if (auto result = event->getValue()) {
if (result->isOk()) {
auto path = result->unwrap();
auto res = exportLevelAsGmd(level, path);
Result<> res;
if constexpr (std::is_same_v<L, GJLevelList>) {
res = exportListAsGmd(level, path);
}
else {
res = exportLevelAsGmd(level, path);
}
if (res) {
createQuickPopup(
"Exported",
"Succesfully exported level",
(std::is_same_v<L, GJLevelList> ?
"Succesfully exported list" :
"Succesfully exported level"
),
"OK", "Open File",
[path](auto, bool btn2) {
if (btn2) file::openFolder(path);
Expand All @@ -61,9 +73,10 @@ static void onExportFilePick(GJGameLevel* level, typename Task<Result<ghc::files

struct $modify(ExportMyLevelLayer, EditLevelLayer) {
struct Fields {
EventListener<Task<Result<ghc::filesystem::path>>> pickListener;
EventListener<Task<Result<std::filesystem::path>>> pickListener;
};

$override
bool init(GJGameLevel* level) {
if (!EditLevelLayer::init(level))
return false;
Expand Down Expand Up @@ -94,9 +107,10 @@ struct $modify(ExportMyLevelLayer, EditLevelLayer) {

struct $modify(ExportOnlineLevelLayer, LevelInfoLayer) {
struct Fields {
EventListener<Task<Result<ghc::filesystem::path>>> pickListener;
EventListener<Task<Result<std::filesystem::path>>> pickListener;
};

$override
bool init(GJGameLevel* level, bool challenge) {
if (!LevelInfoLayer::init(level, challenge))
return false;
Expand Down Expand Up @@ -127,29 +141,41 @@ struct $modify(ExportOnlineLevelLayer, LevelInfoLayer) {

struct $modify(ImportLayer, LevelBrowserLayer) {
struct Fields {
EventListener<Task<Result<std::vector<ghc::filesystem::path>>>> pickListener;
EventListener<Task<Result<std::vector<std::filesystem::path>>>> pickListener;
};

static void importFiles(std::vector<ghc::filesystem::path> const& paths) {
static void importFiles(std::vector<std::filesystem::path> const& paths) {
for (auto const& path : paths) {
auto import = ImportGmdFile::from(path);
if (!import.tryInferType()) {
// todo: show popup to pick type
return FLAlertLayer::create(
"Error Importing",
"Unable to figure out <cy>file type</c>!",
"OK"
)->show();
}
auto res = import.intoLevel();
if (!res) {
return FLAlertLayer::create(
"Error Importing",
res.error(),
"OK"
)->show();
switch (getGmdFileKind(path)) {
case GmdFileKind::List: {
auto res = gmd::importGmdAsList(path);
if (res) {
LocalLevelManager::get()->m_localLists->insertObject(*res, 0);
}
else {
return FLAlertLayer::create("Error Importing", res.unwrapErr(), "OK")->show();
}
} break;

case GmdFileKind::Level: {
auto res = gmd::importGmdAsLevel(path);
if (res) {
LocalLevelManager::get()->m_localLevels->insertObject(*res, 0);
}
else {
return FLAlertLayer::create("Error Importing", res.unwrapErr(), "OK")->show();
}
} break;

case GmdFileKind::None: {
// todo: show popup to pick type
return FLAlertLayer::create(
"Error Importing",
fmt::format("Selected file '<cp>{}</c>' is not a GMD file!", path),
"OK"
)->show();
} break;
}
LocalLevelManager::get()->m_localLevels->insertObject(res.value(), 0);
}

auto scene = CCScene::create();
Expand All @@ -174,6 +200,7 @@ struct $modify(ImportLayer, LevelBrowserLayer) {
m_fields->pickListener.setFilter(file::pickMany(IMPORT_PICK_OPTIONS));
}

$override
bool init(GJSearchObject* search) {
if (!LevelBrowserLayer::init(search))
return false;
Expand All @@ -198,3 +225,36 @@ struct $modify(ImportLayer, LevelBrowserLayer) {
return true;
}
};

struct $modify(ExportListLayer, LevelListLayer) {
struct Fields {
EventListener<Task<Result<std::filesystem::path>>> pickListener;
};

$override
bool init(GJLevelList* level) {
if (!LevelListLayer::init(level))
return false;

if (auto menu = this->getChildByID("main-menu")) {
auto btn = CCMenuItemSpriteExtra::create(
CircleButtonSprite::createWithSpriteFrameName(
"file.png"_spr, .8f,
CircleBaseColor::Green,
CircleBaseSize::Medium
),
this, menu_selector(ExportListLayer::onExport)
);
btn->setID("export-button"_spr);
menu->addChild(btn);
menu->updateLayout();
}

return true;
}

void onExport(CCObject*) {
m_fields->pickListener.bind([list = m_levelList](auto* ev) { onExportFilePick(list, ev); });
m_fields->pickListener.setFilter(promptExportLevel(m_levelList));
}
};

0 comments on commit 97cb788

Please sign in to comment.