gamefic 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6840c99f360ddbe9171237724e2462369b6e9436
4
- data.tar.gz: dae8127b46901506eaf847fbb1c56db6591d69af
3
+ metadata.gz: c9653029c10eea5877023b0f33166f04097390a0
4
+ data.tar.gz: 7fc2ed5e68a3e308524abb5f2d273fbc69ea18bd
5
5
  SHA512:
6
- metadata.gz: 7276ad50d8871721e1999184e3e37ae6fafd8523a816d35708a2c0ac3766c1453cbe3449a73c2205481266cf2200c14309f53accc8ad15573ae1db4cdfc85f33
7
- data.tar.gz: d5ce49c27cff38d30024bd418b2b979e20b3acd78f2c14e2b16ff82662086084965fa767a4d8bbe6e6b6bc4ff88cb48952cdb7f5bf349d64577a922005d9bd3e
6
+ metadata.gz: 55f967f633d6054a4b9f3700938a0f0eb81a877957f3aa11c09119d102ddaac71fdb566ac9ffa5a9daddceec22aa523228c0271707d8a60ce71629618d666517
7
+ data.tar.gz: 857869d33e31abb8ca303b070210e626e7d4e0572416a71a70d2411e8878960100a2543d4c3887bad2cdd21cf4fe7bdf5135bebb363652551f1736ed69d387bd
@@ -47,7 +47,7 @@ class Array
47
47
  if self.length < 3
48
48
  self.join(andSep)
49
49
  else
50
- start = self - [self.last]
50
+ start = self[0..-2]
51
51
  start.join(sep) + "#{serial ? sep.strip : ''}#{andSep}#{self.last}"
52
52
  end
53
53
  end
@@ -66,12 +66,12 @@ module Gamefic
66
66
  scenes[key] = Scene::Passive.new &block
67
67
  end
68
68
 
69
- # Branch to a new scene based on a list of options.
69
+ # Choose a new scene based on a list of options.
70
70
  # This is a specialized type of multiple-choice scene that determines
71
71
  # which scene to cue based on a Hash of choices and scene keys.
72
72
  #
73
73
  # @example Select a scene
74
- # branch :select_one_or_two, { "one" => :scene_one, "two" => :scene_two }
74
+ # multiple_scene :select_one_or_two, { "one" => :scene_one, "two" => :scene_two }
75
75
  # scene :scene_one do |actor|
76
76
  # actor.tell "You went to scene one"
77
77
  # end
@@ -79,12 +79,12 @@ module Gamefic
79
79
  # actor.tell "You went to scene two"
80
80
  # end
81
81
  # introduction do |actor|
82
- # actor.cue, :select_one_or_two # The actor will be prompted to select "one" or "two" and get sent to the corresponding scene
82
+ # actor.cue :select_one_or_two # The actor will be prompted to select "one" or "two" and get sent to the corresponding scene
83
83
  # end
84
84
  #
85
85
  # @param key [Symbol] A unique name for the scene.
86
86
  # @param map [Hash] A Hash of options and associated scene keys.
