Commit 4d2b2bf3 authored by Joe Libipl's avatar Joe Libipl
Browse files

Conditional selections

parent a88274b5
Pipeline #10811716 passed with stage
in 1 minute and 41 seconds
......@@ -38,12 +38,12 @@ class SMSBeholder < Sinatra::Base
def self.selections(state, player)
selections = []
if @states[state] && @states[state].key?('selection')
@states[state]['selection'].keys.each do |selection|
@states[state]['selection'].each do |selection|
selections << selection
end
end
if @states[state] && @states[state].key?('conditionalSelection')
@states[state]['conditionalSelection']['constants'].keys.each do |selection|
@states[state]['conditionalSelection']['constants'].each do |selection|
selections << selection
end
......@@ -59,13 +59,13 @@ class SMSBeholder < Sinatra::Base
end
if conditions_met
@states[state]['conditionalSelection']['ifConditionTrue'].keys.each do |selection|
@states[state]['conditionalSelection']['ifConditionTrue'].each do |selection|
selections << selection
end
end
end
puts "returning selections: #{selections}"
selections
end
end
......@@ -97,10 +97,10 @@ class SMSBeholder < Sinatra::Base
if params.key?('SkipToState')
state = params['SkipToState']
elsif GameStates.states[state].key?('selection')
elsif GameStates.states[state].key?('selection') || GameStates.states[state].key?('conditionalSelection')
# handle using the input to choose selection
if (index = body.to_i) != 0
selections = GameStates.states[state]['selection'].to_a
selections = GameStates.selections(state, player)
if selections.length >= index
state = selections[index - 1].last
else
......@@ -127,7 +127,7 @@ class SMSBeholder < Sinatra::Base
response = GameStates.story(state)
GameStates.selections(state, player).each_with_index do |selection, index|
response += "\n#{index + 1}) #{selection}"
response += "\n#{index + 1}) #{selection.first}"
end
# Fill in values in response
......
......@@ -109,6 +109,13 @@ describe SMSBeholder do
expect(last_response.body).to include("3) So I was wondering if you could show me that killer bicycle kick")
end
it 'allows conditional selection with passed condition' do
get '/', From: 'Dude', SkipToState: 'M00', SetKey: 'mox-kick', SetKeyValue: 'known'
get '/', From: 'Dude', Body: '3'
expect(last_response.body).to include("Do you think you can keep up with me?")
end
# it 'can be played all the way through' do
# get '/', From: 'Dude'
# Timeout::timeout(10) do
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment