gamefic 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,7 @@ module Gamefic
6
6
  autoload :Base, 'gamefic/query/base'
7
7
  autoload :Children, 'gamefic/query/children'
8
8
  autoload :Descendants, 'gamefic/query/descendants'
9
+ autoload :External, 'gamefic/query/external'
9
10
  autoload :Family, 'gamefic/query/family'
10
11
  autoload :Itself, 'gamefic/query/itself'
11
12
  autoload :Matches, 'gamefic/query/matches'
@@ -21,9 +21,10 @@ module Gamefic
21
21
  []
22
22
  end
23
23
 
24
- # Get an array of objects that exist in the subject's context and match
25
- # the provided token.
24
+ # Get a collection of objects that exist in the subject's context and
25
+ # match the provided token. The result is provided as a Matches object.
26
26
  #
27
+ # @return [Gamefic::Query::Matches]
27
28
  def resolve(subject, token, continued: false)
28
29
  available = context_from(subject)
29
30
  return Matches.new([], '', token) if available.empty?
@@ -51,13 +52,18 @@ module Gamefic
51
52
  if @precision.nil?
52
53
  @precision = 1
53
54
  arguments.each { |a|
54
- if a.kind_of?(Symbol) or a.kind_of?(Regexp)
55
- @precision += 1
56
- elsif a.kind_of?(Class)
57
- @precision += (count_superclasses(a) * 100)
58
- elsif a.kind_of?(Module)
59
- @precision += 10
60
- elsif a.kind_of?(Object)
55
+ #if a.kind_of?(Symbol) or a.kind_of?(Regexp)
56
+ # @precision += 1
57
+ #elsif a.kind_of?(Class)
58
+ # @precision += (count_superclasses(a) * 100)
59
+ #elsif a.kind_of?(Module)
60
+ # @precision += 10
61
+ #elsif a.kind_of?(Object)
62
+ # @precision += 1000
63
+ #end
64
+ if a.kind_of?(Class)
65
+ @precision += 100
66
+ elsif a.kind_of?(Gamefic::Entity)
61
67
  @precision += 1000
62
68
  end
63
69
  }
@@ -111,16 +117,6 @@ module Gamefic
111
117
 
112
118
  private
113
119
 
114
- def count_superclasses cls
115
- s = cls.superclass
116
- c = 1
117
- until s.nil? or s == Object or s == BasicObject
118
- c += 1
119
- s = s.superclass
120
- end
121
- c
122
- end
123
-
124
120
  def nested?(token)
125
121
  !token.match(NEST_REGEXP).nil?
126
122
  end
@@ -0,0 +1,14 @@
1
+ module Gamefic
2
+ module Query
3
+ class External < Base
4
+ def initialize objects, *args
5
+ super(*args)
6
+ @objects = objects
7
+ end
8
+
9
+ def context_from subject
10
+ @objects
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,16 +1,14 @@
1
- #require 'gamefic/scene_data'
2
-
3
1
  module Gamefic
4
2
 
5
3
  module Scene
6
4
  autoload :Base, 'gamefic/scene/base'
7
5
  autoload :Custom, 'gamefic/scene/custom'
8
- autoload :Active, 'gamefic/scene/active'
6
+ autoload :Activity, 'gamefic/scene/activity'
9
7
  autoload :Pause, 'gamefic/scene/pause'
10
8
  autoload :Conclusion, 'gamefic/scene/conclusion'
11
9
  autoload :MultipleChoice, 'gamefic/scene/multiple_choice'
12
10
  autoload :MultipleScene, 'gamefic/scene/multiple_scene'
13
11
  autoload :YesOrNo, 'gamefic/scene/yes_or_no'
14
12
  end
15
-
13
+
16
14
  end
