Skip to content
This repository was archived by the owner on Mar 15, 2023. It is now read-only.

Commit 85025af

Browse files
authored
Merge pull request #4 from oganexon/develop
1.1.0
2 parents 20f6f63 + 32cbd6e commit 85025af

File tree

13 files changed

+618
-148
lines changed

13 files changed

+618
-148
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
<!-- ## [Unreleased]
8+
9+
### Added
10+
### Changed
11+
### Deprecated
12+
### Removed
13+
### Fixed
14+
### Security -->
15+
16+
## [1.1.0] - 2020-05-05
17+
18+
### Added
19+
20+
- `rails` command

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- [tpll](#tpll)
3333
- [tpdms](#tpdms)
3434
- [draw](#draw)
35+
- [rails](#rails)
3536
- [🔍 Find a railroad name](#%f0%9f%94%8d-find-a-railroad-name)
3637
- [📜 Roadmap](#%f0%9f%93%9c-roadmap)
3738
- [🏗️ Contributing](#%f0%9f%8f%97%ef%b8%8f-contributing)
@@ -84,6 +85,7 @@ These are WorldEdit scripts, if blocks are modified you have access to `//undo`.
8485
- **tpll** : Replaces the tpll command since permissions can be a problem.
8586
- **tpdms** : Same as tpll but takes `degrees minutes seconds` (such as `47°35'6.32"N 6°53'50.06"E` ).
8687
- **draw** : Traces any imported shape of an OpenStreetMap query - railroads, roads, etc.
88+
- **rails** : Traces all railroads in an area
8789

8890
Do you need another function? Request it [here](https://github.com/oganexon/BTE-tools/issues).
8991

@@ -143,7 +145,7 @@ Examples :
143145
```
144146
Traces any imported shape of an OpenStreetMap query - railroads, roads, etc.
145147

146-
Options :
148+
Flags :
147149
- **u** (up): Draw a block above
148150

149151
Setup :
@@ -162,6 +164,32 @@ Examples :
162164
/cs draw file3 stone u
163165
```
164166

167+
### rails
168+
169+
```bash
170+
/cs <mode> [...args] [flags]
171+
```
172+
Traces all railroads in an area
173+
174+
Modes:
175+
- **radius** Select rails in a radius `<radius> [flags]`
176+
- **region** Select rails in a region `[flags]`
177+
- **regionEdge** Select rails in a region and draw only in the defined region `[flags]`
178+
179+
Flags :
180+
- **u** (up): Draw a block above
181+
182+
Examples :
183+
184+
```bash
185+
/cs rails radius 7
186+
/cs rails radius 50 u
187+
/cs rails region
188+
/cs rails region u
189+
/cs rails regionEdge
190+
/cs rails regionEdge u
191+
```
192+
165193

166194

167195
## 🔍 Find a railroad name
@@ -208,3 +236,4 @@ Distributed under the MIT License. See `LICENSE` for more information.
208236
## Contact
209237

210238
Oganexon#2001 - Discord
239+

gulpfile.babel.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const { src, dest, series } = require('gulp')
22
const babel = require('gulp-babel')
33
const uglify = require('gulp-uglify')
4-
const bro = require('gulp-bro')
4+
const browserify = require('gulp-bro')
55
const fs = require('fs')
66
const path = require('path')
77

8-
const files = ['tpll', 'tpdms', 'draw', 'list', 'help']
9-
108
exports.default = series(bundle, copyData)
119

1210
function bundle () {
13-
return src(`src/+(${files.join('|')}).js`)
14-
.pipe(bro())
11+
return src('src/*.js')
12+
.pipe(browserify())
1513
.pipe(babel())
1614
.pipe(uglify())
1715
.pipe(dest('craftscripts/'))
1816
}
1917

2018
function copyData (cb) {
21-
fs.mkdirSync(path.resolve(__dirname, './craftscripts/data'))
22-
fs.copyFileSync(path.resolve(__dirname, './src/data/conformal.txt'), path.resolve(__dirname, './craftscripts/data/conformal.txt'))
23-
cb()
19+
fs.mkdir(path.resolve(__dirname, './craftscripts/data'), (err) => {
20+
if (err && err.code !== 'EEXIST') throw err
21+
fs.copyFile(path.resolve(__dirname, './src/data/conformal.txt'), path.resolve(__dirname, './craftscripts/data/conformal.txt'), (err) => {
22+
if (err) throw err
23+
cb()
24+
})
25+
})
2426
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bte-tools",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "Awesome tools and scripts to enhance your experience on the Build The Earth project!",
55
"scripts": {
66
"lint": "standard src/**/*.js --fix",
@@ -26,5 +26,7 @@
2626
"gulp-uglify": "^3.0.2",
2727
"standard": "^14.3.3"
2828
},
29-
"dependencies": {}
29+
"dependencies": {
30+
"osmtogeojson": "^3.0.0-beta.4"
31+
}
3032
}

src/draw.js

Lines changed: 6 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
/* global importPackage Packages context player argv BufferedReader FileReader Vector */
2-
const getProjection = require('./getProjection')
1+
/* global importPackage Packages context player argv BufferedReader FileReader */
2+
const draw = require('./modules/drawGeoJSON')
33

44
importPackage(Packages.java.io)
55
importPackage(Packages.java.awt)
66
importPackage(Packages.com.sk89q.worldedit)
77
importPackage(Packages.com.sk89q.worldedit.math)
88
importPackage(Packages.com.sk89q.worldedit.blocks)
99

10-
const usage = `/cs draw <file> <block> [options]
10+
const usage = `/cs draw <file> <block> [flags]
1111
• §o/cs draw rails1 iron_block
1212
• §o/cs draw file3 stone u
13-
Options:
13+
Flags:
1414
• §lu§r§c Draw a block above`
1515

1616
context.checkArgs(2, 3, usage)
@@ -21,15 +21,8 @@ if (argv[3]) {
2121
options.up = argv[3].includes('u')
2222
}
2323

24-
const blocks = context.remember()
25-
let changedBlocks = 0
26-
27-
const ignoreBlocks = getIgnoredBlocks()
28-
const allowedBlocks = getAllowedBlocks()
29-
30-
const DataError = new Error('Incorrect data format')
31-
32-
draw(parse(readFile()))
24+
player.print('§7Please wait...')
25+
draw(readFile(), argv[2], options)
3326

3427
function readFile () {
3528
const file = context.getSafeOpenFile('drawings', argv[1], 'geojson', ['json', 'geojson'])
@@ -52,112 +45,3 @@ function readFile () {
5245
return JSON.parse(bufStr)
5346
}
5447
}
55-
56-
function parse (data) {
57-
if (data.type !== 'FeatureCollection') throw DataError
58-
if (!Array.isArray(data.features)) throw DataError
59-
60-
const geometry = []
61-
let lines = 0
62-
for (let i = 0; i < data.features.length; i++) {
63-
if (data.features[i].geometry.type !== 'LineString') continue
64-
const coordinates = data.features[i].geometry.coordinates
65-
geometry.push(coordinates)
66-
lines += coordinates.length
67-
}
68-
69-
player.print(`§7${lines} lines to draw`)
70-
71-
return geometry
72-
}
73-
74-
function draw (geometry) {
75-
const y = player.getPosition().y
76-
const block = context.getBlock(argv[2])
77-
78-
player.print('§7Please wait...')
79-
const projection = getProjection()
80-
81-
for (let i = 0; i < geometry.length; i++) {
82-
const shape = geometry[i]
83-
for (let j = 0; j < shape.length - 1; j++) {
84-
const [x1, z1] = projection.fromGeo(...shape[j])
85-
const [x2, z2] = projection.fromGeo(...shape[j + 1])
86-
drawLine(x1, y, z1, x2, y, z2, block)
87-
}
88-
}
89-
90-
player.print('Operation completed (' + changedBlocks + ' blocks affected).')
91-
}
92-
93-
function drawLine (x1, y1, z1, x2, y2, z2, block) {
94-
const lenX = x2 - x1
95-
const lenY = y2 - y1
96-
const lenZ = z2 - z1
97-
98-
const max = Math.max(Math.abs(lenX), Math.abs(lenY), Math.abs(lenZ))
99-
100-
const incrX = lenX / max
101-
const incrY = lenY / max
102-
const incrZ = lenZ / max
103-
104-
const incrMax = Math.max(Math.abs(incrX), Math.abs(incrY), Math.abs(incrZ))
105-
106-
for (var i = 0; i < max; i += incrMax) {
107-
var pos = new Vector(Math.floor(x1 + incrX * i), Math.floor(y1 + incrY * i), Math.floor(z1 + incrZ * i))
108-
109-
while (!ignoreBlocks.includes(blocks.getBlock(pos.add(new Vector(0, 1, 0))).id)) {
110-
pos = pos.add(new Vector(0, 1, 0))
111-
}
112-
while (ignoreBlocks.includes(blocks.getBlock(pos).id)) {
113-
pos = pos.add(new Vector(0, -1, 0))
114-
}
115-
116-
if (allowedBlocks.includes(blocks.getBlock(pos).id)) {
117-
if (options.up) {
118-
pos = pos.add(new Vector(0, 1, 0))
119-
}
120-
blocks.setBlock(pos, block)
121-
changedBlocks++
122-
}
123-
}
124-
}
125-
126-
function getIgnoredBlocks () {
127-
return [
128-
context.getBlock('air').id,
129-
context.getBlock('tallgrass').id,
130-
context.getBlock('sapling').id,
131-
context.getBlock('log').id,
132-
context.getBlock('log2').id,
133-
context.getBlock('leaves').id,
134-
context.getBlock('leaves2').id,
135-
context.getBlock('deadbush').id,
136-
context.getBlock('red_flower').id,
137-
context.getBlock('yellow_flower').id,
138-
context.getBlock('red_mushroom').id,
139-
context.getBlock('brown_mushroom').id,
140-
context.getBlock('vine').id,
141-
context.getBlock('waterlily').id,
142-
context.getBlock('cactus').id,
143-
context.getBlock('reeds').id,
144-
context.getBlock('pumpkin').id,
145-
context.getBlock('melon_block').id,
146-
context.getBlock('snow_layer').id,
147-
context.getBlock('double_plant').id
148-
]
149-
}
150-
151-
function getAllowedBlocks () {
152-
return [
153-
context.getBlock('grass').id,
154-
context.getBlock('dirt').id,
155-
context.getBlock('stone').id,
156-
context.getBlock('sand').id,
157-
context.getBlock('grass_path').id,
158-
context.getBlock('concrete').id,
159-
context.getBlock('gravel').id,
160-
context.getBlock('water').id,
161-
context.getBlock('lava').id
162-
]
163-
}

src/list.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
/* global player */
2+
const bte = require('../package.json')
23

34
const list = `Usage: /cs <COMMAND> [ARGS]
45
• list : Lists all available commands.
56
• tpll : Replaces the tpll command.
67
• tpdms : Same as tpll but takes degrees minutes seconds (such as 47°35'6.32"N 6°53'50.06"E ).
7-
• draw : Traces any imported shape of an OpenStreetMap query - railroads, roads, etc.`
8+
• draw : Traces any imported shape of an OpenStreetMap query - railroads, roads, etc.
9+
• rails : Traces all railroads in an area
10+
11+
BTE-tools v${bte.version}
12+
Request features & report issues : ${bte.bugs.url}
13+
`
814

915
player.print(list)

0 commit comments

Comments
 (0)