Skip to content

Commit

Permalink
initial code
Browse files Browse the repository at this point in the history
  • Loading branch information
EnoxRCT committed Jan 14, 2023
0 parents commit f473a61
Show file tree
Hide file tree
Showing 31 changed files with 7,492 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = tabs
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = crlf
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
dist
36 changes: 36 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"no-unused-vars": "off",
"semi": "off",
"@typescript-eslint/explicit-function-return-type": ["warn"],
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/semi": ["warn"],
"@typescript-eslint/triple-slash-reference": "off"
},
"settings": {
"import/resolver": {
"node": { "extensions": [ ".js", ".ts" ] }
}
}
}
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Bug report
about: Create a report to help us fix any issues
title: ''
labels: 'bug'
---

**Describe the bug**
Please describe clearly and concisely what the bug is.

**To reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See problem

**Expected behavior**
A short but clear description of what you expected to happen.

**Screenshots**
If applicable, please add screenshots or a video to help explain the problem.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: true
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Feature request
about: Suggest an idea for this plugin
title: ''
labels: 'enhancement'
---

**Idea**
Please describe what you'd like to see added or changed.

**Additional context**
Add any other context, screenshots, related information about the feature request here.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: monthly
day: "saturday"
time: "04:00"
open-pull-requests-limit: 1
labels:
- dependencies
110 changes: 110 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# OpenRCT2 TypeScript API declaration file
lib/openrct2.d.ts

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Visual Studio
.vs/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Manticore-007

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# LitterEditor plugin for OpenRCT2

## Installation

