Permalink
Browse files

got to 100% coverage, and passed flay, into flog

  • Loading branch information...
bgoodspeed committed Nov 12, 2010
1 parent 97a92da commit b4c977cca2956fa73aba5e9ff732a325fb64677a
Showing with 799 additions and 118 deletions.
  1. +1 −1 lib/battle/menu/selectors/battle_targets_menu_selector.rb
  2. +3 −2 lib/domain/party.rb
  3. +1 −1 lib/helpers/animated_sprite_helper.rb
  4. +2 −2 lib/layers/abstract_layer.rb
  5. +1 −1 lib/layers/game_layers.rb
  6. +4 −4 lib/layers/hud.rb
  7. +5 −17 lib/menu/cursor_helper.rb
  8. +1 −1 lib/menu/selectors/drawable_element_menu_selector_helper.rb
  9. +1 −1 lib/menu/selectors/filtered_inventory_menu_selector.rb
  10. +6 −2 lib/missions/mission_archive.rb
  11. +2 −1 lib/npcs/monster.rb
  12. +34 −28 lib/tile_system/interaction_helper.rb
  13. +4 −8 lib/tile_system/topo_map.rb
  14. +1 −1 lib/traits/character_state.rb
  15. +1 −1 lib/world_weapons/world_weapon.rb
  16. +1 −0 lib/world_weapons/world_weapon_helper.rb
  17. +1 −1 lib/world_weapons/world_weapon_interaction_helper.rb
  18. +4 −0 spec/ai/repeating_path_follower_spec.rb
  19. +4 −0 spec/ai/static_path_follower_spec.rb
  20. +2 −0 spec/ai/target_matcher_spec.rb
  21. +12 −0 spec/battle/battle_readiness_helper_spec.rb
  22. +20 −0 spec/battle/battle_spec.rb
  23. +6 −2 spec/battle/menu/selectors/battle_ready_party_menu_selector_spec.rb
  24. +5 −2 spec/battle/menu/selectors/battle_targets_menu_selector_spec.rb
  25. +5 −0 spec/domain/inventory_spec.rb
  26. +44 −0 spec/domain/party_spec.rb
  27. +6 −0 spec/domain/player_spec.rb
  28. +3 −0 spec/factories/game_internals_factory_spec.rb
  29. +15 −3 spec/helpers/animated_sprite_helper_spec.rb
  30. +8 −0 spec/helpers/json_helper_spec.rb
  31. +14 −2 spec/input/event_helper_spec.rb
  32. +4 −0 spec/interactables/treasure_spec.rb
  33. +5 −0 spec/interactables/warp_point_spec.rb
  34. +14 −0 spec/items/equipment/equipment_holder_spec.rb
  35. +6 −0 spec/items/equipment/equippable_game_item_spec.rb
  36. +11 −0 spec/items/game_item_spec.rb
  37. +16 −0 spec/layers/dialog_layer_spec.rb
  38. +41 −1 spec/layers/game_layers_spec.rb
  39. +15 −1 spec/layers/hud_spec.rb
  40. +26 −0 spec/menu/cursor_helper_spec.rb
  41. +17 −1 spec/menu/selectors/drawable_element_menu_selector_helper_spec.rb
  42. +6 −0 spec/menu/selectors/filtered_inventory_menu_selector_spec.rb
  43. +4 −0 spec/menu/selectors/save_slot_menu_selector_spec.rb
  44. +8 −0 spec/menu/selectors/stat_line_menu_selector_spec.rb
  45. +14 −0 spec/missions/mission_archive_spec.rb
  46. +4 −0 spec/npcs/monster_coordinate_helper_spec.rb
  47. +50 −1 spec/npcs/monster_spec.rb
  48. +7 −0 spec/npcs/talking_n_p_c_spec.rb
  49. +21 −2 spec/palettes/i_s_b_p_result_spec.rb
  50. +15 −1 spec/palettes/pallette_spec.rb
  51. +4 −0 spec/palettes/surface_backed_pallette_spec.rb
  52. +118 −3 spec/rspec_helper.rb
  53. +57 −1 spec/tile_system/interaction_helper_spec.rb
  54. +28 −8 spec/tile_system/interpreted_map_spec.rb
  55. +3 −1 spec/tile_system/topo_map_spec.rb
  56. +11 −0 spec/traits/character_attributes_spec.rb
  57. +17 −0 spec/traits/character_attribution_spec.rb
  58. +33 −0 spec/traits/character_state_spec.rb
  59. +18 −15 spec/world_weapons/world_weapon_helper_spec.rb
  60. +2 −2 spec/world_weapons/world_weapon_interaction_helper_spec.rb
  61. +7 −0 spec/world_weapons/world_weapon_spec.rb
