From f3f57919ff17e66948648e77a56b0b8751fb8b7d Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <the@jeffreyfreeman.me> Date: Wed, 6 May 2020 18:32:03 -0400 Subject: [PATCH] Fixed and refactored to pull out clse command. --- lib/aethyr/core/actions/commands/close.rb | 30 +++++++++++++++++++++++ lib/aethyr/core/input_handlers/close.rb | 27 +------------------- 2 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 lib/aethyr/core/actions/commands/close.rb diff --git a/lib/aethyr/core/actions/commands/close.rb b/lib/aethyr/core/actions/commands/close.rb new file mode 100644 index 0000000..ec14e2f --- /dev/null +++ b/lib/aethyr/core/actions/commands/close.rb @@ -0,0 +1,30 @@ +require "aethyr/core/actions/command_action" + +module Aethyr + module Core + module Actions + module Close + class CloseCommand < Aethyr::Extend::CommandAction + def initialize(actor, **data) + super(actor, **data) + end + + def action() + event = @data + room = $manager.get_object(@player.container) + object = expand_direction(event[:object]) + object = @player.search_inv(object) || $manager.find(object, room) + + if object.nil? + @player.output("Close what?") + elsif not object.can? :open + @player.output("You cannot close #{object.name}.") + else + object.close(event) + end + end + end + end + end + end +end diff --git a/lib/aethyr/core/input_handlers/close.rb b/lib/aethyr/core/input_handlers/close.rb index 2603057..535a34e 100644 --- a/lib/aethyr/core/input_handlers/close.rb +++ b/lib/aethyr/core/input_handlers/close.rb @@ -3,6 +3,7 @@ require "aethyr/core/input_handlers/command_handler" require "aethyr/core/util/direction" require "aethyr/core/help/help_entry" require "aethyr/core/actions/command_action" +require "aethyr/core/actions/commands/close" module Aethyr module Core @@ -50,34 +51,8 @@ EOF end end end - Aethyr::Extend::HandlerRegistry.register_handler(CloseHandler) end end - - module Actions - module Close - class CloseCommand < Aethyr::Core::Actions::CommandAction - def initialize(actor, **data) - super(actor, **data) - end - - def action() - event = @data - room = $manager.get_object(@player.container) - object = expand_direction(event[:object]) - object = @player.search_inv(object) || $manager.find(object, room) - - if object.nil? - @player.output("Close what?") - elsif not object.can? :open - @player.output("You cannot close #{object.name}.") - else - object.close(event) - end - end - end - end - end end end -- GitLab