From 21a6f9c16dff7a19a51625400500be94f22a3ea3 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <the@jeffreyfreeman.me> Date: Sun, 26 Apr 2020 12:20:23 -0400 Subject: [PATCH] Cleaned up command handler hierarchy. --- lib/aethyr/core/commands/command_handler.rb | 3 ++- lib/aethyr/core/commands/help.rb | 30 +++++++++++++++++++++ lib/aethyr/core/commands/help_handler.rb | 2 +- lib/aethyr/core/objects/player.rb | 3 --- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 lib/aethyr/core/commands/help.rb diff --git a/lib/aethyr/core/commands/command_handler.rb b/lib/aethyr/core/commands/command_handler.rb index f263145..8f3a97d 100644 --- a/lib/aethyr/core/commands/command_handler.rb +++ b/lib/aethyr/core/commands/command_handler.rb @@ -25,7 +25,8 @@ module Aethyr protected #event listener parent that listens for when a new user is added to the manager - def self.object_added(data, child_class) + def self.object_added(data, child_class = nil) + raise "child_class must be defined, object_added is likely not implemented in the child class" if child_class.nil? return unless data[:game_object].is_a? Player data[:game_object].subscribe(child_class.new(data[:game_object])) end diff --git a/lib/aethyr/core/commands/help.rb b/lib/aethyr/core/commands/help.rb new file mode 100644 index 0000000..441fb57 --- /dev/null +++ b/lib/aethyr/core/commands/help.rb @@ -0,0 +1,30 @@ +require 'aethyr/core/registry' +require 'aethyr/core/commands/command_handler' + +module Aethyr + module Core + module Commands + module Help + class HelpHandler < Aethyr::Extend::CommandHandler + def self.object_added(data) + super(data, self) + end + + def initialize(player) + super(player, ["help"]) + end + + 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) + end + end + end + + Aethyr::Extend::HandlerRegistry.register_handler(HelpHandler) + end + end + end +end diff --git a/lib/aethyr/core/commands/help_handler.rb b/lib/aethyr/core/commands/help_handler.rb index 3b056c5..16f579d 100644 --- a/lib/aethyr/core/commands/help_handler.rb +++ b/lib/aethyr/core/commands/help_handler.rb @@ -20,7 +20,7 @@ module Aethyr end end - class HelpHandler + class HelpEntryHandler include Aethyr::Extend::HandleHelp def initialize(player, commands, *args, help_entries: []) diff --git a/lib/aethyr/core/objects/player.rb b/lib/aethyr/core/objects/player.rb index a7c433b..ec39655 100644 --- a/lib/aethyr/core/objects/player.rb +++ b/lib/aethyr/core/objects/player.rb @@ -211,10 +211,7 @@ class Player < LivingObject end clean_input = input.downcase.strip - self.output("Help topics available: ", false) if (clean_input.eql? "help") or (clean_input.eql? "help topics") broadcast(:player_input, {:publisher => self, :input => input}) - self.output(" ", false) if (clean_input.eql? "help") or (clean_input.eql? "help topics") - end #The player's next input will go to the block. -- GitLab