gamefic 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +13 -0
- data/lib/gamefic.rb +1 -2
- data/lib/gamefic/action.rb +34 -38
- data/lib/gamefic/active.rb +18 -12
- data/lib/gamefic/core_ext/array.rb +3 -0
- data/lib/gamefic/element.rb +6 -2
- data/lib/gamefic/plot.rb +10 -12
- data/lib/gamefic/plot/darkroom.rb +49 -61
- data/lib/gamefic/plot/snapshot.rb +13 -5
- data/lib/gamefic/query.rb +1 -0
- data/lib/gamefic/query/base.rb +25 -24
- data/lib/gamefic/query/descendants.rb +2 -2
- data/lib/gamefic/query/family.rb +2 -0
- data/lib/gamefic/query/text.rb +10 -11
- data/lib/gamefic/query/tree.rb +17 -0
- data/lib/gamefic/scene.rb +0 -1
- data/lib/gamefic/scene/base.rb +7 -2
- data/lib/gamefic/scene/conclusion.rb +1 -1
- data/lib/gamefic/scene/multiple_choice.rb +2 -12
- data/lib/gamefic/scene/pause.rb +1 -1
- data/lib/gamefic/scene/yes_or_no.rb +1 -1
- data/lib/gamefic/scriptable.rb +1 -0
- data/lib/gamefic/serialize.rb +172 -17
- data/lib/gamefic/subplot.rb +11 -2
- data/lib/gamefic/syntax.rb +1 -0
- data/lib/gamefic/version.rb +1 -1
- data/lib/gamefic/world.rb +2 -0
- data/lib/gamefic/world/commands.rb +8 -8
- data/lib/gamefic/world/entities.rb +11 -14
- data/lib/gamefic/world/playbook.rb +30 -40
- data/lib/gamefic/world/players.rb +18 -2
- data/lib/gamefic/world/scenes.rb +13 -13
- metadata +18 -18
- data/lib/gamefic/index.rb +0 -121
- data/lib/gamefic/scene/custom.rb +0 -7
data/lib/gamefic/index.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module Gamefic
|
4
|
-
module Index
|
5
|
-
@@elements = []
|
6
|
-
@@stuck_length = 0
|
7
|
-
|
8
|
-
def initialize **data
|
9
|
-
data.each_pair do |k, v|
|
10
|
-
public_send "#{k}=", v
|
11
|
-
end
|
12
|
-
@@elements.push self
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_serial
|
16
|
-
index = @@elements.index(self)
|
17
|
-
raise RuntimeError, "#{self} is not an indexed element" unless index
|
18
|
-
"#<ELE_#{index}>"
|
19
|
-
end
|
20
|
-
|
21
|
-
def destroy
|
22
|
-
@@elements.delete self unless Index.stuck?(self)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.elements
|
26
|
-
@@elements
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.serials
|
30
|
-
result = []
|
31
|
-
@@elements.each do |e|
|
32
|
-
d = {}
|
33
|
-
d['class'] = e.class.to_s
|
34
|
-
e.instance_variables.each do |k|
|
35
|
-
v = e.instance_variable_get(k)
|
36
|
-
d[k] = v.to_serial
|
37
|
-
end
|
38
|
-
result.push d
|
39
|
-
end
|
40
|
-
result
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.from_serial serial
|
44
|
-
if serial.is_a?(Hash) && serial['class']
|
45
|
-
klass = eval(serial['class'])
|
46
|
-
object = klass.allocate
|
47
|
-
serial.each_pair do |k, v|
|
48
|
-
next unless k.to_s.start_with?('@')
|
49
|
-
object.instance_variable_set(k, from_serial(v))
|
50
|
-
end
|
51
|
-
object
|
52
|
-
elsif serial.is_a?(Numeric)
|
53
|
-
serial
|
54
|
-
elsif serial.is_a?(String)
|
55
|
-
match = serial.match(/#<ELE_([0-9]+)>/)
|
56
|
-
return Gamefic::Index.elements[match[1].to_i] if match
|
57
|
-
match = serial.match(/#<SYM:([a-z0-9_\?\!]+)>/i)
|
58
|
-
return match[1].to_sym if match
|
59
|
-
serial
|
60
|
-
elsif serial.is_a?(Array)
|
61
|
-
result = serial.map { |e| from_serial(e) }
|
62
|
-
result = "#<UNKNOWN>" if result.any? { |e| e == "#<UNKNOWN>" }
|
63
|
-
result
|
64
|
-
elsif serial.is_a?(Hash)
|
65
|
-
result = {}
|
66
|
-
unknown = false
|
67
|
-
serial.each_pair do |k, v|
|
68
|
-
k2 = from_serial(k)
|
69
|
-
v2 = from_serial(v)
|
70
|
-
if k2 == "#<UNKNOWN>" || v2 == "#<UNKNOWN>"
|
71
|
-
unknown = true
|
72
|
-
break
|
73
|
-
end
|
74
|
-
result[k2] = v2
|
75
|
-
end
|
76
|
-
result = "#<UNKNOWN>" if unknown
|
77
|
-
result
|
78
|
-
elsif serial && serial != true
|
79
|
-
STDERR.puts "Unable to unserialize #{serial.class}"
|
80
|
-
nil
|
81
|
-
else
|
82
|
-
# true, false, or nil
|
83
|
-
serial
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.unserialize serials
|
88
|
-
serials.each_with_index do |s, i|
|
89
|
-
next if elements[i]
|
90
|
-
klass = eval(s['class'])
|
91
|
-
klass.new
|
92
|
-
end
|
93
|
-
serials.each_with_index do |s, i|
|
94
|
-
s.each_pair do |k, v|
|
95
|
-
next unless k.to_s.start_with?('@')
|
96
|
-
next if v == "#<UNKNOWN>"
|
97
|
-
elements[i].instance_variable_set(k, from_serial(v))
|
98
|
-
end
|
99
|
-
end
|
100
|
-
elements
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.stick
|
104
|
-
@@stuck_length = @@elements.length
|
105
|
-
end
|
106
|
-
|
107
|
-
def self.stuck
|
108
|
-
@@stuck_length
|
109
|
-
end
|
110
|
-
|
111
|
-
def self.clear
|
112
|
-
@@stuck_length = 0
|
113
|
-
@@elements.clear
|
114
|
-
end
|
115
|
-
|
116
|
-
def self.stuck? thing
|
117
|
-
index = @@elements.index(thing)
|
118
|
-
index && index <= @@stuck_length - 1
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|