room 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/bin/room CHANGED
@@ -10,22 +10,39 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
10
10
 
11
11
  require "room"
12
12
 
13
- opts = OptionParser.new
14
- opts.on("-h", "--help") do
13
+ def usage
15
14
  puts "usage: room"
16
- puts " room [room-file.rb]"
15
+ puts " room for [room name]"
17
16
  exit
18
17
  end
19
- opts.parse! ARGV
20
18
 
21
- FILENAME = ARGV[0] || File.join(File.dirname(__FILE__), '..', 'examples', 'example1.rb')
19
+ def find_room name
20
+ files = []
21
+ files << "#{name}.rb"
22
+ files << File.join(File.dirname(__FILE__), "..", "rooms", "#{name}.rb")
23
+
24
+ files.find { |f| File.readable? f }
25
+ end
26
+
27
+ opts = OptionParser.new
28
+ opts.on("-h", "--help") { usage }
29
+ opts.parse! ARGV
22
30
 
23
- unless File.readable?(FILENAME)
24
- $stderr.puts "cannot read file #{FILENAME}"
25
- exit 1
31
+ if ARGV.length > 0
32
+ if ARGV[0] == "for" && !ARGV[1].nil?
33
+ @filename = find_room ARGV[1]
34
+ unless @filename
35
+ puts "room \"#{ARGV[1]}\" not found"
36
+ exit 1
37
+ end
38
+ else
39
+ usage
40
+ end
41
+ else
42
+ @filename = find_room "beginners"
26
43
  end
27
44
 
28
- reload!
45
+ reload! @filename
29
46
 
30
47
  3.times { Printer.puts }
31
48
 
@@ -37,6 +54,8 @@ loop do
37
54
  else
38
55
  Readline.readline("> ", true)
39
56
  end
57
+
58
+ break unless line
40
59
  Room.do line.chomp
41
60
  end
42
61
 
data/lib/room.rb CHANGED
@@ -1,11 +1,12 @@
1
1
 
2
2
  require "thread"
3
3
 
4
- def reload!
4
+ def reload! filename=nil
5
5
  $commands = {}
6
+ $last_filename ||= filename
6
7
 
7
8
  old_count = Room.rooms.keys.length
8
- load FILENAME
9
+ load $last_filename
9
10
  Room.rooms.keys.length - old_count
10
11
  end
11
12
 
@@ -21,6 +22,16 @@ class String
21
22
  def commandify
22
23
  Regexp.compile("^" + Regexp.escape(self.gsub("_", " ")).gsub("XXX", "(.+)") + "$")
23
24
  end
25
+
26
+ # I actively support the inclusion of this method
27
+ def underscore
28
+ word = dup
29
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
30
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
31
+ word.tr!("-", "_")
32
+ word.downcase!
33
+ word
34
+ end
24
35
  end
25
36
 
26
37
  class Printer
@@ -40,7 +51,11 @@ class Room
40
51
  Room.go key
41
52
  end
42
53
 
43
- def be_secretive
54
+ def quietly_go key
55
+ Room.go key, false
56
+ end
57
+
58
+ def no_echo
44
59
  $secretive = true
45
60
  end
46
61
 
@@ -97,7 +112,7 @@ class Room
97
112
 
98
113
  class << self
99
114
  def key
100
- self.to_s.downcase
115
+ self.to_s.underscore
101
116
  end
102
117
 
103
118
  def commands
@@ -109,10 +124,10 @@ class Room
109
124
  $rooms ||= {}
110
125
  end
111
126
 
112
- def go key
127
+ def go key, look = true
113
128
  if rooms[key]
114
129
  $here = rooms[key]
115
- "\n" + $here.look
130
+ "\n" + $here.look if look
116
131
  else
117
132
  $here.unknown_room key
118
133
  end
data/room.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{room}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tom Lieber"]
12
- s.date = %q{2011-03-17}
12
+ s.date = %q{2011-04-01}
13
13
  s.default_executable = %q{room}
14
14
  s.description = %q{the game is making the game}
15
15
  s.email = %q{tom@alltom.com}
@@ -25,17 +25,14 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "bin/room",
28
- "examples/example1.rb",
29
28
  "lib/room.rb",
30
- "room.gemspec"
29
+ "room.gemspec",
30
+ "rooms/beginners.rb"
31
31
  ]
32
32
  s.homepage = %q{http://github.com/alltom/room}
33
33
  s.require_paths = ["lib"]
34
34
  s.rubygems_version = %q{1.6.2}
35
35
  s.summary = %q{the game is making the game}
36
- s.test_files = [
37
- "examples/example1.rb"
38
- ]
39
36
 
40
37
  if s.respond_to? :specification_version then
41
38
  s.specification_version = 3
File without changes
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: room
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Lieber
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-17 00:00:00 -07:00
18
+ date: 2011-04-01 00:00:00 -07:00
19
19
  default_executable: room
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -80,9 +80,9 @@ files:
80
80
  - Rakefile
81
81
  - VERSION
82
82
  - bin/room
83
- - examples/example1.rb
84
83
  - lib/room.rb
85
84
  - room.gemspec
85
+ - rooms/beginners.rb
86
86
  has_rdoc: true
87
87
  homepage: http://github.com/alltom/room
88
88
  licenses: []
@@ -117,5 +117,5 @@ rubygems_version: 1.6.2
117
117
  signing_key:
118
118
  specification_version: 3
119
119
  summary: the game is making the game
120
- test_files:
121
- - examples/example1.rb
120
+ test_files: []
121
+