Make the launcher functional with bare minimum features
This commit is contained in:
parent
89d3834154
commit
6377405ec1
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "open-plutonium-launcher",
|
||||
"version": "0.0.1",
|
||||
"version": "0.5.4",
|
||||
"description": "Open-source Plutonium launcher",
|
||||
"main": "src/index.js",
|
||||
"repository": "https://gitea.x3f200c.net/X3F200C/open-plutonium-launcher",
|
||||
"repository": "https://gitea.x3f200c.net/Kroniker/open-plutonium-launcher",
|
||||
"author": "X3F200C",
|
||||
"license": "GPL-3.0",
|
||||
"scripts": {
|
||||
|
155
src/index.js
155
src/index.js
@ -1,5 +1,6 @@
|
||||
const path = require("node:path");
|
||||
const fs = require("node:fs");
|
||||
const child_process = require("node:child_process");
|
||||
const nodeGUI = require("@nodegui/nodegui");
|
||||
|
||||
var configFile = path.join(process.env["APPDATA"], "open-plutonium-launcher.json");
|
||||
@ -24,11 +25,14 @@ const games = [
|
||||
{
|
||||
"id": "mp",
|
||||
"name": "Multiplayer"
|
||||
},
|
||||
{
|
||||
"id": "sp",
|
||||
"name": "Co-Op/Zombies"
|
||||
}
|
||||
}// ,
|
||||
// {
|
||||
// "id": "sp",
|
||||
// "name": "Co-Op/Zombies"
|
||||
// }
|
||||
],
|
||||
"checks": [
|
||||
["main", "iw_00.iwd"]
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -43,6 +47,9 @@ const games = [
|
||||
"id": "sp",
|
||||
"name": "Co-Op/Zombies"
|
||||
}
|
||||
],
|
||||
"checks": [
|
||||
["main", "iw_00.iwd"]
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -57,6 +64,9 @@ const games = [
|
||||
"id": "sp",
|
||||
"name": "Co-Op/Zombies"
|
||||
}
|
||||
],
|
||||
"checks": [
|
||||
["main", "iw_00.iwd"]
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -71,6 +81,9 @@ const games = [
|
||||
"id": "zm",
|
||||
"name": "Co-Op/Zombies"
|
||||
}
|
||||
],
|
||||
"checks": [
|
||||
["zone", "all", "base.ipak"]
|
||||
]
|
||||
}
|
||||
];
|
||||
@ -86,6 +99,115 @@ function writeConfig(asDefault = false) {
|
||||
fs.writeFileSync(configFile, JSON.stringify((asDefault ? defaultConfig : config)));
|
||||
}
|
||||
|
||||
function showMessage(content) {
|
||||
var messageBox = new nodeGUI.QMessageBox();
|
||||
messageBox.setText("Information");
|
||||
messageBox.setInformativeText(content);
|
||||
var okButton = new nodeGUI.QPushButton();
|
||||
okButton.setText("OK");
|
||||
messageBox.addButton(okButton, nodeGUI.ButtonRole.AcceptRole);
|
||||
messageBox.exec();
|
||||
}
|
||||
|
||||
function showError(content) {
|
||||
var messageBox = new nodeGUI.QMessageBox();
|
||||
messageBox.setText("Error");
|
||||
messageBox.setInformativeText(content);
|
||||
var okButton = new nodeGUI.QPushButton();
|
||||
okButton.setText("OK");
|
||||
messageBox.addButton(okButton, nodeGUI.ButtonRole.AcceptRole);
|
||||
messageBox.exec();
|
||||
}
|
||||
|
||||
function showPrompt(question) {
|
||||
var dialogBox = new nodeGUI.QInputDialog();
|
||||
dialogBox.setLabelText(question);
|
||||
dialogBox.exec();
|
||||
|
||||
return dialogBox.textValue();
|
||||
}
|
||||
|
||||
function chooseFolder() {
|
||||
var fileDialog = new nodeGUI.QFileDialog();
|
||||
fileDialog.setFileMode(nodeGUI.FileMode.Directory);
|
||||
fileDialog.setNameFilter("Directories");
|
||||
fileDialog.exec();
|
||||
|
||||
var entries = fileDialog.selectedFiles();
|
||||
|
||||
if (entries.length < 1) {
|
||||
return null;
|
||||
} else {
|
||||
return entries[0];
|
||||
}
|
||||
}
|
||||
|
||||
function checkPlutonium() {
|
||||
var bootstrapperPath = path.join(config.directories["plutonium"], "bin", "plutonium-bootstrapper-win32.exe");
|
||||
|
||||
if (fs.existsSync(bootstrapperPath)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkGame(id) {
|
||||
var game = games.find(g => g.id == id);
|
||||
|
||||
if (!game) return false;
|
||||
|
||||
for (let c = 0; c < game.checks.length; c++) {
|
||||
var check = game.checks[c];
|
||||
var checkPath = path.join(config.directories[id], ...check);
|
||||
|
||||
if (!fs.existsSync(checkPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function launchGame(gameID, modeID) {
|
||||
if (!checkPlutonium()) {
|
||||
showMessage("Please select Plutonium's folder. ");
|
||||
config.directories["plutonium"] = chooseFolder();
|
||||
if (!checkPlutonium()) {
|
||||
return showError("Sorry, we were unable to find Plutonium's files. ");
|
||||
}
|
||||
}
|
||||
|
||||
var game = games.find(g => g.id == gameID);
|
||||
if (!checkGame(gameID)) {
|
||||
showMessage("Please select " + game.name + "'s folder. ");
|
||||
config.directories[gameID] = chooseFolder();
|
||||
if (!checkGame(gameID)) {
|
||||
return showError("Sorry, we were unable to find " + game.name + "'s files. ");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.username.length < 1) {
|
||||
config.username = showPrompt("What's your username ? ");
|
||||
if (config.username.length < 1) {
|
||||
return showError("You must enter a username ! ");
|
||||
}
|
||||
}
|
||||
|
||||
writeConfig();
|
||||
|
||||
var bootstrapperPath = path.join(config.directories["plutonium"], "bin", "plutonium-bootstrapper-win32.exe");
|
||||
|
||||
var gameProcess = child_process.spawn(bootstrapperPath, [gameID + modeID, config.directories[gameID], "+name", config.username, "-lan"], {
|
||||
"cwd": config.directories["plutonium"],
|
||||
"stdio": "inherit"
|
||||
});
|
||||
|
||||
gameProcess.unref();
|
||||
|
||||
process.exit();
|
||||
}
|
||||
|
||||
if (!fs.existsSync(configFile)) {
|
||||
writeConfig(true);
|
||||
}
|
||||
@ -96,9 +218,15 @@ var mainWindow = new nodeGUI.QMainWindow();
|
||||
var mainWidget = new nodeGUI.QWidget();
|
||||
mainWidget.setObjectName("root");
|
||||
|
||||
var rootLayout = new nodeGUI.FlexLayout();
|
||||
var rootLayout = new nodeGUI.QBoxLayout(nodeGUI.Direction.TopToBottom);
|
||||
mainWidget.setLayout(rootLayout);
|
||||
|
||||
var gameSel = new nodeGUI.QBoxLayout(nodeGUI.Direction.LeftToRight);
|
||||
|
||||
var gameSelectLabel = new nodeGUI.QLabel();
|
||||
gameSelectLabel.setText("Select a game : ");
|
||||
gameSel.addWidget(gameSelectLabel);
|
||||
|
||||
var gameSelectionBox = new nodeGUI.QComboBox();
|
||||
for (let g = 0; g < games.length; g++) {
|
||||
var game = games[g];
|
||||
@ -113,10 +241,21 @@ for (let g = 0; g < games.length; g++) {
|
||||
gameSelectionBox.addItem(undefined, game.name + " " + mode.name);
|
||||
}
|
||||
}
|
||||
gameSelectionBox.setToolTip(config.directories[gameSelections[0][0]]);
|
||||
gameSelectionBox.addEventListener("currentIndexChanged", function (index) {
|
||||
selectedGame = index;
|
||||
gameSelectionBox.setToolTip(config.directories[gameSelections[index][0]]);
|
||||
});
|
||||
rootLayout.addWidget(gameSelectionBox);
|
||||
gameSel.addWidget(gameSelectionBox);
|
||||
rootLayout.addLayout(gameSel);
|
||||
|
||||
var launchButton = new nodeGUI.QPushButton();
|
||||
launchButton.setText("Launch");
|
||||
launchButton.addEventListener("clicked", function () {
|
||||
var selection = gameSelections[selectedGame];
|
||||
launchGame(selection[0], selection[1]);
|
||||
});
|
||||
rootLayout.addWidget(launchButton);
|
||||
|
||||
mainWindow.setCentralWidget(mainWidget);
|
||||
mainWindow.setStyleSheet(`
|
||||
@ -126,6 +265,6 @@ mainWindow.setStyleSheet(`
|
||||
}
|
||||
`);
|
||||
mainWindow.setWindowTitle("Open Plutonium launcher");
|
||||
mainWindow.resize(854, 480);
|
||||
// mainWindow.resize(427, 240);
|
||||
mainWindow.show();
|
||||
global.mainWindow = mainWindow;
|
||||
|
Loading…
Reference in New Issue
Block a user