Skip to content

Commit

Permalink
feat: allow overriding -game, add tooltips, override window size in c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
craftablescience committed Jun 27, 2024
1 parent b4479e6 commit a372f42
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 89 deletions.
4 changes: 3 additions & 1 deletion 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.2.0"
VERSION "0.3.0"
HOMEPAGE_URL "https://github.com/StrataSource/sdk-launcher")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -152,3 +152,5 @@ target_include_directories(
"${QT_INCLUDE}/QtCore"
"${QT_INCLUDE}/QtGui"
"${QT_INCLUDE}/QtWidgets")

set_target_properties(${PROJECT_TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "C:/Program Files (x86)/Steam/steamapps/common/Portal 2 Community Edition/bin/win64")
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ Here is an example config file that may be loaded into the SDK launcher.
```json5
{
// The name of the game directory
"game": "p2ce",
// Optional, the default is game.ico (searches in the <game>/resource/ directory)
"game_icon": "game.ico",
// Optional, the default is false (set this to true if the SDK launcher is inside bin/ instead of bin/<platform>/)
"game_default": "p2ce",
// Optional, the default is "${ROOT}/${GAME}/resource/game.ico"
"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)
"window_height": 450,
// Sections hold titled groups of buttons
"sections": [
{
Expand All @@ -44,10 +48,10 @@ Here is an example config file that may be loaded into the SDK launcher.
// of the action is command, ".exe" will be appended to search for the
// default icon on Windows. Link types are Internet URLs, and directory
// types are directories that open in a file explorer.
"action": "${ROOT}/bin/${PLATFORM}/strata", // Expands to "./bin/win64/strata" on Windows.
"action": "${ROOT}/bin/${PLATFORM}/strata", // Expands to "<Game Directory>/bin/win64/strata" on Windows.
// Arguments are optional for command-type actions, and will be passed
// to the command when ran.
"arguments": ["-game", "p2ce", "-dev"],
// to the command when ran. ${GAME} expands to the game directory name.
"arguments": ["-game", "${GAME}", "-dev"],
// The icon override (optional) allows the config creator to change the
// icon for any button. ${GAME_ICON} is a special keyword for steam-type
// configs which loads the game icon from Steam. ${STRATA_ICON} is a
Expand All @@ -65,7 +69,7 @@ Here is an example config file that may be loaded into the SDK launcher.
"name": "Portal 2: CE - Dev Mode && Tools Mode",
"type": "command",
"action": "${ROOT}/bin/${PLATFORM}/strata",
"arguments": ["-game", "p2ce", "-dev", "-tools"],
"arguments": ["-game", "${GAME}", "-dev", "-tools"],
"icon_override": "${GAME_ICON}"
}
]
Expand Down
12 changes: 6 additions & 6 deletions res/config/momentum.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"game": "momentum",
"game_default": "momentum",
"sections": [
{
"name": "Game",
Expand All @@ -8,14 +8,14 @@
"name": "Momentum Mod - Dev Mode",
"type": "command",
"action": "${ROOT}/bin/${PLATFORM}/chaos",
"arguments": ["-game", "momentum", "-dev", "-console"],
"arguments": ["-game", "${GAME}", "-dev", "-console"],
"icon_override": "${GAME_ICON}"
},
{
"name": "Momentum Mod - Dev && Tools Mode",
"type": "command",
"action": "${ROOT}/bin/${PLATFORM}/chaos",
"arguments": ["-game", "momentum", "-dev", "-console", "-tools"],
"arguments": ["-game", "${GAME}", "-dev", "-console", "-tools"],
"icon_override": "${GAME_ICON}"
}
]
Expand All @@ -27,21 +27,21 @@
"name": "Hammer Editor",
"type": "command",
"action": "${ROOT}/bin/win64/hammer",
"arguments": ["-game", "momentum"],
"arguments": ["-game", "${GAME}"],
"os": "windows"
},
{
"name": "Model Viewer",
"type": "command",
"action": "${ROOT}/bin/win64/hlmv",
"arguments": ["-game", "momentum"],
"arguments": ["-game", "${GAME}"],
"os": "windows"
},
{
"name": "Face Poser",
"type": "command",
"action": "${ROOT}/bin/win64/hlfaceposer",
"arguments": ["-game", "momentum"],
"arguments": ["-game", "${GAME}"],
"os": "windows"
}
]
Expand Down
15 changes: 8 additions & 7 deletions res/config/p2ce.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"game": "p2ce",
"game_default": "p2ce",
"window_height": 575,
"sections": [
{
"name": "Game",
Expand All @@ -8,14 +9,14 @@
"name": "Portal 2: CE - Dev Mode",
"type": "command",
"action": "${ROOT}/bin/${PLATFORM}/chaos",
"arguments": ["-game", "p2ce", "-dev", "-console"],
"arguments": ["-game", "${GAME}", "-dev", "-console"],
"icon_override": "${GAME_ICON}"
},
{
"name": "Portal 2: CE - Dev && Tools Mode",
"type": "command",
"action": "${ROOT}/bin/${PLATFORM}/chaos",
"arguments": ["-game", "p2ce", "-dev", "-console", "-tools"],
"arguments": ["-game", "${GAME}", "-dev", "-console", "-tools"],
"icon_override": "${GAME_ICON}"
}
]
Expand All @@ -27,21 +28,21 @@
"name": "Hammer Editor",
"type": "command",
"action": "${ROOT}/bin/win64/hammer",
"arguments": ["-game", "p2ce"],
"arguments": ["-game", "${GAME}"],
"os": "windows"
},
{
"name": "Model Viewer",
"type": "command",
"action": "${ROOT}/bin/win64/hlmv",
"arguments": ["-game", "p2ce"],
"arguments": ["-game", "${GAME}"],
"os": "windows"
},
{
"name": "Face Poser",
"type": "command",
"action": "${ROOT}/bin/win64/hlfaceposer",
"arguments": ["-game", "p2ce"],
"arguments": ["-game", "${GAME}"],
"os": "windows"
},
{
Expand All @@ -58,7 +59,7 @@
"name": "Workshop Uploader",
"type": "command",
"action": "${ROOT}/bin/${PLATFORM}/workshopgui",
"arguments": ["-game", "p2ce"]
"arguments": ["-game", "${GAME}"]
}
]
},
Expand Down
28 changes: 6 additions & 22 deletions res/config/revolution.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"game": "revolution",
"game_default": "revolution",
"sections": [
{
"name": "Game",
Expand All @@ -8,21 +8,14 @@
"name": "Portal: Revolution - Dev Mode",
"type": "command",
"action": "${ROOT}/bin/${PLATFORM}/revolution",
"arguments": [
"-dev",
"-console"
],
"arguments": ["-game", "${GAME}", "-dev", "-console"],
"icon_override": "${GAME_ICON}"
},
{
"name": "Portal: Revolution - Dev && Tools Mode",
"type": "command",
"action": "${ROOT}/bin/${PLATFORM}/revolution",
"arguments": [
"-dev",
"-console",
"-tools"
],
"arguments": ["-game", "${GAME}", "-dev", "-console", "-tools"],
"icon_override": "${GAME_ICON}"
}
]
Expand All @@ -34,30 +27,21 @@
"name": "Hammer Editor",
"type": "command",
"action": "${ROOT}/bin/win64/hammer",
"arguments": [
"-game",
"revolution"
],
"arguments": ["-game", "${GAME}"],
"os": "windows"
},
{
"name": "Model Viewer",
"type": "command",
"action": "${ROOT}/bin/win64/hlmv",
"arguments": [
"-game",
"revolution"
],
"arguments": ["-game", "${GAME}"],
"os": "windows"
},
{
"name": "Face Poser",
"type": "command",
"action": "${ROOT}/bin/win64/hlfaceposer",
"arguments": [
"-game",
"revolution"
],
"arguments": ["-game", "${GAME}"],
"os": "windows"
}
]
Expand Down
32 changes: 29 additions & 3 deletions src/GameConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,29 @@ std::optional<GameConfig> GameConfig::parse(const QString& path) {

GameConfig gameConfig;

if (!configObject.contains("game") || !configObject["game"].isString()) {
if (!configObject.contains("game_default") || !configObject["game_default"].isString()) {
return std::nullopt;
}
gameConfig.game = configObject["game"].toString();
gameConfig.gameDefault = configObject["game_default"].toString();

if (configObject.contains("game_icon") && configObject["game_icon"].isString()) {
gameConfig.gameIcon = configObject["game_icon"].toString();
} else {
gameConfig.gameIcon = "game.ico";
gameConfig.gameIcon = "${ROOT}/${GAME}/resource/game.ico";
}

if (configObject.contains("uses_legacy_bin_dir") && configObject["uses_legacy_bin_dir"].isBool()) {
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("sections") || !configObject["sections"].isArray()) {
return std::nullopt;
}
Expand Down Expand Up @@ -130,3 +138,21 @@ std::optional<GameConfig> GameConfig::parse(const QString& path) {
}
return gameConfig;
}

void GameConfig::setVariable(const QString& variable, const QString& replacement) {
const auto setVar = [&variable, &replacement](QString& str) {
str.replace(QString("${%1}").arg(variable), replacement);
};
setVar(this->gameIcon);
for (auto& section : this->sections) {
setVar(section.name);
for (auto& entry : section.entries) {
setVar(entry.name);
setVar(entry.action);
for (auto& argument : entry.arguments) {
setVar(argument);
}
setVar(entry.iconOverride);
}
}
}
15 changes: 13 additions & 2 deletions src/GameConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <QList>
#include <QString>

constexpr int DEFAULT_WINDOW_WIDTH = 256;
constexpr int DEFAULT_WINDOW_HEIGHT = 450;

class GameConfig {
public:
enum class ActionType : unsigned char {
Expand Down Expand Up @@ -39,18 +42,26 @@ class GameConfig {

[[nodiscard]] static std::optional<GameConfig> parse(const QString& path);

[[nodiscard]] const QString& getGame() const { return this->game; }
[[nodiscard]] const QString& getGameDefault() const { return this->gameDefault; }

[[nodiscard]] const QString& getGameIcon() const { return this->gameIcon; }

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

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

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

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

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

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

GameConfig() = default;
Expand Down
Loading

0 comments on commit a372f42

Please sign in to comment.