@@ -1,26 +1,26 @@
1
- module Gamefic
2
-
3
- # Active Scenes handle the default command prompt, where input is parsed
4
- # into an Action performed by the Character. This is the default scene in
5
- # a Plot.
6
- #
7
- class Scene::Active < Scene::Base
8
- def post_initialize
9
- self.type = 'Active'
10
- end
11
-
12
- def finish
13
- super
14
- o = nil
15
- o = actor.perform input.strip unless input.nil?
16
- actor.performed o
17
- end
18
-
19
- class << self
20
- def type
21
- 'Active'
22
- end
23
- end
24
- end
25
-
26
- end
1
+ module Gamefic
2
+
3
+ # Active Scenes handle the default command prompt, where input is parsed
4
+ # into an Action performed by the Character. This is the default scene in
5
+ # a Plot.
6
+ #
7
+ class Scene::Activity < Scene::Base
8
+ def post_initialize
9
+ self.type = 'Activity'
10
+ end
11
+
12
+ def finish
13
+ super
14
+ o = nil
15
+ o = actor.perform input.strip unless input.to_s.strip.empty?
16
+ actor.performed o
17
+ end
18
+
19
+ class << self
20
+ def type
21
+ 'Activity'
22
+ end
23
+ end
24
+ end
25
+
26
+ end
@@ -27,11 +27,16 @@ module Gamefic
27
27
  end
28
28
 
29
29
  def start
30
- self.class.initialize_block.call @actor, self unless self.class.initialize_block.nil?
30
+ self.class.start_block.call @actor, self unless self.class.start_block.nil?
31
31
  end
32
32
 
33
33
  def finish
34
34
  @finish_block.call @actor, self unless @finish_block.nil?
35
+ @finished = true
36
+ end
37
+
38
+ def finished?
39
+ @finished ||= false
35
40
  end
36
41
 
37
42
  def flush
@@ -40,13 +45,13 @@ module Gamefic
40
45
 
41
46
  def state
42
47
  {
43
- scene: type, prompt: prompt, input: input #, output: actor.messages, busy: !actor.queue.empty?
48
+ scene: type, prompt: prompt
44
49
  }
45
50
  end
46
51
 
47
52
  def self.subclass &block
48
53
  c = Class.new(self) do
49
- on_initialize &block
54
+ on_start &block
50
55
  end
51
56
  c
52
57
  end
@@ -62,13 +67,13 @@ module Gamefic
62
67
  @type ||= 'Scene'
63
68
  end
64
69
 
65
- def self.on_initialize &block
66
- @initialize_block = block
70
+ def self.on_start &block
71
+ @start_block = block
67
72
  end
68
73
 
69
74
  class << self
70
- def initialize_block
71
- @initialize_block
75
+ def start_block
76
+ @start_block
72
77
  end
73
78
  end
74
79
  end
@@ -18,20 +18,7 @@ module Gamefic
18
18
  self.prompt = 'Enter a choice:'
19
19
  end
20
20
 
21
- #def start actor
22
- # data = start_data_for(actor)
23
- # data.clear
24
- # do_start_block actor, data
25
- # tell_options
26
- #end
27
-
28
- def start
29
- super
30
- raise "MultipleChoice scene has zero options" if options.empty?
31
- end
32
-
33
21
  def finish
34
- #data = finish_data_for(actor, input)
35
22
  get_choice
36
23
  if selection.nil?
37
24
  actor.tell invalid_message
@@ -13,7 +13,7 @@ module Gamefic
13
13
  def finish
14
14
  get_choice
15
15
  unless selection.nil?
16
- actor.cue option_map[selection]
16
+ actor.prepare option_map[selection]
17
17
  end
18
18
  end
19
19
  end
@@ -3,9 +3,6 @@ require 'gamefic/plot'
3
3
  module Gamefic
4
4
 
5
5
  class Subplot
6
- attr_reader :plot
7
- attr_writer :denied_message
8
-
9
6
  include Plot::Theater
10
7
  include Plot::Entities
11
8
  include Plot::Commands
@@ -13,6 +10,9 @@ module Gamefic
13
10
  include Plot::Scenes
14
11
  include Plot::Articles
15
12
 
13
+ # @return [Gamefic::Plot]
14
+ attr_reader :plot
15
+
16
16
  class << self
17
17
  attr_reader :start_proc
18
18
 
