diff --git a/src/Skybolt/SkyboltCommon/Expected.h b/src/Skybolt/SkyboltCommon/Expected.h index 383aee7..defe950 100644 --- a/src/Skybolt/SkyboltCommon/Expected.h +++ b/src/Skybolt/SkyboltCommon/Expected.h @@ -1,75 +1,81 @@ -#pragma once - -#include "Exception.h" - -#include -#include -#include -#include - -namespace skybolt { - -struct UnexpectedMessage { std::string str; }; - -//! This could be replaced by std::expected (c++23) -template -using Expected = std::variant; - -template -std::optional value(const Expected& expected) -{ - if (std::holds_alternative(expected)) - { - return std::get(expected); - } - - return std::nullopt; -} - -template -std::optional valueOrElse(const Expected& expected, const FunctionT& f) -{ - static_assert(std::is_convertible>::value, "Function must take UnexpectedMessage as an argument"); - - if (std::holds_alternative(expected)) - { - return std::get(expected); - } - - f(std::get(expected)); - return std::nullopt; -} - -template -std::optional valueOrLogWarning(const Expected& expected) -{ - return valueOrElse(expected, [](const auto& m) { - BOOST_LOG_TRIVIAL(warning) << m.str; - }); -} - -template -std::optional valueOrLogError(const Expected& expected) -{ - return valueOrElse(expected, [](const auto& m) { - BOOST_LOG_TRIVIAL(error) << m.str; - }); -} - -template -T valueOrThrow(const Expected& expected) -{ - if (std::holds_alternative(expected)) - { - return std::get(expected); - } - throw ExceptionT(std::get(expected).str); -} - -template -T valueOrThrowException(const Expected& expected) -{ - return valueOrThrow(expected); -} - +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#pragma once + +#include "Exception.h" + +#include +#include +#include +#include + +namespace skybolt { + +struct UnexpectedMessage { std::string str; }; + +//! This could be replaced by std::expected (c++23) +template +using Expected = std::variant; + +template +std::optional value(const Expected& expected) +{ + if (std::holds_alternative(expected)) + { + return std::get(expected); + } + + return std::nullopt; +} + +template +std::optional valueOrElse(const Expected& expected, const FunctionT& f) +{ + static_assert(std::is_convertible>::value, "Function must take UnexpectedMessage as an argument"); + + if (std::holds_alternative(expected)) + { + return std::get(expected); + } + + f(std::get(expected)); + return std::nullopt; +} + +template +std::optional valueOrLogWarning(const Expected& expected) +{ + return valueOrElse(expected, [](const auto& m) { + BOOST_LOG_TRIVIAL(warning) << m.str; + }); +} + +template +std::optional valueOrLogError(const Expected& expected) +{ + return valueOrElse(expected, [](const auto& m) { + BOOST_LOG_TRIVIAL(error) << m.str; + }); +} + +template +T valueOrThrow(const Expected& expected) +{ + if (std::holds_alternative(expected)) + { + return std::get(expected); + } + throw ExceptionT(std::get(expected).str); +} + +template +T valueOrThrowException(const Expected& expected) +{ + return valueOrThrow(expected); +} + } // namespace skybolt \ No newline at end of file diff --git a/src/Skybolt/SkyboltEngine/FactoryRegistries.h b/src/Skybolt/SkyboltEngine/FactoryRegistries.h index 5becb56..190dcbf 100644 --- a/src/Skybolt/SkyboltEngine/FactoryRegistries.h +++ b/src/Skybolt/SkyboltEngine/FactoryRegistries.h @@ -1,21 +1,27 @@ -#pragma once - -#include -#include - -namespace skybolt { - -using FactoryRegistries = TypedItemContainer; - -template -Expected> getExpectedRegistry(const FactoryRegistries& registries) -{ - auto registry = registries.getFirstItemOfType(); - if (!registry) - { - return UnexpectedMessage{ "Could not find factory registry of type: " + std::string(typeid(T).name()) }; - } - return registry; -} - +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#pragma once + +#include +#include + +namespace skybolt { + +using FactoryRegistries = TypedItemContainer; + +template +Expected> getExpectedRegistry(const FactoryRegistries& registries) +{ + auto registry = registries.getFirstItemOfType(); + if (!registry) + { + return UnexpectedMessage{ "Could not find factory registry of type: " + std::string(typeid(T).name()) }; + } + return registry; +} + } // namespace skybolt \ No newline at end of file diff --git a/src/Skybolt/SkyboltEnginePlugins/Python/PythonInterpreter.cpp b/src/Skybolt/SkyboltEnginePlugins/Python/PythonInterpreter.cpp index 2140bbd..be37fc1 100644 --- a/src/Skybolt/SkyboltEnginePlugins/Python/PythonInterpreter.cpp +++ b/src/Skybolt/SkyboltEnginePlugins/Python/PythonInterpreter.cpp @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #include "PythonInterpreter.h" #include diff --git a/src/Skybolt/SkyboltEnginePlugins/Python/PythonInterpreter.h b/src/Skybolt/SkyboltEnginePlugins/Python/PythonInterpreter.h index a32eb36..7487ddf 100644 --- a/src/Skybolt/SkyboltEnginePlugins/Python/PythonInterpreter.h +++ b/src/Skybolt/SkyboltEnginePlugins/Python/PythonInterpreter.h @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #pragma once #include diff --git a/src/Skybolt/SkyboltEnginePlugins/Python/PythonPlugin.cpp b/src/Skybolt/SkyboltEnginePlugins/Python/PythonPlugin.cpp index 06c3614..0171d93 100644 --- a/src/Skybolt/SkyboltEnginePlugins/Python/PythonPlugin.cpp +++ b/src/Skybolt/SkyboltEnginePlugins/Python/PythonPlugin.cpp @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #include "PythonInterpreter.h" #include "PythonPluginUtil.h" #include diff --git a/src/Skybolt/SkyboltEnginePlugins/Python/PythonPluginUtil.cpp b/src/Skybolt/SkyboltEnginePlugins/Python/PythonPluginUtil.cpp index b5718d3..6771510 100644 --- a/src/Skybolt/SkyboltEnginePlugins/Python/PythonPluginUtil.cpp +++ b/src/Skybolt/SkyboltEnginePlugins/Python/PythonPluginUtil.cpp @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #include "PythonPluginUtil.h" #include diff --git a/src/Skybolt/SkyboltEnginePlugins/Python/PythonPluginUtil.h b/src/Skybolt/SkyboltEnginePlugins/Python/PythonPluginUtil.h index 3a35f6a..46fe267 100644 --- a/src/Skybolt/SkyboltEnginePlugins/Python/PythonPluginUtil.h +++ b/src/Skybolt/SkyboltEnginePlugins/Python/PythonPluginUtil.h @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #pragma once #include diff --git a/src/Skybolt/SkyboltQt/Engine/FindPython.cpp b/src/Skybolt/SkyboltQt/Engine/FindPython.cpp index 8be8daa..520d644 100644 --- a/src/Skybolt/SkyboltQt/Engine/FindPython.cpp +++ b/src/Skybolt/SkyboltQt/Engine/FindPython.cpp @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #include "FindPython.h" #include diff --git a/src/Skybolt/SkyboltQt/Engine/FindPython.h b/src/Skybolt/SkyboltQt/Engine/FindPython.h index dba684e..3b59199 100644 --- a/src/Skybolt/SkyboltQt/Engine/FindPython.h +++ b/src/Skybolt/SkyboltQt/Engine/FindPython.h @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #pragma once #include diff --git a/src/Skybolt/SkyboltQt/Widgets/ErrorLogModel.cpp b/src/Skybolt/SkyboltQt/Widgets/ErrorLogModel.cpp index bbcd6f9..c2b921e 100644 --- a/src/Skybolt/SkyboltQt/Widgets/ErrorLogModel.cpp +++ b/src/Skybolt/SkyboltQt/Widgets/ErrorLogModel.cpp @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #include "ErrorLogModel.h" #include diff --git a/src/Skybolt/SkyboltQt/Widgets/ErrorLogModel.h b/src/Skybolt/SkyboltQt/Widgets/ErrorLogModel.h index ff0c028..03caa43 100644 --- a/src/Skybolt/SkyboltQt/Widgets/ErrorLogModel.h +++ b/src/Skybolt/SkyboltQt/Widgets/ErrorLogModel.h @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #pragma once #include diff --git a/src/Skybolt/SkyboltQt/Widgets/ErrorLogWidget.cpp b/src/Skybolt/SkyboltQt/Widgets/ErrorLogWidget.cpp index 4dcc591..f5b4332 100644 --- a/src/Skybolt/SkyboltQt/Widgets/ErrorLogWidget.cpp +++ b/src/Skybolt/SkyboltQt/Widgets/ErrorLogWidget.cpp @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #include "ErrorLogWidget.h" #include diff --git a/src/Skybolt/SkyboltQt/Widgets/ErrorLogWidget.h b/src/Skybolt/SkyboltQt/Widgets/ErrorLogWidget.h index f889aea..9e441e4 100644 --- a/src/Skybolt/SkyboltQt/Widgets/ErrorLogWidget.h +++ b/src/Skybolt/SkyboltQt/Widgets/ErrorLogWidget.h @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #pragma once #include "ErrorLogModel.h" diff --git a/src/Skybolt/SkyboltQt/Widgets/StatusBar.cpp b/src/Skybolt/SkyboltQt/Widgets/StatusBar.cpp index 9220265..b979e70 100644 --- a/src/Skybolt/SkyboltQt/Widgets/StatusBar.cpp +++ b/src/Skybolt/SkyboltQt/Widgets/StatusBar.cpp @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #include "StatusBar.h" #include "ErrorLogModel.h" #include "ErrorLogWidget.h" diff --git a/src/Skybolt/SkyboltQt/Widgets/StatusBar.h b/src/Skybolt/SkyboltQt/Widgets/StatusBar.h index aef1064..d46f902 100644 --- a/src/Skybolt/SkyboltQt/Widgets/StatusBar.h +++ b/src/Skybolt/SkyboltQt/Widgets/StatusBar.h @@ -1,3 +1,9 @@ +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #pragma once class ErrorLogModel; diff --git a/src/Skybolt/SkyboltQt/Widgets/ViewportToolBar.cpp b/src/Skybolt/SkyboltQt/Widgets/ViewportToolBar.cpp index 20a8048..9605c53 100644 --- a/src/Skybolt/SkyboltQt/Widgets/ViewportToolBar.cpp +++ b/src/Skybolt/SkyboltQt/Widgets/ViewportToolBar.cpp @@ -1,107 +1,113 @@ -#include "ViewportToolBar.h" -#include "SkyboltQt/Entity/EntityListModel.h" -#include "SkyboltQt/Icon/SkyboltIcons.h" -#include "SkyboltQt/Property/PropertyEditor.h" -#include "SkyboltQt/QtUtil/QtDialogUtil.h" -#include "SkyboltQt/QtUtil/QtTimerUtil.h" -#include "SkyboltQt/Viewport/ViewportPropertiesModel.h" -#include "SkyboltQt/Widgets/CameraControllerWidget.h" -#include "SkyboltQt/Widgets/ViewportWidget.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -using namespace skybolt; - -static sim::Entity* getSelectedCamera(const sim::World& world, const QComboBox& comboBox) -{ - return world.findObjectByName(comboBox.currentText().toStdString()).get(); -} - -ViewportToolBar::ViewportToolBar(ViewportToolBarConfig config) : - QToolBar(config.parent), - mFilterMenu(new QMenu(this)) -{ - sim::World* world = &config.engineRoot->scenario->world; - - { - auto cameraListModel = new EntityListModel(world, [](const sim::Entity& entity) { - return entity.getFirstComponent() != nullptr; - }); - - auto proxyModel = new QSortFilterProxyModel(this); - proxyModel->sort(0); - proxyModel->setSourceModel(cameraListModel); - - mCameraCombo = new QComboBox(this); - mCameraCombo->setToolTip("Camera"); - mCameraCombo->setModel(proxyModel); - addWidget(mCameraCombo); - - mCameraControllerWidget = new CameraControllerWidget(world, this); - addWidget(mCameraControllerWidget); - - auto updateViewportSelectedCamera = [this, world, viewport = config.viewport] { - if (viewport) - { - sim::Entity* camera = getSelectedCamera(*world, *mCameraCombo); - viewport->setCamera(camera); - } - }; - updateViewportSelectedCamera(); - - connect(mCameraCombo, &QComboBox::currentTextChanged, this, [updateViewportSelectedCamera = std::move(updateViewportSelectedCamera)](const QString& text) { - updateViewportSelectedCamera(); - }); - } - - addAction(getSkyboltIcon(SkyboltIcon::Screenshot), "Capture Image", - [this, scenarioFilenameGetter = std::move(config.scenarioFilenameGetter), viewport = config.viewport] { - if (viewport) - { - viewport->captureImage(scenarioFilenameGetter()); - }; - }); - - { - QToolButton* toolButton = new QToolButton(this); - toolButton->setText("Filter"); - toolButton->setToolTip("Filter"); - toolButton->setIcon(getSkyboltIcon(SkyboltIcon::Filter)); - toolButton->setMenu(mFilterMenu); - toolButton->setPopupMode(QToolButton::InstantPopup); - addWidget(toolButton); - } - - addAction(getSkyboltIcon(SkyboltIcon::Settings), "Settings", - [this, viewport = config.viewport, scene = config.engineRoot->scene.get()] { - if (viewport && viewport->getCamera()) - { - PropertyEditor* editor = new PropertyEditor(); - editor->setModel(std::make_shared(scene, viewport->getCamera()->getFirstComponent().get())); - QDialog* dialog = createDialogNonModal(editor, "Settings", this); - dialog->exec(); - } - }); - - createAndStartIntervalTimer(/* intervalMilliseconds */ 100, this, [this, viewport = config.viewport] { - if (viewport) - { - sim::Entity* camera = viewport->getCamera(); - if (mCameraControllerWidget->getCamera() != camera) - { - mCameraControllerWidget->setCamera(camera); - mCameraCombo->setCurrentText(camera ? QString::fromStdString(getName(*camera)) : ""); - } - mCameraControllerWidget->update(); - } - }); +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#include "ViewportToolBar.h" +#include "SkyboltQt/Entity/EntityListModel.h" +#include "SkyboltQt/Icon/SkyboltIcons.h" +#include "SkyboltQt/Property/PropertyEditor.h" +#include "SkyboltQt/QtUtil/QtDialogUtil.h" +#include "SkyboltQt/QtUtil/QtTimerUtil.h" +#include "SkyboltQt/Viewport/ViewportPropertiesModel.h" +#include "SkyboltQt/Widgets/CameraControllerWidget.h" +#include "SkyboltQt/Widgets/ViewportWidget.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace skybolt; + +static sim::Entity* getSelectedCamera(const sim::World& world, const QComboBox& comboBox) +{ + return world.findObjectByName(comboBox.currentText().toStdString()).get(); +} + +ViewportToolBar::ViewportToolBar(ViewportToolBarConfig config) : + QToolBar(config.parent), + mFilterMenu(new QMenu(this)) +{ + sim::World* world = &config.engineRoot->scenario->world; + + { + auto cameraListModel = new EntityListModel(world, [](const sim::Entity& entity) { + return entity.getFirstComponent() != nullptr; + }); + + auto proxyModel = new QSortFilterProxyModel(this); + proxyModel->sort(0); + proxyModel->setSourceModel(cameraListModel); + + mCameraCombo = new QComboBox(this); + mCameraCombo->setToolTip("Camera"); + mCameraCombo->setModel(proxyModel); + addWidget(mCameraCombo); + + mCameraControllerWidget = new CameraControllerWidget(world, this); + addWidget(mCameraControllerWidget); + + auto updateViewportSelectedCamera = [this, world, viewport = config.viewport] { + if (viewport) + { + sim::Entity* camera = getSelectedCamera(*world, *mCameraCombo); + viewport->setCamera(camera); + } + }; + updateViewportSelectedCamera(); + + connect(mCameraCombo, &QComboBox::currentTextChanged, this, [updateViewportSelectedCamera = std::move(updateViewportSelectedCamera)](const QString& text) { + updateViewportSelectedCamera(); + }); + } + + addAction(getSkyboltIcon(SkyboltIcon::Screenshot), "Capture Image", + [this, scenarioFilenameGetter = std::move(config.scenarioFilenameGetter), viewport = config.viewport] { + if (viewport) + { + viewport->captureImage(scenarioFilenameGetter()); + }; + }); + + { + QToolButton* toolButton = new QToolButton(this); + toolButton->setText("Filter"); + toolButton->setToolTip("Filter"); + toolButton->setIcon(getSkyboltIcon(SkyboltIcon::Filter)); + toolButton->setMenu(mFilterMenu); + toolButton->setPopupMode(QToolButton::InstantPopup); + addWidget(toolButton); + } + + addAction(getSkyboltIcon(SkyboltIcon::Settings), "Settings", + [this, viewport = config.viewport, scene = config.engineRoot->scene.get()] { + if (viewport && viewport->getCamera()) + { + PropertyEditor* editor = new PropertyEditor(); + editor->setModel(std::make_shared(scene, viewport->getCamera()->getFirstComponent().get())); + QDialog* dialog = createDialogNonModal(editor, "Settings", this); + dialog->exec(); + } + }); + + createAndStartIntervalTimer(/* intervalMilliseconds */ 100, this, [this, viewport = config.viewport] { + if (viewport) + { + sim::Entity* camera = viewport->getCamera(); + if (mCameraControllerWidget->getCamera() != camera) + { + mCameraControllerWidget->setCamera(camera); + mCameraCombo->setCurrentText(camera ? QString::fromStdString(getName(*camera)) : ""); + } + mCameraControllerWidget->update(); + } + }); } \ No newline at end of file diff --git a/src/Skybolt/SkyboltQt/Widgets/ViewportToolBar.h b/src/Skybolt/SkyboltQt/Widgets/ViewportToolBar.h index d57e780..4ef20d8 100644 --- a/src/Skybolt/SkyboltQt/Widgets/ViewportToolBar.h +++ b/src/Skybolt/SkyboltQt/Widgets/ViewportToolBar.h @@ -1,29 +1,35 @@ -#pragma once - -#include "SkyboltQt/SkyboltQtFwd.h" -#include -#include -#include - -class QComboBox; - -struct ViewportToolBarConfig -{ - skybolt::EngineRoot* engineRoot; - std::function scenarioFilenameGetter; - QPointer viewport; - QWidget* parent = nullptr; -}; - -class ViewportToolBar : public QToolBar -{ -public: - ViewportToolBar(ViewportToolBarConfig config); - - QMenu* getVisibilityFilterMenu() const { return mFilterMenu; } - -private: - QMenu* mFilterMenu; - CameraControllerWidget* mCameraControllerWidget; - QComboBox* mCameraCombo; -}; +/* Copyright Matthew Reid + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#pragma once + +#include "SkyboltQt/SkyboltQtFwd.h" +#include +#include +#include + +class QComboBox; + +struct ViewportToolBarConfig +{ + skybolt::EngineRoot* engineRoot; + std::function scenarioFilenameGetter; + QPointer viewport; + QWidget* parent = nullptr; +}; + +class ViewportToolBar : public QToolBar +{ +public: + ViewportToolBar(ViewportToolBarConfig config); + + QMenu* getVisibilityFilterMenu() const { return mFilterMenu; } + +private: + QMenu* mFilterMenu; + CameraControllerWidget* mCameraControllerWidget; + QComboBox* mCameraCombo; +};