Skip to content

Commit

Permalink
remove askGame dialog
Browse files Browse the repository at this point in the history
Am not done with this but it better cus there was a crash in askGame dialog if it was Chronicles
  • Loading branch information
noisecode3 committed Dec 26, 2024
1 parent 0c38e94 commit 8d7bd6c
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 216 deletions.
54 changes: 23 additions & 31 deletions .neovim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ vim.api.nvim_set_keymap('n', 'ø', ":lua require'dapui'.toggle()<CR>", { noremap
-- https://sourceware.org/gdb/current/onlinedocs/gdb.html/Interpreters.html
-- https://sourceware.org/gdb/current/onlinedocs/gdb.html/Debugger-Adapter-Protocol.html
-- Require DAP and DAP-Python
-- Use qtcreator to debug c++ part
local dap = require("dap")
require("dap-python").setup("python")

Expand All @@ -48,33 +49,6 @@ dap.configurations.python = {
},
}

-- C++ configuration with GDB
dap.adapters.gdb = {
type = "executable",
command = "gdb", -- Ensure GDB is installed and available in your PATH
args = { "-i", "dap" }
}

dap.configurations.cpp = {
{
name = 'Launch executable (GDB)',
type = 'gdb',
request = 'launch',
program = '~/TombRaiderLinuxLauncher/TombRaiderLinuxLauncher',
stopOnEntry = false, -- or true if you want to stop at the beginning
cwd = '${workspaceFolder}',
setupCommands = {
{
text = '-enable-pretty-printing', -- Enable pretty-printing for gdb
description = 'enable pretty printing',
ignoreFailures = false
},
},
args = {}, -- Pass arguments to the executable
environment = {}, -- Set environment variables here
}
}

require("dapui").setup()

local nvim_lsp = require('lspconfig')
Expand All @@ -92,7 +66,6 @@ vim.api.nvim_create_autocmd("FileType", {
end,
})


function ToggleShiftwidth()
if vim.g.current_shiftwidth == 2 then
vim.g.current_shiftwidth = 4
Expand All @@ -105,16 +78,14 @@ end
-- The style is meant to keep the code narrow, never let it over 80-100
-- With cpplint --filter=-whitespace/braces,-whitespace/newline


require('lint').linters_by_ft = {
sh = {'shellcheck'}, -- Ensure you have shellcheck installed
python = {'pylint', 'bandit', 'ruff', 'pydocstyle', 'mypy', 'flake8'}, -- Ensure these are installed
cmake = { 'cmakelint' },
cpp = {'cppcheck', 'cpplint', 'flawfinder'},
}
-- add:
-- --check-level=exhaustive

-- .local/share/nvim/plugged/nvim-lint/lua/lint/linters/cppcheck.lua
-- cppcheck <= 1.84 doesn't support {column} so the start_col group is ambiguous
local pattern = [[([^:]*):(%d*):([^:]*): %[([^%]\]*)%] ([^:]*): (.*)]]
local groups = { "file", "lnum", "col", "code", "severity", "message" }
Expand Down Expand Up @@ -150,8 +121,29 @@ return {
"--template={file}:{line}:{column}: [{id}] {severity}: {message}",
"--check-level=exhaustive",
"--library=qt",
"--suppress=unmatchedSuppression",
"--suppress=unusedStructMember",
},
stream = "stderr",
parser = require("lint.parser").from_pattern(pattern, groups, severity_map, { ["source"] = "cppcheck" }),
}

-- .local/share/nvim/plugged/nvim-lint/lua/lint/linters/cpplint.lua
-- path/to/file:line: message [code] [code_id]
local pattern = '([^:]+):(%d+): (.+) (.+)'
local groups = { 'file', 'lnum', 'message', 'code'}

return {
cmd = 'cpplint',
stdin = false,
args = {
"--filter=-build/include_subdir",
},
ignore_exitcode = true,
stream = 'stderr',
parser = require('lint.parser').from_pattern(pattern, groups, nil, {
['source'] = 'cpplint',
['severity'] = vim.diagnostic.severity.WARN,
}),
}

22 changes: 0 additions & 22 deletions setup_nvim_lsp.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
#!/bin/bash
cd "$(dirname "$0")" || exit 1
# don't forget that you need to build it one time
# and look at .neovim how to use debuger
mkdir -p .gdb/qt5prettyprinters/

