Permalink
Browse files

down to 50/125 classes

  • Loading branch information...
1 parent 246d19c commit a4d52f0a3d33330015f901b5c458ded14ceeae0f @bgoodspeed committed Nov 10, 2010
Showing with 2,315 additions and 90 deletions.
  1. +52 −0 Rakefile
  2. +1 −1 lib/battle/menu/selectors/battle_targets_menu_selector.rb
  3. +1 −1 lib/event_system/event_system.rb
  4. +18 −0 lib/factories/character_attribution_factory.rb
  5. +9 −6 lib/factories/game_internals_factory.rb
  6. +1 −3 lib/factories/monster_factory.rb
  7. +2 −0 lib/game_requirements.rb
  8. +1 −1 lib/interactables/treasure.rb
  9. +5 −4 lib/interactables/warp_point.rb
  10. +6 −2 lib/layers/battle_layer.rb
  11. +5 −5 lib/menu/selectors/drawable_element_menu_selector_helper.rb
  12. +2 −11 lib/menu/selectors/filtered_inventory_menu_selector.rb
  13. +1 −1 lib/menu/selectors/inventory_filter_menu_selector.rb
  14. +2 −2 lib/menu/selectors/mission_menu_selector.rb
  15. +2 −2 lib/menu/selectors/party_menu_selector.rb
  16. +1 −1 lib/menu/selectors/save_slot_menu_selector.rb
  17. +8 −8 lib/menu/selectors/selections.rb
  18. +2 −7 lib/menu/selectors/stat_line_menu_selector.rb
  19. +3 −3 lib/menu/task_menu.rb
  20. +1 −0 lib/sound/background_music.rb
  21. +37 −22 lib/tile_system/coordinate_helper.rb
  22. +2 −0 lib/tile_system/topo_map.rb
  23. +1 −1 lib/world_weapons/world_weapon.rb
  24. +5 −4 lib/world_weapons/world_weapon_helper.rb
  25. +66 −0 missing_specs.rb
  26. +5 −0 nbproject/private/rake-d.txt
  27. +1 −1 spec/ai/artificial_intelligence_spec.rb
  28. +12 −0 spec/battle/battle_participant_cursor_text_rendering_config_spec.rb
  29. +12 −0 spec/battle/battle_readiness_helper_spec.rb
  30. +12 −0 spec/battle/menu/actions/accept_battle_outcome_menu_action_spec.rb
  31. +12 −0 spec/battle/menu/actions/attack_battle_menu_action_spec.rb
  32. +12 −0 spec/battle/menu/actions/battle_menu_action_spec.rb
  33. +12 −0 spec/battle/menu/actions/battle_selector_dependency_helper_spec.rb
  34. +12 −0 spec/battle/menu/actions/flee_battle_menu_action_spec.rb
  35. +12 −0 spec/battle/menu/actions/use_battle_item_battle_menu_action_spec.rb
  36. +12 −0 spec/battle/menu/actions/use_skill_battle_menu_action_spec.rb
  37. +12 −0 spec/battle/menu/selectors/battle_accept_spoils_menu_selector_spec.rb
  38. +12 −0 spec/battle/menu/selectors/battle_filtered_inventory_menu_selector_spec.rb
  39. +12 −0 spec/battle/menu/selectors/battle_ready_party_menu_selector_spec.rb
  40. +12 −0 spec/battle/menu/selectors/battle_skill_menu_selector_spec.rb
  41. +12 −0 spec/battle/menu/selectors/battle_targets_menu_selector_spec.rb
  42. +12 −0 spec/domain/game_spec.rb
  43. +12 −0 spec/domain/hero_spec.rb
  44. +12 −0 spec/domain/inventory_spec.rb
  45. +12 −0 spec/domain/party_spec.rb
  46. +12 −0 spec/domain/player_spec.rb
  47. +12 −0 spec/domain/universe_spec.rb
  48. +12 −0 spec/domain/world_state_spec.rb
  49. +19 −0 spec/event_system/event_system_spec.rb
  50. +13 −0 spec/facades/clock_facade_spec.rb
  51. +12 −0 spec/facades/event_handler_facade_spec.rb
  52. +13 −0 spec/facades/event_hook_facade_spec.rb
  53. +17 −0 spec/facades/event_queue_facade_spec.rb
  54. +12 −0 spec/facades/font_facade_spec.rb
  55. +14 −0 spec/facades/key_press_trigger_facade_spec.rb
  56. +12 −0 spec/facades/key_pressed_facade_spec.rb
  57. +15 −0 spec/facades/key_release_trigger_facade_spec.rb
  58. +18 −0 spec/facades/method_action_facade_spec.rb
  59. +16 −0 spec/facades/music_facade_spec.rb
  60. +12 −0 spec/facades/quit_requested_facade_spec.rb
  61. +13 −0 spec/facades/screen_facade_spec.rb
  62. +12 −0 spec/facades/sound_facade_spec.rb
  63. +13 −0 spec/facades/surface_facade_spec.rb
  64. +14 −0 spec/facades/tick_trigger_facade_spec.rb
  65. +19 −0 spec/factories/character_attribution_factory_spec.rb
  66. +20 −0 spec/factories/game_internals_factory_spec.rb
  67. +14 −0 spec/factories/game_item_factory_spec.rb
  68. +16 −0 spec/factories/monster_factory_spec.rb
  69. +12 −0 spec/factories/music_factory_spec.rb
  70. +15 −0 spec/factories/surface_factory_spec.rb
  71. +15 −0 spec/factories/topo_map_factory_spec.rb
  72. +38 −0 spec/factories/trigger_factory_spec.rb
  73. +20 −0 spec/factories/world_state_factory_spec.rb
  74. +13 −0 spec/helpers/animated_sprite_helper_spec.rb
  75. +26 −0 spec/helpers/animation_helper_spec.rb
  76. +27 −0 spec/helpers/color_key_helper_spec.rb
  77. +17 −0 spec/helpers/json_helper_spec.rb
  78. +18 −0 spec/helpers/resource_loader_spec.rb
  79. +11 −0 spec/helpers/screen_offset_helper_spec.rb
  80. +12 −0 spec/input/event_helper_spec.rb
  81. +12 −0 spec/input/key_holder_spec.rb
  82. +12 −0 spec/interactables/open_treasure_spec.rb
  83. +24 −0 spec/interactables/treasure_spec.rb
  84. +28 −0 spec/interactables/warp_point_spec.rb
  85. +12 −0 spec/items/equipment/equipment_holder_spec.rb
  86. +12 −0 spec/items/equipment/equipment_info_spec.rb
  87. +12 −0 spec/items/equipment/equippable_game_item_spec.rb
  88. +13 −0 spec/items/game_item_spec.rb
  89. +12 −0 spec/items/item_attributes_spec.rb
  90. +15 −0 spec/items/item_state_spec.rb
  91. +15 −0 spec/layers/abstract_layer_spec.rb
  92. +24 −0 spec/layers/battle_layer_spec.rb
  93. +20 −0 spec/layers/dialog_layer_spec.rb
  94. +19 −0 spec/layers/game_layers_spec.rb
  95. +16 −0 spec/layers/hud_spec.rb
  96. +23 −0 spec/layers/menu_layer_spec.rb
  97. +23 −0 spec/layers/notifications_layer_spec.rb
  98. +12 −0 spec/menu/actions/base_selector_dependency_helper_spec.rb
  99. +12 −0 spec/menu/actions/menu_action_spec.rb
  100. +12 −0 spec/menu/menu_layer_config_spec.rb
  101. +12 −0 spec/menu/selectors/drawable_element_menu_selector_helper_spec.rb
  102. +12 −0 spec/menu/selectors/equipment_slot_menu_selector_spec.rb
  103. +12 −0 spec/menu/selectors/filtered_inventory_menu_selector_spec.rb
  104. +12 −0 spec/menu/selectors/inventory_filter_menu_selector_spec.rb
  105. +1 −1 spec/menu/selectors/mission_menu_selector_spec.rb
  106. +1 −1 spec/menu/selectors/party_menu_selector_spec.rb
  107. +12 −0 spec/menu/selectors/save_slot_menu_selector_spec.rb
  108. +12 −0 spec/menu/selectors/stat_line_menu_selector_spec.rb
  109. +12 −0 spec/menu/selectors/static_menu_selector_spec.rb
  110. +12 −0 spec/missions/milestones/character_progress_milestone_spec.rb
  111. +12 −0 spec/missions/milestones/party_size_milestone_spec.rb
  112. +12 −0 spec/missions/rewards/item_reward_spec.rb
  113. +12 −0 spec/missions/rewards/money_reward_spec.rb
  114. +26 −0 spec/notifications/battle_screen_notification_spec.rb
  115. +26 −0 spec/notifications/notification_spec.rb
  116. +26 −0 spec/notifications/world_screen_notification_spec.rb
  117. +12 −0 spec/npcs/always_down_monster_key_holder_spec.rb
  118. +17 −0 spec/npcs/monster_coordinate_helper_spec.rb
  119. +12 −0 spec/npcs/monster_spec.rb
  120. +12 −0 spec/npcs/talking_n_p_c_spec.rb
  121. +12 −0 spec/palettes/c_i_s_b_p_entry_spec.rb
  122. +18 −0 spec/palettes/composite_interactable_surface_backed_pallette_spec.rb
  123. +13 −0 spec/palettes/i_s_b_p_entry_spec.rb
  124. +14 −0 spec/palettes/i_s_b_p_result_spec.rb
  125. +13 −0 spec/palettes/interactable_surface_backed_pallette_spec.rb
  126. +12 −0 spec/palettes/pallette_spec.rb
  127. +13 −0 spec/palettes/s_b_p_entry_spec.rb
  128. +15 −0 spec/palettes/s_b_p_result_spec.rb
  129. +13 −0 spec/palettes/surface_backed_pallette_spec.rb
  130. +27 −0 spec/processes/attack_action_spec.rb
  131. +21 −0 spec/processes/item_action_spec.rb
  132. +10 −0 spec/processes/reloader_helper_spec.rb
  133. +122 −2 spec/rspec_helper.rb
  134. +12 −0 spec/sound/background_music_spec.rb
  135. +12 −0 spec/sound/sound_effect_set_spec.rb
  136. +16 −0 spec/sound/sound_effect_spec.rb
  137. +12 −0 spec/text/text_rendering_config_spec.rb
  138. +12 −0 spec/text/text_rendering_helper_spec.rb
  139. +12 −0 spec/tile_system/coordinate_helper_spec.rb
  140. +12 −0 spec/tile_system/interaction_helper_spec.rb
  141. +12 −0 spec/tile_system/interaction_policy_spec.rb
  142. +12 −0 spec/tile_system/interpreted_map_spec.rb
  143. +12 −0 spec/tile_system/json_loadable_surface_spec.rb
  144. +12 −0 spec/tile_system/json_surface_spec.rb
  145. +12 −0 spec/tile_system/positioned_tile_coordinate_spec.rb
  146. +12 −0 spec/tile_system/sdl_coordinate_spec.rb
  147. +12 −0 spec/tile_system/tile_coordinate_set_spec.rb
  148. +12 −0 spec/traits/character_attributes_spec.rb
  149. +25 −0 spec/traits/character_attribution_spec.rb
  150. +21 −0 spec/traits/character_state_spec.rb
  151. +36 −0 spec/world_weapons/shot_world_weapon_spec.rb
  152. +36 −0 spec/world_weapons/swung_world_weapon_spec.rb
  153. +59 −0 spec/world_weapons/world_weapon_helper_spec.rb
  154. +16 −0 spec/world_weapons/world_weapon_interaction_helper_spec.rb
  155. +32 −0 spec/world_weapons/world_weapon_spec.rb
