gamefic 0.1.1 → 0.2.0
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/lib/gamefic/action.rb +7 -6
- data/lib/gamefic/before.rb +12 -0
- data/lib/gamefic/character.rb +1 -1
- data/lib/gamefic/core_ext/array.rb +4 -0
- data/lib/gamefic/core_ext/string.rb +0 -31
- data/lib/gamefic/describable.rb +68 -8
- data/lib/gamefic/director.rb +108 -75
- data/lib/gamefic/engine.rb +74 -10
- data/lib/gamefic/entity.rb +3 -3
- data/lib/gamefic/import/basics/actions/close.rb +16 -0
- data/lib/gamefic/import/basics/actions/commands.rb +3 -0
- data/lib/gamefic/import/basics/actions/drop-in.rb +17 -0
- data/lib/gamefic/import/basics/actions/drop-on.rb +16 -0
- data/lib/gamefic/import/basics/actions/drop.rb +30 -0
- data/lib/gamefic/import/basics/actions/enter.rb +16 -0
- data/lib/gamefic/import/basics/actions/{traversal.rb → go.rb} +35 -35
- data/lib/gamefic/import/basics/actions/inventory.rb +8 -49
- data/lib/gamefic/import/basics/actions/leave.rb +29 -0
- data/lib/gamefic/import/basics/actions/look-in-at.rb +27 -0
- data/lib/gamefic/import/basics/actions/look-under.rb +3 -0
- data/lib/gamefic/import/basics/actions/look.rb +71 -67
- data/lib/gamefic/import/basics/actions/nil.rb +25 -0
- data/lib/gamefic/import/basics/actions/open.rb +23 -0
- data/lib/gamefic/import/basics/actions/quit.rb +3 -0
- data/lib/gamefic/import/basics/actions/take.rb +107 -0
- data/lib/gamefic/import/basics/entities/container.rb +8 -24
- data/lib/gamefic/import/basics/entities/entity.rb +11 -0
- data/lib/gamefic/import/basics/entities/fixture.rb +5 -5
- data/lib/gamefic/import/basics/entities/item.rb +5 -7
- data/lib/gamefic/import/basics/entities/portal.rb +40 -43
- data/lib/gamefic/import/basics/entities/room.rb +30 -24
- data/lib/gamefic/import/basics/entities/scenery.rb +5 -3
- data/lib/gamefic/import/basics/entities/supporter.rb +6 -0
- data/lib/gamefic/import/basics/entities/thing.rb +16 -0
- data/lib/gamefic/import/basics/queries/reachable.rb +38 -0
- data/lib/gamefic/import/basics/queries/room.rb +8 -0
- data/lib/gamefic/import/basics/queries/visible.rb +32 -0
- data/lib/gamefic/import/basics/rules/has-enough-light.rb +14 -0
- data/lib/gamefic/import/{basics → basics.old}/actions/container.rb +13 -12
- data/lib/gamefic/import/basics.old/actions/inventory.rb +50 -0
- data/lib/gamefic/import/basics.old/actions/look.rb +53 -0
- data/lib/gamefic/import/basics.old/actions/meta.rb +6 -0
- data/lib/gamefic/import/basics.old/actions/traversal.rb +35 -0
- data/lib/gamefic/import/{basics → basics.old}/actions.rb +0 -0
- data/lib/gamefic/import/basics.old/entities/container.rb +3 -0
- data/lib/gamefic/import/basics.old/entities/fixture.rb +3 -0
- data/lib/gamefic/import/basics.old/entities/item.rb +3 -0
- data/lib/gamefic/import/basics.old/entities/portal.rb +43 -0
- data/lib/gamefic/import/basics.old/entities/room.rb +27 -0
- data/lib/gamefic/import/basics.old/entities/scenery.rb +3 -0
- data/lib/gamefic/import/basics.old/entities/supporter.rb +3 -0
- data/lib/gamefic/import/{basics → basics.old}/entities.rb +0 -0
- data/lib/gamefic/import/basics.old/room_modes.rb +48 -0
- data/lib/gamefic/import/basics.rb +6 -2
- data/lib/gamefic/import/{basics/room_modes.rb → room_modes.rb} +6 -6
- data/lib/gamefic/import/standard.rb +1 -0
- data/lib/gamefic/meta.rb +12 -0
- data/lib/gamefic/optionset.rb +114 -0
- data/lib/gamefic/plot.rb +54 -21
- data/lib/gamefic/query.rb +214 -188
- data/lib/gamefic/requirement.rb +14 -0
- data/lib/gamefic/shell.rb +7 -4
- data/lib/gamefic/syntax.rb +35 -18
- data/lib/gamefic/thing.rb +7 -0
- data/lib/gamefic.rb +5 -1
- metadata +46 -12
- data/lib/gamefic/import/basics/actions/meta.rb +0 -6
- data/lib/gamefic/import/basics/entities/itemized.rb +0 -3
- data/lib/gamefic/import/basics/entities/portable.rb +0 -3
- data/lib/gamefic/user.rb +0 -66
data/lib/gamefic/query.rb
CHANGED
@@ -1,188 +1,214 @@
|
|
1
|
-
require "gamefic/keywords"
|
2
|
-
|
3
|
-
module Gamefic
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
end
|
166
|
-
else
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
1
|
+
require "gamefic/keywords"
|
2
|
+
|
3
|
+
module Gamefic
|
4
|
+
|
5
|
+
module Query
|
6
|
+
|
7
|
+
class Base
|
8
|
+
attr_accessor :arguments
|
9
|
+
def initialize *arguments
|
10
|
+
@optional = false
|
11
|
+
if arguments.include?(:optional)
|
12
|
+
@optional = true
|
13
|
+
arguments.delete :optional
|
14
|
+
end
|
15
|
+
@arguments = arguments
|
16
|
+
end
|
17
|
+
def optional?
|
18
|
+
@optional
|
19
|
+
end
|
20
|
+
def context_from(subject)
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
def execute(subject, description)
|
24
|
+
array = context_from(subject)
|
25
|
+
@arguments.each { |arg|
|
26
|
+
array = array.that_are(arg)
|
27
|
+
}
|
28
|
+
return Query.match(description, array)
|
29
|
+
end
|
30
|
+
def base_specificity
|
31
|
+
0
|
32
|
+
end
|
33
|
+
def specificity
|
34
|
+
if @specificity == nil
|
35
|
+
@specificity = base_specificity
|
36
|
+
magnitude = 1
|
37
|
+
@arguments.each { |item|
|
38
|
+
if item.kind_of?(Entity)
|
39
|
+
@specificity += (magnitude * 10)
|
40
|
+
item = item.class
|
41
|
+
end
|
42
|
+
if item.kind_of?(Class)
|
43
|
+
s = item
|
44
|
+
while s != nil
|
45
|
+
@specificity += magnitude
|
46
|
+
s = s.superclass
|
47
|
+
end
|
48
|
+
else
|
49
|
+
@specificity += magnitude
|
50
|
+
end
|
51
|
+
#magnitude = magnitude * 10
|
52
|
+
}
|
53
|
+
end
|
54
|
+
@specificity
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Text < Base
|
59
|
+
def base_specificity
|
60
|
+
10
|
61
|
+
end
|
62
|
+
def execute(subject, description)
|
63
|
+
if @arguments.length == 0
|
64
|
+
return Matches.new([description], description, '')
|
65
|
+
end
|
66
|
+
keywords = Keywords.new(description)
|
67
|
+
args = Keywords.new(@arguments)
|
68
|
+
found = Array.new
|
69
|
+
remainder = Array.new
|
70
|
+
keywords.each { |key|
|
71
|
+
if args.include?(key)
|
72
|
+
found.push key
|
73
|
+
else
|
74
|
+
remainder.push key
|
75
|
+
end
|
76
|
+
}
|
77
|
+
if found.length > 0
|
78
|
+
return Matches.new([description], found.join(' '), remainder.join(' '))
|
79
|
+
else
|
80
|
+
return Matches.new([], '', description)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Self < Base
|
86
|
+
def base_specificity
|
87
|
+
30
|
88
|
+
end
|
89
|
+
def context_from(subject)
|
90
|
+
[subject]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class Parent < Base
|
95
|
+
def base_specificity
|
96
|
+
30
|
97
|
+
end
|
98
|
+
def context_from(subject)
|
99
|
+
[subject.parent]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Children < Base
|
104
|
+
def base_specificity
|
105
|
+
50
|
106
|
+
end
|
107
|
+
def context_from(subject)
|
108
|
+
subject.children
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class Siblings < Base
|
113
|
+
def base_specificity
|
114
|
+
40
|
115
|
+
end
|
116
|
+
def context_from(subject)
|
117
|
+
(subject.parent.children - [subject])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
class Family < Base
|
122
|
+
def base_specificity
|
123
|
+
40
|
124
|
+
end
|
125
|
+
def context_from(subject)
|
126
|
+
subject.children + subject.parent.children #+ [subject.parent]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.match(description, array)
|
131
|
+
array.each {|e|
|
132
|
+
if e.uid == description
|
133
|
+
return Matches.new([e], description, '')
|
134
|
+
end
|
135
|
+
}
|
136
|
+
keywords = description.split_words
|
137
|
+
results = array
|
138
|
+
used = Array.new
|
139
|
+
if results.length > 0
|
140
|
+
previous_match = false
|
141
|
+
while keywords.length > 0
|
142
|
+
used.push keywords.shift
|
143
|
+
new_results = Array.new
|
144
|
+
mostMatches = 0.0
|
145
|
+
results.each { |r|
|
146
|
+
words = Keywords.new(used.join(' '))
|
147
|
+
if words.length > 0
|
148
|
+
matches = words.found_in r.keywords
|
149
|
+
if matches >= mostMatches and matches > 0
|
150
|
+
if matches - mostMatches > 0.5
|
151
|
+
new_results = Array.new
|
152
|
+
end
|
153
|
+
new_results.push r
|
154
|
+
mostMatches = matches
|
155
|
+
end
|
156
|
+
end
|
157
|
+
}
|
158
|
+
if new_results.length == 0
|
159
|
+
if previous_match == true
|
160
|
+
keywords.unshift used.pop
|
161
|
+
if used.length == 0
|
162
|
+
results = new_results
|
163
|
+
end
|
164
|
+
break
|
165
|
+
end
|
166
|
+
else
|
167
|
+
previous_match = true
|
168
|
+
results = new_results
|
169
|
+
# TODO: Uncommenting this code results in "lazy" word matching
|
170
|
+
#if results.length == 1
|
171
|
+
# break
|
172
|
+
#end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
if previous_match == false
|
176
|
+
# Scrolled through every word and not a single thing matched
|
177
|
+
results = Array.new
|
178
|
+
end
|
179
|
+
end
|
180
|
+
return Matches.new(results, used.join(' '), keywords.join(' '))
|
181
|
+
end
|
182
|
+
|
183
|
+
class Subquery < Base
|
184
|
+
def base_specificity
|
185
|
+
40
|
186
|
+
end
|
187
|
+
def context_from(subject)
|
188
|
+
last = Matches.last_match
|
189
|
+
return [] if last.nil?
|
190
|
+
last.children
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
class Matches
|
195
|
+
@@last_match = nil
|
196
|
+
attr_reader :objects, :matching_text, :remainder
|
197
|
+
def initialize(objects, matching_text, remainder)
|
198
|
+
@objects = objects
|
199
|
+
@matching_text = matching_text
|
200
|
+
@remainder = remainder
|
201
|
+
@@last_match = self
|
202
|
+
end
|
203
|
+
def self.last_match
|
204
|
+
return nil if @@last_match.nil?
|
205
|
+
if @@last_match.objects.length == 1
|
206
|
+
return @@last_match.objects[0]
|
207
|
+
end
|
208
|
+
return nil
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
data/lib/gamefic/shell.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'rubygems/package'
|
2
3
|
require 'zlib'
|
3
4
|
require 'tmpdir'
|
4
5
|
require 'getoptlong'
|
6
|
+
require 'gamefic/engine/tty'
|
5
7
|
|
6
8
|
# Crazy hack to set file mtimes in tar file
|
7
9
|
class Gem::Package::TarHeader
|
@@ -66,7 +68,7 @@ module Gamefic
|
|
66
68
|
exit 1
|
67
69
|
end
|
68
70
|
story.load dir + '/main.rb'
|
69
|
-
engine = Engine.new story
|
71
|
+
engine = Tty::Engine.new story
|
70
72
|
puts "\n"
|
71
73
|
engine.run
|
72
74
|
end
|
@@ -88,7 +90,8 @@ module Gamefic
|
|
88
90
|
# puts "#{e.inspect}"
|
89
91
|
# exit 1
|
90
92
|
#end
|
91
|
-
engine = Engine.new story
|
93
|
+
engine = Tty::Engine.new story
|
94
|
+
puts "\n"
|
92
95
|
engine.run
|
93
96
|
end
|
94
97
|
def init directory
|
@@ -112,7 +115,7 @@ module Gamefic
|
|
112
115
|
Dir.mkdir(directory + '/import')
|
113
116
|
main_rb = File.new(directory + '/main.rb', 'w')
|
114
117
|
main_rb.write <<EOS
|
115
|
-
import '
|
118
|
+
import 'standard'
|
116
119
|
|
117
120
|
room = make Room, :name => 'room'
|
118
121
|
|
@@ -122,7 +125,7 @@ introduction do |player|
|
|
122
125
|
end
|
123
126
|
EOS
|
124
127
|
main_rb.close
|
125
|
-
fetch directory
|
128
|
+
#fetch directory
|
126
129
|
puts "Game directory '#{directory}' initialized."
|
127
130
|
end
|
128
131
|
def fetch directory
|
data/lib/gamefic/syntax.rb
CHANGED
@@ -7,37 +7,54 @@ module Gamefic
|
|
7
7
|
if arguments.length < 2
|
8
8
|
raise "Syntax.new requires at least two arguments (template and command)"
|
9
9
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
if arguments.length == 2 and arguments[0].kind_of?(Array) and arguments[1].kind_of?(Array)
|
11
|
+
@template = arguments[0]
|
12
|
+
@command = arguments[1].shift
|
13
|
+
@arguments = arguments[1]
|
14
|
+
else
|
15
|
+
@template = []
|
16
|
+
string = arguments.shift
|
17
|
+
string.split_words.each { |word|
|
18
|
+
if word[0,1] == ":"
|
19
|
+
@template.push word[1..-1].to_sym
|
20
|
+
else
|
21
|
+
@template.push word
|
22
|
+
end
|
23
|
+
}
|
24
|
+
#@template = arguments.shift
|
25
|
+
@command = arguments.shift
|
26
|
+
@arguments = arguments
|
27
|
+
if story == nil
|
28
|
+
#@@defaults.push self
|
29
|
+
raise "Default syntaxes are deprecated"
|
30
|
+
else
|
31
|
+
story.send :add_syntax, self
|
32
|
+
@story = story
|
33
|
+
end
|
34
|
+
end
|
19
35
|
end
|
20
36
|
def self.defaults
|
21
37
|
@@defaults.clone
|
22
38
|
end
|
23
|
-
def self.match(input,
|
39
|
+
def self.match(input, context)
|
24
40
|
# Given the input, return all the syntaxes that potentially match it.
|
41
|
+
syntaxes = (context.kind_of?(Plot) ? context.syntaxes : context)
|
25
42
|
matches = Array.new
|
26
43
|
words = input.split_words
|
27
44
|
syntaxes.each { |syntax|
|
28
45
|
input_words = words.clone
|
29
46
|
tokens = Hash.new
|
30
|
-
syntax_words = syntax.template.
|
47
|
+
syntax_words = syntax.template.clone
|
31
48
|
while syntax_words.length > 0
|
32
49
|
if input_words.length == 0
|
33
50
|
# No more input. Break with an imbalance.
|
34
51
|
break
|
35
52
|
end
|
36
53
|
symbol = syntax_words.shift
|
37
|
-
if symbol
|
54
|
+
if symbol.kind_of?(Symbol)
|
38
55
|
if syntax_words.length == 0
|
39
56
|
# Last syntax word.
|
40
|
-
tokens[symbol
|
57
|
+
tokens[symbol] = input_words.join(' ')
|
41
58
|
input_words.clear
|
42
59
|
break
|
43
60
|
elsif input_words.length == 0
|
@@ -45,11 +62,11 @@ module Gamefic
|
|
45
62
|
break
|
46
63
|
else
|
47
64
|
non_vars = syntax_words.clone.delete_if { |w|
|
48
|
-
w
|
65
|
+
w.kind_of?(Symbol)
|
49
66
|
}
|
50
67
|
if non_vars.length == 0
|
51
68
|
# All remaining words in the syntax are variables. Dump everything now.
|
52
|
-
tokens[symbol
|
69
|
+
tokens[symbol] = input_words.join(' ')
|
53
70
|
syntax_words.clear
|
54
71
|
input_words.clear
|
55
72
|
else
|
@@ -58,7 +75,7 @@ module Gamefic
|
|
58
75
|
if syntax_words.length == 0
|
59
76
|
last_input_word = input_words.pop
|
60
77
|
if last_input_word == next_syntax_word
|
61
|
-
tokens[symbol
|
78
|
+
tokens[symbol] = input_words.join(' ')
|
62
79
|
input_words.clear
|
63
80
|
end
|
64
81
|
break
|
@@ -71,7 +88,7 @@ module Gamefic
|
|
71
88
|
if input_words.length == 0 and syntax_words.length > 0
|
72
89
|
break
|
73
90
|
else
|
74
|
-
tokens[symbol
|
91
|
+
tokens[symbol] = token.strip
|
75
92
|
end
|
76
93
|
end
|
77
94
|
end
|
@@ -93,7 +110,7 @@ module Gamefic
|
|
93
110
|
else
|
94
111
|
if a != nil and a != ''
|
95
112
|
arguments.push(a)
|
96
|
-
end
|
113
|
+
end
|
97
114
|
end
|
98
115
|
}
|
99
116
|
if syntax.arguments.length == arguments.length
|
data/lib/gamefic.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
require "gamefic/core_ext/array"
|
2
2
|
require "gamefic/core_ext/string"
|
3
|
+
require "gamefic/optionset"
|
3
4
|
require "gamefic/keywords"
|
4
5
|
require "gamefic/entity"
|
6
|
+
require "gamefic/thing"
|
5
7
|
require "gamefic/character"
|
6
8
|
require "gamefic/action"
|
9
|
+
require "gamefic/before"
|
10
|
+
require "gamefic/meta"
|
11
|
+
require "gamefic/requirement"
|
7
12
|
require "gamefic/syntax"
|
8
13
|
require "gamefic/query"
|
9
14
|
require "gamefic/director"
|
10
15
|
require "gamefic/plot"
|
11
16
|
require "gamefic/story"
|
12
17
|
require "gamefic/engine"
|
13
|
-
require "gamefic/user"
|