super_simple_world_builder 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README +47 -0
- data/bin/super_simple_world_builder +53 -0
- data/lib/super_simple_world_builder/feature_set.rb +15 -0
- data/lib/super_simple_world_builder/world.rb +143 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de14f50b2e48b61cb7ae290b22dade156d622f48d2385dfcb9adb93eaafdcc89
|
4
|
+
data.tar.gz: 80526ac2883656e8fc735a2baff4058c67505a80c90159aba9d92bdd78083ec4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f2abf5f973ea291d49c42c774b1de12248de91f12c37a9a8e43cd7cd1d6e69233b5817cc93c4c3d85bd7d759e790968146bd0da811363faea8c87dfe7852b91
|
7
|
+
data.tar.gz: 2fcea5a1fd2a7d6cc25d477510471f681420e1bf71ee55438b837416506e51e7ed2370dc5fa401a1d31e1f73b6095c135c0a5d4a06653df44369bddb8b7c9b56
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2020 Kevin Tanyag
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
USE CASES:
|
2
|
+
|
3
|
+
1. Your friends bully you because your imaginary role playing worlds are predictable and boring.
|
4
|
+
2. You like seeing chars printed in nifty patterns.
|
5
|
+
|
6
|
+
HOW TO RUN:
|
7
|
+
|
8
|
+
1. Run `ruby super_simple_world_builder.rb`
|
9
|
+
2. Follow the prompts
|
10
|
+
|
11
|
+
EXAMPLE INPUT:
|
12
|
+
|
13
|
+
Guten Tag! Welcome to Super Simple World Builder.
|
14
|
+
Enter 1 to build a random world
|
15
|
+
Enter 2 to build a custom world
|
16
|
+
Please enter your selection (1, 2, or exit):
|
17
|
+
2
|
18
|
+
Enter the name of your world:
|
19
|
+
Community-Town
|
20
|
+
Enter the minimum width of the world:
|
21
|
+
15
|
22
|
+
Enter the minimum height of the world:
|
23
|
+
15
|
24
|
+
What character do you want to fill the background of your world with? (i.e. any character or single space)
|
25
|
+
|
26
|
+
How many lake features do you want?
|
27
|
+
3
|
28
|
+
How many mountain features do you want?
|
29
|
+
2
|
30
|
+
How many town features do you want?
|
31
|
+
3
|
32
|
+
How many forest features do you want?
|
33
|
+
4
|
34
|
+
|
35
|
+
OUTPUT:
|
36
|
+
|
37
|
+
1. Console print out of the world map
|
38
|
+
2. A text file of the world map
|
39
|
+
|
40
|
+
ACHTUNG:
|
41
|
+
|
42
|
+
1. Don't worry if the width or height entered is too small. The world will automatically enlarge to fit all features.
|
43
|
+
2. World maps look better when you enter a <space> as the character to fill the background.
|
44
|
+
3. This is a quick-and-dirty project so yolo with the specs. I added comments as a consolation prize.
|
45
|
+
4. See `feature_set.rb` to tweak the features that can be added to the world map.
|
46
|
+
5. Interestingly, menu prompts may not show up in the git bash terminal. But they do show up in Windows command prompt, so lmao.
|
47
|
+
6. Feel free to tweak the code however you like. I plan to refactor in the future to dry up some sections.
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/super_simple_world_builder/world'
|
3
|
+
require_relative '../lib/super_simple_world_builder/feature_set'
|
4
|
+
|
5
|
+
module SuperSimpleWorldBuilder
|
6
|
+
features = FeatureSet::FEATURES
|
7
|
+
user_features = {}
|
8
|
+
|
9
|
+
loop do
|
10
|
+
puts "Guten Tag! Welcome to Super Simple World Builder.\n"
|
11
|
+
puts "Enter 1 to build a random world"
|
12
|
+
puts "Enter 2 to build a custom world"
|
13
|
+
puts "Please enter your selection (1, 2, or exit): "
|
14
|
+
answer = gets.chomp.downcase
|
15
|
+
|
16
|
+
case answer
|
17
|
+
when "1"
|
18
|
+
puts "Building a random world..."
|
19
|
+
world = SuperSimpleWorldBuilder::World.new("Randoville#{rand(1..10000000)}", 20, 20)
|
20
|
+
world.print_map_to_console
|
21
|
+
world.export_map_to_file
|
22
|
+
break
|
23
|
+
when "2"
|
24
|
+
puts "Enter the name of your world: "
|
25
|
+
name = gets.chomp
|
26
|
+
|
27
|
+
puts "Enter the minimum width of the world: "
|
28
|
+
width = gets.chomp.downcase.to_i
|
29
|
+
|
30
|
+
puts "Enter the minimum height of the world: "
|
31
|
+
height = gets.chomp.downcase.to_i
|
32
|
+
|
33
|
+
puts "What character do you want to fill the background of your world with? (i.e. any character or single space)"
|
34
|
+
filler = gets.chomp.downcase
|
35
|
+
|
36
|
+
features.each do |f|
|
37
|
+
puts "How many #{f.name} features do you want?"
|
38
|
+
answer = gets.chomp.downcase.to_i
|
39
|
+
user_features[f.name] = answer
|
40
|
+
end
|
41
|
+
|
42
|
+
puts "Generating #{name}..."
|
43
|
+
world = SuperSimpleWorldBuilder::World.new(name, width, height, filler, user_features)
|
44
|
+
world.print_map_to_console
|
45
|
+
world.export_map_to_file
|
46
|
+
break
|
47
|
+
when "quit", "exit"
|
48
|
+
break
|
49
|
+
else
|
50
|
+
puts "Woops. Enter 1, 2, or exit:"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SuperSimpleWorldBuilder
|
2
|
+
Feature = Struct.new(:name, :width, :height, :filler)
|
3
|
+
|
4
|
+
module FeatureSet
|
5
|
+
FEATURES = [
|
6
|
+
Feature.new(:lake, rand(4..7), rand(5..11), '~' ),
|
7
|
+
Feature.new(:mountain, rand(4..12), rand(2..13), 'M'),
|
8
|
+
Feature.new(:town, rand(4..6), rand(5..14), '#'),
|
9
|
+
Feature.new(:forest, rand(4..10), rand(5..11), '^'),
|
10
|
+
]
|
11
|
+
|
12
|
+
RANDOM_FEATURE_MIN = 1
|
13
|
+
RANDOM_FEATURE_MAX = 20
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require_relative 'feature_set'
|
2
|
+
|
3
|
+
module SuperSimpleWorldBuilder
|
4
|
+
class World
|
5
|
+
|
6
|
+
#Number of iterations of randomly placing features on map before enlarging
|
7
|
+
DEPTH_MAX = 30
|
8
|
+
|
9
|
+
#Number of rows and cols to expand map by
|
10
|
+
DEPTH_INCR = 3
|
11
|
+
|
12
|
+
def initialize(name, width, height, filler=' ', user_features={})
|
13
|
+
@name = name
|
14
|
+
@width = width
|
15
|
+
@height = height
|
16
|
+
@filler = filler
|
17
|
+
@user_features = user_features
|
18
|
+
|
19
|
+
#initialize 2d array
|
20
|
+
@map = Array.new(@height) { Array.new(@width, @filler) }
|
21
|
+
|
22
|
+
@depth_count = 0
|
23
|
+
@map_enlarged = false
|
24
|
+
|
25
|
+
@features = FeatureSet::FEATURES
|
26
|
+
|
27
|
+
#randomly defines number of each feature if random world created
|
28
|
+
if user_features.empty?
|
29
|
+
@features.each do |f|
|
30
|
+
@user_features[f.name] = rand(FeatureSet::RANDOM_FEATURE_MIN..FeatureSet::RANDOM_FEATURE_MAX)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
add_feature_shuffler.each { |f| add_feature_to_map(f) }
|
35
|
+
end
|
36
|
+
|
37
|
+
#shuffles feature names into array to keep distribution random if map enlarged
|
38
|
+
#iterates over names and adds to map
|
39
|
+
def add_feature_shuffler
|
40
|
+
user_features_shuffled = []
|
41
|
+
@user_features.each do |k, v|
|
42
|
+
v.times {user_features_shuffled << k}
|
43
|
+
end
|
44
|
+
|
45
|
+
user_features_shuffled.shuffle!
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_feature(name)
|
49
|
+
feature = ""
|
50
|
+
@features.each do |f|
|
51
|
+
if f.name == name.to_sym
|
52
|
+
feature = f
|
53
|
+
end
|
54
|
+
end
|
55
|
+
feature
|
56
|
+
end
|
57
|
+
|
58
|
+
def print_legend
|
59
|
+
puts "Legend"
|
60
|
+
puts "-------"
|
61
|
+
@features.each do |f|
|
62
|
+
puts "#{f.name.capitalize} (#{@user_features[f.name]})".ljust(30, ".") + " #{f.filler}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_feature_to_map(name)
|
67
|
+
feature = get_feature(name)
|
68
|
+
|
69
|
+
#randomly pick x,y coords on map
|
70
|
+
x = rand(0..@map[0].size)
|
71
|
+
y = rand(0..@map.size)
|
72
|
+
|
73
|
+
#if there's enough space at the coords, add the feature to the map
|
74
|
+
#see FeatureSet::FEATURES for dimensions and filler char
|
75
|
+
if enough_space?(x, y, feature)
|
76
|
+
feature.height.times do |i|
|
77
|
+
feature.width.times do |j|
|
78
|
+
@map[y+i][x+j] = feature.filler
|
79
|
+
end
|
80
|
+
end
|
81
|
+
else
|
82
|
+
@depth_count += 1
|
83
|
+
|
84
|
+
#if feature couldn't be placed at coords the max amount of times then enlarge map and try again
|
85
|
+
if @depth_count > DEPTH_MAX
|
86
|
+
@depth_count = 0
|
87
|
+
|
88
|
+
#increases HEIGHT of existing 2d arr by DEPTH_INCR
|
89
|
+
#and fill with existing number of arr elements
|
90
|
+
DEPTH_INCR.times {@map.push([])}
|
91
|
+
DEPTH_INCR.times do |i|
|
92
|
+
@map[0].size.times { @map[@map.size-DEPTH_INCR+i] << @filler }
|
93
|
+
end
|
94
|
+
|
95
|
+
#increases WIDTH of existing 2d arr by DEPTH_INCR
|
96
|
+
@map.size.times do |i|
|
97
|
+
DEPTH_INCR.times {@map[i] << @filler}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
@map_enlarged = true
|
102
|
+
add_feature_to_map(name)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
#point (x,y) indicates top left corner of feature
|
107
|
+
def enough_space?(x, y, feature)
|
108
|
+
result = true
|
109
|
+
if (x + feature.width) > @map[0].size || (y + feature.height) > @map.size
|
110
|
+
result = false
|
111
|
+
elsif
|
112
|
+
feature.height.times do |i|
|
113
|
+
feature.width.times do |j|
|
114
|
+
if @map[y+i][x+j] != @filler
|
115
|
+
result = false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
result
|
121
|
+
end
|
122
|
+
|
123
|
+
def print_map_to_console
|
124
|
+
puts "#{@name.center((@map[0].size*2)-1, '~')}\n\n"
|
125
|
+
puts @map.map { |x| x.join(' ') }
|
126
|
+
print_legend
|
127
|
+
puts "\n#{@name} was enlarged from #{@width}x#{@height} to #{@map[0].size}x#{@map.size} to accomodate all #{@user_features.values.reduce(:+)} features." if @map_enlarged
|
128
|
+
end
|
129
|
+
|
130
|
+
def export_map_to_file
|
131
|
+
File.open("#{@name}.txt", "w") do |file|
|
132
|
+
file.puts "#{@name.center((@map[0].size*2)-1, '~')}\n\n"
|
133
|
+
file.puts @map.map { |x| x.join(' ') }
|
134
|
+
file.puts "\nLegend"
|
135
|
+
file.puts "-------"
|
136
|
+
@features.each do |f|
|
137
|
+
file.puts "#{f.name.capitalize} (#{@user_features[f.name]})".ljust(30, ".") + " #{f.filler}"
|
138
|
+
end
|
139
|
+
file.puts "\n#{@name} was enlarged from #{@width}x#{@height} to #{@map[0].size}x#{@map.size} to accomodate all #{@user_features.values.reduce(:+)} features." if @map_enlarged
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: super_simple_world_builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- andydwyer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.8.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.8'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.8.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.8'
|
33
|
+
description: "USE CASES:\n\n1. Your friends bully you because your imaginary role
|
34
|
+
playing worlds are predictable and boring.\n2. You like seeing chars printed in
|
35
|
+
nifty patterns.\n\nHOW TO RUN:\n\n1. Run `ruby super_simple_world_builder.rb`\n2.
|
36
|
+
Follow the prompts\n\nEXAMPLE INPUT:\n\nGuten Tag! Welcome to Super Simple World
|
37
|
+
Builder.\nEnter 1 to build a random world\nEnter 2 to build a custom world\nPlease
|
38
|
+
enter your selection (1, 2, or exit):\n2\nEnter the name of your world:\nCommunity-Town\nEnter
|
39
|
+
the minimum width of the world:\n15\nEnter the minimum height of the world:\n15\nWhat
|
40
|
+
character do you want to fill the background of your world with? (i.e. any character
|
41
|
+
or single space)\n \nHow many lake features do you want?\n3\nHow many mountain features
|
42
|
+
do you want?\n2\nHow many town features do you want?\n3\nHow many forest features
|
43
|
+
do you want?\n4\n\nOUTPUT:\n\n1. Console print out of the world map\n2. A text file
|
44
|
+
of the world map\n\nACHTUNG:\n\n1. Don't worry if the width or height entered is
|
45
|
+
too small. The world will automatically enlarge to fit all features.\n2. World maps
|
46
|
+
look better when you enter a <space> as the character to fill the background.\n3.
|
47
|
+
This is a quick-and-dirty project so yolo with the specs. I added comments as a
|
48
|
+
consolation prize.\n4. See `feature_set.rb` to tweak the features that can be added
|
49
|
+
to the world map.\n5. Interestingly, menu prompts may not show up in the git bash
|
50
|
+
terminal. But they do show up in Windows command prompt, so lmao.\n6. Feel free
|
51
|
+
to tweak the code however you like. I plan to refactor in the future to dry up some
|
52
|
+
sections."
|
53
|
+
email: ktanyag@gmail.com
|
54
|
+
executables:
|
55
|
+
- super_simple_world_builder
|
56
|
+
extensions: []
|
57
|
+
extra_rdoc_files: []
|
58
|
+
files:
|
59
|
+
- LICENSE
|
60
|
+
- README
|
61
|
+
- bin/super_simple_world_builder
|
62
|
+
- lib/super_simple_world_builder/feature_set.rb
|
63
|
+
- lib/super_simple_world_builder/world.rb
|
64
|
+
homepage:
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.9'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.0.3
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: CL tool to create a super simple world for role playing and such.
|
87
|
+
test_files: []
|