Top Level Namespace
Defined Under Namespace
Classes: Printer, Room, String
Instance Method Summary
collapse
Instance Method Details
#find_room(name) ⇒ Object
19
20
21
22
23
24
25
|
# File 'bin/room', line 19
def find_room name
files = []
files << "#{name}.rb"
files << File.join(File.dirname(__FILE__), "..", "rooms", "#{name}.rb")
files.find { |f| File.readable? f }
end
|
#load! ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/room.rb', line 44
def load!
_, file_path = prefs_paths
return unless File.exist? file_path
begin
$state = Marshal.load(File.read(file_path))
@previous_load_error = false
rescue Exception => e
unless @previous_load_error
Printer.puts "[warning: couldn't load state: #{e}]"
@previous_load_error = true
end
end
end
|
#no_save! ⇒ Object
24
25
26
|
# File 'lib/room.rb', line 24
def no_save!
$no_save = true
end
|
#prefs_paths ⇒ Object
18
19
20
21
22
|
# File 'lib/room.rb', line 18
def prefs_paths
dir_path = File.expand_path("~/.room")
file_path = File.join(dir_path, $room_name)
[dir_path, file_path]
end
|
#reload!(room_name = nil, filename = nil) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/room.rb', line 6
def reload! room_name = nil, filename = nil
$commands = {}
$room_name ||= room_name
$last_filename ||= filename
load $last_filename
load!
$state[:here] ||= $starting_room
end
|
#save!(obj = $state) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/room.rb', line 28
def save! obj = $state
return if $no_save
dir_path, file_path = prefs_paths
begin
Dir::mkdir dir_path unless File.exist? dir_path
File.open(file_path, "wb") { |f| f.write Marshal.dump(obj || {}) }
@previous_save_error = false
rescue Exception => e
unless @previous_save_error
Printer.puts "[warning: couldn't save state: #{e}]"
@previous_save_error = true
end
end
end
|
#usage ⇒ Object
13
14
15
16
17
|
# File 'bin/room', line 13
def usage
puts "usage: room"
puts " room for [room name]"
exit
end
|