Skip to content

Commit

Permalink
got to 100% coverage, and passed flay, into flog
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoodspeed committed Nov 12, 2010
1 parent 97a92da commit b4c977c
Show file tree
Hide file tree
Showing 61 changed files with 799 additions and 118 deletions.
2 changes: 1 addition & 1 deletion lib/battle/menu/selectors/battle_targets_menu_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class BattleTargetsMenuSelector
include DrawableElementMenuSelectorHelper

def initialize(game)
@game = game
end
Expand Down
5 changes: 3 additions & 2 deletions lib/domain/party.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/animated_sprite_helper.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/layers/abstract_layer.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/layers/game_layers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/layers/hud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 5 additions & 17 deletions lib/menu/cursor_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/menu/selectors/filtered_inventory_menu_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def elements(selected)
end

def select_element_at(idx, selections)
rv = elements[idx]
rv = elements(selections)[idx]
rv
end

Expand Down
8 changes: 6 additions & 2 deletions lib/missions/mission_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/npcs/monster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 34 additions & 28 deletions lib/tile_system/interaction_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
12 changes: 4 additions & 8 deletions lib/tile_system/topo_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/traits/character_state.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/world_weapons/world_weapon.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/world_weapons/world_weapon_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/world_weapons/world_weapon_interaction_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions spec/ai/repeating_path_follower_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 4 additions & 0 deletions spec/ai/static_path_follower_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions spec/ai/target_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/battle/battle_readiness_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit b4c977c

Please sign in to comment.