Class: Adventure::World
- Inherits:
-
Object
- Object
- Adventure::World
- Defined in:
- lib/adventure/world.rb
Overview
Represents the world where the game takes place.
Instance Attribute Summary collapse
-
#authors ⇒ Object
readonly
An Array of authors, in the format
Name <email> (url). -
#current_room ⇒ Object
readonly
The index of the game's current Room, initially the starting Room.
-
#description ⇒ Object
readonly
A description of the adventure.
-
#global_vars ⇒ Object
readonly
A Hash of variables to be used by the adventure --- currently unused, kept as placeholder.
-
#license ⇒ Object
readonly
The full name of the license the adventure is released under.
-
#player ⇒ Object
readonly
The adventure's player object.
-
#subtitle ⇒ Object
readonly
The adventure's subtitle / flavor text.
-
#title ⇒ Object
readonly
The adventure's title / name.
-
#year ⇒ Object
readonly
The year (or years) of development of the adventure.
Class Method Summary collapse
-
.load(file) ⇒ Object
Class method.
Instance Method Summary collapse
-
#initialize(**opts) ⇒ World
constructor
Create a new game instance - a new World.
-
#save(file) ⇒ Object
Instance methods.
Constructor Details
#initialize(**opts) ⇒ World
Create a new game instance - a new World.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/adventure/world.rb', line 47 def initialize(**opts) @title = opts.key?(:title) ? opts[:title].trim : '' @subtitle = opts.key?(:subtitle) ? opts[:subtitle].trim : nil @authors = opts.key?(:authors) ? opts[:authors].to_a : [] @license = opts.key?(:license) ? opts[:license].trim : 'Creative Commons 0 1.0 Universal' @year = opts.key?(:year) ? opts[:year].trim : Date.today.year.to_s @description = opts.key?(:description) ? opts[:description].trim : '' @player = opts.key?(:player) ? opts[:player].to_i : nil @atlas = opts.key?(:atlas) ? opts[:atlas].to_a : [] @current_room = opts.key?(:current_room) ? opts[:current_room].to_i : 0 @global_vars = opts.key?(:global_vars) ? opts[:global_vars].to_h : {} end |
Instance Attribute Details
#authors ⇒ Object (readonly)
An Array of authors, in the format Name <email> (url).
20 21 22 |
# File 'lib/adventure/world.rb', line 20 def @authors end |
#current_room ⇒ Object (readonly)
The index of the game's current Room, initially the starting Room.
30 31 32 |
# File 'lib/adventure/world.rb', line 30 def current_room @current_room end |
#description ⇒ Object (readonly)
A description of the adventure.
26 27 28 |
# File 'lib/adventure/world.rb', line 26 def description @description end |
#global_vars ⇒ Object (readonly)
A Hash of variables to be used by the adventure --- currently unused, kept as placeholder.
32 33 34 |
# File 'lib/adventure/world.rb', line 32 def global_vars @global_vars end |
#license ⇒ Object (readonly)
The full name of the license the adventure is released under.
22 23 24 |
# File 'lib/adventure/world.rb', line 22 def license @license end |
#player ⇒ Object (readonly)
The adventure's player object.
28 29 30 |
# File 'lib/adventure/world.rb', line 28 def player @player end |
#subtitle ⇒ Object (readonly)
The adventure's subtitle / flavor text.
18 19 20 |
# File 'lib/adventure/world.rb', line 18 def subtitle @subtitle end |
#title ⇒ Object (readonly)
The adventure's title / name.
16 17 18 |
# File 'lib/adventure/world.rb', line 16 def title @title end |
#year ⇒ Object (readonly)
The year (or years) of development of the adventure.
24 25 26 |
# File 'lib/adventure/world.rb', line 24 def year @year end |
Class Method Details
.load(file) ⇒ Object
Class method
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/adventure/world.rb', line 62 def self.load(file) yaml = Psych.safe_load_file( file, permitted_classes: [ Adventure::Being, Adventure::Inventory, Adventure::Item, # Adventure::Player, Adventure::Purse, Adventure::Room, Adventure::World ], aliases: true ) raise StandardError, 'Invalid input.' if yaml.nil? yaml end |
Instance Method Details
#save(file) ⇒ Object
Instance methods
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/adventure/world.rb', line 82 def save(file) yaml = Psych.safe_dump( self, permitted_classes: [ Adventure::Being, Adventure::Inventory, Adventure::Item, # Adventure::Player, Adventure::Purse, Adventure::Room, Adventure::World ] ) File.write(file, yaml) end |