Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved all rubygame references to facade

  • Loading branch information...
commit ea7436e242bd14a7af6c7f9460c8a2ab41c82a5e 1 parent 6e05afa
@bgoodspeed authored
View
76 lib/domain/game.rb
@@ -1,12 +1,5 @@
class Game
- include Rubygame
- include Rubygame::Events
- include Rubygame::EventActions
- include Rubygame::EventTriggers
-
- include EventHandler::HasEventHandler
-
attr_accessor :player, :universe, :screen
def initialize()
@factory = GameInternalsFactory.new
@@ -22,34 +15,57 @@ def initialize()
world1.add_npc(@factory.make_npc(@player, @universe))
world1.add_npc(@factory.make_monster(@player, @universe))
@hud = @factory.make_hud(@screen, @player, @universe)
- always_on_hooks = {
- :escape => :quit,
- :q => :quit,
- QuitRequested => :quit,
- :c => :capture_ss,
- :d => :toggle_dialog_layer,
- :m => :toggle_menu,
- :p => :pause
- }
- menu_killed_hooks = { :i => :interact_with_facing, :space => :use_weapon, :p => :toggle_bg_music }
- menu_active_hooks = { :left => :menu_left, :right => :menu_right, :up => :menu_up, :down => :menu_down, :i => :menu_enter, :b => :menu_cancel }
- battle_hooks = {
- :left => :battle_left, :right => :battle_right, :up => :battle_up, :down => :battle_down,
- :i => :battle_confirm, :b => :battle_cancel
- }
+ trigger_factory = TriggerFactory.new
+
+ #TODO FIXMENOW TODOFIXMENOW
+# QuitRequestedFacade.quit_request_type => :quit, #TODO i'd rather not see direct references to facade objects, hide in a factory
+ always_on_hooks = [
+ trigger_factory.make_key_press_event_hook(self, :escape, :quit),
+ trigger_factory.make_key_press_event_hook(self, :q, :quit),
+ trigger_factory.make_key_press_event_hook(self, :c, :capture_ss),
+ trigger_factory.make_key_press_event_hook(self, :d, :toggle_dialog_layer),
+ trigger_factory.make_key_press_event_hook(self, :m, :toggle_menu),
+ trigger_factory.make_key_press_event_hook(self, :p, :pause)
+ ]
+ menu_killed_hooks = [
+ trigger_factory.make_key_press_event_hook(self, :i, :interact_with_facing),
+ trigger_factory.make_key_press_event_hook(self, :space, :use_weapon),
+ trigger_factory.make_key_press_event_hook(self, :b, :toggle_bg_music)
+ ]
+ menu_active_hooks = [
+ trigger_factory.make_key_press_event_hook(self, :left, :menu_left),
+ trigger_factory.make_key_press_event_hook(self, :right, :menu_right),
+ trigger_factory.make_key_press_event_hook(self, :up, :menu_up),
+ trigger_factory.make_key_press_event_hook(self, :down, :menu_down),
+ trigger_factory.make_key_press_event_hook(self, :i, :menu_enter),
+ trigger_factory.make_key_press_event_hook(self, :b, :menu_cancel)
+ ]
+
+ battle_hooks = [
+ trigger_factory.make_key_press_event_hook(self, :left, :battle_left),
+ trigger_factory.make_key_press_event_hook(self, :right, :battle_right),
+ trigger_factory.make_key_press_event_hook(self, :up, :battle_up),
+ trigger_factory.make_key_press_event_hook(self, :down, :battle_down),
+ trigger_factory.make_key_press_event_hook(self, :i, :battle_enter),
+ trigger_factory.make_key_press_event_hook(self, :b, :battle_cancel)
+ ]
+
battle_layer_hooks = [
- EventHook.new(:owner => battle_layer, :trigger => TickTrigger.new, :action => MethodAction.new(:update) )
+ trigger_factory.make_event_hook(battle_layer, :tick, :update)
]
player_hooks = [
- EventHook.new(:owner => player, :trigger => KeyPressTrigger.new, :action => MethodAction.new(:key_pressed) ),
- EventHook.new(:owner => player, :trigger => KeyReleaseTrigger.new, :action => MethodAction.new(:key_released) ),
- EventHook.new(:owner => player, :trigger => TickTrigger.new, :action => MethodAction.new(:update) )
+ trigger_factory.make_event_hook(player, :key_press, :key_pressed),
+ trigger_factory.make_event_hook(player, :key_release, :key_released),
+ trigger_factory.make_event_hook(player, :tick, :update)
]
- npc_hooks = npcs.collect {|npc| EventHook.new(:owner => npc, :trigger => TickTrigger.new, :action => MethodAction.new(:update))}
+ npc_hooks = npcs.collect {|npc|
+ trigger_factory.make_event_hook(npc, :tick, :update)
+ }
+ @event_handler = trigger_factory.make_event_handler
@event_system = @factory.make_event_system(self, always_on_hooks, menu_killed_hooks, menu_active_hooks, battle_hooks, battle_layer_hooks, player_hooks, npc_hooks)
# @event_helper = @factory.make_event_hooks(self, always_on_hooks, menu_killed_hooks, menu_active_hooks, battle_hooks)
@@ -129,6 +145,10 @@ def remove_all_hooks
:notifications, :current_selected_menu_entry_name, :current_menu_entries,
:monsters
+
+ #TODO the handler should be internal to event system, these should delegate there
+ def_delegators :@event_handler, :make_magic_hooks, :make_magic_hooks_for,
+ :append_hook, :remove_hook, :handle
def_delegators :@event_system, :non_menu_hooks, :rebuild_event_hooks
def_delegator :@event_system, :menu_active_hooks, :menu_hooks
def_delegator :@event_system, :battle_active_hooks, :battle_hooks
@@ -162,7 +182,7 @@ def interact_with_facing(event)
end
def simulate_event_with_key(k)
- @event_system.queue << KeyPressed.new(k)
+ @event_system.queue << KeyPressedFacade.new(k) #TODO don't have references to the facades leak outside factories
end
private
View
9 lib/game_requirements.rb
@@ -3,6 +3,14 @@
+require 'lib/facades/quit_requested_facade'
+require 'lib/facades/event_handler_facade'
+require 'lib/facades/method_action_facade'
+require 'lib/facades/event_hook_facade'
+require 'lib/facades/key_release_trigger_facade'
+require 'lib/facades/key_press_trigger_facade'
+require 'lib/facades/tick_trigger_facade'
+require 'lib/facades/key_pressed_facade'
require 'lib/facades/screen_facade'
require 'lib/facades/clock_facade'
require 'lib/facades/event_queue_facade'
@@ -63,6 +71,7 @@
require 'lib/factories/world_state_factory'
require 'lib/factories/game_internals_factory'
require 'lib/factories/topo_map_factory'
+require 'lib/factories/trigger_factory'
require 'lib/tile_system/topo_map'
require 'lib/tile_system/interpreted_map'
View
37 lib/input/event_helper.rb
@@ -17,29 +17,24 @@ def initialize(game, always_on_hooks, menu_killed_hooks, menu_active_hooks, batt
rebuild_event_hooks
end
- def rebuild_event_hooks
- @always_on_hooks = @game.make_magic_hooks(@always_on_hooks_config)
- @menu_killed_hooks = @game.make_magic_hooks(@menu_killed_hooks_config)
- @menu_active_hooks = @game.make_magic_hooks(@menu_active_hooks_config)
- @battle_active_hooks = @game.make_magic_hooks(@battle_hooks_config)
-
- @battle_layer_hooks = []
- @battle_layer_hooks_config.each {|hook|
- @battle_layer_hooks << @game.append_hook(hook)
- }
-
-
- @npc_hooks = []
- @npc_hooks_config.each {|hook|
- @npc_hooks << @game.append_hook(hook)
- }
-
- @player_hooks = []
- @player_hooks_config.each {|hook|
- @player_hooks << @game.append_hook(hook)
+ def accumulate_hooks_from_config(cfg)
+ hooks = []
+ cfg.each {|hook|
+ hooks << @game.append_hook(hook)
}
+ hooks
+ end
-
+ def rebuild_event_hooks
+ #TODO these should probably occasionally not target game.. not really urgent
+ @always_on_hooks = accumulate_hooks_from_config(@always_on_hooks_config)
+ @menu_killed_hooks = accumulate_hooks_from_config(@menu_killed_hooks_config)
+ @menu_active_hooks = accumulate_hooks_from_config(@menu_active_hooks_config)
+ @battle_active_hooks = accumulate_hooks_from_config(@battle_hooks_config)
+
+ @battle_layer_hooks = accumulate_hooks_from_config(@battle_layer_hooks_config)
+ @npc_hooks = accumulate_hooks_from_config(@npc_hooks_config)
+ @player_hooks = accumulate_hooks_from_config(@player_hooks_config)
remove_menu_active_hooks
remove_battle_active_hooks
Please sign in to comment.
Something went wrong with that request. Please try again.