@@ -3,7 +3,7 @@
class BattleTargetsMenuSelector
include DrawableElementMenuSelectorHelper
-
+
def initialize(game)
@game = game
end
View
@@ -4,10 +4,11 @@ class Party
def_delegators :@inventory, :add_item, :gain_inventory, :inventory_info,
:inventory_item_at, :inventory_count
def_delegators :leader, :world_weapon
- attr_reader :members, :inventory
- def initialize(members, inventory)
+ attr_reader :members, :inventory, :money
+ def initialize(members, inventory, money=0)
@members = members
@inventory = inventory
+ @money = money
end
def collect
@@ -1,6 +1,6 @@
class AnimatedSpriteHelper
- attr_reader :image, :rect, :px, :py
+ attr_reader :image, :rect, :px, :py, :last_direction_offset
include ColorKeyHelper
def initialize(filename, position, surface_factory=SurfaceFactory.new)
@@ -1,13 +1,13 @@
class AbstractLayer
include ResourceLoader
- attr_accessor :active, :layer
+ attr_accessor :active, :layer, :font
def initialize(screen, layer_width, layer_height, surface_factory=SurfaceFactory.new)
@screen = screen
@active = false
@layer = surface_factory.make_surface([layer_width, layer_height])
- @font = load_font("FreeSans.ttf")
+ @font = load_font("FreeSans.ttf") #XXX this should come from a factory and not use resource loader
@text_rendering_helper = TextRenderingHelper.new(@layer, @font)
end
@@ -13,7 +13,7 @@ class GameLayers
- attr_reader :dialog_layer, :menu_layer, :battle_layer, :notifications_layer
+ attr_accessor :dialog_layer, :menu_layer, :battle_layer, :notifications_layer
def initialize(dialog_layer=nil, menu_layer=nil, battle_layer=nil, notif_layer=nil)
@dialog_layer = dialog_layer
@menu_layer = menu_layer
View
@@ -2,25 +2,25 @@
class Hud
include ResourceLoader
- # construct the HUD
+ attr_reader :time, :font, :player
def initialize options
@screen = options[:screen] # need that to blit on it
@player = options[:player]
@topomap = options[:topomap]
- @cosmic_font = load_font("FreeSans.ttf")
+ @font = load_font("FreeSans.ttf")
@time = "-"
end
# called from the game class in each loop. updates options that are displayed
def update options
- @time = "#{options[:time]}, Items collected: #{@player.inventory.keys.size}"
+ @time = "#{options[:time]}, Items collected: #{@player.inventory_count}"
end
# called from the game class in the draw method. render any options
# and blit the surface on the screen
def draw
- timer = @cosmic_font.render @time.to_s, true, [123,123,123]
+ timer = @font.render @time.to_s, true, [123,123,123]
timer.blit @screen, [@screen.w-timer.w-6, 6] # blit to upper right corner
end
View
@@ -22,10 +22,6 @@ def reset_selections
@currently_selected = Selections.new
end
- def selected_amongst(sections)
- current_section_in(sections).section_by_index(@position)
- end
-
def path
@path.clone
@@ -74,7 +70,10 @@ def reduce_only_to_zero(v)
end
def cancel
- @path.shift
+ reved = @path.reverse
+ reved.shift
+
+ @path = reved.reverse
@depth = reduce_only_to_zero(@depth)
end
@@ -103,18 +102,7 @@ def path_element_at_index(idx)
([@position] + @path)[idx]
end
- def should_display_submenu_for?(index, depth)
- (depth < @path.size) && @path.first == index
- end
-
- def selections_made
- @path.size - 1
- end
-
- def selector_menus_to_draw_at_depth(depth, needed)
- needed - selections_made
- end
-
+
def color_for_current_section_cursor
@current_color
end
@@ -2,7 +2,7 @@
# and open the template in the editor.
module DrawableElementMenuSelectorHelper
-
+ attr_reader :game
def element_names(selections)
elements(selections).collect {|el| el.name }
end
@@ -28,7 +28,7 @@ def elements(selected)
end
def select_element_at(idx, selections)
- rv = elements[idx]
+ rv = elements(selections)[idx]
rv
end
@@ -2,14 +2,18 @@
# and open the template in the editor.
class MissionArchive
+
def initialize(game)
@game = game
@achieved_mission_tokens = []
end
+ def mark_completed(mission)
+ @achieved_mission_tokens << mission.id_token
+ end
+
def mission_achieved?(mission_id_token)
- @achieved_mission_tokens.include?(:fooasdf)
-
+ @achieved_mission_tokens.include?(mission_id_token)
end
def missions
View
@@ -9,7 +9,8 @@ class Monster
def_delegator :@readiness_helper, :points, :readiness_points
- attr_reader :inventory, :player
+ attr_reader :inventory, :player, :animated_sprite_helper, :animation_helper,
+ :coordinate_helper, :ai, :readiness_helper
def initialize(player, universe, filename, position, inventory=Inventory.new(255), character_attrib=nil, ai=nil)
@npc_x = position.dimension.x
@npc_y = position.dimension.y
@@ -10,18 +10,14 @@ def initialize(game, policy)
@policy = policy
end
- def interact_with_current_tile(game, tilex, tiley, this_tile_interacts)
- this_tile_interacts.activate(game, game.player, game.universe.current_world, tilex, tiley)
+ def interact_with_tile(game, tilex, tiley, tile)
+ tile.activate(game, game.player, game.universe.current_world, tilex, tiley)
end
- def interact_with_dialog
- @universe.dialog_layer.toggle_activity
+ def interact_with_dialog(layer)
+ layer.toggle_activity
end
-
- def interact_with_facing_tile(game, facing_tilex, facing_tiley, facing_tile_interacts)
- facing_tile_interacts.activate(game, game.player, game.universe.current_world, facing_tilex, facing_tiley)
- end
-
+
def interact_with_npc(game, interactable_npcs)
npc = interactable_npcs[0] #TODO what if there are multiple npcs to interact w/? one at a time? all of them?
npc.interact(game, game.universe, game.player) #TODO change the expected signature for interact and make interactable api tests
@@ -58,24 +54,40 @@ def facing_tile_distance_for(game, tilex, tiley, px, py)
facing_tile_dist
end
+ def attempt_interaction_with_dialog(layer)
+ return false unless layer.active
+ interact_with_dialog(layer)
+ true
+ end
+
+ def attempt_interaction_with_tile(game, tilex, tiley, tile)
+ return false unless tile
+ interact_with_tile(game, tilex, tiley, tile)
+ true
+ end
+
+ def attempt_interaction_with_facing(game, tilex, tiley, tile, close_enough)
+ return false unless tile and close_enough
+ interact_with_tile(game, tilex, tiley, tile)
+ true
+ end
+
+ def attempt_interaction_with_npcs(game, npcs)
+ return false if npcs.empty?
+ interact_with_npc(game, npcs)
+ true
+ end
+
def interact_with_facing(game, px,py)
puts "mapped key to interaction helper"
-
- if game.universe.dialog_layer.active
- puts "confirming/closing/paging dialog"
- interact_with_dialog
- return if @policy.return_after_dialog
- end
+ return if attempt_interaction_with_dialog(game.universe.dialog_layer) and @policy.return_after_dialog
tilex = game.universe.current_world.x_offset_for_interaction(px)
tiley = game.universe.current_world.y_offset_for_interaction(py)
this_tile_interacts = game.universe.current_world.interaction_interpreter.interpret(tilex, tiley)
facing_tile_interacts = false
-
- if this_tile_interacts
- interact_with_current_tile(game, tilex, tiley, this_tile_interacts)
- return if @policy.return_after_current
- end
+
+ return if attempt_interaction_with_tile(game, tilex, tiley, this_tile_interacts) and @policy.return_after_current
facing_tilex = facing_tilex_for(tilex)
facing_tiley = facing_tiley_for(tiley)
@@ -84,16 +96,10 @@ def interact_with_facing(game, px,py)
facing_tile_interacts = game.universe.current_world.interaction_interpreter.interpret(facing_tilex, facing_tiley)
facing_tile_close_enough = facing_tile_dist < @@INTERACTION_DISTANCE_THRESHOLD
- if facing_tile_close_enough and facing_tile_interacts
- interact_with_facing_tile(game, facing_tilex, facing_tiley, facing_tile_interacts)
-
- return if @policy.return_after_facing
- end
+ return if attempt_interaction_with_facing(game, facing_tilex, facing_tiley, facing_tile_interacts, facing_tile_close_enough) and @policy.return_after_facing
interactable_npcs = game.universe.current_world.npcs.select {|npc| npc.nearby?(px,py, @@INTERACTION_DISTANCE_THRESHOLD, @@INTERACTION_DISTANCE_THRESHOLD) }
- unless interactable_npcs.empty?
- interact_with_npc(game, interactable_npcs)
- end
+ attempt_interaction_with_npcs(game, interactable_npcs)
end
end
@@ -85,14 +85,10 @@ def blit_foreground(palette, screen, px, py)
end
- def to_json(*a)
- {
- 'json_class' => self.class.name,
- 'data' => [ @x, @y, @world_x, @world_y, @data]
- }.to_json(*a)
- end
- def self.json_create(o)
- new(*o['data'])
+ include JsonHelper
+
+ def json_params
+ [ @x, @y, @world_x, @world_y, @data]
end
end
@@ -1,6 +1,6 @@
class CharacterState
- attr_accessor :current_hp, :current_mp, :status_effects, :experience, :level_points
+ attr_accessor :current_hp, :current_mp, :status_effects, :experience, :level_points, :attributes
extend Forwardable
def_delegators :@attributes, :hp, :mp, :add_attributes
def initialize(attributes, exp=nil, chp=nil, cmp=nil, statii=nil, lvp=nil)
@@ -1,7 +1,7 @@
class WorldWeapon
attr_reader :ticks, :max_ticks
- attr_accessor :facing
+ attr_accessor :facing, :startx, :starty
def initialize(pallette, max_ticks=25)
@pallette = pallette
@ticks = 0
@@ -5,6 +5,7 @@ class WorldWeaponHelper
def_delegators :@weapon, :draw_weapon
def_delegators :@interaction_helper, :facing, :facing=
+ attr_reader :weapon
def initialize(game, helper = WorldWeaponInteractionHelper.new(game, InteractionPolicy.process_all))
@game = game
@player = game.player
@@ -4,7 +4,7 @@ def interact_with_current_tile(game, tilex, tiley)
#TODO revisit this class
end
- def interact_with_dialog
+ def interact_with_dialog(layer)
puts "noop dialog"
end
@@ -34,5 +34,9 @@
keys.should include(:right)
end
+
+ it "should be json ified" do
+ @repeating_path_follower.json_params.should be_an_instance_of(Array)
+ end
end
@@ -11,5 +11,9 @@
it "should do nothing" do
@static_path_follower.update(nil)
end
+
+ it "is json ified" do
+ @static_path_follower.json_params.should be_an_instance_of Array
+ end
end
@@ -6,6 +6,7 @@
describe TargetMatcher do
before(:each) do
@target_matcher = TargetMatcher.new("Enemy")
+ @non_enemy_matcher = TargetMatcher.new("Foo")
end
it "should discern enemy targets" do
@@ -21,6 +22,7 @@
end
it "should be able to determine if it matches" do
+ @non_enemy_matcher.matches?(hero, hero).should be_true
@target_matcher.matches?(monster, hero).should be_true
@target_matcher.matches?(monster, monster).should be_false
end
@@ -12,5 +12,17 @@
it "should grow by growth rate" do
@helper.add_readiness(1)
@helper.points.should == 15
+
+ end
+ it "should consume readiness" do
+ @helper.consume_readiness(7)
+ @helper.points.should == 3
end
+
+ it "should know when it is ready" do
+ @helper.ready?.should be_false
+ @helper.add_readiness(1000)
+ @helper.ready?.should be_true
+ end
+
end
Oops, something went wrong.

0 comments on commit b4c977c

Please sign in to comment.