From e8bdb95f13a9b874529ba34875082b61d5ec6823 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Tue, 31 Jul 2018 17:59:48 +0200 Subject: [PATCH] format new files Since many of the changes were made before the clang-format changes went live, the new source files used a different format still. This PR applies the new style to all the new source files. --- src/openrct2-ui/interface/Widget.cpp | 4 +- src/openrct2-ui/scripting/CustomWindow.cpp | 199 +++++++++------------ src/openrct2-ui/scripting/ScUi.hpp | 26 ++- src/openrct2-ui/scripting/ScWindow.hpp | 35 ++-- src/openrct2-ui/scripting/UiExtensions.cpp | 4 +- src/openrct2-ui/scripting/UiExtensions.h | 2 +- src/openrct2/core/FileWatcher.cpp | 43 ++--- src/openrct2/core/FileWatcher.h | 6 +- src/openrct2/interface/StdInOutConsole.cpp | 3 +- src/openrct2/interface/Window.h | 2 +- src/openrct2/interface/Window_internal.h | 2 +- src/openrct2/scripting/HookEngine.cpp | 16 +- src/openrct2/scripting/HookEngine.h | 25 +-- src/openrct2/scripting/Plugin.cpp | 33 ++-- src/openrct2/scripting/Plugin.h | 17 +- src/openrct2/scripting/ScConsole.hpp | 34 ++-- src/openrct2/scripting/ScContext.hpp | 19 +- src/openrct2/scripting/ScDisposable.hpp | 8 +- src/openrct2/scripting/ScMap.hpp | 13 +- src/openrct2/scripting/ScPark.hpp | 43 +++-- src/openrct2/scripting/ScThing.hpp | 46 +++-- src/openrct2/scripting/ScTile.hpp | 83 +++++---- src/openrct2/scripting/ScriptEngine.cpp | 53 +++--- src/openrct2/scripting/ScriptEngine.h | 36 ++-- 24 files changed, 409 insertions(+), 343 deletions(-) diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index b5cc9cfd16..7f4072b40f 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -362,7 +362,7 @@ static void widget_text_centred(rct_drawpixelinfo* dpi, rct_window* w, rct_widge t = w->windowPos.y + widget->top; auto stringId = widget->text; - void * formatArgs = gCommonFormatArgs; + void* formatArgs = gCommonFormatArgs; if (widget->flags & WIDGET_FLAGS::TEXT_IS_STRING) { stringId = STR_STRING; @@ -407,7 +407,7 @@ static void widget_text(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex w t = w->windowPos.y + widget->top; auto stringId = widget->text; - void * formatArgs = gCommonFormatArgs; + void* formatArgs = gCommonFormatArgs; if (widget->flags & WIDGET_FLAGS::TEXT_IS_STRING) { stringId = STR_STRING; diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index 72b0172f56..72d0ad25f3 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -7,19 +7,20 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../interface/Dropdown.h" +#include "ScUi.hpp" +#include "ScWindow.hpp" + #include -#include -#include -#include +#include +#include #include #include #include #include -#include -#include -#include "../interface/Dropdown.h" -#include "ScUi.hpp" -#include "ScWindow.hpp" +#include +#include +#include using namespace OpenRCT2; using namespace OpenRCT2::Scripting; @@ -36,51 +37,48 @@ namespace OpenRCT2::Ui::Windows }; static rct_widget CustomDefaultWidgets[] = { - { WWT_FRAME, 0, 0, 0, 0, 0, 0xFFFFFFFF, STR_NONE }, // panel / background - { WWT_CAPTION, 0, 1, 0, 1, 14, STR_STRING, STR_WINDOW_TITLE_TIP }, // title bar - { WWT_CLOSEBOX, 0, 0, 0, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button - { WWT_RESIZE, 1, 0, 0, 14, 0, 0xFFFFFFFF, STR_NONE }, // content panel + { WWT_FRAME, 0, 0, 0, 0, 0, 0xFFFFFFFF, STR_NONE }, // panel / background + { WWT_CAPTION, 0, 1, 0, 1, 14, STR_STRING, STR_WINDOW_TITLE_TIP }, // title bar + { WWT_CLOSEBOX, 0, 0, 0, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button + { WWT_RESIZE, 1, 0, 0, 14, 0, 0xFFFFFFFF, STR_NONE }, // content panel }; - static void window_custom_close(rct_window * w); - static void window_custom_mouseup(rct_window * w, rct_widgetindex widgetIndex); - static void window_custom_mousedown(rct_window * w, rct_widgetindex widgetIndex, rct_widget * widget); - static void window_custom_resize(rct_window * w); - static void window_custom_dropdown(rct_window * w, rct_widgetindex widgetIndex, int32_t dropdownIndex); - static void window_custom_invalidate(rct_window * w); - static void window_custom_paint(rct_window * w, rct_drawpixelinfo * dpi); + static void window_custom_close(rct_window* w); + static void window_custom_mouseup(rct_window* w, rct_widgetindex widgetIndex); + static void window_custom_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget); + static void window_custom_resize(rct_window* w); + static void window_custom_dropdown(rct_window* w, rct_widgetindex widgetIndex, int32_t dropdownIndex); + static void window_custom_invalidate(rct_window* w); + static void window_custom_paint(rct_window* w, rct_drawpixelinfo* dpi); - static rct_window_event_list window_custom_events = - { - window_custom_close, - window_custom_mouseup, - window_custom_resize, - window_custom_mousedown, - window_custom_dropdown, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - window_custom_invalidate, - window_custom_paint, - nullptr - }; + static rct_window_event_list window_custom_events = { window_custom_close, + window_custom_mouseup, + window_custom_resize, + window_custom_mousedown, + window_custom_dropdown, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + window_custom_invalidate, + window_custom_paint, + nullptr }; struct CustomWidgetDesc { @@ -165,8 +163,9 @@ namespace OpenRCT2::Ui::Windows if (desc["widgets"].is_array()) { auto dukWidgets = desc["widgets"].as_array(); - std::transform(dukWidgets.begin(), dukWidgets.end(), std::back_inserter(result.Widgets), - [](const DukValue& w) { return CustomWidgetDesc::FromDukValue(w); }); + std::transform(dukWidgets.begin(), dukWidgets.end(), std::back_inserter(result.Widgets), [](const DukValue& w) { + return CustomWidgetDesc::FromDukValue(w); + }); } return std::move(result); @@ -174,9 +173,7 @@ namespace OpenRCT2::Ui::Windows static std::optional GetOptionalInt(DukValue input) { - return input.type() == DukValue::Type::NUMBER ? - std::make_optional(input.as_int()) : - std::nullopt; + return input.type() == DukValue::Type::NUMBER ? std::make_optional(input.as_int()) : std::nullopt; } }; @@ -193,20 +190,17 @@ namespace OpenRCT2::Ui::Windows std::vector WidgetIndexMap; CustomWindowInfo( - rct_windowclass cls, - rct_windownumber number, - std::shared_ptr owner, - const CustomWindowDesc& desc) - : _class(cls), - _number(number), - Owner(owner), - Desc(desc) + rct_windowclass cls, rct_windownumber number, std::shared_ptr owner, const CustomWindowDesc& desc) + : _class(cls) + , _number(number) + , Owner(owner) + , Desc(desc) { } CustomWindowInfo(const CustomWindowInfo&) = delete; - const CustomWidgetDesc * GetCustomWidgetDesc(size_t widgetIndex) const + const CustomWidgetDesc* GetCustomWidgetDesc(size_t widgetIndex) const { if (widgetIndex < WidgetIndexMap.size()) { @@ -222,13 +216,14 @@ namespace OpenRCT2::Ui::Windows static rct_windownumber _nextWindowNumber; - static CustomWindowInfo& GetInfo(rct_window * w); + static CustomWindowInfo& GetInfo(rct_window* w); static rct_windownumber GetNewWindowNumber(); - static void RefreshWidgets(rct_window * w); + static void RefreshWidgets(rct_window* w); static void InvokeEventHandler(std::shared_ptr owner, const DukValue& dukHandler); - static void InvokeEventHandler(std::shared_ptr owner, const DukValue& dukHandler, const std::vector& args); + static void InvokeEventHandler( + std::shared_ptr owner, const DukValue& dukHandler, const std::vector& args); - rct_window * window_custom_open(std::shared_ptr owner, DukValue dukDesc) + rct_window* window_custom_open(std::shared_ptr owner, DukValue dukDesc) { auto desc = CustomWindowDesc::FromDukValue(dukDesc); @@ -238,26 +233,15 @@ namespace OpenRCT2::Ui::Windows windowFlags |= WF_RESIZABLE; } - rct_window * window; + rct_window* window; if (desc.X && desc.Y) { window = window_create( - desc.X.value(), - desc.Y.value(), - desc.Width, - desc.Height, - &window_custom_events, - WC_CUSTOM, - windowFlags); + desc.X.value(), desc.Y.value(), desc.Width, desc.Height, &window_custom_events, WC_CUSTOM, windowFlags); } else { - window = window_create_auto_pos( - desc.Width, - desc.Height, - &window_custom_events, - WC_CUSTOM, - windowFlags); + window = window_create_auto_pos(desc.Width, desc.Height, &window_custom_events, WC_CUSTOM, windowFlags); } window->number = GetNewWindowNumber(); @@ -278,19 +262,20 @@ namespace OpenRCT2::Ui::Windows return window; } - static void window_custom_close(rct_window * w) + static void window_custom_close(rct_window* w) { - delete static_cast(w->custom_info); + delete static_cast(w->custom_info); w->custom_info = nullptr; } - static void window_custom_mouseup(rct_window * w, rct_widgetindex widgetIndex) + static void window_custom_mouseup(rct_window* w, rct_widgetindex widgetIndex) { - switch (widgetIndex) { - case WIDX_CLOSE: - window_close(w); - break; - default: + switch (widgetIndex) + { + case WIDX_CLOSE: + window_close(w); + break; + default: { const auto& info = GetInfo(w); const auto widgetDesc = info.GetCustomWidgetDesc(widgetIndex); @@ -306,7 +291,7 @@ namespace OpenRCT2::Ui::Windows } } - static void window_custom_resize(rct_window * w) + static void window_custom_resize(rct_window* w) { const auto& desc = GetInfo(w).Desc; if (desc.IsResizable()) @@ -324,7 +309,7 @@ namespace OpenRCT2::Ui::Windows } } - static void window_custom_mousedown(rct_window * w, rct_widgetindex widgetIndex, rct_widget * widget) + static void window_custom_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget) { const auto& info = GetInfo(w); const auto widgetDesc = info.GetCustomWidgetDesc(widgetIndex); @@ -338,22 +323,16 @@ namespace OpenRCT2::Ui::Windows for (size_t i = 0; i < numItems; i++) { gDropdownItemsFormat[i] = STR_STRING; - set_format_arg_on((uint8_t*)&gDropdownItemsArgs[i], 0, const char *, items[i].c_str()); + set_format_arg_on((uint8_t*)&gDropdownItemsArgs[i], 0, const char*, items[i].c_str()); } window_dropdown_show_text_custom_width( - w->x + widget->left, - w->y + widget->top, - widget->bottom - widget->top + 1, - w->colours[widget->colour], - 0, - DROPDOWN_FLAG_STAY_OPEN, - numItems, - widget->right - widget->left - 3); + w->x + widget->left, w->y + widget->top, widget->bottom - widget->top + 1, w->colours[widget->colour], 0, + DROPDOWN_FLAG_STAY_OPEN, numItems, widget->right - widget->left - 3); } } } - static void window_custom_dropdown(rct_window * w, rct_widgetindex widgetIndex, int32_t dropdownIndex) + static void window_custom_dropdown(rct_window* w, rct_widgetindex widgetIndex, int32_t dropdownIndex) { if (dropdownIndex == -1) return; @@ -379,7 +358,7 @@ namespace OpenRCT2::Ui::Windows } } - static void window_custom_invalidate(rct_window * w) + static void window_custom_invalidate(rct_window* w) { w->widgets[WIDX_BACKGROUND].right = w->width - 1; w->widgets[WIDX_BACKGROUND].bottom = w->height - 1; @@ -390,17 +369,17 @@ namespace OpenRCT2::Ui::Windows w->widgets[WIDX_CONTENT_PANEL].bottom = w->height - 1; const auto& desc = GetInfo(w).Desc; - set_format_arg(0, void *, desc.Title.c_str()); + set_format_arg(0, void*, desc.Title.c_str()); } - static void window_custom_paint(rct_window * w, rct_drawpixelinfo * dpi) + static void window_custom_paint(rct_window* w, rct_drawpixelinfo* dpi) { window_draw_widgets(w, dpi); } - static CustomWindowInfo& GetInfo(rct_window * w) + static CustomWindowInfo& GetInfo(rct_window* w) { - return *(static_cast(w->custom_info)); + return *(static_cast(w->custom_info)); } static rct_windownumber GetNewWindowNumber() @@ -413,7 +392,7 @@ namespace OpenRCT2::Ui::Windows return result; } - static void CreateWidget(std::vector& widgetList, const CustomWidgetDesc &desc) + static void CreateWidget(std::vector& widgetList, const CustomWidgetDesc& desc) { rct_widget widget{}; widget.colour = 1; @@ -456,7 +435,7 @@ namespace OpenRCT2::Ui::Windows } } - static void RefreshWidgets(rct_window * w) + static void RefreshWidgets(rct_window* w) { auto& info = GetInfo(w); auto& widgets = info.Widgets; @@ -521,4 +500,4 @@ namespace OpenRCT2::Ui::Windows } } } -} +} // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/scripting/ScUi.hpp b/src/openrct2-ui/scripting/ScUi.hpp index 9b46766ed7..1d58081e4c 100644 --- a/src/openrct2-ui/scripting/ScUi.hpp +++ b/src/openrct2-ui/scripting/ScUi.hpp @@ -9,13 +9,14 @@ #pragma once +#include "../Context.h" +#include "../common.h" +#include "ScWindow.hpp" + #include #include -#include #include -#include "../common.h" -#include "../Context.h" -#include "ScWindow.hpp" +#include namespace OpenRCT2::Scripting { @@ -24,7 +25,7 @@ namespace OpenRCT2::Scripting namespace OpenRCT2::Ui::Windows { - rct_window * window_custom_open(std::shared_ptr owner, DukValue dukDesc); + rct_window* window_custom_open(std::shared_ptr owner, DukValue dukDesc); } namespace OpenRCT2::Scripting @@ -33,14 +34,21 @@ namespace OpenRCT2::Scripting { private: ScriptEngine& _scriptEngine; + public: ScUi(ScriptEngine& scriptEngine) : _scriptEngine(scriptEngine) { } - int32_t width_get() { return context_get_width(); } - int32_t height_get() { return context_get_height(); } + int32_t width_get() + { + return context_get_width(); + } + int32_t height_get() + { + return context_get_height(); + } int32_t windows_get() { return static_cast(g_window_list.size()); @@ -97,7 +105,7 @@ namespace OpenRCT2::Scripting return nullptr; } - static void Register(duk_context * ctx) + static void Register(duk_context* ctx) { dukglue_register_property(ctx, &ScUi::height_get, nullptr, "height"); dukglue_register_property(ctx, &ScUi::width_get, nullptr, "width"); @@ -114,4 +122,4 @@ namespace OpenRCT2::Scripting return WC_NULL; } }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2-ui/scripting/ScWindow.hpp b/src/openrct2-ui/scripting/ScWindow.hpp index ee834e516a..1925e7bf2e 100644 --- a/src/openrct2-ui/scripting/ScWindow.hpp +++ b/src/openrct2-ui/scripting/ScWindow.hpp @@ -9,11 +9,12 @@ #pragma once -#include #include "../common.h" #include "../interface/Window.h" #include "../interface/Window_internal.h" +#include + namespace OpenRCT2::Scripting { class ScWindow @@ -23,38 +24,50 @@ namespace OpenRCT2::Scripting rct_windownumber _number; public: - ScWindow(rct_window * w) + ScWindow(rct_window* w) : ScWindow(w->classification, w->number) { } ScWindow(rct_windowclass c, rct_windownumber n) - : _class(c), - _number(n) + : _class(c) + , _number(n) { } - int32_t x_get() { return GetWindow()->x; } + int32_t x_get() + { + return GetWindow()->x; + } void x_set(int32_t value) { auto w = GetWindow(); window_set_position(w, value, w->y); } - int32_t y_get() { return GetWindow()->y; } + int32_t y_get() + { + return GetWindow()->y; + } void y_set(int32_t value) { auto w = GetWindow(); window_set_position(w, w->x, value); } - int32_t width_get() { return GetWindow()->width; } - int32_t height_get() { return GetWindow()->height; } + int32_t width_get() + { + return GetWindow()->width; + } + int32_t height_get() + { + return GetWindow()->height; + } bool isSticky_get() { auto flags = GetWindow()->flags; return (flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) != 0; } - static void Register(duk_context * ctx) + static void Register(duk_context* ctx) { dukglue_register_property(ctx, &ScWindow::x_get, &ScWindow::x_set, "x"); dukglue_register_property(ctx, &ScWindow::y_get, &ScWindow::y_set, "y"); @@ -64,9 +77,9 @@ namespace OpenRCT2::Scripting } private: - rct_window * GetWindow() const + rct_window* GetWindow() const { return window_find_by_number(_class, _number); } }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2-ui/scripting/UiExtensions.cpp b/src/openrct2-ui/scripting/UiExtensions.cpp index 667d0eb9fe..773d466cd8 100644 --- a/src/openrct2-ui/scripting/UiExtensions.cpp +++ b/src/openrct2-ui/scripting/UiExtensions.cpp @@ -7,11 +7,13 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include #include "UiExtensions.h" + #include "ScUi.hpp" #include "ScWindow.hpp" +#include + using namespace OpenRCT2::Scripting; void UiScriptExtensions::Extend(ScriptEngine& scriptEngine) diff --git a/src/openrct2-ui/scripting/UiExtensions.h b/src/openrct2-ui/scripting/UiExtensions.h index fc361da666..4f9fbfcd45 100644 --- a/src/openrct2-ui/scripting/UiExtensions.h +++ b/src/openrct2-ui/scripting/UiExtensions.h @@ -18,4 +18,4 @@ namespace OpenRCT2::Scripting public: static void Extend(ScriptEngine& scriptEngine); }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2/core/FileWatcher.cpp b/src/openrct2/core/FileWatcher.cpp index 9b989cedd0..6725870cf8 100644 --- a/src/openrct2/core/FileWatcher.cpp +++ b/src/openrct2/core/FileWatcher.cpp @@ -8,17 +8,17 @@ *****************************************************************************/ #include -#include #include +#include #ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include +# define WIN32_LEAN_AND_MEAN +# include #else -#include -#include -#include -#include +# include +# include +# include +# include #endif #include "../core/String.hpp" @@ -61,9 +61,9 @@ void FileWatcher::FileDescriptor::Close() } FileWatcher::WatchDescriptor::WatchDescriptor(int fd, const std::string& path) - : Fd(fd), - Wd(inotify_add_watch(fd, path.c_str(), IN_CLOSE_WRITE)), - Path(path) + : Fd(fd) + , Wd(inotify_add_watch(fd, path.c_str(), IN_CLOSE_WRITE)) + , Path(path) { if (Wd >= 0) { @@ -83,11 +83,13 @@ FileWatcher::WatchDescriptor::~WatchDescriptor() } #endif -FileWatcher::FileWatcher(const std::string &directoryPath) +FileWatcher::FileWatcher(const std::string& directoryPath) { #ifdef _WIN32 _path = directoryPath; - _directoryHandle = CreateFileA(directoryPath.c_str(), FILE_LIST_DIRECTORY, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr); + _directoryHandle = CreateFileA( + directoryPath.c_str(), FILE_LIST_DIRECTORY, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, + nullptr); if (_directoryHandle == INVALID_HANDLE_VALUE) { throw std::runtime_error("Unable to open directory '" + directoryPath + "'"); @@ -123,12 +125,14 @@ void FileWatcher::WatchDirectory() #ifdef _WIN32 std::array eventData; DWORD bytesReturned; - while (ReadDirectoryChangesW(_directoryHandle, eventData.data(), (DWORD)eventData.size(), TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE, &bytesReturned, nullptr, nullptr)) + while (ReadDirectoryChangesW( + _directoryHandle, eventData.data(), (DWORD)eventData.size(), TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE, &bytesReturned, + nullptr, nullptr)) { auto onFileChanged = OnFileChanged; if (onFileChanged) { - FILE_NOTIFY_INFORMATION * notifyInfo; + FILE_NOTIFY_INFORMATION* notifyInfo; size_t offset = 0; do { @@ -139,8 +143,7 @@ void FileWatcher::WatchDirectory() auto fileName = String::ToUtf8(fileNameW); auto path = fs::path(_path) / fs::path(fileName); onFileChanged(path.u8string()); - } - while (notifyInfo->NextEntryOffset != 0); + } while (notifyInfo->NextEntryOffset != 0); } } #else @@ -165,11 +168,9 @@ void FileWatcher::WatchDirectory() // Find watch descriptor int wd = e->wd; - auto findResult = std::find_if(_watchDescs.begin(), _watchDescs.end(), - [wd](const WatchDescriptor& watchDesc) - { - return wd == watchDesc.Wd; - }); + auto findResult = std::find_if( + _watchDescs.begin(), _watchDescs.end(), + [wd](const WatchDescriptor& watchDesc) { return wd == watchDesc.Wd; }); if (findResult != _watchDescs.end()) { auto directory = findResult->Path; diff --git a/src/openrct2/core/FileWatcher.h b/src/openrct2/core/FileWatcher.h index 4d977be4be..1db80379db 100644 --- a/src/openrct2/core/FileWatcher.h +++ b/src/openrct2/core/FileWatcher.h @@ -15,7 +15,7 @@ #include #ifdef _WIN32 -typedef void * HANDLE; +typedef void* HANDLE; #endif /** @@ -53,9 +53,9 @@ private: #endif public: - std::function OnFileChanged; + std::function OnFileChanged; - FileWatcher(const std::string &directoryPath); + FileWatcher(const std::string& directoryPath); ~FileWatcher(); private: diff --git a/src/openrct2/interface/StdInOutConsole.cpp b/src/openrct2/interface/StdInOutConsole.cpp index c4338d98bb..a52d9dc346 100644 --- a/src/openrct2/interface/StdInOutConsole.cpp +++ b/src/openrct2/interface/StdInOutConsole.cpp @@ -7,13 +7,14 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include #include "../Context.h" #include "../OpenRCT2.h" #include "../platform/Platform2.h" #include "../scripting/ScriptEngine.h" #include "InteractiveConsole.h" +#include + using namespace OpenRCT2; void StdInOutConsole::Start() diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index ee60345b1e..fa3ddbedf6 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -69,7 +69,7 @@ namespace WIDGET_FLAGS { const WidgetFlags TEXT_IS_STRING = 1 << 0; const WidgetFlags IS_ENABLED = 1 << 1; -} +} // namespace WIDGET_FLAGS /** * Widget structure diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index 1ba55eab3c..7e64440a55 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -55,7 +55,7 @@ struct rct_window scenery_variables scenery; track_list_variables track_list; error_variables error; - void * custom_info; + void* custom_info; }; int16_t page; union diff --git a/src/openrct2/scripting/HookEngine.cpp b/src/openrct2/scripting/HookEngine.cpp index b6a1823e4f..3ef3f239e6 100644 --- a/src/openrct2/scripting/HookEngine.cpp +++ b/src/openrct2/scripting/HookEngine.cpp @@ -7,26 +7,26 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include #include "HookEngine.h" + #include "ScriptEngine.h" +#include + using namespace OpenRCT2::Scripting; -HOOK_TYPE OpenRCT2::Scripting::GetHookType(const std::string &name) +HOOK_TYPE OpenRCT2::Scripting::GetHookType(const std::string& name) { static const std::unordered_map LookupTable({ { "interval.tick", HOOK_TYPE::INTERVAL_TICK }, { "interval.day", HOOK_TYPE::INTERVAL_DAY }, }); auto result = LookupTable.find(name); - return (result != LookupTable.end()) ? - result->second : - HOOK_TYPE::UNDEFINED; + return (result != LookupTable.end()) ? result->second : HOOK_TYPE::UNDEFINED; } -HookEngine::HookEngine(ScriptExecutionInfo& execInfo) : - _execInfo(execInfo) +HookEngine::HookEngine(ScriptExecutionInfo& execInfo) + : _execInfo(execInfo) { _hookMap.resize(NUM_HOOK_TYPES); for (size_t i = 0; i < NUM_HOOK_TYPES; i++) @@ -35,7 +35,7 @@ HookEngine::HookEngine(ScriptExecutionInfo& execInfo) : } } -uint32_t HookEngine::Subscribe(HOOK_TYPE type, std::shared_ptr owner, const DukValue &function) +uint32_t HookEngine::Subscribe(HOOK_TYPE type, std::shared_ptr owner, const DukValue& function) { auto& hookList = GetHookList(type); auto cookie = _nextCookie++; diff --git a/src/openrct2/scripting/HookEngine.h b/src/openrct2/scripting/HookEngine.h index 24cdd36d89..ed426a42c6 100644 --- a/src/openrct2/scripting/HookEngine.h +++ b/src/openrct2/scripting/HookEngine.h @@ -10,10 +10,11 @@ #pragma once #include "../common.h" + +#include #include #include #include -#include namespace OpenRCT2::Scripting { @@ -28,7 +29,7 @@ namespace OpenRCT2::Scripting UNDEFINED = -1, }; constexpr size_t NUM_HOOK_TYPES = static_cast(HOOK_TYPE::COUNT); - HOOK_TYPE GetHookType(const std::string &name); + HOOK_TYPE GetHookType(const std::string& name); struct Hook { @@ -37,10 +38,10 @@ namespace OpenRCT2::Scripting DukValue Function; Hook(); - Hook(uint32_t cookie, std::shared_ptr owner, const DukValue &function) - : Cookie(cookie), - Owner(owner), - Function(function) + Hook(uint32_t cookie, std::shared_ptr owner, const DukValue& function) + : Cookie(cookie) + , Owner(owner) + , Function(function) { } }; @@ -50,11 +51,13 @@ namespace OpenRCT2::Scripting HOOK_TYPE Type; std::vector Hooks; - HookList() {} + HookList() + { + } HookList(const HookList&) = delete; HookList(HookList&& src) - : Type(std::move(src.Type)), - Hooks(std::move(src.Hooks)) + : Type(std::move(src.Type)) + , Hooks(std::move(src.Hooks)) { } }; @@ -70,7 +73,7 @@ namespace OpenRCT2::Scripting public: HookEngine(ScriptExecutionInfo& execInfo); HookEngine(const HookEngine&) = delete; - uint32_t Subscribe(HOOK_TYPE type, std::shared_ptr owner, const DukValue &function); + uint32_t Subscribe(HOOK_TYPE type, std::shared_ptr owner, const DukValue& function); void Unsubscribe(HOOK_TYPE type, uint32_t cookie); void UnsubscribeAll(std::shared_ptr owner); void Call(HOOK_TYPE type); @@ -78,4 +81,4 @@ namespace OpenRCT2::Scripting private: HookList& GetHookList(HOOK_TYPE type); }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2/scripting/Plugin.cpp b/src/openrct2/scripting/Plugin.cpp index 4367e02514..234c8a3e7f 100644 --- a/src/openrct2/scripting/Plugin.cpp +++ b/src/openrct2/scripting/Plugin.cpp @@ -8,26 +8,27 @@ *****************************************************************************/ #include "Plugin.h" + +#include #include #include -#include #include #include #ifdef _WIN32 - + #else - #include - #include - #include - #include +# include +# include +# include +# include #endif using namespace OpenRCT2::Scripting; -Plugin::Plugin(duk_context * context, const std::string &path) - : _context(context), - _path(path) +Plugin::Plugin(duk_context* context, const std::string& path) + : _context(context) + , _path(path) { } @@ -39,12 +40,10 @@ void Plugin::Load() std::ifstream fs(_path); if (fs.is_open()) { - fs.seekg(0, std::ios::end); + fs.seekg(0, std::ios::end); code.reserve(fs.tellg()); fs.seekg(0, std::ios::beg); - code.assign( - std::istreambuf_iterator(fs), - std::istreambuf_iterator()); + code.assign(std::istreambuf_iterator(fs), std::istreambuf_iterator()); } } // Wrap the script in a function and pass the global objects as variables @@ -98,11 +97,9 @@ PluginMetadata Plugin::GetMetadata(const DukValue& dukMetadata) if (dukAuthors.is_array()) { auto elements = dukAuthors.as_array(); - std::transform( - elements.begin(), - elements.end(), - std::back_inserter(metadata.Authors), - [](const DukValue& v) { return v.as_string(); }); + std::transform(elements.begin(), elements.end(), std::back_inserter(metadata.Authors), [](const DukValue& v) { + return v.as_string(); + }); } else { diff --git a/src/openrct2/scripting/Plugin.h b/src/openrct2/scripting/Plugin.h index 99171e4540..c95ca31315 100644 --- a/src/openrct2/scripting/Plugin.h +++ b/src/openrct2/scripting/Plugin.h @@ -9,10 +9,10 @@ #pragma once +#include #include #include #include -#include namespace OpenRCT2::Scripting { @@ -27,15 +27,20 @@ namespace OpenRCT2::Scripting class Plugin { private: - duk_context * _context; + duk_context* _context; std::string _path; PluginMetadata _metadata; public: - std::string GetPath() const { return _path; }; + std::string GetPath() const + { + return _path; + }; - Plugin() { } - Plugin(duk_context * context, const std::string &path); + Plugin() + { + } + Plugin(duk_context* context, const std::string& path); Plugin(const Plugin&) = delete; Plugin(Plugin&&) = delete; @@ -46,4 +51,4 @@ namespace OpenRCT2::Scripting private: static PluginMetadata GetMetadata(const DukValue& dukMetadata); }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2/scripting/ScConsole.hpp b/src/openrct2/scripting/ScConsole.hpp index ceee2643da..c6fb8038e0 100644 --- a/src/openrct2/scripting/ScConsole.hpp +++ b/src/openrct2/scripting/ScConsole.hpp @@ -9,9 +9,8 @@ #pragma once -#include -#include "../interface/InteractiveConsole.h" #include "../core/Math.hpp" +#include "../interface/InteractiveConsole.h" #include @@ -38,9 +37,15 @@ namespace OpenRCT2::Scripting std::string str; switch (val.type()) { - case DukValue::Type::UNDEFINED: str = "undefined"; break; - case DukValue::Type::NULLREF: str = "null"; break; - case DukValue::Type::BOOLEAN: str = val.as_bool() ? "true" : "false"; break; + case DukValue::Type::UNDEFINED: + str = "undefined"; + break; + case DukValue::Type::NULLREF: + str = "null"; + break; + case DukValue::Type::BOOLEAN: + str = val.as_bool() ? "true" : "false"; + break; case DukValue::Type::NUMBER: { const auto d = val.as_double(); @@ -55,11 +60,20 @@ namespace OpenRCT2::Scripting } break; } - case DukValue::Type::STRING: str = val.as_string(); break; - case DukValue::Type::OBJECT: str = "{}"; break; - case DukValue::Type::BUFFER: str = "buffer"; break; - case DukValue::Type::POINTER: str = "pointer"; break; - case DukValue::Type::LIGHTFUNC: break; + case DukValue::Type::STRING: + str = val.as_string(); + break; + case DukValue::Type::OBJECT: + str = "{}"; + break; + case DukValue::Type::BUFFER: + str = "buffer"; + break; + case DukValue::Type::POINTER: + str = "pointer"; + break; + case DukValue::Type::LIGHTFUNC: + break; } _console.WriteLine(str); diff --git a/src/openrct2/scripting/ScContext.hpp b/src/openrct2/scripting/ScContext.hpp index 1cd1fdd638..85b8de1956 100644 --- a/src/openrct2/scripting/ScContext.hpp +++ b/src/openrct2/scripting/ScContext.hpp @@ -9,11 +9,12 @@ #pragma once -#include #include "HookEngine.h" #include "ScDisposable.hpp" #include "ScriptEngine.h" + #include +#include #include namespace OpenRCT2::Scripting @@ -26,8 +27,8 @@ namespace OpenRCT2::Scripting public: ScContext(ScriptExecutionInfo& execInfo, HookEngine& hookEngine) - : _execInfo(execInfo), - _hookEngine(hookEngine) + : _execInfo(execInfo) + , _hookEngine(hookEngine) { } @@ -35,7 +36,7 @@ namespace OpenRCT2::Scripting { } - std::shared_ptr subscribe(const std::string &hook, const DukValue &callback) + std::shared_ptr subscribe(const std::string& hook, const DukValue& callback) { auto hookType = GetHookType(hook); if (hookType == HOOK_TYPE::UNDEFINED) @@ -55,17 +56,13 @@ namespace OpenRCT2::Scripting } auto cookie = _hookEngine.Subscribe(hookType, owner, callback); - return std::make_shared( - [this, hookType, cookie]() - { - _hookEngine.Unsubscribe(hookType, cookie); - }); + return std::make_shared([this, hookType, cookie]() { _hookEngine.Unsubscribe(hookType, cookie); }); } - static void Register(duk_context * ctx) + static void Register(duk_context* ctx) { dukglue_register_method(ctx, &ScContext::registerIntent, "registerIntent"); dukglue_register_method(ctx, &ScContext::subscribe, "subscribe"); } }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2/scripting/ScDisposable.hpp b/src/openrct2/scripting/ScDisposable.hpp index a285d05018..7e2840710b 100644 --- a/src/openrct2/scripting/ScDisposable.hpp +++ b/src/openrct2/scripting/ScDisposable.hpp @@ -20,8 +20,8 @@ namespace OpenRCT2::Scripting std::function _onDispose; public: - ScDisposable(std::function onDispose) : - _onDispose(onDispose) + ScDisposable(std::function onDispose) + : _onDispose(onDispose) { } @@ -33,9 +33,9 @@ namespace OpenRCT2::Scripting } } - static void Register(duk_context * ctx) + static void Register(duk_context* ctx) { dukglue_register_method(ctx, &ScDisposable::dispose, "dispose"); } }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2/scripting/ScMap.hpp b/src/openrct2/scripting/ScMap.hpp index 989eb61105..84866ac2f6 100644 --- a/src/openrct2/scripting/ScMap.hpp +++ b/src/openrct2/scripting/ScMap.hpp @@ -9,22 +9,23 @@ #pragma once -#include #include "../common.h" #include "../ride/Ride.h" #include "../world/Map.h" -#include "ScTile.hpp" #include "ScThing.hpp" +#include "ScTile.hpp" + +#include namespace OpenRCT2::Scripting { class ScMap { private: - duk_context * _context; + duk_context* _context; public: - ScMap(duk_context * ctx) + ScMap(duk_context* ctx) : _context(ctx) { } @@ -69,7 +70,7 @@ namespace OpenRCT2::Scripting return nullptr; } - static void Register(duk_context * ctx) + static void Register(duk_context* ctx) { dukglue_register_property(ctx, &ScMap::size_get, nullptr, "size"); dukglue_register_property(ctx, &ScMap::rides_get, nullptr, "rides"); @@ -78,4 +79,4 @@ namespace OpenRCT2::Scripting dukglue_register_method(ctx, &ScMap::getThing, "getThing"); } }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2/scripting/ScPark.hpp b/src/openrct2/scripting/ScPark.hpp index 67ddf6ec82..bc966afb7f 100644 --- a/src/openrct2/scripting/ScPark.hpp +++ b/src/openrct2/scripting/ScPark.hpp @@ -9,21 +9,25 @@ #pragma once -#include -#include -#include "../common.h" #include "../Context.h" +#include "../common.h" #include "../management/Finance.h" #include "../management/NewsItem.h" #include "../windows/Intent.h" #include "../world/Park.h" +#include +#include + namespace OpenRCT2::Scripting { class ScPark { public: - money32 cash_get() { return gCash; } + money32 cash_get() + { + return gCash; + } void cash_set(money32 value) { gCash = value; @@ -31,7 +35,10 @@ namespace OpenRCT2::Scripting context_broadcast_intent(&intent); } - int32_t rating_get() { return gParkRating; } + int32_t rating_get() + { + return gParkRating; + } void rating_set(int32_t value) { gParkRating = std::min(std::max(0, value), 999); @@ -39,7 +46,10 @@ namespace OpenRCT2::Scripting context_broadcast_intent(&intent); } - money32 bankLoan_get() { return gBankLoan; } + money32 bankLoan_get() + { + return gBankLoan; + } void bankLoan_set(money32 value) { gBankLoan = value; @@ -47,7 +57,10 @@ namespace OpenRCT2::Scripting context_broadcast_intent(&intent); } - money32 maxBankLoan_get() { return gMaxBankLoan; } + money32 maxBankLoan_get() + { + return gMaxBankLoan; + } void maxBankLoan_set(money32 value) { gMaxBankLoan = value; @@ -77,7 +90,7 @@ namespace OpenRCT2::Scripting } } - static void Register(duk_context * ctx) + static void Register(duk_context* ctx) { dukglue_register_property(ctx, &ScPark::cash_get, &ScPark::cash_set, "cash"); dukglue_register_property(ctx, &ScPark::rating_get, &ScPark::rating_set, "rating"); @@ -89,16 +102,8 @@ namespace OpenRCT2::Scripting private: uint8_t GetParkMessageType(const std::string& key) { - static auto keys = { - "attraction", - "peep_on_attraction", - "peep", - "money", - "blank", - "research", - "guests", - "award", - "chart" }; + static auto keys = { "attraction", "peep_on_attraction", "peep", "money", "blank", "research", "guests", "award", + "chart" }; uint8_t i = 0; for (const auto& k : keys) { @@ -111,4 +116,4 @@ namespace OpenRCT2::Scripting return NEWS_ITEM_BLANK; } }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2/scripting/ScThing.hpp b/src/openrct2/scripting/ScThing.hpp index 0de40ee18f..f6d14cff8a 100644 --- a/src/openrct2/scripting/ScThing.hpp +++ b/src/openrct2/scripting/ScThing.hpp @@ -9,19 +9,20 @@ #pragma once -#include #include "../common.h" #include "../world/Sprite.h" +#include + namespace OpenRCT2::Scripting { class ScThing { private: - rct_sprite * _sprite; + rct_sprite* _sprite; public: - ScThing(rct_sprite * sprite) + ScThing(rct_sprite* sprite) : _sprite(sprite) { } @@ -35,16 +36,37 @@ namespace OpenRCT2::Scripting return "unknown"; } - int32_t x_get() { return _sprite->unknown.x; } - int32_t y_get() { return _sprite->unknown.y; } - int32_t z_get() { return _sprite->unknown.z; } + int32_t x_get() + { + return _sprite->unknown.x; + } + int32_t y_get() + { + return _sprite->unknown.y; + } + int32_t z_get() + { + return _sprite->unknown.z; + } - uint8_t tshirtColour_get() { return _sprite->peep.tshirt_colour; } - void tshirtColour_set(uint8_t value) { _sprite->peep.tshirt_colour = value; } - uint8_t trousersColour_get() { return _sprite->peep.trousers_colour; } - void trousersColour_set(uint8_t value) { _sprite->peep.trousers_colour = value; } + uint8_t tshirtColour_get() + { + return _sprite->peep.tshirt_colour; + } + void tshirtColour_set(uint8_t value) + { + _sprite->peep.tshirt_colour = value; + } + uint8_t trousersColour_get() + { + return _sprite->peep.trousers_colour; + } + void trousersColour_set(uint8_t value) + { + _sprite->peep.trousers_colour = value; + } - static void Register(duk_context * ctx) + static void Register(duk_context* ctx) { dukglue_register_property(ctx, &ScThing::type_get, nullptr, "type"); dukglue_register_property(ctx, &ScThing::x_get, nullptr, "x"); @@ -54,4 +76,4 @@ namespace OpenRCT2::Scripting dukglue_register_property(ctx, &ScThing::trousersColour_get, &ScThing::trousersColour_set, "trousersColour"); } }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2/scripting/ScTile.hpp b/src/openrct2/scripting/ScTile.hpp index 39ba7d5a3c..78661aef0d 100644 --- a/src/openrct2/scripting/ScTile.hpp +++ b/src/openrct2/scripting/ScTile.hpp @@ -9,20 +9,21 @@ #pragma once -#include #include "../common.h" #include "../world/Sprite.h" + #include +#include namespace OpenRCT2::Scripting { class ScTileElement { protected: - rct_tile_element * _element; + rct_tile_element* _element; public: - ScTileElement(rct_tile_element * element) + ScTileElement(rct_tile_element* element) : _element(element) { } @@ -31,21 +32,30 @@ namespace OpenRCT2::Scripting { switch (_element->GetType()) { - case TILE_ELEMENT_TYPE_SURFACE: return "surface"; - case TILE_ELEMENT_TYPE_PATH: return "footpath"; - case TILE_ELEMENT_TYPE_TRACK: return "track"; - case TILE_ELEMENT_TYPE_SMALL_SCENERY: return "small-scenery"; - case TILE_ELEMENT_TYPE_ENTRANCE: return "entrance"; - case TILE_ELEMENT_TYPE_WALL: return "wall"; - case TILE_ELEMENT_TYPE_LARGE_SCENERY: return "large-scenery"; - case TILE_ELEMENT_TYPE_BANNER: return "banner"; - case TILE_ELEMENT_TYPE_CORRUPT: return "openrct2-corrupt"; - default: return "unknown"; + case TILE_ELEMENT_TYPE_SURFACE: + return "surface"; + case TILE_ELEMENT_TYPE_PATH: + return "footpath"; + case TILE_ELEMENT_TYPE_TRACK: + return "track"; + case TILE_ELEMENT_TYPE_SMALL_SCENERY: + return "small-scenery"; + case TILE_ELEMENT_TYPE_ENTRANCE: + return "entrance"; + case TILE_ELEMENT_TYPE_WALL: + return "wall"; + case TILE_ELEMENT_TYPE_LARGE_SCENERY: + return "large-scenery"; + case TILE_ELEMENT_TYPE_BANNER: + return "banner"; + case TILE_ELEMENT_TYPE_CORRUPT: + return "openrct2-corrupt"; + default: + return "unknown"; } } - template - T* getAs() + template T* getAs() { return static_cast(this); } @@ -85,8 +95,7 @@ namespace OpenRCT2::Scripting } static void Register(duk_context* ctx); - template - static void RegisterSharedProperties(duk_context* ctx); + template static void RegisterSharedProperties(duk_context* ctx); }; class ScSurfaceElement final : public ScTileElement @@ -190,38 +199,31 @@ namespace OpenRCT2::Scripting ScBannerElement ::Register(ctx); } - template - void ScTileElement::RegisterSharedProperties(duk_context* ctx) + template void ScTileElement::RegisterSharedProperties(duk_context* ctx) { // When you register a member function of a parent class, it belongs to the parent and cannot be accessed by its // children. To get around this issue, we need to force the function pointer types to be of the class we want them to be // available for. This needs to be done for every child. dukglue_register_property(ctx, static_cast(&ScTileElement::type_get), nullptr, "type"); dukglue_register_property( - ctx, - static_cast(&ScTileElement::broken_get), - static_cast(&ScTileElement::broken_set), - "broken"); + ctx, static_cast(&ScTileElement::broken_get), + static_cast(&ScTileElement::broken_set), "broken"); dukglue_register_property( - ctx, - static_cast(&ScTileElement::baseHeight_get), - static_cast(&ScTileElement::baseHeight_set), - "baseHeight"); + ctx, static_cast(&ScTileElement::baseHeight_get), + static_cast(&ScTileElement::baseHeight_set), "baseHeight"); dukglue_register_property( - ctx, - static_cast(&ScTileElement::clearanceHeight_get), - static_cast(&ScTileElement::clearanceHeight_set), - "clearanceHeight"); + ctx, static_cast(&ScTileElement::clearanceHeight_get), + static_cast(&ScTileElement::clearanceHeight_set), "clearanceHeight"); } class ScTile { private: - rct_tile_element * _first; + rct_tile_element* _first; size_t _count = 0; public: - ScTile(rct_tile_element * first) + ScTile(rct_tile_element* first) : _first(first) { _count = 0; @@ -231,16 +233,19 @@ namespace OpenRCT2::Scripting do { _count++; - } - while (!(element++)->IsLastForTile()); + } while (!(element++)->IsLastForTile()); } } - size_t numElements_get() { return _count; } + size_t numElements_get() + { + return _count; + } std::shared_ptr getElement(size_t index) { - if (index >= _count) return nullptr; + if (index >= _count) + return nullptr; return std::make_shared(&_first[index]); } @@ -256,11 +261,11 @@ namespace OpenRCT2::Scripting // return elements; // } - static void Register(duk_context * ctx) + static void Register(duk_context* ctx) { // dukglue_register_property(ctx, &ScTile::elements_get, nullptr, "elements"); dukglue_register_property(ctx, &ScTile::numElements_get, nullptr, "numElements"); dukglue_register_method(ctx, &ScTile::getElement, "getElement"); } }; -} +} // namespace OpenRCT2::Scripting diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 7d4d4999cc..b413227f8a 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -8,28 +8,29 @@ *****************************************************************************/ #include "ScriptEngine.h" + +#include "../PlatformEnvironment.h" #include "../core/FileScanner.h" #include "../core/Path.hpp" #include "../interface/InteractiveConsole.h" #include "../platform/Platform2.h" -#include "../PlatformEnvironment.h" -#include -#include -#include -#include - #include "ScConsole.hpp" #include "ScContext.hpp" #include "ScDisposable.hpp" #include "ScMap.hpp" #include "ScPark.hpp" -#include "ScTile.hpp" #include "ScThing.hpp" +#include "ScTile.hpp" + +#include +#include +#include +#include using namespace OpenRCT2; using namespace OpenRCT2::Scripting; -static std::string Stringify(duk_context * ctx, duk_idx_t idx); +static std::string Stringify(duk_context* ctx, duk_idx_t idx); DukContext::DukContext() { @@ -45,10 +46,10 @@ DukContext::~DukContext() duk_destroy_heap(_context); } -ScriptEngine::ScriptEngine(InteractiveConsole& console, IPlatformEnvironment& env) : - _console(console), - _env(env), - _hookEngine(_execInfo) +ScriptEngine::ScriptEngine(InteractiveConsole& console, IPlatformEnvironment& env) + : _console(console) + , _env(env) + , _hookEngine(_execInfo) { } @@ -88,7 +89,7 @@ void ScriptEngine::LoadPlugins() plugin->Load(); _plugins.push_back(std::move(plugin)); } - catch (const std::exception &e) + catch (const std::exception& e) { _console.WriteLineError(e.what()); } @@ -98,12 +99,10 @@ void ScriptEngine::LoadPlugins() { // Enable hot reloading _pluginFileWatcher = std::make_unique(base); - _pluginFileWatcher->OnFileChanged = - [this](const std::string &path) - { - std::lock_guard guard(_changedPluginFilesMutex); - _changedPluginFiles.push_back(path); - }; + _pluginFileWatcher->OnFileChanged = [this](const std::string& path) { + std::lock_guard guard(_changedPluginFilesMutex); + _changedPluginFiles.push_back(path); + }; } catch (const std::exception& e) { @@ -118,11 +117,9 @@ void ScriptEngine::AutoReloadPlugins() std::lock_guard guard(_changedPluginFilesMutex); for (auto& path : _changedPluginFiles) { - auto findResult = std::find_if(_plugins.begin(), _plugins.end(), - [&path](const std::shared_ptr& plugin) - { - return Path::Equals(path, plugin->GetPath()); - }); + auto findResult = std::find_if(_plugins.begin(), _plugins.end(), [&path](const std::shared_ptr& plugin) { + return Path::Equals(path, plugin->GetPath()); + }); if (findResult != _plugins.end()) { auto& plugin = *findResult; @@ -134,7 +131,7 @@ void ScriptEngine::AutoReloadPlugins() plugin->Load(); plugin->Start(); } - catch (const std::exception &e) + catch (const std::exception& e) { _console.WriteLineError(e.what()); } @@ -153,7 +150,7 @@ void ScriptEngine::StartPlugins() { plugin->Start(); } - catch (const std::exception &e) + catch (const std::exception& e) { _console.WriteLineError(e.what()); } @@ -196,7 +193,7 @@ void ScriptEngine::Update() } } -std::future ScriptEngine::Eval(const std::string &s) +std::future ScriptEngine::Eval(const std::string& s) { std::promise barrier; auto future = barrier.get_future(); @@ -204,7 +201,7 @@ std::future ScriptEngine::Eval(const std::string &s) return future; } -static std::string Stringify(duk_context * ctx, duk_idx_t idx) +static std::string Stringify(duk_context* ctx, duk_idx_t idx) { auto type = duk_get_type(ctx, idx); if (type == DUK_TYPE_OBJECT && !duk_is_function(ctx, idx)) diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 04318f87e9..551ba200bc 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -13,6 +13,7 @@ #include "../core/FileWatcher.h" #include "HookEngine.h" #include "Plugin.h" + #include #include #include @@ -47,8 +48,8 @@ namespace OpenRCT2::Scripting public: PluginScope(ScriptExecutionInfo& execInfo, std::shared_ptr plugin) - : _execInfo(execInfo), - _plugin(plugin) + : _execInfo(execInfo) + , _plugin(plugin) { _execInfo._plugin = plugin; } @@ -59,13 +60,16 @@ namespace OpenRCT2::Scripting } }; - std::shared_ptr GetCurrentPlugin() { return _plugin; } + std::shared_ptr GetCurrentPlugin() + { + return _plugin; + } }; class DukContext { private: - duk_context * _context{}; + duk_context* _context{}; public: DukContext(); @@ -76,7 +80,10 @@ namespace OpenRCT2::Scripting } ~DukContext(); - operator duk_context*() { return _context; } + operator duk_context*() + { + return _context; + } }; class ScriptEngine @@ -100,12 +107,21 @@ namespace OpenRCT2::Scripting ScriptEngine(InteractiveConsole& console, IPlatformEnvironment& env); ScriptEngine(ScriptEngine&) = delete; - duk_context * GetContext() { return _context; } - HookEngine& GetHookEngine() { return _hookEngine; } - ScriptExecutionInfo& GetExecInfo() { return _execInfo; } + duk_context* GetContext() + { + return _context; + } + HookEngine& GetHookEngine() + { + return _hookEngine; + } + ScriptExecutionInfo& GetExecInfo() + { + return _execInfo; + } void Update(); - std::future Eval(const std::string &s); + std::future Eval(const std::string& s); private: void Initialise(); @@ -113,4 +129,4 @@ namespace OpenRCT2::Scripting void StartPlugins(); void AutoReloadPlugins(); }; -} +} // namespace OpenRCT2::Scripting