@@ -23,16 +23,19 @@ module Gamefic
23
23
  end
24
24
  end
25
25
 
26
- def initialize plot, introduce: nil, next_cue: nil, busy_cue: nil
26
+ def initialize plot, introduce: nil, next_cue: nil
27
27
  @plot = plot
28
28
  @next_cue = next_cue
29
- @busy_cue = busy_cue
30
29
  @concluded = false
31
30
  stage &self.class.start_proc unless self.class.start_proc.nil?
32
31
  playbook.freeze
33
32
  self.introduce introduce unless introduce.nil?
34
33
  end
35
34
 
35
+ def add_entity e
36
+ @p_entities.push e
37
+ end
38
+
36
39
  def subplot
37
40
  self
38
41
  end
@@ -46,7 +49,13 @@ module Gamefic
46
49
  end
47
50
 
48
51
  def playbook
49
- @playbook ||= plot.playbook.dup
52
+ @playbook ||= Gamefic::Plot::Playbook.new
53
+ end
54
+
55
+ def cast cls, args = {}, &block
56
+ ent = super
57
+ ent.playbooks.push plot.playbook unless ent.playbooks.include?(plot.playbook)
58
+ ent
50
59
  end
51
60
 
52
61
  # HACK: Always assume subplots are running for the sake of entity destruction
@@ -54,24 +63,8 @@ module Gamefic
54
63
  true
55
64
  end
56
65
 
57
- def denied_message
58
- @denied_message ||= 'You are already involved in another subplot.'
59
- end
60
-
61
- def introduce player
62
- if plot.in_subplot?(player)
63
- if @busy_cue.nil?
64
- player.tell denied_message
65
- else
66
- player.cue @busy_cue
67
- end
68
- else
69
- super
70
- end
71
- end
72
-
73
66
  def exeunt player
74
- player.playbook = plot.playbook
67
+ player.playbooks.delete playbook
75
68
  player.cue (@next_cue || default_scene)
76
69
  p_players.delete player
77
70
  end
@@ -2,7 +2,6 @@ module Gamefic
2
2
 
3
3
  module User
4
4
  autoload :Base, 'gamefic/user/base'
5
- autoload :Buffer, 'gamefic/user/buffer'
6
5
  end
7
6
 
8
7
  end
@@ -1,5 +1,19 @@
1
1
  module Gamefic
2
- class User::Base
2
+ class User::Base
3
+ # @return [Gamefic::Active]
4
+ attr_reader :character
5
+
6
+ # @return [Gamefic::Engine::Base]
7
+ attr_reader :engine
8
+
9
+ def initialize engine
10
+ @engine = engine
11
+ end
12
+
13
+ def connect entity
14
+ @character = entity
15
+ end
16
+
3
17
  def update state
4
18
  raise 'Unimplemented'
5
19
  end
@@ -11,44 +11,28 @@ module Gamefic
11
11
  # need them.
12
12
  #
13
13
  class User::Tty < User::Base
14
- def update state
15
- print Gamefic::Text::Html::Conversions.html_to_ansi(state[:output])
14
+ def update
15
+ unless character.state[:options].nil?
16
+ list = '<ol class="multiple_choice">'
17
+ character.state[:options].each { |o|
18
+ list += "<li><a href=\"#\" rel=\"gamefic\" data-command=\"#{o}\">#{o}</a></li>"
19
+ }
20
+ list += "</ol>"
21
+ character.tell list
22
+ end
23
+ print Gamefic::Text::Html::Conversions.html_to_ansi(character.state[:output])
16
24
  end
17
25
 
18
26
  def save filename, snapshot
19
- json = JSON.generate snapshot
20
- if json.nil?
21
- @character.tell "Nothing to save."
22
- end
23
- if filename.nil?
24
- stream.select "Enter the filename to save:"
25
- filename = stream.queue.pop
26
- end
27
- if filename != ''
28
- File.open(filename, 'w') do |f|
29
- f.write json
30
- end
27
+ File.open(filename, 'w') do |file|
28
+ file << snapshot.to_json
31
29
  end
