-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaptool.rb
More file actions
executable file
·161 lines (146 loc) · 3.36 KB
/
maptool.rb
File metadata and controls
executable file
·161 lines (146 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env ruby
# map tool
# 2006 drr
# all rights negated
require 'conf'
require 'map'
class Maptool
def initialize
puts "\nwelcome to maptool\n"
menu
end
def menu
puts ""
puts "n) new map"
puts "l) load map"
if @map != nil
puts "s) save map"
puts "z) clear map"
puts "c) generate land"
puts "i) generate island"
puts "e) edit tile"
end
puts "q) quit"
print "maptool> "
option = STDIN.gets.chomp
puts ""
case option
when "n"
newmap
when "l"
loadmap
when "e"
edittile
when "s"
savemap
when "q"
puts "buh bye!"
when "i"
newisland
when "c"
newlands
when "z"
clearmap
else
puts "invalid command"
menu
end
end
def loadmap
print "Enter map name: "
mapfile = STDIN.gets.chomp
@map = YAML::load( File.open( "#{$root_dir}/maps/#{mapfile}.fmap" ) )
@map.composite($temp_map_name)
puts "loaded #{mapfile}"
menu
end
def savemap
print "Enter map name: "
mapfilename = STDIN.gets.chomp
mapfile = File.new("#{$root_dir}/maps/#{mapfilename}.fmap", "w")
mapfile.puts @map.to_yaml
mapfile.close
@map.composite("#{mapfilename}")
puts "saved"
menu
end
def edittile
print "x: "
x = STDIN.gets.chomp.to_i
print "y: "
y = STDIN.gets.chomp.to_i
print "type: "
type = STDIN.gets.chomp
case type
when "w"
type = "water"
when "l"
type = "land"
end
@map.set_tile(x,y,type)
@map.composite($temp_map_name)
menu
end
def newisland
puts "map is #{@map.tiles_across} tiles across"
print "x: "
x = STDIN.gets.chomp.to_i
print "y: "
y = STDIN.gets.chomp.to_i
print "size: "
size = STDIN.gets.chomp.to_i
@map.generate_island(x,y,size)
@map.composite($temp_map_name)
puts "island generated"
menu
end
def newlands
print "Enter percentage of map to be land: "
landpercentage = STDIN.gets.chomp
landpercentage = "0.#{landpercentage}".to_f
@map.generate_lands(landpercentage)
@map.composite($temp_map_name)
puts "land generated"
menu
end
def clearmap
@map = Map.new
@map.create(@map_pixels_across,@tile_pixels_across,@map_base_tile,@tileset,@map_edge_space)
@map.composite($temp_map_name)
puts "cleared map"
menu
end
def newmap
@map = Map.new
print "Enter how many pixels across the map should be: [ Enter for default of #{$map_pixels_across} ] "
@map_pixels_across = STDIN.gets.chomp.to_i
if @map_pixels_across < 1
@map_pixels_across = $map_pixels_across
end
print "Enter how many pixels across each tile should be: [ Enter for default of #{$tile_pixels_across} ] "
@tile_pixels_across = STDIN.gets.chomp.to_i
if @tile_pixels_across < 1
@tile_pixels_across = $tile_pixels_across
end
print "Enter name of the tileset: [ Enter for default of #{$tileset} ] "
@tileset = STDIN.gets.chomp
if @tileset == ""
@tileset = $tileset
end
print "Enter name of base tile: [ Enter for default of #{$map_base_tile} ] "
@map_base_tile = STDIN.gets.chomp
if @map_base_tile == ""
@map_base_tile = $map_base_tile
end
print "Enter amount of base tile to border the edge of the map [ Enter for default of #{$map_edge_space} ] "
@map_edge_space = STDIN.gets.chomp.to_i
if @map_edge_space < 1
@map_edge_space = $map_edge_space
end
@map.create(@map_pixels_across,@tile_pixels_across,@map_base_tile,@tileset,@map_edge_space)
@map.composite($temp_map_name)
puts "created new map"
menu
end
end
Maptool.new