Skip to content

Commit

Permalink
Merge pull request #62 from KelvinShadewing/unstable
Browse files Browse the repository at this point in the history
Unstable
  • Loading branch information
KelvinShadewing committed Jun 30, 2023
2 parents 9a82c7d + 6067a9e commit 462f263
Show file tree
Hide file tree
Showing 64 changed files with 2,879 additions and 935 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gnu_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
include:
- build_type: Release
arch: 32
release: ON
release: OFF
- build_type: Release
arch: 64
release: ON
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ rte/bin/log.txt
rte/XYG_Runtime.layout
rte/XYG_Runtime.depend
test/log.txt
.vscode/*
70 changes: 69 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,74 @@
{
"files.associations": {
"random": "cpp",
"bitset": "cpp"
"bitset": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ratio": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"*.ipp": "cpp"
}
}
24 changes: 21 additions & 3 deletions docs/en/audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@

* <a name="playsound"></a>**`playSound( sound, loops )`**

Plays a sound that repeats as many times as defined by `loops`. If `-1` is used, the sound will loop until stopped. Returns the channel number of the sound being played. If looping, the return value should be stored in order to stop it later.
Plays a sound that repeats as many times as defined by `loops`.

If `-1` is used, the sound will loop until stopped. Returns the channel number of the sound being played. If looping, the return value should be stored in order to stop it later.

* <a name="playmusic"></a>**`playMusic( music, loops )`**

Plays a music track and repeats as many times as `loops` says. Unlike with sound, it does not return a channel since only one music track can play at once.
Plays a music track and repeats as many times as `loops` says.

Unlike with sound, it does not return a channel since only one music track can play at once.

* <a name="deletesound"></a>**`deleteSound( sound )`**

Expand Down Expand Up @@ -83,4 +87,18 @@

* <a name="getSoundVolume"></a>**`getSoundVolume()`**

Returns the current sound volume with an integer between 0 and 128.
Returns the current sound volume with an integer between 0 and 128.

* <a name="getAudioDriver"></a>**`getAudioDriver()`**

Returns the name of the currently active audio driver.

If no audio driver is present, this will return the string `None`.

Note that `None` actually is an audio driver (see `src/audio/audio_none.cpp`), but it does not actually handle audio and is only used as a fallback.

* <a name="isAudioAvailable"></a>**`isAudioAvailable()`**

Checks if audio playback is currently available.

Note that this function's implementation currently does not check that the audio stack is working, it only checks that a real audio driver (not the fallback `None` driver, which doesn't actually handle audio) is present.
4 changes: 0 additions & 4 deletions docs/en/fileio.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@
The intended usage of this function is by providing the result of `getPrefDir()` as a parameter. This usage allows setting a proper writing directory for the game.
By default, Brux uses the `brux` (or `brux/brux`) user-and-app specific directory for writing.

* <a name="chdir"></a>**`chdir( string )`**

Attempts to change the current working directory.

* <a name="lsdir"></a>**`lsdir( string )`**

Returns a list of the directory `string`'s contents as an array.
Expand Down
4 changes: 2 additions & 2 deletions docs/en/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

Returns whether or not `key` was just released.

* <a name="anyKeyPress"></a>**`anyKeyPress()`**
* <a name="keyPressAny"></a>**`keyPressAny()`**

If any key was pressed on the current frame, this returns the first one detected, otherwise, it returns -1. Useful for remapping controls.

Expand Down Expand Up @@ -105,7 +105,7 @@

Returns if a gamepad's button numbered `button` is held.

* <a name="anyJoyPress"></a>**`anyJoyPress( id )`**
* <a name="joyPressAny"></a>**`joyPressAny( id )`**

If any button on the gamepad is pressed, it returns the number, otherwise, it returns -1.

Expand Down
4 changes: 2 additions & 2 deletions docs/en/tutorials.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# **XYG Tutorials**
# **Brux GDK Tutorials**



Expand All @@ -25,4 +25,4 @@

----

At the time of this writing, XYG is just a simple runtime that only works with one file: test.nut. All your game's code will be put in there for the time being. Later updates will allow XYG to execute precompiled .sq files.
Welcome to Brux GDK. This game engine uses Squirrel scripting to create simple 2D games. These tutorials will help you get started in creating your own games.
97 changes: 60 additions & 37 deletions ide/editorwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "editorwindow.h"
#include "editorwindow.hpp"
#include "ui_editorwindow.h"

#include <iostream>
Expand All @@ -10,29 +10,30 @@
#include <KHelpMenu>
#include <KAboutData>

EditorWindow::EditorWindow(QWidget *parent, QString projectDirectory) : QMainWindow(parent), ui(new Ui::EditorWindow), Directory(projectDirectory) {
EditorWindow::EditorWindow(QWidget *parent, QString projectDirectory) : QMainWindow(parent), ui(new Ui::EditorWindow), directory(projectDirectory) {
ui->setupUi(this);
setWindowTitle("BRUX IDE");
QMenu* newMenu = new QMenu("File");
connect(newMenu->addAction("Open File"), SIGNAL(triggered()) , this, SLOT(openFile()));
connect(newMenu->addAction("Open Folder"), SIGNAL(triggered()) , this, SLOT(openDirectory()));
connect(newMenu->addAction("Test Project"), SIGNAL(triggered()) , this, SLOT(testProject()));
KHelpMenu* Help = new KHelpMenu(this, KAboutData::applicationData());
ui->menubar->addMenu(newMenu);
ui->menubar->addMenu(Help->menu());

DirectoryView.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
directoryView.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);

auto TreeView = ui->centralwidget->findChild<QTreeView*>("treeView");
QTreeView* treeView = ui->centralwidget->findChild<QTreeView*>("treeView");
connect(ui->centralwidget->findChild<QTabWidget*>("fileTabs"), &QTabWidget::tabCloseRequested, this, &EditorWindow::closeFile);
connect(TreeView, &QTreeView::doubleClicked, this, &EditorWindow::handleDoubleClick);
connect(treeView, &QTreeView::doubleClicked, this, &EditorWindow::handleDoubleClick);

TextEditorInstance = KTextEditor::Editor::instance();
textEditorInstance = KTextEditor::Editor::instance();
}

EditorWindow::~EditorWindow() {
int remainingFiles = Documents.size();
int remainingFiles = documentList.size();

OpenSourceFiles.clear();
openTextFiles.clear();

while (remainingFiles != 0) {
closeFile(0);
Expand All @@ -49,7 +50,7 @@ void EditorWindow::handleDoubleClick(QModelIndex index) {
QTreeView* treeView = ui->centralwidget->findChild<QTreeView*>("treeView");
QString item = treeView->model()->data(index).toString();

processFile(DirectoryView.filePath(index), item);
processFile(directoryView.filePath(index), item);
}

void EditorWindow::openDirectory(bool checked) {
Expand All @@ -60,6 +61,25 @@ void EditorWindow::openDirectory(bool checked) {
}
}

void EditorWindow::testProject() {
if (directory == "") return; // No directory open, return.
char* desktop = getenv("XDG_CURRENT_DESKTOP");
std::string environment, command;

if (desktop == NULL) {
std::cout << "XDG_CURRENT_DESKTOP is unset. Defaulting to no terminal." << std::endl;
environment = "";
} else environment = desktop;

// Determine which command should be used
if (environment == "KDE") command = "konsole --workdir " + directory.toStdString() + " -e \"brux\" &";
else if (environment == "XFCE") command = "xfce4-terminal --working-directory " + directory.toStdString() + " --command=\"brux\" &";
else if (environment.find("GNOME") != environment.npos) command = "gnome-terminal --working-directory " + directory.toStdString() + " --command=\"brux\" &"; // GNOME and GNOME Flashback
else command = ("cd " + directory + " && brux &").toStdString(); // Default to running in the background with no terminal
system(command.c_str());
}


void EditorWindow::openFile(bool checked) {
QString openFile = QFileDialog::getOpenFileName(this, tr("Open File"), getenv("HOME"));

Expand Down Expand Up @@ -92,12 +112,12 @@ bool EditorWindow::isTilemap(QString path) {
}

void EditorWindow::processFile(QString path, QString name, bool newFile) {
int vecSize = Documents.size();
int listSize = documentList.size();
// New file logic
if (newFile) {
Documents.push_back(TextEditorInstance->createDocument(this));
DocumentViews.push_back(Documents[vecSize]->createView(nullptr));
createTab("New File", vecSize);
documentList.push_back(textEditorInstance->createDocument(this));
documentViewList.push_back(documentList[listSize]->createView(nullptr));
createTab("New File", listSize);
return;
}

Expand All @@ -107,24 +127,24 @@ void EditorWindow::processFile(QString path, QString name, bool newFile) {
return; // Do this later
}

if(std::find(OpenSourceFiles.begin(), OpenSourceFiles.end(), path) != OpenSourceFiles.end()) return;
if(std::find(openTextFiles.begin(), openTextFiles.end(), path) != openTextFiles.end()) return;

QDir dirExistsCheck{path};
if (!dirExistsCheck.exists()) {
Documents.push_back(TextEditorInstance->createDocument(this));
Documents[vecSize]->openUrl(QUrl("file://" + path));
DocumentViews.push_back(Documents[vecSize]->createView(nullptr));
createTab(name, vecSize);
OpenSourceFiles.push_back(path);
documentList.push_back(textEditorInstance->createDocument(this));
documentList[listSize]->openUrl(QUrl("file://" + path));
documentViewList.push_back(documentList[listSize]->createView(nullptr));
createTab(name, listSize);
openTextFiles.push_back(path);
}
}

void EditorWindow::processDirectory(QString path, bool doCloseFiles) {
if (!isDirectory(path)) return;
if (doCloseFiles) {
int remainingFiles = Documents.size();
int remainingFiles = documentList.size();

OpenSourceFiles.clear();
openTextFiles.clear();

while (remainingFiles != 0) {
closeFile(0);
Expand All @@ -136,25 +156,25 @@ void EditorWindow::processDirectory(QString path, bool doCloseFiles) {

setWindowTitle(shortDir + " - BRUX IDE");

Directory = path;
DirectoryView.setRootPath(Directory);

auto TreeView = ui->centralwidget->findChild<QTreeView*>("treeView");
TreeView->setModel(&DirectoryView);
TreeView->setRootIndex(DirectoryView.index(Directory));
TreeView->hideColumn(3);
int sizeOfColumn = TreeView->maximumWidth() / 4;
TreeView->setColumnWidth(0, sizeOfColumn * 2.5f);
TreeView->setColumnWidth(1, sizeOfColumn * 0.75f);
TreeView->setColumnWidth(2, sizeOfColumn * 0.5f);
directory = path;
directoryView.setRootPath(directory);

QTreeView* treeView = ui->centralwidget->findChild<QTreeView*>("treeView");
treeView->setModel(&directoryView);
treeView->setRootIndex(directoryView.index(directory));
treeView->hideColumn(3);
int sizeOfColumn = treeView->maximumWidth() / 4;
treeView->setColumnWidth(0, sizeOfColumn * 2.5f);
treeView->setColumnWidth(1, sizeOfColumn * 0.75f);
treeView->setColumnWidth(2, sizeOfColumn * 0.5f);
}

void EditorWindow::closeFile(int index) {
DocumentViews[index]->close();
Documents[index]->closeStream();
documentViewList[index]->close();
documentList[index]->closeStream();
closeTab(index);
if (OpenSourceFiles.size() == 0) return; // We manually cleared this so don't erase from OpenSourceFiles.
OpenSourceFiles.erase(OpenSourceFiles.begin() + index);
if (openTextFiles.size() == 0) return; // We manually cleared this so don't erase from openTextFiles.
openTextFiles.erase(openTextFiles.begin() + index);
}

void EditorWindow::createTab(QString name, int documentIndex) {
Expand All @@ -167,7 +187,10 @@ void EditorWindow::createTab(QString name, int documentIndex) {
else tabWidget->insertTab(0, newTab, name);

// Create a new document view for the new tab
newTabLayout->addWidget(DocumentViews[documentIndex]);
newTabLayout->addWidget(documentViewList[documentIndex]);

// Finally, change the current index to the newest tab
tabWidget->setCurrentIndex(tabWidget->count()-1);
}

void EditorWindow::closeTab(int index) {
Expand Down

0 comments on commit 462f263

Please sign in to comment.