32
30
  end
33
31
 
34
32
  def restore filename
35
- if filename.nil?
36
- stream.select "Enter the filename to restore:"
37
- filename = stream.queue.pop
38
- end
39
- if filename != ''
40
- if File.exists?(filename)
41
- data = JSON.parse File.read(filename), symbolize_names: true
42
- #if (data[:metadata] != @character.plot.metadata)
43
- # @character.tell "The save file is not compatible with this version of the game."
44
- #else
45
- return data
46
- #end
47
- else
48
- @character.tell "File \"#{filename}\" not found."
49
- end
50
- end
51
- nil
33
+ json = File.read(filename)
34
+ snapshot = JSON.parse(json, symbolize_names: true)
35
+ engine.plot.restore snapshot
52
36
  end
53
37
  end
54
38
  end
@@ -1,3 +1,3 @@
1
1
  module Gamefic
2
- VERSION = '1.6.0'
2
+ VERSION = '1.7.0'
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: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-31 00:00:00.000000000 Z
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -90,26 +90,6 @@ dependencies:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: 11.3.0
93
- - !ruby/object:Gem::Dependency
94
- name: codeclimate-test-reporter
95
- requirement: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - "~>"
98
- - !ruby/object:Gem::Version
99
- version: '1.0'
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: 1.0.0
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '1.0'
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 1.0.0
113
93
  description: An adventure game and interactive fiction framework
114
94
  email: fsnyder@gamefic.com
115
95
  executables:
@@ -120,12 +100,13 @@ files:
120
100
  - bin/gamefic
121
101
  - lib/gamefic.rb
122
102
  - lib/gamefic/action.rb
123
- - lib/gamefic/character.rb
124
- - lib/gamefic/character/state.rb
103
+ - lib/gamefic/active.rb
104
+ - lib/gamefic/actor.rb
125
105
  - lib/gamefic/command.rb
126
106
  - lib/gamefic/core_ext/array.rb
127
107
  - lib/gamefic/core_ext/string.rb
128
108
  - lib/gamefic/describable.rb
109
+ - lib/gamefic/element.rb
129
110
  - lib/gamefic/engine.rb
130
111
  - lib/gamefic/engine/base.rb
131
112
  - lib/gamefic/engine/tty.rb
@@ -147,6 +128,7 @@ files:
147
128
  - lib/gamefic/plot/articles.rb
148
129
  - lib/gamefic/plot/callbacks.rb
149
130
  - lib/gamefic/plot/commands.rb
131
+ - lib/gamefic/plot/darkroom.rb
150
132
  - lib/gamefic/plot/entities.rb
151
133
  - lib/gamefic/plot/host.rb
152
134
  - lib/gamefic/plot/playbook.rb
@@ -159,6 +141,7 @@ files:
159
141
  - lib/gamefic/query/base.rb
160
142
  - lib/gamefic/query/children.rb
161
143
  - lib/gamefic/query/descendants.rb
144
+ - lib/gamefic/query/external.rb
162
145
  - lib/gamefic/query/family.rb
163
146
  - lib/gamefic/query/itself.rb
164
147
  - lib/gamefic/query/matches.rb
@@ -166,7 +149,7 @@ files:
166
149
  - lib/gamefic/query/siblings.rb
167
150
  - lib/gamefic/query/text.rb
168
151
  - lib/gamefic/scene.rb
169
- - lib/gamefic/scene/active.rb
152
+ - lib/gamefic/scene/activity.rb
170
153
  - lib/gamefic/scene/base.rb
171
154
  - lib/gamefic/scene/conclusion.rb
172
155
  - lib/gamefic/scene/custom.rb
@@ -194,7 +177,6 @@ files:
194
177
  - lib/gamefic/tty.rb
195
178
  - lib/gamefic/user.rb
196
179
  - lib/gamefic/user/base.rb
197
- - lib/gamefic/user/buffer.rb
198
180
  - lib/gamefic/user/tty.rb
199
181
  - lib/gamefic/version.rb
200
182
  homepage: http://gamefic.com