Skip to content

Commit

Permalink
changing directory structure for player profiles, this change is inco…
Browse files Browse the repository at this point in the history
…mpatible with earlier versions - closes ryanb#3
  • Loading branch information
ryanb committed Jul 17, 2009
1 parent b04d9fb commit 7209b37
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 28 deletions.
7 changes: 3 additions & 4 deletions features/levels.feature
Expand Up @@ -8,20 +8,19 @@ Feature: Play levels

Scenario: Pass first level, fail second level
Given a profile named "Joe" on "beginner"
When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/beginner-tower/level-001/player.rb"
When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/joe-beginner/player.rb"
And I run rubywarrior
And I choose "Joe - beginner - level 1" for "profile"
Then I answer "y" to "next level"
And I should see "directory for the next level"
When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/beginner-tower/level-002/player.rb"
And I run rubywarrior
And I choose "Joe - beginner - level 2" for "profile"
And I answer "y" to "clues"
Then I should see "warrior.feel.empty?"

Scenario: Retry first level
Given a profile named "Joe" on "beginner"
When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/beginner-tower/level-001/player.rb"
When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/joe-beginner/player.rb"
And I run rubywarrior
And I choose "Joe - beginner - level 1" for "profile"
Then I answer "n" to "next level"
Expand All @@ -32,7 +31,7 @@ Feature: Play levels
Scenario: Replay levels as epic when finishing last level
When I copy fixture "short-tower" to "towers/short"
Given a profile named "Bill" on "short"
When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/short-tower/level-001/player.rb"
When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/bill-short/player.rb"
And I run rubywarrior
And I choose "Bill - short - level 1" for "profile"
Then I answer "y" to "next level"
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_warrior/level.rb
Expand Up @@ -10,7 +10,7 @@ def initialize(profile, number)
end

def player_path
@profile.player_path + "/level-" + @number.to_s.rjust(3, '0')
@profile.player_path
end

def load_path
Expand Down
5 changes: 1 addition & 4 deletions lib/ruby_warrior/player_generator.rb
Expand Up @@ -18,10 +18,7 @@ def previous_level

# TODO refactor and test this method
def generate
if File.exist? previous_level.player_path
FileUtils.cp_r(previous_level.player_path, level.player_path)
FileUtils.rm(level.player_path + '/README')
else
if level.number == 1
FileUtils.mkdir_p(level.player_path)
FileUtils.cp(templates_path + '/player.rb', level.player_path)
end
Expand Down
10 changes: 3 additions & 7 deletions lib/ruby_warrior/profile.rb
Expand Up @@ -33,15 +33,11 @@ def self.load(path)
end

def player_path
Config.path_prefix + "/ruby-warrior/#{tower.name}-tower"
Config.path_prefix + "/ruby-warrior/#{directory_name}"
end

def current_level_path
if epic?
player_path + "/epic"
else
player_path + "/level-" + level_number.to_s.rjust(3, '0')
end
def directory_name
[warrior_name.downcase.gsub(/[^a-z0-9]+/, '-'), tower.name].join('-')
end

def to_s
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby_warrior/level_spec.rb
Expand Up @@ -28,9 +28,9 @@
@level.description.should == 'foo'
end

it "should have a player path from profile with level number in it" do
it "should have a player path from profile" do
@profile.stubs(:player_path).returns('path/to/player')
@level.player_path.should == 'path/to/player/level-001'
@level.player_path.should == 'path/to/player'
end

it "should have a load path from profile tower with level number in it" do
Expand Down
12 changes: 2 additions & 10 deletions spec/ruby_warrior/profile_spec.rb
Expand Up @@ -83,6 +83,7 @@

describe "with tower path" do
before(:each) do
@profile.warrior_name = "John Smith"
@profile.tower_path = 'path/to/tower'
end

Expand All @@ -106,16 +107,7 @@
end

it "should guess at the player path" do
@profile.player_path.should == './ruby-warrior/tower-tower'
end

it "should append level dir to player path" do
@profile.current_level_path.should == './ruby-warrior/tower-tower/level-000'
end

it "should use 'epic' as level directory" do
@profile.enable_epic_mode
@profile.current_level_path.should == './ruby-warrior/tower-tower/epic'
@profile.player_path.should == './ruby-warrior/john-smith-tower'
end

it "should load tower from path" do
Expand Down

0 comments on commit 7209b37

Please sign in to comment.