-
Notifications
You must be signed in to change notification settings - Fork 0
/
rby.rb
74 lines (60 loc) · 1.69 KB
/
rby.rb
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
require 'rubygems'
require 'rack-flash'
require 'sinatra'
require 'erb'
use Rack::Session::Cookie
use Rack::Flash
helpers do
def requested_maps
params.keys & valid_maps
end
def valid_maps
%w[
aethermaw arcanclave_citadel astral_port caves_of_the_basilisk clearing_gushes crescent_lake cynsaun_battlefield
den_of_onis elensefar_courtyard fallenstar_lake hamlets hornshark_island howling_ghost_badlands
sablestone_delta serpent_ford scarred_foothills silverhead_crossing sullas_ruins swamp_of_dread the_freelands
the_walls_of_pyrennis thousand_stings_garrison tombs_of_kesorak weldyn_channel
]
end
def template
File.read 'template.tpl'
end
def max
(requested_maps.size * 2 - 1).to_s
end
def names
requested_maps.map{|name| normalize name}.join ', '
end
def normalize name
name.split('_').map{|word| word.capitalize}.join(' ')
end
def render_template
template.gsub('/names/', names).gsub('/max/', max).gsub('/scenarios/', scenarios)
end
def scenario number, name
scenario = ''
scenario << %Q[\n {RBY_CASE_NEXTSCEN #{number * 2} "RBY #{name} 12"}]
scenario << %Q[\n {RBY_CASE_NEXTSCEN #{number * 2 + 1} "RBY #{name} 21"}]
end
def scenarios
scenarios = ''
requested_maps.each_with_index do |map, index|
normalized_map = normalize map
scenarios << scenario(index, normalized_map)
end
scenarios
end
end
get '/' do
erb :index
end
post '/' do
if requested_maps.size > 1
attachment 'RBY_Custom.cfg' ; content_type 'text/plain' ; render_template
else
flash[:warn] = 'Select at least two maps.' ; redirect '/'
end
end
not_found do
redirect '/'
end