Skip to content

Commit

Permalink
Fixes for working on Ruby 1.9.1-preview1 merged from branch ruby19-po…
Browse files Browse the repository at this point in the history
…rting
  • Loading branch information
menthal committed Nov 6, 2008
1 parent 726d60d commit 65ce8f2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
18 changes: 14 additions & 4 deletions magicmaze/filemap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@ def initialize( filename, monster_maker = nil )
}
end


def convert_string_to_bytes( str )
if str.respond_to?(:bytes) then
str.bytes.collect{|i| i } # Ruby 1.9
else
str # Ruby 1.8
end
end
##
# Extract various data from the header part of the map.
def extract_from_header( header_data )
def extract_from_header( header_data_str )
header_data = convert_string_to_bytes( header_data_str )
@checksum = header_data[16] + (header_data[17]<<8)
@startx = header_data[24]
@starty = header_data[25]
@default_wall_tile = header_data[30]
@last_level = header_data[32]&BLOCKED_BIT==BLOCKED_BIT
@last_level = header_data[32] & BLOCKED_BIT == BLOCKED_BIT

@title = ""
index = 128
Expand Down Expand Up @@ -123,7 +132,7 @@ def each_column( &block )
# If the most significant bit is set, it is blocked.
# If the coordinate is outside the map, a default block is returned.
def get_background_data( x, y )
row = @map_rows[y]
row = convert_string_to_bytes(@map_rows[y])
row ||= EMPTY_ROW
index = x*2
if (index<0||index>=row.size) then
Expand All @@ -143,7 +152,8 @@ def get_background_tile( x, y )
##
# return object code for the position given.
def get_object( x, y )
object = @map_rows[y][x*2+1]
row = convert_string_to_bytes(@map_rows[y])
object = row[x*2+1]
end
alias :get_object_data :get_object

Expand Down
4 changes: 2 additions & 2 deletions magicmaze/graphics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def show_help
'Alt :- Cast secondary spell',
'X / Z :- Toggle attack spell',
'A / S :- Toggle secondary spell',
'',
'', # Failed for RubySDL2.0.1 and Ruby1.9.1-p1
'Esc / Q :- Quit playing',
'F9 / R :- Restart level',
# '[F4]: Load game [F5]: Save game',
Expand All @@ -502,7 +502,7 @@ def show_help
y_offset = 0
font = @font16
lines.each{|line|
write_smooth_text( line, 5, y_offset, font )
write_smooth_text( line, 5, y_offset, font ) if line.size.nonzero? # Failed for RubySDL2.0.1 and Ruby1.9.1-p1 on empty string.
y_offset+= font.height
}

Expand Down
2 changes: 1 addition & 1 deletion magicmaze/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def write_text( text, x, y, font = @font16 )
end

def write_smooth_text( text, x, y, font = @font16,r=255,g=255,b=255 )
font.drawBlendedUTF8(@screen, text, x,y, r,g,b)
font.drawBlendedUTF8(@screen, text, x,y, r,g,b) # Failed for RubySDL2.0.1 and Ruby1.9.1-p1 on multiline strings.
end

def set_palette( pal, start_color = 0 )
Expand Down
1 change: 1 addition & 0 deletions magicmaze/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
############################################################

require 'magicmaze/tile'
require 'magicmaze/entity'

module MagicMaze

Expand Down
19 changes: 19 additions & 0 deletions magicmaze/test_filemap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'test/unit'

require 'magicmaze/filemap'

class TestFileMap < Test::Unit::TestCase
def setup
end

def test_loading_filemaps
(1..10).each do|level|
filename = sprintf "data/maps/mm_map.%03d", level
filemap = MagicMaze::FileMap.new( filename )
assert( filemap )
gamemap = filemap.to_gamemap
assert( gamemap )
assert( filemap.title.size.nonzero? )
end
end
end
2 changes: 1 addition & 1 deletion magicmaze/test_graphics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_write_score
def test_show_message
@g.show_message("Test")
@g.show_message("Testing the message box", false)
@g.show_message("Testing the message box... \n" * 5)
# @g.show_message("Testing the message box... \n" * 5 + "And stop!") # Failed for RubySDL2.0.1 and Ruby1.9.1-p1
end

def test_show_long_message
Expand Down
1 change: 1 addition & 0 deletions magicmaze/test_magicmaze.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'test/unit'

require 'magicmaze/test_tile'
require 'magicmaze/test_filemap'
require 'magicmaze/test_map'
require 'magicmaze/test_movement'
require 'magicmaze/test_player'
Expand Down

0 comments on commit 65ce8f2

Please sign in to comment.