gamefic 1.7.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +16 -0
- data/.solargraph.yml +5 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +7 -0
- data/LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +10 -0
- data/gamefic.gemspec +27 -0
- data/lib/gamefic.rb +7 -7
- data/lib/gamefic/action.rb +66 -60
- data/lib/gamefic/active.rb +331 -280
- data/lib/gamefic/actor.rb +8 -5
- data/lib/gamefic/command.rb +9 -7
- data/lib/gamefic/core_ext/array.rb +27 -49
- data/lib/gamefic/core_ext/string.rb +25 -16
- data/lib/gamefic/describable.rb +21 -23
- data/lib/gamefic/element.rb +47 -31
- data/lib/gamefic/entity.rb +6 -12
- data/lib/gamefic/{matchable.rb → keywords.rb} +52 -50
- data/lib/gamefic/messaging.rb +43 -44
- data/lib/gamefic/node.rb +14 -5
- data/lib/gamefic/plot.rb +69 -91
- data/lib/gamefic/plot/darkroom.rb +80 -264
- data/lib/gamefic/plot/host.rb +42 -48
- data/lib/gamefic/plot/snapshot.rb +14 -19
- data/lib/gamefic/query.rb +15 -18
- data/lib/gamefic/query/base.rb +50 -37
- data/lib/gamefic/query/children.rb +0 -0
- data/lib/gamefic/query/descendants.rb +2 -2
- data/lib/gamefic/query/external.rb +18 -14
- data/lib/gamefic/query/family.rb +3 -7
- data/lib/gamefic/query/matches.rb +75 -67
- data/lib/gamefic/query/parent.rb +0 -0
- data/lib/gamefic/query/siblings.rb +0 -0
- data/lib/gamefic/query/text.rb +12 -12
- data/lib/gamefic/query/tree.rb +17 -0
- data/lib/gamefic/scene.rb +0 -2
- data/lib/gamefic/scene/activity.rb +24 -26
- data/lib/gamefic/scene/base.rb +71 -10
- data/lib/gamefic/scene/conclusion.rb +1 -3
- data/lib/gamefic/scene/multiple_choice.rb +19 -14
- data/lib/gamefic/scene/multiple_scene.rb +29 -20
- data/lib/gamefic/scene/pause.rb +8 -3
- data/lib/gamefic/scene/yes_or_no.rb +22 -10
- data/lib/gamefic/scriptable.rb +88 -0
- data/lib/gamefic/serialize.rb +223 -0
- data/lib/gamefic/subplot.rb +38 -35
- data/lib/gamefic/syntax.rb +15 -13
- data/lib/gamefic/version.rb +3 -3
- data/lib/gamefic/world.rb +18 -0
- data/lib/gamefic/world/callbacks.rb +135 -0
- data/lib/gamefic/world/commands.rb +184 -0
- data/lib/gamefic/{plot → world}/entities.rb +33 -35
- data/lib/gamefic/{plot → world}/playbook.rb +245 -240
- data/lib/gamefic/world/players.rb +37 -0
- data/lib/gamefic/world/scenes.rb +226 -0
- metadata +37 -88
- data/bin/gamefic +0 -9
- data/lib/gamefic/engine.rb +0 -7
- data/lib/gamefic/engine/base.rb +0 -59
- data/lib/gamefic/engine/tty.rb +0 -24
- data/lib/gamefic/grammar.rb +0 -13
- data/lib/gamefic/grammar/conjugator.rb +0 -20
- data/lib/gamefic/grammar/gender.rb +0 -11
- data/lib/gamefic/grammar/person.rb +0 -10
- data/lib/gamefic/grammar/plural.rb +0 -13
- data/lib/gamefic/grammar/pronouns.rb +0 -106
- data/lib/gamefic/grammar/tense.rb +0 -6
- data/lib/gamefic/grammar/verb_set.rb +0 -43
- data/lib/gamefic/grammar/verbs.rb +0 -26
- data/lib/gamefic/grammar/word_adapter.rb +0 -49
- data/lib/gamefic/plot/articles.rb +0 -22
- data/lib/gamefic/plot/callbacks.rb +0 -126
- data/lib/gamefic/plot/commands.rb +0 -120
- data/lib/gamefic/plot/players.rb +0 -15
- data/lib/gamefic/plot/scenes.rb +0 -187
- data/lib/gamefic/plot/theater.rb +0 -73
- data/lib/gamefic/plot/you_mount.rb +0 -22
- data/lib/gamefic/scene/custom.rb +0 -9
- data/lib/gamefic/script.rb +0 -13
- data/lib/gamefic/script/base.rb +0 -42
- data/lib/gamefic/script/file.rb +0 -14
- data/lib/gamefic/script/text.rb +0 -14
- data/lib/gamefic/shell.rb +0 -76
- data/lib/gamefic/source.rb +0 -14
- data/lib/gamefic/source/base.rb +0 -12
- data/lib/gamefic/source/file.rb +0 -23
- data/lib/gamefic/source/text.rb +0 -16
- data/lib/gamefic/tester.rb +0 -19
- data/lib/gamefic/text.rb +0 -8
- data/lib/gamefic/text/ansi.rb +0 -53
- data/lib/gamefic/text/html.rb +0 -68
- data/lib/gamefic/text/html/conversions.rb +0 -250
- data/lib/gamefic/text/html/entities.rb +0 -9
- data/lib/gamefic/tty.rb +0 -10
- data/lib/gamefic/user.rb +0 -7
- data/lib/gamefic/user/base.rb +0 -29
- data/lib/gamefic/user/tty.rb +0 -38
data/bin/gamefic
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'gamefic'
|
4
|
-
require 'gamefic/shell'
|
5
|
-
|
6
|
-
# Make play the default command if the first argument is an existing file
|
7
|
-
args = %w(play help).include?(ARGV[0]) || ARGV.count.zero? || !File.exist?(ARGV[0]) ? ARGV : ARGV.dup.unshift('play')
|
8
|
-
|
9
|
-
Gamefic::Shell.start(args)
|
data/lib/gamefic/engine.rb
DELETED
data/lib/gamefic/engine/base.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
module Gamefic
|
2
|
-
|
3
|
-
# Basic functionality for running a single-player game from a console.
|
4
|
-
#
|
5
|
-
class Engine::Base
|
6
|
-
# @return [Class]
|
7
|
-
attr_writer :user_class
|
8
|
-
|
9
|
-
# @return [Gamefic::Plot]
|
10
|
-
attr_reader :plot
|
11
|
-
|
12
|
-
def initialize(plot)
|
13
|
-
@plot = plot
|
14
|
-
post_initialize
|
15
|
-
end
|
16
|
-
|
17
|
-
def post_initialize
|
18
|
-
# Override in subclasses
|
19
|
-
end
|
20
|
-
|
21
|
-
def user_class
|
22
|
-
@user_class ||= Gamefic::User::Base
|
23
|
-
end
|
24
|
-
|
25
|
-
def connect
|
26
|
-
raise 'Plot did not specify a player class' if @plot.player_class.nil?
|
27
|
-
# @todo The plot itself can define name, etc.
|
28
|
-
character = @plot.make @plot.player_class, name: 'yourself', synonyms: 'self myself you me', proper_named: true
|
29
|
-
@user = user_class.new(self)
|
30
|
-
@user.connect character
|
31
|
-
character.connect @user
|
32
|
-
end
|
33
|
-
|
34
|
-
def run
|
35
|
-
connect
|
36
|
-
@plot.introduce @user.character
|
37
|
-
#@user.update @character.state
|
38
|
-
turn until @user.character.concluded?
|
39
|
-
@user.update
|
40
|
-
#print @user.flush
|
41
|
-
end
|
42
|
-
|
43
|
-
def turn
|
44
|
-
@plot.ready
|
45
|
-
@user.update
|
46
|
-
if @user.character.queue.empty?
|
47
|
-
receive
|
48
|
-
end
|
49
|
-
@plot.update
|
50
|
-
end
|
51
|
-
|
52
|
-
def receive
|
53
|
-
print @user.character.scene.prompt + ' '
|
54
|
-
input = STDIN.gets
|
55
|
-
@user.character.queue.push input unless input.nil?
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
data/lib/gamefic/engine/tty.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'gamefic/user/tty'
|
2
|
-
|
3
|
-
module Gamefic
|
4
|
-
|
5
|
-
# Extend Engine::Base to connect with User::Tty, which provides ANSI
|
6
|
-
# formatting for HTML.
|
7
|
-
#
|
8
|
-
# @note Due to their dependency on io/console, User::Tty and Engine::Tty are
|
9
|
-
# not included in the core Gamefic library. `require gamefic/tty` if you
|
10
|
-
# need them.
|
11
|
-
#
|
12
|
-
class Engine::Tty < Engine::Base
|
13
|
-
def post_initialize
|
14
|
-
self.user_class = Gamefic::User::Tty
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.start plot
|
18
|
-
engine = self.new(plot)
|
19
|
-
engine.connect
|
20
|
-
engine.run
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
data/lib/gamefic/grammar.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Gamefic
|
2
|
-
module Grammar
|
3
|
-
autoload :Tense, 'gamefic/grammar/tense'
|
4
|
-
autoload :Pronouns, 'gamefic/grammar/pronouns'
|
5
|
-
autoload :Conjugator, 'gamefic/grammar/conjugator'
|
6
|
-
autoload :Verbs, 'gamefic/grammar/verbs'
|
7
|
-
autoload :VerbSet, 'gamefic/grammar/verb_set'
|
8
|
-
autoload :Person, 'gamefic/grammar/person'
|
9
|
-
autoload :Plural, 'gamefic/grammar/plural'
|
10
|
-
autoload :Gender, 'gamefic/grammar/gender'
|
11
|
-
autoload :WordAdapter, 'gamefic/grammar/word_adapter'
|
12
|
-
end
|
13
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'gamefic'
|
2
|
-
require 'gamefic/grammar'
|
3
|
-
|
4
|
-
module Gamefic::Grammar
|
5
|
-
module Conjugator
|
6
|
-
module ClassMethods
|
7
|
-
@@conjugated_verbs = {}
|
8
|
-
def conjugate infinitive, tense, *forms
|
9
|
-
@@conjugated_verbs[infinitive] ||= {}
|
10
|
-
@@conjugated_verbs[infinitive][tense] = VerbSet.new(infinitive, *forms)
|
11
|
-
end
|
12
|
-
def conjugated_verbs
|
13
|
-
@@conjugated_verbs
|
14
|
-
end
|
15
|
-
end
|
16
|
-
#def self.included(base)
|
17
|
-
# base.extend ClassMethods
|
18
|
-
#end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'gamefic'
|
2
|
-
require 'gamefic/grammar'
|
3
|
-
|
4
|
-
module Gamefic::Grammar
|
5
|
-
class Pronouns
|
6
|
-
def initialize object
|
7
|
-
@object = object
|
8
|
-
end
|
9
|
-
|
10
|
-
# Get the subjective pronoun (I, you, we, etc.)
|
11
|
-
#
|
12
|
-
# @return [String]
|
13
|
-
def subj
|
14
|
-
Pronouns.get_pronoun_set(@object)[0]
|
15
|
-
end
|
16
|
-
|
17
|
-
# Get the objective pronoun (me, them, us, etc.)
|
18
|
-
#
|
19
|
-
# @return [String]
|
20
|
-
def obj
|
21
|
-
Pronouns.get_pronoun_set(@object)[1]
|
22
|
-
end
|
23
|
-
|
24
|
-
# Get the possessive pronoun (my, your, our, etc.)
|
25
|
-
#
|
26
|
-
# @return [String]
|
27
|
-
def poss
|
28
|
-
Pronouns.get_pronoun_set(@object)[2]
|
29
|
-
end
|
30
|
-
|
31
|
-
# Get the reflexive pronoun (myself, yourself, etc.)
|
32
|
-
#
|
33
|
-
# @return [String]
|
34
|
-
def reflex
|
35
|
-
Pronouns.get_pronoun_set(@object)[3]
|
36
|
-
end
|
37
|
-
|
38
|
-
# Get the capitalized subjective pronoun
|
39
|
-
#
|
40
|
-
# @return [String]
|
41
|
-
def Subj
|
42
|
-
subj.cap_first
|
43
|
-
end
|
44
|
-
|
45
|
-
# Get the capitalized objective pronoun
|
46
|
-
#
|
47
|
-
# @return [String]
|
48
|
-
def Obj
|
49
|
-
obj.cap_first
|
50
|
-
end
|
51
|
-
|
52
|
-
# Get the capitalized possessive pronoun
|
53
|
-
#
|
54
|
-
# @return [String]
|
55
|
-
def Poss
|
56
|
-
poss.cap_first
|
57
|
-
end
|
58
|
-
|
59
|
-
# Get the capitalized reflexive pronoun
|
60
|
-
#
|
61
|
-
# @return [String]
|
62
|
-
def Reflex
|
63
|
-
reflex.cap_first
|
64
|
-
end
|
65
|
-
|
66
|
-
# Get a an array of pronouns based on the person, gender, and plurality of
|
67
|
-
# the provided object.
|
68
|
-
#
|
69
|
-
# @param obj An object that responds to #person, #gender, and #plural
|
70
|
-
# @return [Array<String>]
|
71
|
-
def self.get_pronoun_set(obj)
|
72
|
-
set = Pronouns.sets["#{obj.person}"]
|
73
|
-
if set.nil?
|
74
|
-
set = Pronouns.sets["#{obj.person}:#{obj.plural? ? 'plural' : 'singular'}"]
|
75
|
-
end
|
76
|
-
if set.nil?
|
77
|
-
set = Pronouns.sets["#{obj.person}:#{obj.plural? ? 'plural' : 'singular'}:#{obj.gender}"]
|
78
|
-
end
|
79
|
-
if set.nil?
|
80
|
-
raise "Pronoun set could not be determined"
|
81
|
-
end
|
82
|
-
set
|
83
|
-
end
|
84
|
-
|
85
|
-
# TODO Consider implementing method_missing to determine correct pronoun
|
86
|
-
# from example, e.g., "he" would change to "she" for female entities
|
87
|
-
def self.sets
|
88
|
-
if @sets.nil?
|
89
|
-
@sets = {}
|
90
|
-
@sets["1:singular"] = ["I", "me", "my", "myself"]
|
91
|
-
@sets["2:singular"] = ["you", "you", "your", "yourself"]
|
92
|
-
@sets["3:singular:male"] = ["he", "him", "his", "himself"]
|
93
|
-
@sets["3:singular:female"] = ["she", "her", "her", "herself"]
|
94
|
-
# "other" refers to a person or living being that is neither
|
95
|
-
# male or female or for whom gender is unspecified. It's
|
96
|
-
# typically used to avoid referring to a person as "it."
|
97
|
-
@sets["3:singular:other"] = ["they", "them", "their", "themselves"]
|
98
|
-
@sets["3:singular:neutral"] = ["it", "it", "its", "itself"]
|
99
|
-
@sets["1:plural"] = ["we", "us", "our", "ourselves"]
|
100
|
-
@sets["2:plural"] = ["you", "you", "your", "yourselves"]
|
101
|
-
@sets["3:plural"] = ["they", "them", "their", "themselves"]
|
102
|
-
end
|
103
|
-
@sets
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'gamefic/grammar'
|
2
|
-
|
3
|
-
module Gamefic::Grammar
|
4
|
-
class VerbSet
|
5
|
-
def initialize infinitive, *forms
|
6
|
-
# TODO what to do with the tense?
|
7
|
-
@infinitive = infinitive.to_s
|
8
|
-
@forms = {}
|
9
|
-
form = forms[0]
|
10
|
-
@forms["1:singular"] = form.nil? ? @infinitive.to_s : form.to_s
|
11
|
-
form = forms[1]
|
12
|
-
@forms["2:singular"] = form.nil? ? @infinitive.to_s : form.to_s
|
13
|
-
form = forms[2]
|
14
|
-
@forms["3:singular"] = form.nil? ? generate_third_singular : form.to_s
|
15
|
-
form = forms[3]
|
16
|
-
@forms["1:plural"] = form.nil? ? @infinitive.to_s : form.to_s
|
17
|
-
form = forms[4]
|
18
|
-
@forms["2:plural"] = form.nil? ? @forms["1:plural"] : form.to_s
|
19
|
-
form = forms[5]
|
20
|
-
@forms["3:plural"] = form.nil? ? @forms["1:plural"] : form.to_s
|
21
|
-
end
|
22
|
-
def conjugate pronoun
|
23
|
-
form = @forms["#{pronoun.person}"]
|
24
|
-
if form.nil?
|
25
|
-
form = @forms["#{pronoun.person}:#{pronoun.plural? ? 'plural' : 'singular'}"]
|
26
|
-
end
|
27
|
-
if form.nil?
|
28
|
-
raise "Unable to conjugate #{@infinitive}"
|
29
|
-
end
|
30
|
-
form
|
31
|
-
end
|
32
|
-
private
|
33
|
-
def generate_third_singular
|
34
|
-
if @infinitive.end_with?('o')
|
35
|
-
@infinitive + "es"
|
36
|
-
elsif @infinitive.end_with?('ry')
|
37
|
-
@infinitive[0..-2] + "ies"
|
38
|
-
else
|
39
|
-
@infinitive + "s"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'gamefic'
|
2
|
-
require 'gamefic/grammar'
|
3
|
-
|
4
|
-
module Gamefic::Grammar
|
5
|
-
class Verbs
|
6
|
-
extend Gamefic::Grammar::Conjugator::ClassMethods
|
7
|
-
def initialize obj
|
8
|
-
@pronoun = obj
|
9
|
-
self.class.conjugated_verbs.each_pair { |infinitive, verbset|
|
10
|
-
define_singleton_method infinitive do
|
11
|
-
verbset[:present].conjugate @pronoun
|
12
|
-
end
|
13
|
-
}
|
14
|
-
end
|
15
|
-
def method_missing infinitive, *args, &block
|
16
|
-
Gamefic::Grammar::VerbSet.new(infinitive, nil, *args).conjugate(@pronoun)
|
17
|
-
end
|
18
|
-
def [] infinitive
|
19
|
-
words = infinitive.split_words
|
20
|
-
Gamefic::Grammar::VerbSet.new(words[0], nil).conjugate(@pronoun) + (words.length > 1 ? ' ' + words[1..-1].join(' ') : '')
|
21
|
-
end
|
22
|
-
conjugate :be, :present, :am, :are, :is, :are
|
23
|
-
conjugate :have, :present, :have, :have, :has, :have
|
24
|
-
conjugate :can, :present, :can, :can, :can
|
25
|
-
end
|
26
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'gamefic/grammar'
|
2
|
-
require 'gamefic/grammar/gender'
|
3
|
-
|
4
|
-
module Gamefic::Grammar
|
5
|
-
module WordAdapter
|
6
|
-
include Gender
|
7
|
-
include Person
|
8
|
-
include Plural
|
9
|
-
# @return [Gamefic::Grammar::Pronouns]
|
10
|
-
def pronoun
|
11
|
-
@pronoun ||= Gamefic::Grammar::Pronouns.new(self)
|
12
|
-
end
|
13
|
-
# @return [Gamefic::Grammar::Verbs]
|
14
|
-
def verb
|
15
|
-
@verb ||= Gamefic::Grammar::Verbs.new(self)
|
16
|
-
end
|
17
|
-
def contract words
|
18
|
-
contractions[words] || words
|
19
|
-
end
|
20
|
-
private
|
21
|
-
def contractions
|
22
|
-
if @contractions.nil?
|
23
|
-
@contractions ||= {
|
24
|
-
"I am" => "I'm",
|
25
|
-
"you are" => "you're",
|
26
|
-
"he is" => "he's",
|
27
|
-
"she is" => "she's",
|
28
|
-
"it is" => "it's",
|
29
|
-
"we are" => "we're",
|
30
|
-
"they are" => "they're",
|
31
|
-
"am not" => "am not",
|
32
|
-
"are not" => "aren't",
|
33
|
-
"is not" => "isn't",
|
34
|
-
"do not" => "don't",
|
35
|
-
"does not" => "doesn't",
|
36
|
-
"can not" => "can't"
|
37
|
-
}
|
38
|
-
capitalized = {}
|
39
|
-
@contractions.each_pair { |k,v |
|
40
|
-
if k[0] != k[0].capitalize
|
41
|
-
capitalized[k.cap_first] = v.cap_first
|
42
|
-
end
|
43
|
-
}
|
44
|
-
@contractions.merge! capitalized
|
45
|
-
end
|
46
|
-
@contractions
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Gamefic
|
2
|
-
module Plot::Articles
|
3
|
-
def a(entity)
|
4
|
-
entity.indefinitely
|
5
|
-
end
|
6
|
-
def an(entity)
|
7
|
-
entity.indefinitely
|
8
|
-
end
|
9
|
-
def the(entity)
|
10
|
-
entity.definitely
|
11
|
-
end
|
12
|
-
def A(entity)
|
13
|
-
entity.indefinitely.cap_first
|
14
|
-
end
|
15
|
-
def An(entity)
|
16
|
-
entity.indefinitely.cap_first
|
17
|
-
end
|
18
|
-
def The(entity)
|
19
|
-
entity.definitely.cap_first
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|