gdbinit=$(cat <<'EOINS'
python
import sys, os
sys.path.insert(0, "./.gdb/qt5prettyprinters")
from qt import register_qt_printers
register_qt_printers (None)
end
EOINS
)
echo "$gdbinit" > .gdbinit
chmod 0644 .gdbinit

wget -O .gdb/qt5prettyprinters/helper.py \
https://invent.kde.org/kdevelop/kdevelop/-/raw/master/plugins/gdb/printers/helper.py
wget -O .gdb/qt5prettyprinters/qt.py \
https://invent.kde.org/kdevelop/kdevelop/-/raw/master/plugins/gdb/printers/qt.py

rm -fr build
mkdir build
Expand Down
15 changes: 6 additions & 9 deletions src/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ void Controller::initializeThread() {
controllerThread->start();

// Using the controller thread to start model work
/*
connect(this, &Controller::checkCommonFilesThreadSignal,
this, [this]() {
model.checkCommonFiles();
});
*/

connect(this, &Controller::setupThreadSignal,
this, [this](const QString& level, const QString& game) {
Expand All @@ -43,7 +45,7 @@ void Controller::initializeThread() {

connect(this, &Controller::setupLevelThreadSignal,
this, [this](int id) {
model.getGame(id);
model.getLevel(id);
});

connect(this, &Controller::setupGameThreadSignal,
Expand All @@ -67,14 +69,9 @@ void Controller::initializeThread() {
emit controllerDownloadError(status);
}, Qt::QueuedConnection);

connect(&model, &Model::askGameSignal,
this, [this](int id) {
emit controllerAskGame(id);
}, Qt::QueuedConnection);

connect(&model, &Model::generateListSignal,
this, [this]() {
emit controllerGenerateList();
this, [this](const QList<int>& availableGames) {
emit controllerGenerateList(availableGames);
}, Qt::QueuedConnection);
}

Expand All @@ -94,7 +91,7 @@ void Controller::setupLevel(int id) {
emit setupLevelThreadSignal(id);
}

// GUI Threads
// Using the GUI Threads
int Controller::checkGameDirectory(int id) {
return model.checkGameDirectory(id);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class Controller : public QObject {
int getItemState(int id);

signals:
void controllerAskGame(int id);
void controllerGenerateList();
void controllerGenerateList(const QList<int>& availableGames);
void controllerTickSignal();
void controllerDownloadError(int status);

Expand Down
12 changes: 6 additions & 6 deletions src/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ bool FileManager::linkGameDir(const QString& levelDir, const QString& gameDir) {

test(levelPath); // here we just output the directory tree for now..

if (QFile::link(levelPath, gamePath)) {
if (QFile::link(levelPath, gamePath) == true) {
qDebug() << "Symbolic link created successfully.";
return 0;
status = true;
} else {
QFileInfo fileInfo(gamePath);
if (fileInfo.isSymLink() == true) {
QFile::remove(gamePath);
if (QFile::link(levelPath, gamePath)) {
if (QFile::link(levelPath, gamePath) == true) {
qDebug() << "Symbolic link created successfully.";
status = true;
} else {
Expand All @@ -256,14 +256,14 @@ bool FileManager::makeRelativeLink(
const QString toPath = QString("%1%2")
.arg(levelPath, to);

if (QFile::link(fromPath, toPath)) {
if (QFile::link(fromPath, toPath) == true) {
qDebug() << "Symbolic link created successfully.";
status = true;
} else {
QFileInfo i(toPath);
if (i.isSymLink()) {
if (i.isSymLink() == true) {
QFile::remove(toPath);
if (QFile::link(fromPath, toPath)) {
if (QFile::link(fromPath, toPath) == true) {
qDebug() << "Symbolic link created successfully.";
status = true;
} else {
Expand Down
92 changes: 45 additions & 47 deletions src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// Those lambda should be in another header file
// I hate this and it should be able to recognize both the directory
// when linking and the game exe to make a symbolic link to automatically
Model::Model(QObject *parent) : QObject(parent), checkCommonFilesIndex_m(1) {
Model::Model(QObject *parent) : QObject(parent) {
instructionManager.addInstruction(4, [this](int id) {
qDebug() << "Perform Operation A";
const QString s = "/"+QString::number(id) + ".TRLE";
Expand All @@ -32,54 +32,41 @@ Model::Model(QObject *parent) : QObject(parent), checkCommonFilesIndex_m(1) {
const QString s = QString::number(id) + ".TRLE/TRBiohazard";
fileManager.moveFilesToParentDirectory(s, 1);
});
/*
instructionManager.addInstruction(12, [this](int id) {
qDebug() << "Perform Operation C";
const QString s = QString::number(id) + ".TRLE/Delca-KittenAdventureDemo/Engine";
fileManager.moveFilesToParentDirectory(s, 2);
});
*/
}

Model::~Model() {}

bool Model::setup(const QString& level, const QString& game) {
bool status = false;
if (setDirectory(level, game)) {
if (setDirectory(level, game) == true) {
status = true;
checkCommonFiles();
emit generateListSignal(checkCommonFiles());
QCoreApplication::processEvents();
}
return status;
}

bool Model::setDirectory(const QString& level, const QString& game) {
bool status = false;
if (fileManager.setUpCamp(level, game) &&
downloader.setUpCamp(level) &&
data.initializeDatabase(level)
)
return true;
else
return false;
downloader.setUpCamp(level) &&
data.initializeDatabase(level)) {
status = true;
}
return status;
}

// true if there was new original game
// false if there was no new original games
bool Model::checkCommonFiles() {
int index = checkCommonFilesIndex_m;
assert(index >= 1 && index <= 5);
for (int i = index; i <= 5; i++) {
if (checkGameDirectory(i) == 2) {
// checkCommonFilesIndex_m this is becouse it should start here
// becouse we use a return, we should only use 1 return...
checkCommonFilesIndex_m = i+1;
emit askGameSignal(i);
QCoreApplication::processEvents();
return true;
const QList<int>& Model::checkCommonFiles() {
m_availableGames.clear();
for (int i = 1; i <= 5; i++) {
int dirStatus = checkGameDirectory(i);
if (dirStatus == 1) { // symbolic link
m_availableGames.append(i);
} else if (dirStatus == 2) { // directory
m_availableGames.append(-i);
}
}
emit generateListSignal();
QCoreApplication::processEvents();
return false;
return m_availableGames;
}

QString Model::getGameDirectory(int id) {
Expand All @@ -95,39 +82,48 @@ QString Model::getGameDirectory(int id) {
return folder.TR4;
case 5:
return folder.TR5;
case 10:
return folder.TEN;
default:
qDebug() << "Id number:" << id << " is not a game.";
return "";
}
}

int Model::checkGameDirectory(int id) {
int status = -1;
const QString s = getGameDirectory(id);
if (s != "")
return fileManager.checkFileInfo(s, true);
return -1;
qDebug() << s;
if (s != "") {
status = fileManager.checkFileInfo(s, true);
}
return status;
}

void Model::getList(QVector<ListItemData>* list) {
*list = data.getListItems();
}

int Model::getItemState(int id) {
int status = 0;
if (id < 0) {
return 1;
status = 1;
} else if (id > 0) {
QString map(QString::number(id) + ".TRLE");
if (fileManager.checkDir(map, false))
return 2;
else
return 0;
QString dir(QString::number(id) + ".TRLE");
if (fileManager.checkDir(dir, false)) {
status = 2;
} else {
status = 0;
}
} else {
status = -1;
}
return -1;
return status;
}

bool Model::setLink(int id) {
bool status = false;
if (id < 0) {
if (id < 0) { // we use original game id as negative number
id = -id;
const QString s = "/Original.TR" + QString::number(id);
if (fileManager.checkDir(s, false ))
Expand Down Expand Up @@ -171,14 +167,16 @@ void Model::setupGame(int id) {
const QString src = levelPath.chopped(1);
const QString des = gamePath.chopped(1);
if (!fileManager.linkGameDir(src, des)) {
checkCommonFiles(); // TODO(noisecode3): Remove this
return;
qDebug() << "Faild to create the link to the new game directory";
}
}
checkCommonFiles(); // TODO(noisecode3): Remove this
for (int i=0; i < 100; i++) {
emit this->modelTickSignal();
QCoreApplication::processEvents();
}
}

bool Model::getGame(int id) {
bool Model::getLevel(int id) {
assert(id > 0);
if (id) {
int status = 0;
Expand Down
Loading

0 comments on commit 8d7bd6c

Please sign in to comment.