mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 07:43:01 +01:00
Apply suggestions from code review
Co-Authored-By: Michał Janiszewski <janisozaur@users.noreply.github.com> Co-Authored-By: Aaron van Geffen <aaron@aaronweb.net> Co-Authored-By: Tulio Leao <tupaschoal@gmail.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
OpenRCT2 allows custom scripts (also known as plug-ins) to be written and executed in the game providing additional behaviour on top of the vanilla experience. This can range from extra windows providing information about the park to entire new multiplayer game modes.
|
||||
|
||||
Each script is a single physical javascript file within the `plugin` directory in your OpenRCT2 user directory. This is usually `C:\Users\YourName\Documents\OpenRCT2` on Windows, or `/home/YourName/.config/openrct2` on Linux. OpenRCT2 will load every single file with the extension `.js` in this directory recursively. So if you want to prevent a plug-in from being used, you must move it outside this directory, or rename it so the filename does not end with `.js`.
|
||||
Each script is a single physical javascript file within the `plugin` directory in your OpenRCT2 user directory. This is usually `C:\Users\YourName\Documents\OpenRCT2` on Windows, or `$XDG_CONFIG_HOME/OpenRCT2` or in its absence `$HOME/.config/OpenRCT2` on Linux. OpenRCT2 will load every single file with the extension `.js` in this directory recursively. So if you want to prevent a plug-in from being used, you must move it outside this directory, or rename it so the filename does not end with `.js`.
|
||||
|
||||
There are two types of scripts:
|
||||
* Local
|
||||
@@ -44,7 +44,7 @@ The hot reload feature can be enabled by editing your `config.ini` file and sett
|
||||
|
||||
> Why was JavaScript chosen instead of LUA or Python.
|
||||
|
||||
JavaScript is a very mature and flexible language with a large, if not largest, resource base available. There are arguably more transpilers, tools, and libraries for JavaScript than any other language. That and also it using a familiar C-like syntax and 0-indexed arrays make it more suitable than LUA and Python. Of course if you would still like to use LUA or another language, there will likely be a JavaScript transpiler for it.
|
||||
JavaScript is a very mature and flexible language with a large, if not the largest, resource base available. There are arguably more transpilers, tools, and libraries for JavaScript than any other language. That and also it using a familiar C-like syntax and 0-indexed arrays make it more suitable than LUA and Python. Of course if you would still like to use LUA or another language, there will likely be a JavaScript transpiler for it.
|
||||
|
||||
Another benefit of using JavaScript is that you get rich editor features such as completion and API documentation by using a TypeScript definition file which works for both TypeScript and JavaScript. [Visual Studio Code](https://code.visualstudio.com) is recommended, as that supports the workflow very well. See the [OpenRCT2 plugin hot-reload demo](https://www.youtube.com/watch?v=jmjWzEhmDjk) video for a demonstration of the editor functionality.
|
||||
|
||||
|
||||
@@ -9,10 +9,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
#include <openrct2/interface/InteractiveConsole.h>
|
||||
#include <openrct2/world/Location.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace OpenRCT2::Ui
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t width_get()
|
||||
int32_t width_get() const
|
||||
{
|
||||
return context_get_width();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRCT2::Scripting
|
||||
std::string Name;
|
||||
std::string Version;
|
||||
std::vector<std::string> Authors;
|
||||
PluginType Type;
|
||||
PluginType Type{};
|
||||
int32_t MinApiVersion{};
|
||||
DukValue Main;
|
||||
};
|
||||
@@ -50,7 +50,7 @@ namespace OpenRCT2::Scripting
|
||||
private:
|
||||
duk_context* _context{};
|
||||
std::string _path;
|
||||
PluginMetadata _metadata;
|
||||
PluginMetadata _metadata{};
|
||||
std::string _code;
|
||||
bool _hasStarted{};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2020 OpenRCT2 developers
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
|
||||
Reference in New Issue
Block a user