This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaeldardin-to-key.rb
65 lines (51 loc) · 1.97 KB
/
aeldardin-to-key.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
# File: aeldardin-to-key.rb
#
# Converts Aeldardin-Key YAML into Markdown describing the dungeon;
# this aims to be a key you could actually run the adventure from.
require 'dungeon'
module Aeldardin
class ToKey
def self.run
case ARGV.length
when 0
input_file = STDIN
when 1
input_file = File.open(ARGV[0], 'r')
else
STDERR.puts "Usage: #{$PROGRAM_NAME} [<filename.yml>]"
exit 1
end
dungeon = Aeldardin::Dungeon.load(input_file)
Aeldardin::ToKey.new(dungeon).generateMarkdown(STDOUT)
end
# @param [Aeldardin::Dungeon] dungeon The dungeon to render to Dot format.
def initialize(dungeon)
@dungeon = dungeon
end
# @param [IO] output_file The IO object to write the output .gv graph data into.
def generateMarkdown(output_file)
# TODO: is it better to sort by key, or by region?
# (assuming the map is already keyed and can't be re-keyed to match the regions).
@dungeon.rooms_by_key.each do |_key, room|
# ## is a level-2 Markdown heading
title = "## #{room.key}."
title << " #{room.name}" if room.name
output_file.puts(title)
output_file.puts
if room.description
output_file.puts room.description
output_file.puts
end
room.objects.each do |object|
# * is a list item; spaces for indentation mean a list continuation.
output_file.puts("* #{object[:item]}")
if object[:description]
output_file.puts(" #{object[:description]}")
end
end
output_file.puts
end
end
private
end
end