From 1477913cb6f77fa3a277b36003d9fbb1da249b61 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <the@jeffreyfreeman.me> Date: Sun, 26 Apr 2020 12:49:47 -0400 Subject: [PATCH] Added displaying help for a command. --- lib/aethyr/core/commands/get.rb | 10 +++++----- lib/aethyr/core/commands/help.rb | 6 ++++-- lib/aethyr/core/help/help_entry.rb | 2 +- lib/aethyr/core/help/help_library.rb | 8 ++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/aethyr/core/commands/get.rb b/lib/aethyr/core/commands/get.rb index 16dcf04..acf7b7c 100644 --- a/lib/aethyr/core/commands/get.rb +++ b/lib/aethyr/core/commands/get.rb @@ -12,7 +12,7 @@ module Aethyr command = "get" see_also = ["GIVE"] - syntax_formats = ["GET [object]", "GRAB [object'", "TAKE [object]"] + syntax_formats = ["GET [object]", "GRAB [object]", "TAKE [object]"] aliases = ["grab", "take"] content = <<'EOF' Pick up an object and put it in your inventory. @@ -27,7 +27,7 @@ EOF def initialize(player) super(player, ["get", "grab", "take"], help_entries: GetHandler.create_help_entries) end - + def self.object_added(data) super(data, self) end @@ -41,9 +41,9 @@ EOF action({ :object => $2.strip }) end end - + private - + #Gets (or takes) an object and puts it in the player's inventory. def action(event) room = $manager.get_object(@player.container) @@ -111,4 +111,4 @@ EOF end end end -end \ No newline at end of file +end diff --git a/lib/aethyr/core/commands/help.rb b/lib/aethyr/core/commands/help.rb index 441fb57..3451997 100644 --- a/lib/aethyr/core/commands/help.rb +++ b/lib/aethyr/core/commands/help.rb @@ -17,8 +17,10 @@ module Aethyr def player_input(data) super(data) case data[:input] - when /^(help|help topics)$/i - self.player.output("Help topics available: " + player.help_library.topics.join(", "), false) + when /^(help)$/i + self.player.output("\nHelp topics available: " + self.player.help_library.topics.join(", ") + "\n", false) + when /^help (.*)$/i + self.player.output("\n" + self.player.help_library.render_topic($1) + "\n", false) end end end diff --git a/lib/aethyr/core/help/help_entry.rb b/lib/aethyr/core/help/help_entry.rb index bcc78c8..f4ba2b9 100644 --- a/lib/aethyr/core/help/help_entry.rb +++ b/lib/aethyr/core/help/help_entry.rb @@ -2,7 +2,7 @@ module Aethyr module Core module Help class HelpEntry - attr_reader :topic, :redirect, :content, :see_also, :aliases + attr_reader :topic, :redirect, :content, :see_also, :aliases, :syntax_formats def initialize(topic, redirect: nil, content: nil, see_also: nil, aliases: nil, syntax_formats: nil) #do some validity checking on the arguments diff --git a/lib/aethyr/core/help/help_library.rb b/lib/aethyr/core/help/help_library.rb index 11009a2..e09f115 100644 --- a/lib/aethyr/core/help/help_library.rb +++ b/lib/aethyr/core/help/help_library.rb @@ -37,18 +37,18 @@ module Aethyr rendered = redirected_from - rendered += "Aliases: " + entry.aliases.join(", ") + "\n" unless aliases.empty? + rendered += "Aliases: " + entry.aliases.join(", ") + "\n" unless entry.aliases.empty? syntaxes = [] - entry.syntax_formates.each do |syntax| + entry.syntax_formats.each do |syntax| syntaxes.push "Syntax: #{syntax}" end rendered += syntaxes.join("\n") - rendered += "\n" unless syntaxes.empty? && aliases.empty? + rendered += "\n\n" unless syntaxes.empty? && aliases.empty? rendered += entry.content + "\n" - rendered += "See also: " + emtry.see_also.join(", ") + "\n" unless see_also.empty? + rendered += "See also: " + entry.see_also.join(", ") + "\n" unless entry.see_also.empty? return rendered end -- GitLab