ruby-perlin-2D-map-generator 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -5
- data/lib/CLI/command.rb +15 -4
- data/lib/map.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bd8731cdd9870723cfcb6b977f7d111cc160591f727598ae05be919d6dd231f
|
4
|
+
data.tar.gz: d13ec13f781e96e6251bf37ee54d998c065698063e59d99b8143735c48e7e28a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 766f4c73584e9e5152bf6842790bb3f330ca7d7fd9b46ab7427754f4c7869c0529e870827f181b0523f341d9134e8c5fdce18eecc2ef8a9ad2d22f17112cb040
|
7
|
+
data.tar.gz: ed3f8b411ccced1c278e0038abd92ccb6f856f67b683f13ab5298b51f762e71683efecf69e87ab53b56ecacf24859a8541336330fb65dcb15da2a8ae1e3b2740
|
data/README.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
# Ruby Perlin 2D Map Generator
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ruby-perlin-2D-map-generator.svg)](https://badge.fury.io/rb/ruby-perlin-2D-map-generator)
|
4
|
+
![CI Status](https://github.com/matthewstyler/ruby-perlin-2D-map-generator/actions/workflows/main.yml/badge.svg)
|
5
|
+
![CodeQL](https://github.com/matthewstyler/ruby-perlin-2D-map-generator/workflows/CodeQL/badge.svg)
|
6
|
+
[![Downloads](https://img.shields.io/gem/dt/ruby-perlin-2D-map-generator.svg?style=flat)](https://rubygems.org/gems/ruby-perlin-2D-map-generator)
|
7
|
+
|
2
8
|
A gem that procedurally generates seeded and customizable 2D map using perlin noise.
|
3
9
|
|
4
10
|
Include the gem in your project, or use the executable from the command line.
|
@@ -55,10 +61,26 @@ See Command line Usage for full customization, below are some examples. Alter th
|
|
55
61
|
|
56
62
|
# Generate without rendering
|
57
63
|
|
58
|
-
```
|
64
|
+
```irb
|
59
65
|
irb(main):001:0> map = Map.new
|
60
|
-
|
61
|
-
|
66
|
+
```
|
67
|
+
|
68
|
+
Map can then be manipulated via traditional x,y lookup
|
69
|
+
```irb
|
70
|
+
map[x, y].to_h
|
71
|
+
=>
|
72
|
+
{:x=>0,
|
73
|
+
:y=>1,
|
74
|
+
:height=>0.29251394359649563,
|
75
|
+
:moist=>0.29100678755603004,
|
76
|
+
:temp=>0.6034041566100443,
|
77
|
+
:biome=>{:name=>"deep_valley", :flora_range=>1, :colour=>"\e[48;5;47m"},
|
78
|
+
:items=>[]}
|
79
|
+
```
|
80
|
+
or the less intuitative multidimensional lookup (reversed axis):
|
81
|
+
|
82
|
+
```irb
|
83
|
+
map.tiles[y][x].to_h
|
62
84
|
=>
|
63
85
|
{:x=>0,
|
64
86
|
:y=>1,
|
@@ -69,6 +91,20 @@ irb(main):002:0> map.describe[1][0]
|
|
69
91
|
:items=>[]}
|
70
92
|
```
|
71
93
|
|
94
|
+
or from the command line:
|
95
|
+
|
96
|
+
```bash
|
97
|
+
$ ruby-perlin-2D-map-generator describe coordinates=0,1
|
98
|
+
|
99
|
+
{:x=>0,
|
100
|
+
:y=>1,
|
101
|
+
:height=>0.29251394359649563,
|
102
|
+
:moist=>0.29100678755603004,
|
103
|
+
:temp=>0.6034041566100443,
|
104
|
+
:biome=>{:name=>"deep_valley", :flora_range=>1, :colour=>"\e[48;5;47m"},
|
105
|
+
:items=>[]}
|
106
|
+
```
|
107
|
+
|
72
108
|
# Full Command line Usage
|
73
109
|
```bash
|
74
110
|
$ ruby-perlin-2D-map-generator --help
|
@@ -82,8 +118,14 @@ hashes with each tiles information.
|
|
82
118
|
|
83
119
|
Arguments:
|
84
120
|
(DESCRIBE | RENDER) command to run: render prints the map to standard
|
85
|
-
output using ansi colors
|
86
|
-
|
121
|
+
output using ansi colors. describe prints each tiles
|
122
|
+
bionome information in the map, can be combined with the
|
123
|
+
coordinates keyword to print a specific tile.
|
124
|
+
(permitted: describe, render)
|
125
|
+
|
126
|
+
Keywords:
|
127
|
+
COORDINATES=INT_LIST Used with the describe command, only returns the given
|
128
|
+
coordinate tile details
|
87
129
|
|
88
130
|
Options:
|
89
131
|
--elevation=float Adjust each generated elevation by this percent (0 -
|
@@ -127,4 +169,7 @@ Examples:
|
|
127
169
|
|
128
170
|
Render with options
|
129
171
|
$ ruby-perlin-2D-map-generator render --elevation=-40 --moisture=25 --hs=1
|
172
|
+
|
173
|
+
Describe tile [1, 1]
|
174
|
+
$ ruby-perlin-2D-map-generator describe coordinates=1,1
|
130
175
|
```
|
data/lib/CLI/command.rb
CHANGED
@@ -20,14 +20,25 @@ module CLI
|
|
20
20
|
|
21
21
|
example 'Render with options',
|
22
22
|
' $ ruby-perlin-2D-map-generator render --elevation=-40 --moisture=25 --hs=1'
|
23
|
+
|
24
|
+
example 'Describe tile [1, 1]',
|
25
|
+
' $ ruby-perlin-2D-map-generator describe coordinates=1,1'
|
23
26
|
end
|
24
27
|
|
25
28
|
argument :command do
|
26
29
|
name '(describe | render)'
|
27
30
|
arity one
|
28
|
-
|
29
|
-
desc 'command to run: render prints the map to standard output using ansi colors
|
30
|
-
'
|
31
|
+
permit %w[describe render]
|
32
|
+
desc 'command to run: render prints the map to standard output using ansi colors. ' \
|
33
|
+
'describe prints each tiles bionome information in the map, can be combined with ' \
|
34
|
+
'the coordinates keyword to print a specific tile.'
|
35
|
+
end
|
36
|
+
|
37
|
+
keyword :coordinates do
|
38
|
+
arity one
|
39
|
+
convert :int_list
|
40
|
+
validate ->(v) { v >= 0 }
|
41
|
+
desc 'Used with the describe command, only returns the given coordinate tile details'
|
31
42
|
end
|
32
43
|
|
33
44
|
option :height_seed do
|
@@ -255,7 +266,7 @@ module CLI
|
|
255
266
|
))
|
256
267
|
case params[:command]
|
257
268
|
when 'render' then map.render
|
258
|
-
when 'describe' then puts map.describe
|
269
|
+
when 'describe' then puts(!params[:coordinates].nil? ? map[params[:coordinates][0], params[:coordinates][1]].to_h : map.describe)
|
259
270
|
end
|
260
271
|
end
|
261
272
|
|
data/lib/map.rb
CHANGED
@@ -21,6 +21,14 @@ class Map
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
# rubocop:disable Naming/MethodParameterName:
|
25
|
+
def [](x, y)
|
26
|
+
raise ArgumentError, 'coordinates out of bounds' if y.nil? || y >= tiles.size || x.nil? || x >= tiles[y].size
|
27
|
+
|
28
|
+
tiles[y][x]
|
29
|
+
end
|
30
|
+
# rubocop:enable Naming/MethodParameterName:
|
31
|
+
|
24
32
|
def tiles
|
25
33
|
@tiles ||= MapTileGenerator.new(map: self).generate
|
26
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-perlin-2D-map-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Matthews (matthewstyler)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: perlin
|