You need to sign in or sign up before continuing.

inform-runtime 1.6.2 → 1.6.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30d774723c5ea67091209135a26685ab0e250a780e3fbadb8a1752fbda94a505
4
- data.tar.gz: 7b40b742e14c98abeef2f5695923a502032334c61e48c00a11d53d40501442cc
3
+ metadata.gz: 292c815478358e64e452d30e5e2b1bc31fb2d5d42fd0998f5020fa2e0b0dc443
4
+ data.tar.gz: 5ae2379ccf6e9adb181a9e5b5c32ba73df67f04fa88722955f9763b77aa4e6a1
5
5
  SHA512:
6
- metadata.gz: 87cdf76656079aca4ccccee3feed0f6dfd6e9f3698b0fb8b46317996316be50a1b7ae00777cbc8ac53dbfa76c09d18bbdda152ee13842f5c5be857cbdaefb83b
7
- data.tar.gz: a18a9f118a5ba0c17271cf9c7a2e632da133ed41d19a4bd22fd2ae8b0e3ca651439e5d79469c7ec29b2084818ff2708e971e2b36373ac9823c9875986a27772e
6
+ metadata.gz: 81793423acc602817ebdd087d7d221cceddbcb7708757647513197d36c644b36deac714f566574f13c37e12525435941ca1cf4abb6639e3835bfcddde6935473
7
+ data.tar.gz: 67a7b61f7d854a5311b600fef2da12340689dcc6e707616adc5d250993b5c0028a32d198f1877443355042bc2d44c873f774f29dbc761386e7f488c400752e11
@@ -57,7 +57,10 @@ module StoryTeller
57
57
  overrides = Thread.current[:channel_overrides]
58
58
  return overrides[self] if overrides&.key?(self)
59
59
 
60
- @channel ||= current_session || default || $stdout
60
+ resolved_session = current_session
61
+ return resolved_session unless resolved_session.nil?
62
+
63
+ @channel ||= default || $stdout
61
64
  end
62
65
 
63
66
  # rubocop: disable Metrics/MethodLength
@@ -181,19 +181,20 @@ class Session
181
181
  include SessionManagementMethods
182
182
  end
183
183
  attr_accessor :channel, :machine, :player, :state, :status
184
- attr_reader :last_good_state, :last_activity, :previous, :inbound, :outbound, :settings, :output
184
+ attr_reader :initial_state, :last_good_state, :last_activity, :previous, :inbound, :outbound, :settings, :output
185
185
 
186
186
  # These states accept any input, including no input
187
187
  Promiscuous = Set.new
188
188
  class BadStateError < StandardError; end
189
189
 
190
190
  # rubocop: disable Metrics/MethodLength
191
- def initialize(channel = nil, machine: nil, player: nil, state: :playing, settings: {})
191
+ def initialize(channel = nil, machine: nil, player: nil, state: nil, settings: {})
192
192
  @channel = channel
193
193
  @machine = machine
194
194
  @player = nil
195
- @state = state
196
- @last_good_state = state
195
+ @state = state || resolve_initial_state(machine)
196
+ @initial_state = @state
197
+ @last_good_state = @state
197
198
  @session_data = {}
198
199
  @settings = settings
199
200
  @status = nil
@@ -205,6 +206,33 @@ class Session
205
206
  end
206
207
  # rubocop: enable Metrics/MethodLength
207
208
 
209
+ def awaiting_input?(machine = @machine)
210
+ return true unless machine.respond_to?(:awaiting_input?)
211
+
212
+ machine.awaiting_input?
213
+ end
214
+
215
+ def prompt_required?(machine = @machine)
216
+ return true unless machine.respond_to?(:prompt_required?)
217
+
218
+ machine.prompt_required?
219
+ end
220
+
221
+ def before_input(machine = @machine)
222
+ machine.before_input if machine.respond_to?(:before_input)
223
+ end
224
+
225
+ def advance(machine = @machine)
226
+ raise ArgumentError, 'Session machine is required' if machine.nil?
227
+
228
+ @machine = machine
229
+ @last_activity = Time.now
230
+ @status = :active
231
+ expose_to(machine)
232
+ update(machine)
233
+ drain_output
234
+ end
235
+
208
236
  alias preferences settings
209
237
 
210
238
  def output=(sink)
@@ -364,6 +392,12 @@ class Session
364
392
 
365
393
  private
366
394
 
395
+ def resolve_initial_state(machine)
396
+ return machine.initial_state if machine.respond_to?(:initial_state)
397
+
398
+ :playing
399
+ end
400
+
367
401
  def prepare_machine(machine)
368
402
  return if machine.equal?(self)
369
403
 
@@ -655,8 +655,23 @@ module Inform
655
655
  # commonly found in interactive fiction games, specifically those created
656
656
  # using Inform. Supporting the principle of least surprise mandates that
657
657
  # the expectations held by the users of such games should be satisfied.
658
- # TODO: Perhaps this should go in the mudlib
659
658
  module Rules
659
+ def initial_state
660
+ :playing
661
+ end
662
+
663
+ def awaiting_input?
664
+ true
665
+ end
666
+
667
+ def prompt_required?
668
+ session.nil? || session.state != :more
669
+ end
670
+
671
+ def before_input
672
+ very__late__error if session && session.state == :playing
673
+ end
674
+
660
675
  def ask(s = nil)
661
676
  println s if s.is_a?(String)
662
677
  if session
@@ -23,7 +23,7 @@
23
23
  module StoryTeller
24
24
  # module Engine
25
25
  module Engine
26
- VERSION = '1.6.2'.freeze
26
+ VERSION = '1.6.3'.freeze
27
27
  end
28
28
  end
29
29
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inform-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nels Nelson
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.1.5
46
+ version: 0.1.6
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.1.5
53
+ version: 0.1.6
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: logger
56
56
  requirement: !ruby/object:Gem::Requirement