gamefic 2.0.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,7 +0,0 @@
1
- module Gamefic
2
- # A Custom Scene allows for complete configuration of its behavior upon
3
- # instantiation. It is suitable for direct instantiation or subclassing.
4
- #
5
- class Scene::Custom < Scene::Base
6
- end
7
- end