2. Download the latest version of the plugin from the [Releases page](https://github.com/EnoxRCT/OpenRCT2-LitterEditor/releases/tag/v1.1).
3. To install it, put the downloaded `*.js` file into your `/OpenRCT2/plugin` folder.
- Easiest way to find the OpenRCT2-folder is by launching the OpenRCT2 game, click and hold on the red toolbox in the main menu, and select "Open custom content folder".
- Otherwise this folder is commonly found in `C:/Users/<YOUR NAME>/Documents/OpenRCT2/plugin` on Windows.
- If you already had this plugin installed before, you can safely overwrite the old file.
4. Once the file is there, it should show up ingame in the dropdown menu under the map icon.

---

## Building the source code

This project is based on [wisnia74's Typescript modding template](https://github.com/wisnia74/openrct2-typescript-mod-template) and uses [Nodemon](https://nodemon.io/), [ESLint](https://eslint.org/) and [TypeScript](https://www.typescriptlang.org/) from this template.

1. Install latest version of [Node](https://nodejs.org/en/) and make sure to include NPM in the installation options.
2. Clone the project to a location of your choice on your PC.
3. Open command prompt, use `cd` to change your current directory to the root folder of this project and run `npm install`.
4. Find `openrct2.d.ts` TypeScript API declaration file in OpenRCT2 files and copy it to `lib` folder (this file can usually be found in `C:/Users/<YOUR NAME>/Documents/OpenRCT2/bin/` or `C:/Program Files/OpenRCT2/`).
- Alternatively, you can make a symbolic link instead of copying the file, which will keep the file up to date whenever you install new versions of OpenRCT2.
5. Run `npm run build` (release build) or `npm run build:dev` (develop build) to build the project.
- Default output folder for release builds: `(project directory)/dist`
- Default output folder for develop builds: `(documents)/OpenRCT2/plugins`
- If your plugin folder is located elsewhere (on for example a non-Windows OS), you can modify it in `rollup.config.js`.

### Hot reload

This project supports the [OpenRCT2 hot reload feature](https://github.com/OpenRCT2/OpenRCT2/blob/master/distribution/scripting.md#writing-scripts) for development.

1. Make sure you've enabled it by setting `enable_hot_reloading = true` in your `/OpenRCT2/config.ini`.
2. If you are on a non-Windows OS, open `rollup.config.js` and change the output file path to your plugin folder.
- Example: `C:/OpenRCT2/plugin/LitterEditor.js`.
- Make sure this path uses `/` instead of `\` slashes!
3. Open command prompt and use `cd` to change your current directory to the root folder of this project.
4. Run `npm start` to start the hot reload server.
5. Use the `/OpenRCT2/bin/openrct2.com` executable to [start OpenRCT2 with console](https://github.com/OpenRCT2/OpenRCT2/blob/master/distribution/scripting.md#writing-scripts) and load a save or start new game.
6. Each time you save any of the files in `./src/`, the server will compile `./src/registerPlugin.ts` and place compiled plugin file inside your local OpenRCT2 plugin directory.
7. OpenRCT2 will notice file changes and it will reload the plugin.

## Notes

Don't touch `app.js`, even though it's just an empty file. Its existence makes Nodemon happy, and Nodemon is what watches your files for changes & fires off new dev builds for hot reloading.

Thanks to [wisnia74](https://github.com/wisnia74/openrct2-typescript-mod-template) for providing the template for this mod and readme.
Empty file added app.js
Empty file.
37 changes: 37 additions & 0 deletions helpers/LitterWall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* const z = 36;
createLitterLine(type, coords, z);
createLitterLine(type, coords, z+4);
createLitterLine(type, coords, z+8);
createLitterLine(type, coords, z+12);
createLitterLine(type, coords, z+16);
createLitterLine(type, coords, z+20);
createLitterLine(type, coords, z+24);
createLitterLine(type, coords, z+28);
createLitterLine(type, coords, z+32);
createLitterLine(type, coords, z+36);
createLitterLine(type, coords, z+40);
createLitterLine(type, coords, z+44);
createLitterLine(type, coords, z+48);
}
}
})
}
}
function createLitterLine(type: EntityType, coords: CoordsXY, z: number): void
{
const c = 10;
map.createEntity(type, {x: 61, y: coords.y -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-4 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-8 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-12 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-16 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-20 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-24 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-28 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-32 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-36 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-40 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-44 -c, z: z });
map.createEntity(type, {x: 61, y: coords.y-48 -c, z: z });
} */
49 changes: 49 additions & 0 deletions helpers/Z-Coords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* A generic TileElement type that exposes element, index and coords at once.
* Used extensively for finding specific tile elements (surface, footpath, track, etc.)
*/
export type TileElementItem<T extends TileElement> = {
element: T,
index: number,
coords: CoordsXY
};

/**
* Utility function to get all "surface" elements at a given coords.
* Replace "surface" & "SurfaceElement" with any other TileElementType to get a different type of element.
* e.g. could use "footpath" & "FootpathElement" to get all footpath elements at a given coords.
*/
export const getSurfaceElementsFromCoords = (coords: CoordsXY | CoordsXYZ | CoordsXYZD): TileElementItem<SurfaceElement>[] => {
return getTileElements<SurfaceElement>("surface", { x: coords.x, y: coords.y });
};

/**
* Utility function to get a specific type of TileElement at a given CoordsXY
* @returns
*/
export const getTileElements = <T extends TileElement>(elementType: TileElementType, coords: CoordsXY): TileElementItem<T>[] => {
// console.log(`Querying tile for ${elementType} elements at coords (${coords.x}, ${coords.y})`);

// have to divide the mapCoords by 32 to get the tile coords
const selectedTile = map.getTile(coords.x / 32, coords.y / 32);

// filter and map to elements of the given type
const reducedELements = selectedTile.elements.reduce<TileElementItem<T>[]>((filtered, el, index) => {
if (el.type === elementType) {
return filtered.concat({
element: <T>el,
index: index,
coords
});
}
return filtered;
}, []);

// console.log(`Query returned ${reducedELements.length} elements`);
return reducedELements;
};

// usage example
const coords: CoordsXY = { x: 0, y: 0 }; // example coords
export const surfaceElements = getTileElements<SurfaceElement>("surface", coords);
export const oneSurfaceElementZValue = surfaceElements[0].element.baseZ; // here's what you're looking for
Empty file added helpers/Z-coordsAlt.ts
Empty file.
Loading

0 comments on commit f473a61

Please sign in to comment.