Module: Inform::Rules
- Defined in:
- lib/story_teller/stdlib.rb,
lib/story_teller/stdlib.rb
Overview
module Rules
Defined Under Namespace
Classes: More
Constant Summary collapse
- SolicitedStates =
%i[asked yesorno? solicited].freeze
- DefaultMoreParameters =
{ page_index: 0, limit: 10, help: nil, done: :playing }.freeze
Instance Method Summary collapse
- #ask(s = nil) ⇒ Object
- #asked ⇒ Object
- #asked? ⇒ Boolean
- #complete ⇒ Object
- #completed ⇒ Object
- #completing ⇒ Object
- #completing? ⇒ Boolean
-
#disambiguate ⇒ Object
rubocop: enable Metrics/MethodLength.
- #disambiguated ⇒ Object
- #disambiguating ⇒ Object
- #disambiguating? ⇒ Boolean
-
#more(text = nil, params = {}) ⇒ Object
This method supports the MoreSub verb implementation.
-
#more_lines(text) ⇒ Object
def more rubocop: enable Metrics/AbcSize rubocop: enable Metrics/CyclomaticComplexity rubocop: enable Metrics/MethodLength rubocop: enable Metrics/PerceivedComplexity.
- #responded ⇒ Object
-
#responded?(_s) ⇒ Boolean
rubocop: disable Metrics/MethodLength.
- #solicit(s = nil) ⇒ Object
- #solicited ⇒ Object
- #solicited? ⇒ Boolean
- #yesorno(s = nil) ⇒ Object
-
#yesorno? ⇒ Boolean
rubocop: disable Metrics/MethodLength.
Instance Method Details
#ask(s = nil) ⇒ Object
629 630 631 632 633 634 635 636 637 |
# File 'lib/story_teller/stdlib.rb', line 629 def ask(s = nil) println s if s.is_a?(String) if session @previous ||= session.state session.state = :asked end # true session.state end |
#asked ⇒ Object
648 649 650 |
# File 'lib/story_teller/stdlib.rb', line 648 def asked yesorno? end |
#asked? ⇒ Boolean
718 719 720 |
# File 'lib/story_teller/stdlib.rb', line 718 def asked? session&.state == :asked end |
#complete ⇒ Object
679 680 681 682 |
# File 'lib/story_teller/stdlib.rb', line 679 def complete session.state = :completing unless session.nil? false end |
#completed ⇒ Object
703 704 705 706 |
# File 'lib/story_teller/stdlib.rb', line 703 def completed session.state = :playing unless session.nil? queue @input end |
#completing ⇒ Object
684 685 686 687 |
# File 'lib/story_teller/stdlib.rb', line 684 def completing Incomplete() if @ambiguity session.state = :playing unless session.nil? end |
#completing? ⇒ Boolean
726 727 728 |
# File 'lib/story_teller/stdlib.rb', line 726 def completing? session&.state == :completing end |
#disambiguate ⇒ Object
rubocop: enable Metrics/MethodLength
669 670 671 672 |
# File 'lib/story_teller/stdlib.rb', line 669 def disambiguate session.state = :disambiguating unless session.nil? false end |
#disambiguated ⇒ Object
698 699 700 701 |
# File 'lib/story_teller/stdlib.rb', line 698 def disambiguated session.state = :playing unless session.nil? queue @input end |
#disambiguating ⇒ Object
674 675 676 677 |
# File 'lib/story_teller/stdlib.rb', line 674 def disambiguating WhichOne() if @ambiguity session.state = :playing unless session.nil? end |
#disambiguating? ⇒ Boolean
722 723 724 |
# File 'lib/story_teller/stdlib.rb', line 722 def disambiguating? session&.state == :disambiguating end |
#more(text = nil, params = {}) ⇒ Object
This method supports the MoreSub verb implementation. rubocop: disable Metrics/AbcSize rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/MethodLength rubocop: disable Metrics/PerceivedComplexity
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 |
# File 'lib/story_teller/stdlib.rb', line 772 def more(text = nil, params = {}) params = DefaultMoreParameters.merge(params) text = more_lines(text) unless text.nil? if session.nil? println text return params[:done] end input = @buffer.dup @more ||= More.new([], params[:page_index]) if text @more.text = text else text = @more.text end case input when /\?/ println params[:help] || "<Help for More goes here>" when /^(q|quit)$/ @more = nil @prompt = nil return session.state = params[:done] else text = @more.text.lines(chomp: true) if @more.text.is_a? String unless text.is_a?(Array) println "[Error: Format problem using the more command -- cannot handle given text.]" return session.state = params[:done] end println text[@more.page_index, params[:limit]].join("\n") @more.page_index += params[:limit] end percent_complete = [100, (100 * (@more.page_index.to_f / text.length)).floor].min @more = nil unless @more.page_index < @more.text.length new_line print "--More--(#{percent_complete}%)" if percent_complete < 100 prompt " [?]: " session.state = :more else new_line prompt nil session.state = params[:done] end end |
#more_lines(text) ⇒ Object
def more rubocop: enable Metrics/AbcSize rubocop: enable Metrics/CyclomaticComplexity rubocop: enable Metrics/MethodLength rubocop: enable Metrics/PerceivedComplexity
829 830 831 832 833 834 |
# File 'lib/story_teller/stdlib.rb', line 829 def more_lines(text) return text if text.is_a?(Array) return text.lines(chomp: true) if text.is_a?(String) nil end |
#responded ⇒ Object
712 713 714 715 716 |
# File 'lib/story_teller/stdlib.rb', line 712 def responded session&.state = previous_state = @previous @previous = nil session&.state || previous_state end |
#responded?(_s) ⇒ Boolean
rubocop: disable Metrics/MethodLength
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 |
# File 'lib/story_teller/stdlib.rb', line 735 def responded?(_s) reset_io # TODO: Remove this. Why is the buffer getting a newline character added to it? if @buffer.empty? prompt else responded @consult_words = @input = @buffer.dup result = resume println(result) if result == :playing reset_prompt prompt end end session&.state end |
#solicit(s = nil) ⇒ Object
690 691 692 693 694 695 696 |
# File 'lib/story_teller/stdlib.rb', line 690 def solicit(s = nil) if !session.nil? && !SolicitedStates.include?(session.state) prompt s if s.is_a?(String) @previous ||= session.state end session.state = :solicited unless session.nil? end |
#solicited ⇒ Object
708 709 710 |
# File 'lib/story_teller/stdlib.rb', line 708 def solicited responded? @input end |
#solicited? ⇒ Boolean
730 731 732 |
# File 'lib/story_teller/stdlib.rb', line 730 def solicited? session&.state == :solicited end |
#yesorno(s = nil) ⇒ Object
639 640 641 642 643 644 645 646 |
# File 'lib/story_teller/stdlib.rb', line 639 def yesorno(s = nil) print s.to_s unless s.nil? # rubocop: disable Lint/RedundantStringCoercion unless session.nil? @previous ||= session.state session.state = :asked end session&.state || false end |
#yesorno? ⇒ Boolean
rubocop: disable Metrics/MethodLength
653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
# File 'lib/story_teller/stdlib.rb', line 653 def yesorno? reset_io # TODO: Remove this. Why is the buffer getting a newline character added to it? case @buffer.split.first when /^(y|yes)$/i println(resume) responded when /^(n|no)$/i prompt responded else L__M(:Quit, 1); print "> " session&.state end end |