mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
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.
This commit is contained in:
@@ -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 <limits>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <openrct2-ui/interface/Widget.h>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include <openrct2/drawing/Drawing.h>
|
||||
#include <openrct2/localisation/Localisation.h>
|
||||
#include <openrct2/localisation/StringIds.h>
|
||||
#include <openrct2/scripting/Plugin.h>
|
||||
#include <openrct2-ui/interface/Widget.h>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include "../interface/Dropdown.h"
|
||||
#include "ScUi.hpp"
|
||||
#include "ScWindow.hpp"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Scripting;
|
||||
@@ -50,9 +51,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
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,
|
||||
static rct_window_event_list window_custom_events = { window_custom_close,
|
||||
window_custom_mouseup,
|
||||
window_custom_resize,
|
||||
window_custom_mousedown,
|
||||
@@ -79,8 +78,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
nullptr,
|
||||
window_custom_invalidate,
|
||||
window_custom_paint,
|
||||
nullptr
|
||||
};
|
||||
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<int32_t> 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,14 +190,11 @@ namespace OpenRCT2::Ui::Windows
|
||||
std::vector<size_t> WidgetIndexMap;
|
||||
|
||||
CustomWindowInfo(
|
||||
rct_windowclass cls,
|
||||
rct_windownumber number,
|
||||
std::shared_ptr<Plugin> owner,
|
||||
const CustomWindowDesc& desc)
|
||||
: _class(cls),
|
||||
_number(number),
|
||||
Owner(owner),
|
||||
Desc(desc)
|
||||
rct_windowclass cls, rct_windownumber number, std::shared_ptr<Plugin> owner, const CustomWindowDesc& desc)
|
||||
: _class(cls)
|
||||
, _number(number)
|
||||
, Owner(owner)
|
||||
, Desc(desc)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -226,7 +220,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
static rct_windownumber GetNewWindowNumber();
|
||||
static void RefreshWidgets(rct_window* w);
|
||||
static void InvokeEventHandler(std::shared_ptr<Plugin> owner, const DukValue& dukHandler);
|
||||
static void InvokeEventHandler(std::shared_ptr<Plugin> owner, const DukValue& dukHandler, const std::vector<DukValue>& args);
|
||||
static void InvokeEventHandler(
|
||||
std::shared_ptr<Plugin> owner, const DukValue& dukHandler, const std::vector<DukValue>& args);
|
||||
|
||||
rct_window* window_custom_open(std::shared_ptr<Plugin> owner, DukValue dukDesc)
|
||||
{
|
||||
@@ -242,22 +237,11 @@ namespace OpenRCT2::Ui::Windows
|
||||
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();
|
||||
@@ -286,7 +270,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
static void window_custom_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
||||
{
|
||||
switch (widgetIndex) {
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_CLOSE:
|
||||
window_close(w);
|
||||
break;
|
||||
@@ -341,14 +326,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -521,4 +500,4 @@ namespace OpenRCT2::Ui::Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace OpenRCT2::Ui::Windows
|
||||
|
||||
@@ -9,13 +9,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Context.h"
|
||||
#include "../common.h"
|
||||
#include "ScWindow.hpp"
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <openrct2/scripting/ScriptEngine.h>
|
||||
#include "../common.h"
|
||||
#include "../Context.h"
|
||||
#include "ScWindow.hpp"
|
||||
#include <string>
|
||||
|
||||
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<int32_t>(g_window_list.size());
|
||||
@@ -114,4 +122,4 @@ namespace OpenRCT2::Scripting
|
||||
return WC_NULL;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include "../common.h"
|
||||
#include "../interface/Window.h"
|
||||
#include "../interface/Window_internal.h"
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
class ScWindow
|
||||
@@ -29,25 +30,37 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -69,4 +82,4 @@ namespace OpenRCT2::Scripting
|
||||
return window_find_by_number(_class, _number);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <openrct2/scripting/ScriptEngine.h>
|
||||
#include "UiExtensions.h"
|
||||
|
||||
#include "ScUi.hpp"
|
||||
#include "ScWindow.hpp"
|
||||
|
||||
#include <openrct2/scripting/ScriptEngine.h>
|
||||
|
||||
using namespace OpenRCT2::Scripting;
|
||||
|
||||
void UiScriptExtensions::Extend(ScriptEngine& scriptEngine)
|
||||
|
||||
@@ -18,4 +18,4 @@ namespace OpenRCT2::Scripting
|
||||
public:
|
||||
static void Extend(ScriptEngine& scriptEngine);
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
#include <experimental/filesystem>
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
@@ -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)
|
||||
{
|
||||
@@ -87,7 +87,9 @@ 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,7 +125,9 @@ void FileWatcher::WatchDirectory()
|
||||
#ifdef _WIN32
|
||||
std::array<char, 1024> 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)
|
||||
@@ -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;
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <linenoise.hpp>
|
||||
#include "../Context.h"
|
||||
#include "../OpenRCT2.h"
|
||||
#include "../platform/Platform2.h"
|
||||
#include "../scripting/ScriptEngine.h"
|
||||
#include "InteractiveConsole.h"
|
||||
|
||||
#include <linenoise.hpp>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
void StdInOutConsole::Start()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <unordered_map>
|
||||
#include "HookEngine.h"
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace OpenRCT2::Scripting;
|
||||
|
||||
HOOK_TYPE OpenRCT2::Scripting::GetHookType(const std::string& name)
|
||||
@@ -20,13 +22,11 @@ HOOK_TYPE OpenRCT2::Scripting::GetHookType(const std::string &name)
|
||||
{ "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++)
|
||||
|
||||
@@ -10,10 +10,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <dukglue/dukglue.h>
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
@@ -38,9 +39,9 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
Hook();
|
||||
Hook(uint32_t cookie, std::shared_ptr<Plugin> owner, const DukValue& function)
|
||||
: Cookie(cookie),
|
||||
Owner(owner),
|
||||
Function(function)
|
||||
: Cookie(cookie)
|
||||
, Owner(owner)
|
||||
, Function(function)
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -50,11 +51,13 @@ namespace OpenRCT2::Scripting
|
||||
HOOK_TYPE Type;
|
||||
std::vector<Hook> 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))
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -78,4 +81,4 @@ namespace OpenRCT2::Scripting
|
||||
private:
|
||||
HookList& GetHookList(HOOK_TYPE type);
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Plugin.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <dukglue/dukglue.h>
|
||||
#include <duktape.h>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
@@ -26,8 +27,8 @@
|
||||
using namespace OpenRCT2::Scripting;
|
||||
|
||||
Plugin::Plugin(duk_context* context, const std::string& path)
|
||||
: _context(context),
|
||||
_path(path)
|
||||
: _context(context)
|
||||
, _path(path)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -42,9 +43,7 @@ void Plugin::Load()
|
||||
fs.seekg(0, std::ios::end);
|
||||
code.reserve(fs.tellg());
|
||||
fs.seekg(0, std::ios::beg);
|
||||
code.assign(
|
||||
std::istreambuf_iterator<char>(fs),
|
||||
std::istreambuf_iterator<char>());
|
||||
code.assign(std::istreambuf_iterator<char>(fs), std::istreambuf_iterator<char>());
|
||||
}
|
||||
}
|
||||
// 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
|
||||
{
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <dukglue/dukglue.h>
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
@@ -32,9 +32,14 @@ namespace OpenRCT2::Scripting
|
||||
PluginMetadata _metadata;
|
||||
|
||||
public:
|
||||
std::string GetPath() const { return _path; };
|
||||
std::string GetPath() const
|
||||
{
|
||||
return _path;
|
||||
};
|
||||
|
||||
Plugin() { }
|
||||
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
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include "../interface/InteractiveConsole.h"
|
||||
#include "../core/Math.hpp"
|
||||
#include "../interface/InteractiveConsole.h"
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include "HookEngine.h"
|
||||
#include "ScDisposable.hpp"
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <dukglue/dukglue.h>
|
||||
#include <memory>
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
@@ -26,8 +27,8 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
public:
|
||||
ScContext(ScriptExecutionInfo& execInfo, HookEngine& hookEngine)
|
||||
: _execInfo(execInfo),
|
||||
_hookEngine(hookEngine)
|
||||
: _execInfo(execInfo)
|
||||
, _hookEngine(hookEngine)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -55,11 +56,7 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
|
||||
auto cookie = _hookEngine.Subscribe(hookType, owner, callback);
|
||||
return std::make_shared<ScDisposable>(
|
||||
[this, hookType, cookie]()
|
||||
{
|
||||
_hookEngine.Unsubscribe(hookType, cookie);
|
||||
});
|
||||
return std::make_shared<ScDisposable>([this, hookType, cookie]() { _hookEngine.Unsubscribe(hookType, cookie); });
|
||||
}
|
||||
|
||||
static void Register(duk_context* ctx)
|
||||
@@ -68,4 +65,4 @@ namespace OpenRCT2::Scripting
|
||||
dukglue_register_method(ctx, &ScContext::subscribe, "subscribe");
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace OpenRCT2::Scripting
|
||||
std::function<void()> _onDispose;
|
||||
|
||||
public:
|
||||
ScDisposable(std::function<void()> onDispose) :
|
||||
_onDispose(onDispose)
|
||||
ScDisposable(std::function<void()> onDispose)
|
||||
: _onDispose(onDispose)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -38,4 +38,4 @@ namespace OpenRCT2::Scripting
|
||||
dukglue_register_method(ctx, &ScDisposable::dispose, "dispose");
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include "../common.h"
|
||||
#include "../ride/Ride.h"
|
||||
#include "../world/Map.h"
|
||||
#include "ScTile.hpp"
|
||||
#include "ScThing.hpp"
|
||||
#include "ScTile.hpp"
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
@@ -78,4 +79,4 @@ namespace OpenRCT2::Scripting
|
||||
dukglue_register_method(ctx, &ScMap::getThing, "getThing");
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -9,21 +9,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <dukglue/dukglue.h>
|
||||
#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 <algorithm>
|
||||
#include <dukglue/dukglue.h>
|
||||
|
||||
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;
|
||||
@@ -89,15 +102,7 @@ namespace OpenRCT2::Scripting
|
||||
private:
|
||||
uint8_t GetParkMessageType(const std::string& key)
|
||||
{
|
||||
static auto keys = {
|
||||
"attraction",
|
||||
"peep_on_attraction",
|
||||
"peep",
|
||||
"money",
|
||||
"blank",
|
||||
"research",
|
||||
"guests",
|
||||
"award",
|
||||
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
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include "../common.h"
|
||||
#include "../world/Sprite.h"
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
class ScThing
|
||||
@@ -35,14 +36,35 @@ 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)
|
||||
{
|
||||
@@ -54,4 +76,4 @@ namespace OpenRCT2::Scripting
|
||||
dukglue_register_property(ctx, &ScThing::trousersColour_get, &ScThing::trousersColour_set, "trousersColour");
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include "../common.h"
|
||||
#include "../world/Sprite.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <dukglue/dukglue.h>
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
@@ -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<typename T>
|
||||
T* getAs()
|
||||
template<typename T> T* getAs()
|
||||
{
|
||||
return static_cast<T*>(this);
|
||||
}
|
||||
@@ -85,8 +95,7 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
|
||||
static void Register(duk_context* ctx);
|
||||
template<typename T>
|
||||
static void RegisterSharedProperties(duk_context* ctx);
|
||||
template<typename T> static void RegisterSharedProperties(duk_context* ctx);
|
||||
};
|
||||
|
||||
class ScSurfaceElement final : public ScTileElement
|
||||
@@ -190,28 +199,21 @@ namespace OpenRCT2::Scripting
|
||||
ScBannerElement ::Register(ctx);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ScTileElement::RegisterSharedProperties(duk_context* ctx)
|
||||
template<typename T> 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<std::string (T::*)() const>(&ScTileElement::type_get), nullptr, "type");
|
||||
dukglue_register_property(
|
||||
ctx,
|
||||
static_cast<bool (T::*)() const>(&ScTileElement::broken_get),
|
||||
static_cast<void (T::*)(bool)>(&ScTileElement::broken_set),
|
||||
"broken");
|
||||
ctx, static_cast<bool (T::*)() const>(&ScTileElement::broken_get),
|
||||
static_cast<void (T::*)(bool)>(&ScTileElement::broken_set), "broken");
|
||||
dukglue_register_property(
|
||||
ctx,
|
||||
static_cast<uint8_t (T::*)() const>(&ScTileElement::baseHeight_get),
|
||||
static_cast<void (T::*)(uint8_t)>(&ScTileElement::baseHeight_set),
|
||||
"baseHeight");
|
||||
ctx, static_cast<uint8_t (T::*)() const>(&ScTileElement::baseHeight_get),
|
||||
static_cast<void (T::*)(uint8_t)>(&ScTileElement::baseHeight_set), "baseHeight");
|
||||
dukglue_register_property(
|
||||
ctx,
|
||||
static_cast<uint8_t (T::*)() const>(&ScTileElement::clearanceHeight_get),
|
||||
static_cast<void (T::*)(uint8_t)>(&ScTileElement::clearanceHeight_set),
|
||||
"clearanceHeight");
|
||||
ctx, static_cast<uint8_t (T::*)() const>(&ScTileElement::clearanceHeight_get),
|
||||
static_cast<void (T::*)(uint8_t)>(&ScTileElement::clearanceHeight_set), "clearanceHeight");
|
||||
}
|
||||
|
||||
class ScTile
|
||||
@@ -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<ScTileElement> getElement(size_t index)
|
||||
{
|
||||
if (index >= _count) return nullptr;
|
||||
if (index >= _count)
|
||||
return nullptr;
|
||||
return std::make_shared<ScTileElement>(&_first[index]);
|
||||
}
|
||||
|
||||
@@ -263,4 +268,4 @@ namespace OpenRCT2::Scripting
|
||||
dukglue_register_method(ctx, &ScTile::getElement, "getElement");
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -8,23 +8,24 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#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 <dukglue/dukglue.h>
|
||||
#include <duktape.h>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#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 <dukglue/dukglue.h>
|
||||
#include <duktape.h>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Scripting;
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -98,9 +99,7 @@ void ScriptEngine::LoadPlugins()
|
||||
{
|
||||
// Enable hot reloading
|
||||
_pluginFileWatcher = std::make_unique<FileWatcher>(base);
|
||||
_pluginFileWatcher->OnFileChanged =
|
||||
[this](const std::string &path)
|
||||
{
|
||||
_pluginFileWatcher->OnFileChanged = [this](const std::string& path) {
|
||||
std::lock_guard<std::mutex> guard(_changedPluginFilesMutex);
|
||||
_changedPluginFiles.push_back(path);
|
||||
};
|
||||
@@ -118,9 +117,7 @@ void ScriptEngine::AutoReloadPlugins()
|
||||
std::lock_guard<std::mutex> guard(_changedPluginFilesMutex);
|
||||
for (auto& path : _changedPluginFiles)
|
||||
{
|
||||
auto findResult = std::find_if(_plugins.begin(), _plugins.end(),
|
||||
[&path](const std::shared_ptr<Plugin>& plugin)
|
||||
{
|
||||
auto findResult = std::find_if(_plugins.begin(), _plugins.end(), [&path](const std::shared_ptr<Plugin>& plugin) {
|
||||
return Path::Equals(path, plugin->GetPath());
|
||||
});
|
||||
if (findResult != _plugins.end())
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "../core/FileWatcher.h"
|
||||
#include "HookEngine.h"
|
||||
#include "Plugin.h"
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -47,8 +48,8 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
public:
|
||||
PluginScope(ScriptExecutionInfo& execInfo, std::shared_ptr<Plugin> plugin)
|
||||
: _execInfo(execInfo),
|
||||
_plugin(plugin)
|
||||
: _execInfo(execInfo)
|
||||
, _plugin(plugin)
|
||||
{
|
||||
_execInfo._plugin = plugin;
|
||||
}
|
||||
@@ -59,7 +60,10 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<Plugin> GetCurrentPlugin() { return _plugin; }
|
||||
std::shared_ptr<Plugin> GetCurrentPlugin()
|
||||
{
|
||||
return _plugin;
|
||||
}
|
||||
};
|
||||
|
||||
class DukContext
|
||||
@@ -76,7 +80,10 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
~DukContext();
|
||||
|
||||
operator duk_context*() { return _context; }
|
||||
operator duk_context*()
|
||||
{
|
||||
return _context;
|
||||
}
|
||||
};
|
||||
|
||||
class ScriptEngine
|
||||
@@ -100,9 +107,18 @@ 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<void> Eval(const std::string& s);
|
||||
@@ -113,4 +129,4 @@ namespace OpenRCT2::Scripting
|
||||
void StartPlugins();
|
||||
void AutoReloadPlugins();
|
||||
};
|
||||
}
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
Reference in New Issue
Block a user