87
- def branch key, map
87
+ def multiple_scene key, map
88
88
  scenes[key] = Scene::MultipleChoice.new(
89
89
  options: map.keys,
90
90
  finish: proc { |actor, input|
@@ -4,41 +4,11 @@ module Gamefic
4
4
  module Plot::Snapshot
5
5
 
6
6
  # Take a snapshot of the plot's current state.
7
+ # The snapshot is a hash with two keys: entities and subplots.
7
8
  #
8
9
  # @return [Hash]
9
10
  def save
10
- store = []
11
- index = 0
12
- entities.each { |e|
13
- hash = {}
14
- e.serialized_attributes.each {|m|
15
- con = m.to_s
16
- if con.end_with?("?")
17
- con = con[0..-2]
18
- end
19
- if e.respond_to?(m) == true
20
- begin
21
- val = e.send(m)
22
- if val == false
23
- hash[con] = false
24
- elsif val
25
- hash[con] = serialize_obj(val)
26
- else
27
- hash[con] = nil
28
- end
29
- rescue Exception => error
30
- hash[con] = nil
31
- end
32
- end
33
- }
34
- hash[:class] = e.class.to_s
35
- hash[:session] = {}
36
- e.session.each_pair { |k, v|
37
- hash[:session][k] = serialize_obj(v)
38
- }
39
- store.push hash
40
- index += 1
41
- }
11
+ store = get_entity_hash
42
12
  if @initial_state.nil?
43
13
  @initial_state = store
44
14
  store = []
@@ -75,6 +45,42 @@ module Gamefic
75
45
  internal_restore @initial_state
76
46
  end
77
47
 
48
+ def get_entity_hash
49
+ store = []
50
+ index = 0
51
+ entities.each { |e|
52
+ hash = {}
53
+ e.serialized_attributes.each {|m|
54
+ con = m.to_s
55
+ if con.end_with?("?")
56
+ con = con[0..-2]
57
+ end
58
+ if e.respond_to?(m) == true
59
+ begin
60
+ val = e.send(m)
61
+ if val == false
62
+ hash[con] = false
63
+ elsif val
64
+ hash[con] = serialize_obj(val)
65
+ else
66
+ hash[con] = nil
67
+ end
68
+ rescue Exception => error
69
+ hash[con] = nil
70
+ end
71
+ end
72
+ }
73
+ hash[:class] = e.class.to_s
74
+ hash[:session] = {}
75
+ e.session.each_pair { |k, v|
76
+ hash[:session][k] = serialize_obj(v)
77
+ }
78
+ store.push hash
79
+ index += 1
80
+ }
81
+ store
82
+ end
83
+
78
84
  def internal_restore snapshot
79
85
  index = 0
80
86
  snapshot.each { |hash|
@@ -45,7 +45,6 @@ module Gamefic
45
45
  else
46
46
  input_object = Input.new(input, index, choice)
47
47
  super actor, input_object
48
- actor.cue :active if (actor.scene == this_scene and actor.next_scene.nil?)
49
48
  end
50
49
  end
51
50
 
@@ -21,9 +21,12 @@ module Gamefic
21
21
  decompress file, dir
22
22
  run_game(dir)
23
23
  end
24
- rescue StandardError => e
24
+ rescue Zip::Error => e
25
25
  puts "'#{file}' does not appear to be a valid Gamefic file."
26
26
  show_exception(e) if options[:verbose]
27
+ rescue StandardError => e
28
+ puts "An error occurred: #{e.message}"
29
+ show_exception(e) if options[:verbose]
27
30
  end
28
31
 
29
32
  desc 'info FILE_NAME', 'Print information about a (.gfic) game'
@@ -25,8 +25,8 @@ module Gamefic
25
25
  #
26
26
  # @param [Class] The class of the subplot to be created (Subplot by default)
27
27
  # @return [Subplot]
28
- def branch subplot_class = Subplot, &block
29
- subplot = subplot_class.new(self, &block)
28
+ def branch subplot_class, feature:nil, &block
29
+ subplot = subplot_class.new(self, feature: feature, &block)
30
30
  p_subplots.push subplot
31
31
  subplot
32
32
  end
@@ -39,13 +39,14 @@ module Gamefic
39
39
 
40
40
  attr_reader :plot, :entities, :players
41
41
 
42
- def initialize plot
42
+ def initialize plot, feature:nil
43
43
  @plot = plot
44
44
  @entities = []
45
45
  @players = []
46
46
  @concluded = false
47
47
  post_initialize
48
48
  yield(self) if block_given?
49
+ introduce feature unless feature.nil?
49
50
  end
50
51
  def post_initialize
51
52
  end
@@ -1,3 +1,3 @@
1
1
  module Gamefic
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-16 00:00:00.000000000 Z
11
+ date: 2016-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor