OpenRCT2/distribution/openrct2.d.ts

761 lines
22 KiB
TypeScript
Raw Normal View History

2018-03-17 19:37:46 +01:00
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
2018-03-17 19:37:46 +01:00
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
// OpenRCT2 Scripting API definition file
2018-03-18 02:55:12 +01:00
// To enable IntelliSense for your scripts in Visual Studio or Visual Studio Code,
// add the following line to the top of your script and change the path appropriately.
//
// /// <reference path="/path/to/openrct2.d.ts" />
//
2020-02-25 01:44:02 +01:00
export type PluginType = "local" | "remote";
2020-02-07 00:15:20 +01:00
declare global {
2020-03-07 14:11:08 +01:00
/**
* Global context for accessing all other APIs.
*/
/** APIs for interacting with the stdout console. */
var console: Console;
/** Core APIs for plugins. */
var context: Context;
/** APIs for getting or setting the in-game date. */
var date: GameDate;
/** APIs for manipulating the map. */
var map: GameMap;
/** APIs for managing the server or interacting with the server or clients. */
var network: Network;
/** APIs for the park and management of it. */
var park: Park;
/**
* APIs for controlling the user interface.
* These will only be available to servers and clients that are not running headless mode.
* Plugin writers should check if ui is available using `typeof ui !== 'undefined'`.
*/
var ui: Ui;
/**
* Registers the plugin. This only only be called once.
* @param metadata Information about the plugin and the entry point.
*/
function registerPlugin(metadata: PluginMetadata): void;
/**
* Represents a JavaScript object that can or should be disposed when no longer needed.
*/
interface IDisposable {
dispose(): void;
}
/**
* A coordinate within the game.
* Each in-game tile is a size of 32x32.
*/
interface Coord2 {
x: number;
y: number;
}
/**
* A coordinate within the game.
* Each in-game tile is a size of 32x32.
* The z-coordinate raises 16 per land increment. A full-height wall is 32 in height.
*/
interface Coord3 extends Coord2 {
z: number;
}
/**
* Represents information about the plugin such as type, name, author and version.
* It also includes the entry point.
*/
interface PluginMetadata {
name: string;
version: string;
authors: string | string[];
type: PluginType;
minApiVersion?: number;
main: () => void;
}
2020-03-07 14:11:08 +01:00
/**
* Console APIs
* Currently interact with stdout.
*/
interface Console {
clear(): void;
log(message?: any, ...optionalParams: any[]): void;
}
2020-03-07 14:11:08 +01:00
/**
* Core APIs for storage and subscriptions.
*/
interface Context {
/**
* The user's current configuration.
*/
configuration: Configuration;
/**
* Shared generic storage for all plugins. Data is persistant across instances
* of OpenRCT2 and is stored externally as a single JSON file in the OpenRCT2
* user directory. Internally it is a JavaScript object. Objects and arrays
* are only copied by reference. The external file is only written when using
* the `set` method, do not rely on the file being saved by modifying your own
* objects. Functions and other internal structures will not be persisted.
*/
sharedStorage: Configuration;
/**
* Gets the loaded object at the given index.
* @param type The object type.
* @param index The index.
*/
getObject(type: ObjectType, index: number): Object;
getObject(type: "ride", index: number): RideObject;
getAllObjects(type: ObjectType): Object[];
getAllObjects(type: "ride"): RideObject[];
2020-03-07 14:11:08 +01:00
/**
* Gets a random integer within the specified range using the game's pseudo-
* random number generator. This is part of the game state and shared across
* all clients, you therefore must be in a context that can mutate the game
* state. Use this to generate random numbers instead of Math.Random during
* game logic routines such as hooks and game actions.
* @param min The minimum value inclusive.
* @param max The maximum value exclusive.
*/
getRandom(min: number, max: number): number;
/**
* Registers a new game action that allows clients to interact with the game.
* @param action The unique name of the action.
* @param query Logic for validating and returning a price for an action.
* @param execute Logic for validating and executing the action.
* @throws An error if the action has already been registered by this or another plugin.
*/
registerAction(
action: string,
query: (args: object) => GameActionResult,
execute: (args: object) => GameActionResult): void;
/**
* Query the result of running a game action. This allows you to check the outcome and validity of
* an action without actually executing it.
* @param action The name of the action.
* @param args The action parameters.
* @param callback The function to be called with the result of the action.
*/
queryAction(action: string, args: object, callback: (result: GameActionResult) => void): void;
/**
* Executes a game action. In a network game, this will send a request to the server and wait
* for the server to reply.
* @param action The name of the action.
* @param args The action parameters.
* @param callback The function to be called with the result of the action.
*/
executeAction(action: string, args: object, callback: (result: GameActionResult) => void): void;
/**
* Subscribes to the given hook.
*/
subscribe(hook: HookType, callback: Function): IDisposable;
subscribe(hook: "action.query", callback: (e: GameActionEventArgs) => void): IDisposable;
subscribe(hook: "action.execute", callback: (e: GameActionEventArgs) => void): IDisposable;
subscribe(hook: "interval.tick", callback: () => void): IDisposable;
subscribe(hook: "interval.day", callback: () => void): IDisposable;
subscribe(hook: "network.chat", callback: (e: NetworkChatEventArgs) => void): IDisposable;
subscribe(hook: "network.join", callback: (e: NetworkEventArgs) => void): IDisposable;
subscribe(hook: "network.leave", callback: (e: NetworkEventArgs) => void): IDisposable;
}
interface Configuration {
2020-03-06 21:17:15 +01:00
getAll(namespace: string): { [name: string]: any };
get<T>(key: string): T | undefined;
get<T>(key: string, defaultValue: T): T;
set<T>(key: string, value: T): void;
has(key: string): boolean;
}
type ObjectType =
"ride" |
"small_scenery" |
"large_scenery" |
"wall" |
"banner" |
"footpath" |
"footpath_addition" |
"scenery_group" |
"park_entrance" |
"water" |
"terrain_surface" |
"terrain_edge" |
"station" |
"music";
type HookType =
"interval.tick" | "interval.day" |
"network.chat" | "network.action" | "network.join" | "network.leave";
type ExpenditureType =
"ride_construction" |
"ride_runningcosts" |
"land_purchase" |
"landscaping" |
"park_entrance_tickets" |
"park_ride_tickets" |
"shop_sales" |
"shop_stock" |
"food_drink_sales" |
"food_drink_stock" |
"wages" |
"marketing" |
"research" |
"interest";
2020-03-07 14:11:08 +01:00
interface GameActionEventArgs {
readonly player: number;
readonly type: string;
readonly isClientOnly: boolean;
result: GameActionResult;
}
interface GameActionResult {
2020-03-04 21:03:13 +01:00
error?: string;
errorTitle?: string;
errorMessage?: string;
2020-03-04 21:03:13 +01:00
position?: Coord3;
cost?: number;
expenditureType?: ExpenditureType;
}
2020-03-06 01:04:29 +01:00
interface RideCreateGameActionResult extends GameActionResult {
readonly ride: number;
}
2020-03-07 14:11:08 +01:00
interface RideCreateActionEventArgs extends GameActionEventArgs {
2020-03-06 01:04:29 +01:00
readonly rideType: number;
readonly rideObject: number;
result: RideCreateGameActionResult;
}
2020-03-04 21:03:13 +01:00
interface NetworkEventArgs {
readonly player: number;
}
interface NetworkChatEventArgs extends NetworkEventArgs {
message: string;
}
2020-03-07 14:11:08 +01:00
/**
* APIs for the in-game date.
*/
interface GameDate {
/**
2020-03-07 14:11:08 +01:00
* The total number of ticks that have elapsed since the beginning of the game / scenario. This
* should never reset.
*/
2020-03-07 14:11:08 +01:00
readonly ticksElapsed: number;
/**
2020-03-07 14:11:08 +01:00
* The total number of months that have elapsed. This will equate to 16 on 1st March, Year 2.
* Note: this represents the current date and may be reset by cheats or scripts.
*/
2020-03-07 14:11:08 +01:00
monthsElapsed: number;
/**
2020-03-07 14:11:08 +01:00
* The total number of years that have elapsed. This always equates to (monthsElapsed / 8).
*/
2020-03-07 14:11:08 +01:00
readonly yearsElapsed: number;
/**
2020-03-07 14:11:08 +01:00
* How far through the month we are between 0 and 65536. This is incremented by 4 each tick, so
* every month takes ~6.8 minutes to complete making a year take just under an hour.
*/
2020-03-07 14:11:08 +01:00
monthProgress: number;
2020-03-07 14:11:08 +01:00
/** The day of the month from 1 to 31. */
readonly day: number;
/** The current month of the year from 0 to 7, where 0 is March and 7 is October. */
readonly month: number;
/** The current year starting from 1. */
readonly year: number;
}
2020-03-07 14:11:08 +01:00
/**
* APIs for the map.
*/
interface GameMap {
readonly size: Coord2;
readonly numRides: number;
readonly numThings: number;
readonly rides: Ride[];
2020-03-07 14:11:08 +01:00
getRide(id: number): Ride;
getTile(x: number, y: number): Tile;
getThing(id: number): Thing;
getAllThings(type: ThingType);
}
type TileElementType =
2020-03-01 13:44:36 +01:00
"surface" | "footpath" | "track" | "small_scenery" | "wall" | "entrance" | "large_scenery" | "banner";
interface BaseTileElement {
type: TileElementType;
baseZ: number;
clearanceZ: number;
}
interface SurfaceElement extends BaseTileElement {
slope: number;
2020-02-29 22:44:40 +01:00
surfaceStyle: number;
edgeStyle: number;
waterHeight: number;
grassLength: number;
ownership: number;
parkFences: number;
2020-02-29 22:44:40 +01:00
readonly hasOwnership: boolean;
readonly hasConstructionRights: boolean;
}
interface FootpathElement extends BaseTileElement {
footpathType: number;
2020-03-08 12:30:57 +01:00
edgesAndCorners: number;
slopeDirection: number | null;
isBlockedByVehicle: boolean;
isWide: boolean;
isQueue: boolean;
2020-03-08 12:30:57 +01:00
queueBannerDirection: number | null;
ride: number;
station: number;
addition: number | null;
isAdditionBroken: boolean;
}
interface TrackElement extends BaseTileElement {
2020-02-29 22:44:40 +01:00
trackType: number;
sequence: number;
ride: number;
station: number;
hasChainLift: boolean;
}
interface SmallSceneryElement extends BaseTileElement {
2020-02-29 23:08:09 +01:00
object: number;
primaryColour: number;
secondaryColour: number;
}
interface EntranceElement extends BaseTileElement {
2020-02-29 23:08:09 +01:00
object: number;
sequence: number;
ride: number;
station: number;
}
interface WallElement extends BaseTileElement {
2020-02-29 23:08:09 +01:00
object: number;
}
interface LargeSceneryElement extends BaseTileElement {
2020-02-29 23:08:09 +01:00
object: number;
primaryColour: number;
secondaryColour: number;
}
interface BannerElement extends BaseTileElement {
}
interface CorruptElement extends BaseTileElement {
}
2020-02-29 22:44:40 +01:00
type TileElement = SurfaceElement | FootpathElement | TrackElement;
2020-02-28 21:56:04 +01:00
/**
* Represents a tile containing tile elements on the map. This is a fixed handle
* for a given tile position. It can be re-used safely between game ticks.
*/
interface Tile {
2020-02-28 21:56:04 +01:00
/** The x position in tiles. */
readonly x: number;
2020-02-28 21:56:04 +01:00
/** The y position in tiles. */
readonly y: number;
2020-02-28 21:56:04 +01:00
/** Gets an array of all the tile elements on this tile. */
readonly elements: TileElement[];
/** Gets the number of tile elements on this tile. */
readonly numElements: number;
/**
* Gets or sets the raw data for this tile.
* This can provide more control and efficiency for tile manipulation but requires
* knowledge of tile element structures and may change between versions of OpenRCT2.
*/
data: Uint8Array;
2020-02-28 21:56:04 +01:00
/** Gets the tile element at the given index on this tile. */
getElement(index: number): TileElement;
2020-02-28 21:56:04 +01:00
/** Gets the tile element at the given index on this tile. */
getElement<T extends BaseTileElement>(index: number): T;
/** Inserts a new tile element at the given index on this tile. */
insertElement(index: number): TileElement;
/** Removes the tile element at the given index from this tile. */
removeElement(index: number): void;
}
2020-03-01 13:44:36 +01:00
/**
* Represents the definition of a loaded object (.DAT or .json) such a ride type or scenery item.
*/
interface Object {
/**
* The object type.
*/
readonly type: ObjectType;
/**
* The index of the loaded object for the object type.
*/
readonly index: number;
2020-03-01 13:44:36 +01:00
/**
* The unique name identifier of the object, e.g. "BURGB ".
* This may have trailing spaces if the name is shorter than 8 characters.
*/
readonly identifier: string;
2020-03-01 13:44:36 +01:00
/**
* The name in the user's current language.
*/
readonly name: string;
}
2020-03-01 13:44:36 +01:00
/**
* Represents the object definition of a ride or stall.
*/
interface RideObject extends Object {
2020-03-01 13:44:36 +01:00
/**
* The description of the ride / stall in the player's current language.
*/
readonly description: string;
2020-03-01 13:44:36 +01:00
/**
* A text description describing the capacity of the ride in the player's current language.
*/
readonly capacity: string;
}
2020-03-01 13:44:36 +01:00
/**
* Represents a ride or stall within the park.
*/
interface Ride {
2020-03-01 13:44:36 +01:00
/**
* The object metadata for this ride.
*/
readonly object: RideObject;
2020-03-01 13:44:36 +01:00
/**
* The unique ID / index of the ride.
*/
readonly id: number;
2020-03-01 13:44:36 +01:00
/**
* The type of the ride represented as the internal built-in ride type ID.
*/
type: number;
2020-03-01 13:44:36 +01:00
/**
* The generated or custom name of the ride.
*/
name: string;
2020-03-01 13:44:36 +01:00
/**
* The excitement metric of the ride represented as a 2 decimal point fixed integer.
* For example, `652` equates to `6.52`.
*/
excitement: number;
2020-03-01 13:44:36 +01:00
/**
* The intensity metric of the ride represented as a 2 decimal point fixed integer.
* For example, `652` equates to `6.52`.
*/
intensity: number;
2020-03-01 13:44:36 +01:00
/**
* The nausea metric of the ride represented as a 2 decimal point fixed integer.
* For example, `652` equates to `6.52`.
*/
nausea: number;
2020-03-01 13:44:36 +01:00
/**
* The total number of customers the ride has served since it was built.
*/
totalCustomers: number;
}
type ThingType =
"car" | "duck" | "peep";
2020-03-01 13:44:36 +01:00
/**
* Represents an object "thing" on the map that can typically moves and has a sub-tile coordinate.
*/
interface Thing {
2020-03-01 13:44:36 +01:00
/**
* The type of thing, e.g. car, duck, litter, or peep.
*/
readonly type: ThingType;
2020-03-01 13:44:36 +01:00
/**
* The x-coordinate of the thing in game units.
*/
x: number;
2020-03-01 13:44:36 +01:00
/**
* The y-coordinate of the thing in game units.
*/
y: number;
2020-03-01 13:44:36 +01:00
/**
* The z-coordinate of the thing in game units.
*/
z: number;
}
2020-03-01 13:44:36 +01:00
/**
* Represents a guest or staff member.
*/
interface Peep extends Thing {
2020-03-01 13:44:36 +01:00
/**
* Colour of the peep's t-shirt.
*/
tshirt: number;
2020-03-01 13:44:36 +01:00
/**
* Colour of the peep's trousers.
*/
trousers: number;
}
2020-03-07 14:11:08 +01:00
/**
* Network APIs
* Use `network.status` to determine whether the current game is a client, server or in single player mode.
*/
interface Network {
readonly mode: NetworkMode;
readonly groups: number;
readonly players: number;
defaultGroup: number;
2020-03-07 14:11:08 +01:00
getServerInfo(): ServerInfo;
getGroup(index: number): PlayerGroup;
setGroups(groups: PlayerGroup[]): void;
getPlayer(index: number): Player;
kickPlayer(index: number): void;
sendMessage(message: string): void;
sendMessage(message: string, players: number[]): void;
}
2020-03-07 14:11:08 +01:00
type NetworkMode = "none" | "server" | "client";
/**
* Represents a player within a network game.
*/
interface Player {
readonly id: number;
readonly name: string;
group: number;
readonly ping: number;
readonly commandsRan: number;
readonly moneySpent: number;
}
interface PlayerGroup {
readonly id: number;
name: string;
permissions: PermissionType[];
}
interface ServerInfo {
readonly name: string;
readonly description: string;
readonly greeting: string;
readonly providerName: string;
readonly providerEmail: string;
readonly providerWebsite: string;
}
type PermissionType =
"chat" |
"terraform" |
"set_water_level" |
"toggle_pause" |
"create_ride" |
"remove_ride" |
"build_ride" |
"ride_properties" |
"scenery" |
"path" |
"clear_landscape" |
"guest" |
"staff" |
"park_properties" |
"park_funding" |
"kick_player" |
"modify_groups" |
"set_player_group" |
"cheat" |
"toggle_scenery_cluster" |
"passwordless_login" |
"modify_tile" |
"edit_scenario_options";
/**
* Park APIs
*/
/**
* The type of park message, including icon and behaviour.
*/
type ParkMessageType =
"attraction" | "peep_on_attraction" | "peep" | "money" | "blank" | "research" | "guests" | "award" | "chart";
interface ParkMessage {
type: ParkMessageType;
text: string;
}
interface Park {
cash: number;
rating: number;
bankLoan: number;
maxBankLoan: number;
postMessage(message: string): void;
postMessage(message: ParkMessage): void;
}
2018-03-20 20:40:38 +01:00
2020-02-06 14:23:04 +01:00
/**
* User Interface APIs
* These will only be available to servers and clients that are not running headless mode.
* Plugin writers should check if ui is available using `typeof ui !== 'undefined'`.
2020-02-06 14:23:04 +01:00
*/
2020-03-07 14:11:08 +01:00
interface Ui {
readonly width: number;
readonly height: number;
readonly windows: number;
readonly mainViewport: Viewport;
getWindow(id: number): Window;
getWindow(classification: string, id?: number): Window;
openWindow(desc: WindowDesc): Window;
closeWindows(classification: string, id?: number): void;
closeAllWindows(): void;
registerMenuItem(text: string, callback: () => void): void;
}
2020-02-06 14:23:04 +01:00
/**
* Represents the type of a widget, e.g. button or label.
2020-02-06 14:23:04 +01:00
*/
type WidgetType =
2020-02-27 20:44:51 +01:00
"button" | "checkbox" | "dropdown" | "groupbox" | "label" | "spinner" | "tabview" | "viewport";
interface Widget {
type: WidgetType;
x: number;
y: number;
width: number;
height: number;
2020-02-20 18:58:15 +01:00
name?: string;
isDisabled?: boolean;
}
interface ButtonWidget extends Widget {
2020-02-27 19:22:32 +01:00
image: number;
text: string;
onClick: () => void;
}
interface CheckboxWidget extends Widget {
text: string;
2020-04-20 00:17:04 +02:00
isChecked: boolean;
onChanged: (isChecked: boolean) => void;
}
interface DropdownWidget extends Widget {
items: string[];
selectedIndex: number;
onChanged: (index: number) => void;
}
interface LabelWidget extends Widget {
text: string;
2020-02-27 20:44:51 +01:00
onChanged: (index: number) => void;
}
interface SpinnerWidget extends Widget {
text: string;
onDecrement: () => void;
onIncrement: () => void;
}
interface ViewportWidget extends Widget {
viewport: Viewport
}
interface Tab {
image: number;
tooltip: string;
widgets: Widget[];
}
interface Window {
classification: number;
number: number;
x: number;
y: number;
width: number;
height: number;
isSticky: boolean;
colours: number[];
title: string;
widgets: Widget[];
close(): void;
2020-02-20 18:58:15 +01:00
bringToFront(): void;
findWidget<T extends Widget>(name: string): T;
}
interface TabbedWindow extends Window {
tabs: Tab[];
activeTabIndex: number;
onTabChanged: (index: number) => void;
}
interface WindowDesc {
classification: string;
x?: number;
y?: number;
width: number;
height: number;
title: string;
id?: number;
minWidth?: number;
minHeight?: number;
widgets?: Widget[];
2020-02-27 20:59:46 +01:00
colours?: number[];
tabs?: Tab[];
2020-02-20 18:58:15 +01:00
onClose?: () => void;
}
interface Viewport {
left: number;
top: number;
right: number;
bottom: number;
rotation: number;
zoom: number;
visibilityFlags: number;
getCentrePosition(): Coord2;
moveTo(position: Coord2 | Coord3): void;
scrollTo(position: Coord2 | Coord3): void;
}
2018-03-18 02:55:12 +01:00
}