View
52 Rakefile
@@ -67,6 +67,58 @@ RCov::VerifyTask.new(:verify_rcov => 'examples_with_rcov') do |t|
t.index_html = 'coverage/index.html'
end
+require 'roodi'
+require 'roodi_task'
+desc "Analyze for code best practices"
+RoodiTask.new 'verify_roodi', ['lib/**/*.rb']
+
+
+require 'reek'
+require 'reek/rake/task'
+
+desc "Analyze for code smells"
+Reek::Rake::Task.new(:verify_reek) do |t|
+ t.fail_on_error = true
+end
+
+require 'flog'
+desc "Analyze for code complexity"
+task :verify_flog do
+ flog = Flog.new
+ files = Flog.expand_dirs_to_files(['lib'])
+ files_to_ignore = ["lib/game_requirements.rb"]
+ files -= files_to_ignore
+ threshold = 40
+
+ flog.flog(*files)
+
+ bad_methods = flog.totals.select do |name, score|
+ score > threshold
+ end
+ bad_methods.sort { |a,b| a[1] <=> b[1] }.each do |name, score|
+ puts "%8.1f: %s" % [score, name]
+ end
+
+ raise "#{bad_methods.size} methods have a flog complexity > #{threshold}" unless bad_methods.empty?
+end
+
+require 'flay'
+
+desc "Analyze for code duplication"
+task :verify_flay do
+ threshold = 20
+ flay = Flay.new({:fuzzy => false, :verbose => false, :mass => threshold})
+ files = Flay.expand_dirs_to_files(['lib'])
+ puts "got files: #{files.join(',')}"
+ flay.process(*files)
+
+ flay.report
+
+ raise "#{flay.masses.size} chunks of code have a duplicate mass > #{threshold}" unless flay.masses.empty?
+end
+
+task :verify => [:verify_rcov, :verify_flay, :verify_flog, :verify_reek, :verify_roodi ]
+
require 'cucumber'
require 'cucumber/rake/task'
View
2 lib/battle/menu/selectors/battle_targets_menu_selector.rb
@@ -8,7 +8,7 @@ def initialize(game)
@game = game
end
- def elements
+ def elements(selections)
@game.battle_members
end
View
2 lib/event_system/event_system.rb
@@ -3,7 +3,7 @@
class EventSystem
extend Forwardable
- attr_reader :queue, :clock
+ attr_accessor :queue, :clock, :helper
def_delegators :@clock, :lifetime
def_delegators :@helper, :non_menu_hooks, :menu_active_hooks, :menu_hooks, :battle_active_hooks
def initialize(clock, queue, helper)
View
18 lib/factories/character_attribution_factory.rb
@@ -0,0 +1,18 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class CharacterAttributionFactory
+ def initialize
+
+ end
+
+ def make_attribution(attributes=make_attributes)
+ CharacterAttribution.new(
+ CharacterState.new(attributes),
+ EquipmentHolder.new)
+ end
+
+ def make_attributes
+ CharacterAttributes.new(5, 5, 1, 0, 0, 0, 0, 0)
+ end
+end
View
15 lib/factories/game_internals_factory.rb
@@ -50,9 +50,7 @@ def make_hud(screen, player, universe)
end
def make_attribution
- CharacterAttribution.new(
- CharacterState.new(CharacterAttributes.new(5, 5, 1, 0, 0, 0, 0, 0)),
- EquipmentHolder.new)
+ CharacterAttributionFactory.new.make_attribution
end
def make_hero(name, weapon, default_start_pts=@@HERO_START_BATTLE_PTS, default_rate=@@HERO_BATTLE_PTS_RATE, attr=make_attribution)
@@ -80,9 +78,14 @@ def make_player(screen, universe, game)
player
# Make event hook to pass all events to @player#handle().
end
+
+ def make_world(bg_filename, inter_filename, pal, inter_pal, bgm)
+ WorldStateFactory.build_world_state(bg_filename,inter_filename, pal, inter_pal, @@BGX, @@BGY, [], bgm)
+ end
+
def make_world1
bgm = BackgroundMusic.new("bonobo-time_is_the_enemy.mp3")
- WorldStateFactory.build_world_state("world1_bg","world1_interaction", pallette, interaction_pallette, @@BGX, @@BGY, [], bgm)
+ make_world("world1_bg","world1_interaction", pallette, interaction_pallette,bgm)
end
def make_monster(player,universe)
@@ -100,10 +103,10 @@ def make_npc(player, universe)
end
def make_world2
- WorldStateFactory.build_world_state("world2_bg","world2_interaction", pallette_160, interaction_pallette_160, @@BGX, @@BGY, [], BackgroundMusic.new("bonobo-gypsy.mp3"))
+ make_world("world2_bg","world2_interaction", pallette_160, interaction_pallette_160, BackgroundMusic.new("bonobo-gypsy.mp3"))
end
def make_world3
- WorldStateFactory.build_world_state("world3_bg","world3_interaction", pallette, interaction_pallette, @@BGX, @@BGY, [], BackgroundMusic.new("bonobo-gypsy.mp3"))
+ make_world("world3_bg","world3_interaction", pallette, interaction_pallette,BackgroundMusic.new("bonobo-gypsy.mp3"))
end
def make_event_hooks(game, always_on_hooks, menu_killed_hooks, menu_active_hooks, battle_hooks, battle_layer_hooks, player_hooks, npc_hooks)
View
4 lib/factories/monster_factory.rb
@@ -5,9 +5,7 @@ class MonsterFactory
def make_monster(player,universe)
monster_inv = Inventory.new(255)
monster_inv.add_item(1, GameItemFactory.potion)
- monattrib = CharacterAttribution.new(
- CharacterState.new(CharacterAttributes.new(3, 0, 1, 0, 0, 0, 0, 0)),
- EquipmentHolder.new)
+ monattrib = CharacterAttributionFactory.new.make_attribution(CharacterAttributes.new(3, 0, 1, 0, 0, 0, 0, 0))
monai = ArtificialIntelligence.new(RepeatingPathFollower.new("DRUL", 80), BattleStrategy.new([BattleTactic.new("Enemy: Any -> Attack")]))
posn = PositionedTileCoordinate.new(SdlCoordinate.new(400, 660), SdlCoordinate.new(@@MONSTER_X, @@MONSTER_Y))
View
2 lib/game_requirements.rb
@@ -60,10 +60,12 @@
require 'lib/items/item_attributes'
require 'lib/items/item_state'
require 'lib/items/game_item'
+require 'lib/items/equipment/equipment_info'
require 'lib/items/equipment/equippable_game_item'
require 'lib/items/equipment/equipment_holder'
+require 'lib/factories/character_attribution_factory'
require 'lib/factories/music_factory'
require 'lib/factories/surface_factory'
require 'lib/factories/monster_factory'
View
2 lib/interactables/treasure.rb
@@ -8,7 +8,7 @@ def initialize(name)
end
def activate(game, player, worldstate, tilex, tiley)
- player.universe.play_sound_effect(SoundEffect::TREASURE)
+ game.universe.play_sound_effect(SoundEffect::TREASURE)
worldstate.update_interaction_map(tilex, tiley, @@OPEN_TREASURE)
player.add_inventory(1, @name)
game.add_notification(WorldScreenNotification.new("Got #{@name}"))
View
9 lib/interactables/warp_point.rb
@@ -13,13 +13,14 @@ def initialize(dest_index, dest_x=nil, dest_y=nil)
@destination_y = dest_y
end
+ #TODO this should invoke a game process
def activate(game, player, worldstate, tilex, tiley)
- uni = player.universe
- player.universe.fade_out_bg_music
- player.universe.play_sound_effect(SoundEffect::WARP)
+ uni = game.universe
+ uni.fade_out_bg_music
+ uni.play_sound_effect(SoundEffect::WARP)
player.set_position(@destination_x, @destination_y)
uni.set_current_world_by_index(@destination)
- player.universe.fade_in_bg_music
+ uni.fade_in_bg_music
end
include JsonHelper
def json_params
View
8 lib/layers/battle_layer.rb
@@ -42,14 +42,18 @@ def end_battle
@active = false
@battle.end_battle
end
+ def battle_text_config_with_actions(actions)
+ BattleParticipantCursorTextRenderingConfig.new(actions , 2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
+ end
+
def menu_layer_config
mlc = MenuLayerConfig.new
mlc.main_menu_text = TextRenderingConfig.new(@@MENU_TEXT_INSET, @@MENU_TEXT_WIDTH, @layer.h - 125, 0)
mlc.section_menu_text = TextRenderingConfig.new(@@MENU_TEXT_INSET, @@MENU_TEXT_WIDTH, @layer.h - 150, 0)
mlc.in_section_cursor = TextRenderingConfig.new(@@MENU_TEXT_INSET , @@MENU_TEXT_WIDTH, @layer.h - 175, 0)
- mlc.in_subsection_cursor = BattleParticipantCursorTextRenderingConfig.new([AttackBattleMenuAction], 2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
- mlc.in_option_section_cursor = BattleParticipantCursorTextRenderingConfig.new([UseBattleItemBattleMenuAction], 2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
+ mlc.in_subsection_cursor = battle_text_config_with_actions([AttackBattleMenuAction])
+ mlc.in_option_section_cursor = battle_text_config_with_actions([UseBattleItemBattleMenuAction])
mlc.main_cursor = TextRenderingConfig.new(@@MENU_TEXT_INSET , @@MENU_TEXT_WIDTH, @layer.h - 100, 0)
mlc.layer_inset_on_screen = [@@LAYER_INSET,@@LAYER_INSET]
mlc.details_inset_on_layer = [@@MENU_DETAILS_INSET_X, @@MENU_DETAILS_INSET_Y]
View
10 lib/menu/selectors/drawable_element_menu_selector_helper.rb
@@ -4,20 +4,20 @@
module DrawableElementMenuSelectorHelper
def element_names(selections)
- elements.collect {|el| el.name }
+ elements(selections).collect {|el| el.name }
end
- def size(selectios=nil)
- elements.size
+ def size(selections=nil)
+ elements(selections).size
end
def select_element_at(idx, selections)
- elements[idx]
+ elements(selections)[idx]
end
alias_method :element_at, :select_element_at
def draw(config, text_rendering_helper, currently_selected)
- member_names = elements.collect {|m| m.name}
+ member_names = elements(currently_selected).collect {|m| m.name}
text_rendering_helper.render_lines_to_layer( member_names, config)
end
View
13 lib/menu/selectors/filtered_inventory_menu_selector.rb
@@ -2,6 +2,7 @@
# and open the template in the editor.
class FilteredInventoryMenuSelector
+ include DrawableElementMenuSelectorHelper
attr_accessor :menu_item
def initialize(game)
@game = game
@@ -22,7 +23,7 @@ def size(selections=nil)
elements(selections).size
end
- def elements(selected=[])
+ def elements(selected)
filter(@game.inventory_info, selected)
end
@@ -31,14 +32,4 @@ def select_element_at(idx, selections)
rv
end
- alias_method :element_at, :select_element_at
-
- def draw(config, text_rendering_helper, currently_selected)
-
- member_names = elements(currently_selected).collect {|m| m.name}
- text_rendering_helper.render_lines_to_layer( member_names, config)
- end
-
-
-
end
View
2 lib/menu/selectors/inventory_filter_menu_selector.rb
@@ -26,7 +26,7 @@ def selection_type
InventoryFilter
end
- def elements
+ def elements(selections)
[InventoryFilter.new, KeyItemInventoryFilter.new]
end
View
4 lib/menu/selectors/mission_menu_selector.rb
@@ -13,10 +13,10 @@ def selection_type
end
def size(selections=nil)
- elements.size
+ elements(selections).size
end
- def elements
+ def elements(selections)
@game.player_missions
end
View
4 lib/menu/selectors/party_menu_selector.rb
@@ -12,10 +12,10 @@ def initialize(game)
end
def size(selections=nil)
- elements.size
+ elements(selections).size
end
- def elements
+ def elements(selections)
@game.party_members
end
View
2 lib/menu/selectors/save_slot_menu_selector.rb
@@ -22,7 +22,7 @@ def selection_type
SaveSlot
end
- def elements
+ def elements(selections)
(0..@@NUM_SLOTS).collect {|i| save_slot(i)}
end
def save_slot(idx)
View
16 lib/menu/selectors/selections.rb
@@ -29,17 +29,17 @@ def search_selected_for(klass)
found.empty? ? nil : found.first
end
- def selected_party_member
- found = search_selected_for(Hero)
- sel = "party member"
- raise "Required selection of #{sel} not performed" if found.nil?
+ def get_selected_type(type, msg)
+ found = search_selected_for(type)
+ raise "Required selection of #{msg} not performed" if found.nil?
found
end
+
+ def selected_party_member
+ get_selected_type(Hero, "party member")
+ end
def selected_inventory_item
- found = search_selected_for(InventoryItem)
- sel = "inventory item"
- raise "Required selection of #{sel} not performed" if found.nil?
- found
+ get_selected_type(InventoryItem, "inventory item")
end
def drop_last
View
9 lib/menu/selectors/stat_line_menu_selector.rb
@@ -9,6 +9,8 @@ def initialize(name)
end
class StatLineMenuSelector
+
+ include DrawableElementMenuSelectorHelper
attr_accessor :menu_item
def initialize(game)
@@ -32,15 +34,8 @@ def element_names(selections)
end
def select_element_at(idx, selections)
- raise "fucking hell" if idx.nil?
elements(selections)[idx]
end
- alias_method :element_at, :select_element_at
-
- def draw(config, text_rendering_helper, selections)
- member_names = elements(selections).collect {|m| m.name}
- text_rendering_helper.render_lines_to_layer( member_names, config)
- end
end
View
6 lib/menu/task_menu.rb
@@ -6,11 +6,11 @@ def initialize(game, actions)
@actions = actions
end
- def elements
+ def elements(selections)
@actions
end
def element_at(idx, selections)
- elements[idx]
+ elements(selections)[idx]
end
def size(selections=nil)
@actions.size
@@ -29,7 +29,7 @@ def size_at(path, selections)
end
def element_names(selections)
- elements.collect {|el| el.name }
+ elements(selections).collect {|el| el.name }
end
def navigate_path(path)
View
1 lib/sound/background_music.rb
@@ -1,5 +1,6 @@
class BackgroundMusic
+ attr_reader :music
def initialize(filename, music_factory=MusicFactory.new)
@filename = filename
@music = music_factory.load_music(filename)
View
59 lib/tile_system/coordinate_helper.rb
@@ -198,47 +198,62 @@ def blocking(col)
npc.is_blocking?
end
end
- def x_hits(npcs)
- npcs.select do |npc|
- npc.collides_on_x?(base_x) or npc.collides_on_x?(max_x)
- end
- end
- def y_hits(npcs)
+
+
+
+ def hits(npcs)
npcs.select do |npc|
- npc.collides_on_y?(base_y) or npc.collides_on_y?(max_y)
+ (npc.collides_on_x?(base_x) or npc.collides_on_x?(max_x)) and
+ (npc.collides_on_y?(base_y) or npc.collides_on_y?(max_y))
end
end
- def hit_blocking_npcs_on_x(npcs)
- blocking(y_hits(x_hits(npcs)))
- end
- def hit_blocking_npcs_on_y(npcs)
- blocking(y_hits(x_hits(npcs)))
+ def hit_blocking_npcs(npcs)
+ blocking(hits(npcs))
end
def candidate_npcs(who=nil)
@universe.current_world.npcs
end
+ def topo
+ @universe.current_world.topo_interpreter
+ end
+
+ def interaction
+ @universe.current_world.interaction_interpreter
+ end
+
+
+ def check_collisions(c)
+ !c.empty?
+ end
+ def check_axis(collisions, axis)
+ if axis == :x
+ c1 = clamp_to_tile_restrictions_on_x(topo, world_coords)
+ c2 = clamp_to_tile_restrictions_on_x(interaction, interact_coords)
+ else
+ c1 = clamp_to_tile_restrictions_on_y(topo, world_coords)
+ c2 = clamp_to_tile_restrictions_on_y(interaction, interact_coords)
+ end
+ c1 or c2 or check_collisions(collisions)
+ end
+
+
def update_pos( dt, who=nil )
dx = @vx * dt
dy = @vy * dt
@px += dx
- x_collisions = hit_blocking_npcs_on_x(candidate_npcs(who))
+ x_collisions = hit_blocking_npcs(candidate_npcs(who))
@py += dy
- y_collisions = hit_blocking_npcs_on_x(candidate_npcs(who)) - x_collisions
+ y_collisions = hit_blocking_npcs(candidate_npcs(who)) - x_collisions
clamp_to_world_dimensions
- topo = @universe.current_world.topo_interpreter
- interact = @universe.current_world.interaction_interpreter
- new_bg_tile_coords = world_coords
- new_interaction_tile_coords = interact_coords
-
- @px -= dx if clamp_to_tile_restrictions_on_x(topo, new_bg_tile_coords) or clamp_to_tile_restrictions_on_x(interact, new_interaction_tile_coords) or !x_collisions.empty?
- @py -= dy if clamp_to_tile_restrictions_on_y(topo, new_bg_tile_coords) or clamp_to_tile_restrictions_on_y(interact, new_interaction_tile_coords) or !y_collisions.empty?
+ @px -= dx if check_axis(x_collisions, :x)
+ @py -= dy if check_axis(y_collisions, :y)
- cols = y_hits(x_hits(candidate_npcs(who)))
+ cols = hits(candidate_npcs(who))
handle_collision(cols) unless cols.empty?
update_tile_coords
end
View
2 lib/tile_system/topo_map.rb
@@ -2,6 +2,8 @@
# and open the template in the editor.
class TopoMap
+
+ attr_reader :world_x, :world_y
def initialize(x,y, world_x, world_y, data)
@x = x
@y = y
View
2 lib/world_weapons/world_weapon.rb
@@ -1,6 +1,6 @@
class WorldWeapon
- attr_reader :ticks
+ attr_reader :ticks, :max_ticks
def initialize(pallette, max_ticks=25)
@pallette = pallette
@ticks = 0
View
9 lib/world_weapons/world_weapon_helper.rb
@@ -5,11 +5,12 @@ class WorldWeaponHelper
def_delegators :@weapon, :draw_weapon
def_delegators :@interaction_helper, :facing, :facing=
- def initialize(game)
+ def initialize(game, helper = WorldWeaponInteractionHelper.new(game, InteractionPolicy.process_all))
+ @game = game
@player = game.player
@weapon = nil
@universe = game.universe
- @interaction_helper = WorldWeaponInteractionHelper.new(game, InteractionPolicy.process_all)
+ @interaction_helper = helper
end
def use_weapon
@@ -23,14 +24,14 @@ def using_weapon?
!@weapon.nil?
end
- def update_weapon_if_active()
+ def update_weapon_if_active
return unless using_weapon?
@weapon.displayed
if @weapon.consumed?
@weapon.die
@weapon = nil
else
- @interaction_helper.interact_with_facing(@universe.game, @player.px, @player.py)
+ @interaction_helper.interact_with_facing(@game, @player.px, @player.py)
end
end
View
66 missing_specs.rb
@@ -0,0 +1,66 @@
+require 'rake'
+
+$dry_run = false
+$chatty = false
+
+all_files = FileList['lib/**/*.rb']
+
+files_to_exclude = [
+ 'lib/game_requirements.rb',
+ 'lib/game_settings.rb'
+]
+
+working_files = all_files - files_to_exclude
+
+newline ='
+'
+
+all_dir_names = working_files.collect {|f| File.dirname(f) }
+dir_names = all_dir_names.uniq.sort
+
+spec_dir_names = dir_names.collect {|name| name.gsub('lib','spec')}
+dirs = spec_dir_names.select {|name| !File.exists?(name)}
+dirs_to_create = dirs.sort {|d1, d2| d1.length <=> d2.length}
+
+
+dirs_to_create.each {|dir|
+ puts "creating directory: #{dir}? #{!$dry_run}" if $chatty
+ FileUtils::mkdir_p(dir) unless $dry_run
+}
+
+
+working_specs = working_files.collect{|name| name.gsub('lib','spec').gsub('.rb','_spec.rb') }
+specs_to_create = working_specs.select{|name| !File.exists?(name)}
+
+spec_template =<<EOF
+
+require 'spec/rspec_helper'
+
+describe %s do
+ before(:each) do
+ @%s = %s.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
+EOF
+
+
+
+def camelize(str)
+ str.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
+end
+
+
+specs_to_create.each {|spec_name|
+ spec_class_var_name = File.basename(spec_name, '.rb').gsub('_spec','')
+ spec_class_name = camelize(spec_class_var_name)
+ puts "make a spec in file #{spec_name} describing #{spec_class_name} with instance var #{spec_class_var_name}" if $chatty
+ spec_content = format(spec_template, spec_class_name, spec_class_var_name, spec_class_name)
+ File.open(spec_name, "w") {|f| f.write(spec_content)} unless $dry_run
+}
+
+puts "Created #{dirs_to_create.size} directories"
+puts "Created #{specs_to_create.size} new specs"
View
5 nbproject/private/rake-d.txt
@@ -22,4 +22,9 @@ repackage=Force a rebuild of the package files
rerdoc=Force a rebuild of the RDOC files
spec=Run specs
test=Run tests
+verify=
+verify_flay=Analyze for code duplication
+verify_flog=Analyze for code complexity
verify_rcov=Verify that rcov coverage is at least 100.0%
+verify_reek=Analyze for code smells
+verify_roodi=Check for design issues in: lib/**/*.rb
View
2 spec/ai/artificial_intelligence_spec.rb
@@ -14,7 +14,7 @@
it "should delegate updates to follow" do
@artificial_intelligence.should delegate_to({:update => [1]}, {:follow_strategy => :update})
end
- it "should delegate updates to follow" do
+ it "should delegate turns to battle strategy" do
@artificial_intelligence.should delegate_to({:take_battle_turn => [1]}, {:battle_strategy => :take_battle_turn})
end
View
12 spec/battle/battle_participant_cursor_text_rendering_config_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BattleParticipantCursorTextRenderingConfig do
+ before(:each) do
+ @battle_participant_cursor_text_rendering_config = BattleParticipantCursorTextRenderingConfig.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/battle_readiness_helper_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BattleReadinessHelper do
+ before(:each) do
+ @battle_readiness_helper = BattleReadinessHelper.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/actions/accept_battle_outcome_menu_action_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe AcceptBattleOutcomeMenuAction do
+ before(:each) do
+ @accept_battle_outcome_menu_action = AcceptBattleOutcomeMenuAction.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/actions/attack_battle_menu_action_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe AttackBattleMenuAction do
+ before(:each) do
+ @attack_battle_menu_action = AttackBattleMenuAction.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/actions/battle_menu_action_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BattleMenuAction do
+ before(:each) do
+ @battle_menu_action = BattleMenuAction.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/actions/battle_selector_dependency_helper_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BattleSelectorDependencyHelper do
+ before(:each) do
+ @battle_selector_dependency_helper = BattleSelectorDependencyHelper.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/actions/flee_battle_menu_action_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe FleeBattleMenuAction do
+ before(:each) do
+ @flee_battle_menu_action = FleeBattleMenuAction.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/actions/use_battle_item_battle_menu_action_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe UseBattleItemBattleMenuAction do
+ before(:each) do
+ @use_battle_item_battle_menu_action = UseBattleItemBattleMenuAction.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/actions/use_skill_battle_menu_action_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe UseSkillBattleMenuAction do
+ before(:each) do
+ @use_skill_battle_menu_action = UseSkillBattleMenuAction.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/selectors/battle_accept_spoils_menu_selector_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BattleAcceptSpoilsMenuSelector do
+ before(:each) do
+ @battle_accept_spoils_menu_selector = BattleAcceptSpoilsMenuSelector.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/selectors/battle_filtered_inventory_menu_selector_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BattleFilteredInventoryMenuSelector do
+ before(:each) do
+ @battle_filtered_inventory_menu_selector = BattleFilteredInventoryMenuSelector.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/selectors/battle_ready_party_menu_selector_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BattleReadyPartyMenuSelector do
+ before(:each) do
+ @battle_ready_party_menu_selector = BattleReadyPartyMenuSelector.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/selectors/battle_skill_menu_selector_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BattleSkillMenuSelector do
+ before(:each) do
+ @battle_skill_menu_selector = BattleSkillMenuSelector.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/battle/menu/selectors/battle_targets_menu_selector_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BattleTargetsMenuSelector do
+ before(:each) do
+ @battle_targets_menu_selector = BattleTargetsMenuSelector.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/domain/game_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe Game do
+ before(:each) do
+ @game = Game.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/domain/hero_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe Hero do
+ before(:each) do
+ @hero = Hero.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/domain/inventory_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe Inventory do
+ before(:each) do
+ @inventory = Inventory.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/domain/party_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe Party do
+ before(:each) do
+ @party = Party.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/domain/player_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe Player do
+ before(:each) do
+ @player = Player.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/domain/universe_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe Universe do
+ before(:each) do
+ @universe = Universe.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/domain/world_state_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe WorldState do
+ before(:each) do
+ @world_state = WorldState.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
19 spec/event_system/event_system_spec.rb
@@ -0,0 +1,19 @@
+
+require 'spec/rspec_helper'
+
+describe EventSystem do
+ include DelegationMatchers
+ before(:each) do
+ @event_system = EventSystem.new(nil, nil, nil)
+ end
+
+ it "should delegate lifetime to clock" do
+ @event_system.should delegate_to({:lifetime => []}, {:clock => :lifetime})
+ end
+ it "should delegate hook methods to helper" do
+ @event_system.should delegate_to({:non_menu_hooks => []}, {:helper => :non_menu_hooks})
+ @event_system.should delegate_to({:menu_active_hooks => []}, {:helper => :menu_active_hooks})
+ @event_system.should delegate_to({:menu_hooks => []}, {:helper => :menu_hooks})
+ @event_system.should delegate_to({:battle_active_hooks => []}, {:helper => :battle_active_hooks})
+ end
+end
View
13 spec/facades/clock_facade_spec.rb
@@ -0,0 +1,13 @@
+
+require 'spec/rspec_helper'
+
+describe ClockFacade do
+ before(:each) do
+ @clock_facade = ClockFacade.new
+ end
+
+ it "should behave as a clock" do
+ @clock_facade.ticks.should == 0
+ @clock_facade.ticks.should == 0
+ end
+end
View
12 spec/facades/event_handler_facade_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe EventHandlerFacade do
+ before(:each) do
+ @event_handler_facade = EventHandlerFacade.new
+ end
+
+ it "should hold hooks" do
+ @event_handler_facade.hooks.should == []
+ end
+end
View
13 spec/facades/event_hook_facade_spec.rb
@@ -0,0 +1,13 @@
+
+require 'spec/rspec_helper'
+
+describe EventHookFacade do
+ before(:each) do
+ @event_hook_facade = EventHookFacade.new
+
+ end
+
+ it "should support event hook binds" do
+ @event_hook_facade.action = "foo"
+ end
+end
View
17 spec/facades/event_queue_facade_spec.rb
@@ -0,0 +1,17 @@
+
+require 'spec/rspec_helper'
+
+describe EventQueueFacade do
+ before(:each) do
+ @event_queue_facade = EventQueueFacade.new
+ end
+
+ it "should start empty" do
+ @event_queue_facade.should == []
+ end
+
+ it "should grow" do
+ @event_queue_facade << "foo"
+ @event_queue_facade.should == ["foo"]
+ end
+end
View
12 spec/facades/font_facade_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe FontFacade do
+ before(:each) do
+ @font_facade = MusicFactory.new.load_font("FreeSans.ttf")
+ end
+
+ it "should be renderable" do
+ @font_facade.respond_to?(:render).should be_true
+ end
+end
View
14 spec/facades/key_press_trigger_facade_spec.rb
@@ -0,0 +1,14 @@
+
+require 'spec/rspec_helper'
+
+describe KeyPressTriggerFacade do
+ include DomainMocks
+ before(:each) do
+ @event = mock_event
+ @key_press_trigger_facade = KeyPressTriggerFacade.new
+ end
+
+ it "should match key presses" do
+ @key_press_trigger_facade.match?(@event).should be_false
+ end
+end
View
12 spec/facades/key_pressed_facade_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe KeyPressedFacade do
+ before(:each) do
+ @key_pressed_facade = KeyPressedFacade.new(:space)
+ end
+
+ it "should store the key" do
+ @key_pressed_facade.key.should == :space
+ end
+end
View
15 spec/facades/key_release_trigger_facade_spec.rb
@@ -0,0 +1,15 @@
+
+require 'spec/rspec_helper'
+
+#TODO these facades are hard to test, must investigate the rubygame model to see how they are used
+describe KeyReleaseTriggerFacade do
+ include DomainMocks
+
+ before(:each) do
+ @key_release_trigger_facade = KeyReleaseTriggerFacade.new
+ end
+
+ it "should be described" do
+ @key_release_trigger_facade.match?(mock_event).should be_false
+ end
+end
View
18 spec/facades/method_action_facade_spec.rb
@@ -0,0 +1,18 @@
+
+require 'spec/rspec_helper'
+
+class FakeOwner
+ def foo
+ "bar"
+ end
+end
+
+describe MethodActionFacade do
+ before(:each) do
+ @method_action_facade = MethodActionFacade.new(:foo)
+ end
+
+ it "should know what method action to invoke" do
+ @method_action_facade.perform(FakeOwner.new, nil).should == "bar"
+ end
+end
View
16 spec/facades/music_facade_spec.rb
@@ -0,0 +1,16 @@
+
+require 'spec/rspec_helper'
+
+describe MusicFacade do
+ include MethodDefinitionMatchers
+
+ before(:each) do
+ @music_facade = MusicFactory.new.load_music("bonobo-gypsy.mp3")
+ end
+
+ it "should meet the music api" do
+ @music_facade.should define(:play)
+ @music_facade.should define(:pause)
+ @music_facade.should define(:playing?)
+ end
+end
View
12 spec/facades/quit_requested_facade_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe QuitRequestedFacade do
+ before(:each) do
+ @quit_requested_facade = QuitRequestedFacade.new
+ end
+#TODO idano how to test this
+ it "should be tested better than this" do
+ @quit_requested_facade.should_not be_nil
+ end
+end
View
13 spec/facades/screen_facade_spec.rb
@@ -0,0 +1,13 @@
+
+require 'spec/rspec_helper'
+
+describe ScreenFacade do
+ before(:each) do
+ @screen_facade = ScreenFacade.new([123,456])
+ end
+
+ it "should be described" do
+ @screen_facade.w.should == 123
+ @screen_facade.h.should == 456
+ end
+end
View
12 spec/facades/sound_facade_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe SoundFacade do
+ before(:each) do
+ @sound_facade = MusicFactory.new.load_sound("battle-start.ogg")
+ end
+
+ it "should support the sound api" do
+ @sound_facade.respond_to?(:play).should be_true
+ end
+end
View
13 spec/facades/surface_facade_spec.rb
@@ -0,0 +1,13 @@
+
+require 'spec/rspec_helper'
+
+describe SurfaceFacade do
+ include MethodDefinitionMatchers
+ before(:each) do
+ @surface_facade = SurfaceFacade.new([2,2])
+ end
+
+ it "should meet the surface api" do
+ @surface_facade.should define(:blit)
+ end
+end
View
14 spec/facades/tick_trigger_facade_spec.rb
@@ -0,0 +1,14 @@
+
+require 'spec/rspec_helper'
+
+describe TickTriggerFacade do
+ include DomainMocks
+
+ before(:each) do
+ @tick_trigger_facade = TickTriggerFacade.new
+ end
+
+ it "should match events" do
+ @tick_trigger_facade.match?(mock_event).should be_false
+ end
+end
View
19 spec/factories/character_attribution_factory_spec.rb
@@ -0,0 +1,19 @@
+
+require 'spec/rspec_helper'
+
+describe CharacterAttributionFactory do
+ before(:each) do
+ @character_attribution_factory = CharacterAttributionFactory.new
+ end
+
+ def make_attribs
+ @character_attribution_factory.make_attributes
+ end
+
+ it "should make attributes" do
+ make_attribs.should be_an_instance_of(CharacterAttributes)
+ end
+ it "should make attribution" do
+ @character_attribution_factory.make_attribution(make_attribs).should be_an_instance_of(CharacterAttribution)
+ end
+end
View
20 spec/factories/game_internals_factory_spec.rb
@@ -0,0 +1,20 @@
+
+require 'spec/rspec_helper'
+
+describe GameInternalsFactory do
+ include DomainMocks
+
+ before(:each) do
+ @screen = mock_screen
+ @universe = mock_universe
+ @game = mock_game
+ @game_internals_factory = GameInternalsFactory.new
+ end
+
+ it "should build game pieces -- clock" do
+ @game_internals_factory.make_clock.should be_an_instance_of ClockFacade
+ end
+ it "should build game pieces -- player" do
+ @game_internals_factory.make_player(@screen, @universe, @game).should be_an_instance_of Player
+ end
+end
View
14 spec/factories/game_item_factory_spec.rb
@@ -0,0 +1,14 @@
+
+require 'spec/rspec_helper'
+
+describe GameItemFactory do
+ before(:each) do
+ @game_item_factory = GameItemFactory.new
+ end
+
+ it "should create items" do
+ GameItemFactory.antidote.should be_an_instance_of GameItem
+ GameItemFactory.potion.should be_an_instance_of GameItem
+ GameItemFactory.sword.should be_an_instance_of EquippableGameItem
+ end
+end
View
16 spec/factories/monster_factory_spec.rb
@@ -0,0 +1,16 @@
+
+require 'spec/rspec_helper'
+
+describe MonsterFactory do
+ include DomainMocks
+
+ before(:each) do
+ @player = mock_player
+ @universe = mock_universe
+ @monster_factory = MonsterFactory.new
+ end
+
+ it "should make monsters" do
+ @monster_factory.make_monster(@player, @universe).should be_an_instance_of(Monster)
+ end
+end
View
12 spec/factories/music_factory_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe MusicFactory do
+ before(:each) do
+ @music_factory = MusicFactory.new
+ end
+
+ it "should build music facades" do
+ @music_factory.load_music("bonobo-gypsy.mp3").should be_an_instance_of(MusicFacade)
+ end
+end
View
15 spec/factories/surface_factory_spec.rb
@@ -0,0 +1,15 @@
+
+require 'spec/rspec_helper'
+
+describe SurfaceFactory do
+ before(:each) do
+ @surface_factory = SurfaceFactory.new
+ end
+
+ it "should build surface facades" do
+ surf = @surface_factory.make_surface([2,3])
+ surf.should be_an_instance_of(SurfaceFacade)
+ surf.w.should == 2
+ surf.h.should == 3
+ end
+end
View
15 spec/factories/topo_map_factory_spec.rb
@@ -0,0 +1,15 @@
+
+require 'spec/rspec_helper'
+
+describe TopoMapFactory do
+ before(:each) do
+ @topo_map_factory = TopoMapFactory.new
+ end
+
+ it "should build topo maps" do
+ map = TopoMapFactory.build_map("world1_bg", 1280, 960)
+ map.should be_an_instance_of TopoMap
+ map.world_x.should == 1280
+ map.world_y.should == 960
+ end
+end
View
38 spec/factories/trigger_factory_spec.rb
@@ -0,0 +1,38 @@
+
+require 'spec/rspec_helper'
+
+describe TriggerFactory do
+ before(:each) do
+ @trigger_factory = TriggerFactory.new
+ end
+
+
+
+ it "should make tick trigger" do
+ @trigger_factory.make_tick_trigger.should be_an_instance_of(TickTriggerFacade)
+ end
+ it "should make any key press trigger" do
+ @trigger_factory.make_any_key_press_trigger.should be_an_instance_of(KeyPressTriggerFacade)
+ end
+ it "should make any key press trigger" do
+ @trigger_factory.make_key_press_trigger(:left).should be_an_instance_of(KeyPressTriggerFacade)
+ end
+ it "should make key release trigger" do
+ @trigger_factory.make_key_release_trigger.should be_an_instance_of(KeyReleaseTriggerFacade)
+ end
+
+
+ it "should make event handler" do
+ @trigger_factory.make_event_handler.should be_an_instance_of(EventHandlerFacade)
+ end
+ it "should make event hook" do
+ @trigger_factory.make_event_hook(:owner, :key_press, :do_foo_action).should be_an_instance_of(EventHookFacade)
+ end
+ it "should make event hook" do
+ @trigger_factory.make_key_press_event_hook(:owner, :key, :do_other_foo).should be_an_instance_of(EventHookFacade)
+ end
+ it "should make " do
+ @trigger_factory.make_method_action(:do_foo).should be_an_instance_of(MethodActionFacade)
+ end
+
+end
View
20 spec/factories/world_state_factory_spec.rb
@@ -0,0 +1,20 @@
+
+require 'spec/rspec_helper'
+
+describe WorldStateFactory do
+ before(:each) do
+ @world_state_factory = WorldStateFactory.new
+ end
+
+ def bgm
+ MusicFactory.new.load_music("bonobo-gypsy.mp3")
+ end
+
+ it "should be described" do
+ JsonSurface.stub!(:new).and_return nil
+ p = Pallette.new(".")
+ ip = Pallette.new("#")
+ world = WorldStateFactory.build_world_state("world1_bg", "world1_interaction", p, ip, 1280, 960, [], bgm)
+ world.should be_an_instance_of WorldState
+ end
+end
View
13 spec/helpers/animated_sprite_helper_spec.rb
@@ -0,0 +1,13 @@
+
+require 'spec/rspec_helper'
+
+describe AnimatedSpriteHelper do
+ before(:each) do
+ position = PositionedTileCoordinate.new(SdlCoordinate.new(1, 2), SdlCoordinate.new(3, 4))
+ @animated_sprite_helper = AnimatedSpriteHelper.new("Charactern8.png", position)
+ end
+
+ it "should be described" do
+ #TODO not complete
+ end
+end
View
26 spec/helpers/animation_helper_spec.rb
@@ -0,0 +1,26 @@
+
+require 'spec/rspec_helper'
+
+describe AnimationHelper do
+ before(:each) do
+ @keys = AlwaysDownMonsterKeyHolder.new
+
+ @animation_helper = AnimationHelper.new(@keys, 3)
+ end
+
+ def dt
+ 0.20
+ end
+
+ it "should store current frame" do
+ @animation_helper.current_frame.should == 0
+ end
+
+ it "should update frame" do
+ how_many = 3
+ called = false
+ how_many.times { @animation_helper.update_animation(dt) { called = true}}
+ @animation_helper.current_frame.should == 1
+ called.should be_true
+ end
+end
View
27 spec/helpers/color_key_helper_spec.rb
@@ -0,0 +1,27 @@
+
+require 'spec/rspec_helper'
+
+class FakeColorKeyHolder
+ include ColorKeyHelper
+end
+
+describe ColorKeyHelper do
+ include DomainMocks
+ include MethodDefinitionMatchers
+
+ before(:each) do
+ @holder = FakeColorKeyHolder.new
+ end
+
+ it "should define set_color_key_from_corner" do
+ @holder.should define(:set_colorkey_from_corner)
+ end
+
+ it "should ask the surface for its color in the top left corner" do
+ surf = mock("surface")
+ surf.should_receive(:get_at).with(0,0).and_return 3
+ surf.should_receive(:colorkey=).with(3)
+
+ @holder.set_colorkey_from_corner(surf)
+ end
+end
View
17 spec/helpers/json_helper_spec.rb
@@ -0,0 +1,17 @@
+
+require 'spec/rspec_helper'
+
+class FakeJsonEntity
+ include JsonHelper
+end
+
+describe JsonHelper do
+ include MethodDefinitionMatchers
+
+ it "should define json_create and to_json on inclusion" do
+ FakeJsonEntity.should define(:json_create)
+ FakeJsonEntity.new.should define(:to_json)
+ end
+
+
+end
View
18 spec/helpers/resource_loader_spec.rb
@@ -0,0 +1,18 @@
+
+require 'spec/rspec_helper'
+
+class FakeResourceLoader
+ include ResourceLoader
+end
+
+describe ResourceLoader do
+ include MethodDefinitionMatchers
+
+ before(:each) do
+ @resource_loader = FakeResourceLoader.new
+ end
+
+ it "should be able to load things" do
+ @resource_loader.should define(:load_music)
+ end
+end
View
11 spec/helpers/screen_offset_helper_spec.rb
@@ -0,0 +1,11 @@
+
+require 'spec/rspec_helper'
+
+describe ScreenOffsetHelper do
+ include ScreenOffsetHelper
+
+ it "should calculate screen offsets" do
+ offset_from_screen(1000, 100, 10).should == 910
+ offset_from_screen(10, 10, 1000).should == 1000
+ end
+end
View
12 spec/input/event_helper_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe EventHelper do
+ before(:each) do
+ @event_helper = EventHelper.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/input/key_holder_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe KeyHolder do
+ before(:each) do
+ @key_holder = KeyHolder.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/interactables/open_treasure_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe OpenTreasure do
+ before(:each) do
+ @open_treasure = OpenTreasure.new("treasure")
+ end
+
+ it "should be a noop for activation" do
+ @open_treasure.activate(nil, nil, nil, nil, nil)
+ end
+end
View
24 spec/interactables/treasure_spec.rb
@@ -0,0 +1,24 @@
+
+require 'spec/rspec_helper'
+
+describe Treasure do
+ include DomainMocks
+ before(:each) do
+ @game = mock_game
+ @world = mock_world
+ @player = mock_player
+ @treasure = Treasure.new("treasure")
+ end
+
+ it "should block" do
+ @treasure.is_blocking?.should be_true
+ end
+
+ it "should activate" do
+ expect_treasure_sound_effect(@game.universe)
+ expect_interaction_update(@world)
+ expect_notification(@game)
+ expect_inventory_added(@player)
+ @treasure.activate(@game, @player, @world, 11, 22)
+ end
+end
View
28 spec/interactables/warp_point_spec.rb
@@ -0,0 +1,28 @@
+
+require 'spec/rspec_helper'
+
+describe WarpPoint do
+ include DomainMocks
+ before(:each) do
+ @game = mock_game
+ @player = mock_player
+ @warp_point = WarpPoint.new(42)
+ end
+
+ it "should store warp target world index" do
+ @warp_point.destination.should == 42
+ end
+ it "should not block" do
+ @warp_point.is_blocking?.should be_false
+ end
+
+
+ it "should be activatable" do
+ expect_warp_sound_effect(@game.universe)
+ expect_fades_out_bg_music(@game.universe)
+ expect_world_change(@game.universe)
+ expect_player_position_set(@player)
+ expect_fades_in_bg_music(@game.universe)
+ @warp_point.activate(@game, @player, mock_world, 69, 96)
+ end
+end
View
12 spec/items/equipment/equipment_holder_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe EquipmentHolder do
+ before(:each) do
+ @equipment_holder = EquipmentHolder.new
+ end
+
+ it "should have slots" do
+ @equipment_holder.slots.should == [:head, :body, :feet, :left_hand, :right_hand]
+ end
+end
View
12 spec/items/equipment/equipment_info_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe EquipmentInfo do
+ before(:each) do
+ @info = EquipmentInfo.new(:feet, nil)
+ end
+
+ it "should be serializable to string" do
+ @info.to_s.should == "feet: empty"
+ end
+end
View
12 spec/items/equipment/equippable_game_item_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe EquippableGameItem do
+ before(:each) do
+ @item = EquippableGameItem.new("foo", nil)
+ end
+
+ it "should not be consumable" do
+ @item.consumeable?.should be_false
+ end
+end
View
13 spec/items/game_item_spec.rb
@@ -0,0 +1,13 @@
+
+require 'spec/rspec_helper'
+
+describe GameItem do
+ before(:each) do
+ @item = GameItemFactory.antidote
+ end
+
+ it "should be consumeable or not" do
+ @item.consumeable?.should be_true
+ GameItemFactory.sword.consumeable?.should be_false
+ end
+end
View
12 spec/items/item_attributes_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe ItemAttributes do
+ before(:each) do
+ @attributes = ItemAttributes.new(10,9,8,7,6,5,4,3)
+ end
+
+ it "should bind attributes from constructor" do
+ @attributes.agility.should == 4
+ end
+end
View
15 spec/items/item_state_spec.rb
@@ -0,0 +1,15 @@
+
+require 'spec/rspec_helper'
+
+describe ItemState do
+ include DomainMocks
+
+ before(:each) do
+ @attributes = mock_attributes
+ @state = ItemState.new(@attributes, 0, 1, 1, [], 3)
+ end
+
+ it "should be have level points" do
+ @state.level_points.should == 3
+ end
+end
View
15 spec/layers/abstract_layer_spec.rb
@@ -0,0 +1,15 @@
+
+require 'spec/rspec_helper'
+
+describe AbstractLayer do
+ include DomainMocks
+
+ before(:each) do
+ @screen = mock_screen
+ @layer = AbstractLayer.new(@screen, 999, 888)
+ end
+
+ it "should be inactive by default" do
+ @layer.active.should be_false
+ end
+end
View
24 spec/layers/battle_layer_spec.rb
@@ -0,0 +1,24 @@
+
+require 'spec/rspec_helper'
+
+describe BattleLayer do
+ include DomainMocks
+ before(:each) do
+ @game = mock_game
+ @screen = mock_screen
+ @layer = BattleLayer.new(@screen, @game)
+ end
+
+ it "should start out inactive" do
+ @layer.active.should be_false
+ end
+ it "should start out without a battle" do
+ @layer.battle.should be_nil
+ end
+
+ it "should start fights " do
+ @layer.start_battle(@game, @monster)
+ @layer.battle.should_not be_nil
+ @layer.active.should be_true
+ end
+end
View
20 spec/layers/dialog_layer_spec.rb
@@ -0,0 +1,20 @@
+
+require 'spec/rspec_helper'
+
+describe DialogLayer do
+ include DomainMocks
+ before(:each) do
+ @game = mock_game
+ @screen = mock_screen
+ @layer = DialogLayer.new(@screen, @game)
+ end
+
+ it "should start out inactive" do
+ @layer.active.should be_false
+ end
+
+ it "should be able to toggle activity" do
+ @layer.toggle_activity
+ @layer.active.should be_true
+ end
+end
View
19 spec/layers/game_layers_spec.rb
@@ -0,0 +1,19 @@
+
+require 'spec/rspec_helper'
+
+describe GameLayers do
+ include DomainMocks
+ include MethodDefinitionMatchers
+ def mock_layer
+ m = mock("layer")
+ m
+ end
+
+ before(:each) do
+ @game_layers = GameLayers.new(mock_layer,mock_layer,mock_layer,mock_layer)
+ end
+
+ it "should define layer accessors" do
+ @game_layers.should define(:menu_layer)
+ end
+end
View
16 spec/layers/hud_spec.rb
@@ -0,0 +1,16 @@
+
+require 'spec/rspec_helper'
+
+describe Hud do
+ include MethodDefinitionMatchers
+ before(:each) do
+ @hud = Hud.new({})
+ end
+
+ it "should define draw" do
+ @hud.should define(:draw)
+ end
+ it "should define update" do
+ @hud.should define(:update)
+ end
+end
View
23 spec/layers/menu_layer_spec.rb
@@ -0,0 +1,23 @@
+
+require 'spec/rspec_helper'
+
+describe MenuLayer do
+ include DomainMocks
+ include MethodDefinitionMatchers
+
+ before(:each) do
+ @screen = mock_screen
+ @game = mock_game
+ @layer = MenuLayer.new(@screen, @game)
+ end
+
+ it "should be inactive by default" do
+ @layer.active.should be_false
+ end
+
+ it "should define menu api" do
+ @layer.should define(:move_cursor_up)
+ @layer.should define(:move_cursor_down)
+ @layer.should define(:enter_current_cursor_location)
+ end
+end
View
23 spec/layers/notifications_layer_spec.rb
@@ -0,0 +1,23 @@
+
+require 'spec/rspec_helper'
+
+describe NotificationsLayer do
+ include DomainMocks
+
+ before(:each) do
+ @screen = mock_screen
+ @game = mock_game
+ @layer = NotificationsLayer.new(@screen, @game)
+ end
+
+ def notification
+ Notification.new("herro", 3, :foo)
+ end
+
+ it "should be able to add notifications" do
+ @layer.notifications.should == []
+ n = notification
+ @layer.add_notification(n)
+ @layer.notifications.should == [n]
+ end
+end
View
12 spec/menu/actions/base_selector_dependency_helper_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe BaseSelectorDependencyHelper do
+ before(:each) do
+ @base_selector_dependency_helper = BaseSelectorDependencyHelper.new
+ end
+
+ it "should be described" do
+ fail
+ end
+end
View
12 spec/menu/actions/menu_action_spec.rb
@@ -0,0 +1,12 @@
+
+require 'spec/rspec_helper'
+
+describe MenuAction do
+ before(:each) do
+ @menu_action = MenuAction.new