Skip to content

Commit

Permalink
feat: add mod creation dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Aug 18, 2024
1 parent 0a5427b commit 76d0376
Show file tree
Hide file tree
Showing 11 changed files with 467 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ext/miniz"]
path = ext/miniz
url = https://github.com/richgel999/miniz
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
# Create project
project(sdk_launcher
DESCRIPTION "A minimal SDK launcher for Strata Source engine games"
VERSION "0.3.0"
VERSION "0.4.0"
HOMEPAGE_URL "https://github.com/StrataSource/sdk-launcher")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -102,6 +102,9 @@ function(sdk_launcher_configure_target TARGET)
endif()
endfunction()

# miniz
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/ext/miniz")

# Qt
if(WIN32 AND NOT DEFINED QT_BASEDIR)
message(FATAL_ERROR "Please define your QT install dir with -DQT_BASEDIR=\"C:/your/qt6/here\"")
Expand All @@ -123,7 +126,7 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Network)

# Generate config header
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/Config.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/Config.h")
Expand All @@ -135,20 +138,25 @@ add_executable(${PROJECT_TARGET_NAME} WIN32
"${CMAKE_CURRENT_SOURCE_DIR}/src/GameConfig.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/GameConfig.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/NewModDialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/NewModDialog.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Window.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Window.h")

sdk_launcher_configure_target(${PROJECT_TARGET_NAME})

target_link_libraries(
${PROJECT_TARGET_NAME} PRIVATE
miniz
Qt::Core
Qt::Gui
Qt::Widgets)
Qt::Widgets
Qt::Network)

target_include_directories(
${PROJECT_TARGET_NAME} PRIVATE
"${QT_INCLUDE}"
"${QT_INCLUDE}/QtCore"
"${QT_INCLUDE}/QtGui"
"${QT_INCLUDE}/QtWidgets")
"${QT_INCLUDE}/QtWidgets"
"${QT_INCLUDE}/QtNetwork")
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ Here is an example config file that may be loaded into the SDK launcher.
"game_icon": "${ROOT}/${GAME}/resource/game.ico",
// Optional, the default is false (set this to true if the SDK launcher is inside bin/ instead of bin/${PLATFORM}/)
"uses_legacy_bin_dir": false,
// Optional, the default is 256 (changes the fixed width of the window)
"window_width": 256,
// Optional, the default is 450 (changes the fixed height of the window)
// Optional, the default is 450 (changes the default height of the window)
"window_height": 450,
// Optional, holds the download URL of the mod template for the game (must point to a zip file)
// For reference, this is the P2CE template mod download URL:
"mod_template_url": "https://github.com/StrataSource/p2ce-mod-template/archive/refs/heads/main.zip",
// Sections hold titled groups of buttons
"sections": [
{
Expand Down
1 change: 1 addition & 0 deletions ext/miniz
Submodule miniz added at 1ff82b
1 change: 1 addition & 0 deletions res/config/p2ce.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"game_default": "p2ce",
"window_height": 575,
"mod_template_url": "https://github.com/StrataSource/p2ce-mod-template/archive/refs/heads/main.zip",
"sections": [
{
"name": "Game",
Expand Down
24 changes: 4 additions & 20 deletions src/GameConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ std::optional<GameConfig> GameConfig::parse(const QString& path) {
gameConfig.usesLegacyBinDir = configObject["uses_legacy_bin_dir"].toBool();
}

if (configObject.contains("window_width")) {
gameConfig.windowWidth = configObject["window_width"].toInt(DEFAULT_WINDOW_WIDTH);
}

if (configObject.contains("window_height")) {
gameConfig.windowHeight = configObject["window_height"].toInt(DEFAULT_WINDOW_HEIGHT);
}

if (configObject.contains("mod_template_url") && configObject["mod_template_url"].isString()) {
gameConfig.modTemplateURL = configObject["mod_template_url"].toString();
}

if (!configObject.contains("sections") || !configObject["sections"].isArray()) {
return std::nullopt;
}
Expand Down Expand Up @@ -141,9 +141,6 @@ std::optional<GameConfig> GameConfig::parse(const QString& path) {
}

void GameConfig::setVariable(const QString& variable, const QString& replacement) {
if (this->finalized) {
return;
}
const auto setVar = [&variable, &replacement](QString& str) {
str.replace(QString("${%1}").arg(variable), replacement);
};
Expand All @@ -160,16 +157,3 @@ void GameConfig::setVariable(const QString& variable, const QString& replacement
}
}
}

void GameConfig::finalize() {
for (auto& section : this->sections) {
for (auto& entry : section.entries) {
if (entry.type == ActionType::COMMAND || entry.type == ActionType::DIRECTORY) {
if (auto cleanPath = QDir::cleanPath(entry.action); !cleanPath.isEmpty()) {
entry.action = cleanPath;
}
}
}
}
this->finalized = true;
}
9 changes: 4 additions & 5 deletions src/GameConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,23 @@ class GameConfig {

[[nodiscard]] bool getUsesLegacyBinDir() const { return this->usesLegacyBinDir; }

[[nodiscard]] int getWindowWidth() const { return this->windowWidth; }
[[nodiscard]] int getWindowWidth() const { return DEFAULT_WINDOW_WIDTH; }

[[nodiscard]] int getWindowHeight() const { return this->windowHeight; }

[[nodiscard]] const QString& getModTemplateURL() const { return this->modTemplateURL; }

[[nodiscard]] const QList<Section>& getSections() const { return this->sections; }

void setVariable(const QString& variable, const QString& replacement);

void finalize();

private:
QString gameDefault;
QString gameIcon;
bool usesLegacyBinDir = false;
int windowWidth = DEFAULT_WINDOW_WIDTH;
int windowHeight = DEFAULT_WINDOW_HEIGHT;
QString modTemplateURL;
QList<Section> sections;
bool finalized = false;

GameConfig() = default;
};
Loading

0 comments on commit 76d0376

Please sign in to comment.