gamefic 2.2.1 → 2.2.2

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
  SHA256:
3
- metadata.gz: daf118f55bd232d6f2025016b109da61fa5fdb8b15b2ca32c3d43e45b42fa0c1
4
- data.tar.gz: 12fcfc441c70b972b87a50f2a056ad6fd9fadcd0dae2eefd276a86fdf31ba26a
3
+ metadata.gz: 7d03f9cc05efbae7569a6dfa66f5ffeccc629180581e8b6acabeddd40f8dca12
4
+ data.tar.gz: f48f8890c0d894be3c2e888a4d7325b936d66ebda39c5e2dd1c1e324dd1c091b
5
5
  SHA512:
6
- metadata.gz: 5ab94298bc3c7bfc03e688a4dea078c2317002c2da7c73d529a61356931b25f8f86b4fd154e75bd8e1fd515aeabb1fcbef4cf24737968f570cc850ee2d08f473
7
- data.tar.gz: aa069d35340b8372c67988a106281fc185241e888293519a878ca4811c1d8976ccec4315772b32ce095f8be2a7be332b3e9ad5b25aef2cb5d9e230f5b7b69fca
6
+ metadata.gz: 7776a069549d44db264d012a00306f95edcf890988cbf2669edd61de97d8cf9527306136bb8c7d07ccb7975c5a48c04029f7401a2e7ea94baf372df58c454722
7
+ data.tar.gz: ed07e4a417207f63b6bd3f84467efb2a0cd32e73d07ecc57a642b05e6dab4bf788f98b2ee3184e42a7ac0cacbb7e2985d2cdade1df513f6f7d3539f5e7ef56c2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.2.2 - September 6, 2021
2
+ - Darkroom indexes non-static elements
3
+
1
4
  ## 2.2.1 - September 5, 2021
2
5
  - Retain unknown values in restored snapshots
3
6
 
@@ -3,9 +3,10 @@ module Gamefic
3
3
  #
4
4
  class Plot
5
5
  class Darkroom
6
- # @return [Gamefic::Plot]
6
+ # @return [Plot]
7
7
  attr_reader :plot
8
8
 
9
+ # @param plot [Plot]
9
10
  def initialize plot
10
11
  @plot = plot
11
12
  end
@@ -14,20 +15,9 @@ module Gamefic
14
15
  #
15
16
  # @return [Hash]
16
17
  def save
17
- index = plot.static + plot.players
18
- plot.to_serial(index)
19
18
  {
20
19
  'program' => {}, # @todo Metadata for version control, etc.
21
- 'index' => index.map do |i|
22
- if i.is_a?(Gamefic::Serialize)
23
- {
24
- 'class' => i.class.to_s,
25
- 'ivars' => i.serialize_instance_variables(index)
26
- }
27
- else
28
- i.to_serial(index)
29
- end
30
- end
20
+ 'index' => index.map { |obj| serialize_indexed(obj) }
31
21
  }
32
22
  end
33
23
 
@@ -75,6 +65,56 @@ module Gamefic
75
65
  end
76
66
  end
77
67
  end
68
+
69
+ private
70
+
71
+ def index
72
+ @index ||= begin
73
+ populate_full_index_from(plot)
74
+ Set.new(plot.static + plot.players).merge(full_index).to_a
75
+ end
76
+ end
77
+
78
+ def full_index
79
+ @full_index ||= Set.new
80
+ end
81
+
82
+ def populate_full_index_from(object)
83
+ return if full_index.include?(object)
84
+ if object.is_a?(Array) || object.is_a?(Set)
85
+ object.each { |ele| populate_full_index_from(ele) }
86
+ elsif object.is_a?(Hash)
87
+ object.each_pair do |k, v|
88
+ populate_full_index_from(k)
89
+ populate_full_index_from(v)
90
+ end
91
+ else
92
+ if object.is_a?(Gamefic::Serialize)
93
+ full_index.add object unless object.is_a?(Module) && object.name
94
+ object.instance_variables.each do |v|
95
+ next if object.class.excluded_from_serial.include?(v)
96
+ populate_full_index_from(object.instance_variable_get(v))
97
+ end
98
+ else
99
+ object.instance_variables.each do |v|
100
+ populate_full_index_from(object.instance_variable_get(v))
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ def serialize_indexed object
107
+ if object.is_a?(Gamefic::Serialize)
108
+ # Serialized objects in the index should be a full serialization.
109
+ # Serialize#to_serial rturns a reference to the indexed object.
110
+ {
111
+ 'class' => object.class.to_s,
112
+ 'ivars' => object.serialize_instance_variables(index)
113
+ }
114
+ else
115
+ object.to_serial(index)
116
+ end
117
+ end
78
118
  end
79
119
  end
80
120
  end
@@ -15,7 +15,6 @@ module Gamefic
15
15
  'name' => name
16
16
  }
17
17
  else
18
- index.push self if self.is_a?(Gamefic::Serialize)
19
18
  {
20
19
  'class' => serialized_class(index),
21
20
  'ivars' => serialize_instance_variables(index)
@@ -89,7 +88,6 @@ class Object
89
88
  end
90
89
  raise "Unable to find class #{self['class']} #{self}" if klass.nil?
91
90
  object = klass.allocate
92
- index.push object if object.is_a?(Gamefic::Serialize)
93
91
  end
94
92
  end
95
93
  self['ivars'].each_pair do |k, v|
@@ -1,3 +1,3 @@
1
1
  module Gamefic
2
- VERSION = '2.2.1'
2
+ VERSION = '2.2.2'
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: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-05 00:00:00.000000000 Z
11
+ date: 2021-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake