AbePralle-FGB/Tools/MapMaker/Source/MapMaker.rogue

618 lines
24 KiB
Plaintext

#===============================================================================
# MapMaker.rogue
# July 6, 2020
#===============================================================================
$requireRogue "1.7.5"
uses Bitmap
MapMaker()
class MapMaker
DEFINITIONS
SCALED_WIDTH = 640
SCALED_HEIGHT = 576
PROPERTIES
levels = FGBLevel[]
METHODS
method init
File.create_folder( "../../Media/Levels" )
print( "Rendering level images" ).flush
forEach (filepath at index in File.listing("../../Data/Levels/L*.lvl"))
if (index % 10 == 9) print( '.' ).flush
levels.add( FGBLevel(filepath) )
endForEach
println
require levels.count
print( "Saving level images" ).flush
forEach (level at index in levels)
if (index % 10 == 9) print( '.' ).flush
level.bitmap.save_as_png( "../../Media/Levels/$.png"(level.level_number.format("04")) )
endForEach
println
File.create_folder( "../../Media/Maps" )
local map = Bitmap( SCALED_WIDTH*11, SCALED_HEIGHT*11, Color.BLACK )
print( "Building WorldMap-Rendered.png" ).flush
forEach (level at index in levels)
if (index % 10 == 9) print( '.' ).flush
if (level.column < 11 and level.row < 11)
place( level, map, level.column, level.row )
endIf
endForEach
println
println "Saving WorldMap-Rendered.png"
map.save_as_png( "../../Media/Maps/WorldMap-Rendered.png" )
create_map( "MoonBase.png",
[
[ -1, 0213, -1, 0314, 0215],
[0013, 0113, 0214, 0114, 0115],
[0313, 0315, -1, 0014, 0015]
]
)
create_map( "Tower.png",
[
[0411],
[0311],
[0211],
[0111]
]
)
create_map( "FourSeasonsHouse.png", 0011 )
create_map( "SunsetVillageHouses.png",
[
[0212,0312,0412]
]
)
create_map( "SpaceStationApocalypse.png",
[
[0811,0012,0911],
[1011,0711,1111]
]
)
create_map( "TheHive.png",
[
[0000,0112]
]
)
create_map( "WitchsHouse.png",
[
[0512],
[0508]
]
)
create_map( "FarmLanding.png",
[
[0103],
[0712]
]
)
create_map( "TheAppomattox.png", 1300 )
#create_map( "DemoWarpZone.png", 0812 ) # can set L1100.asm to exit to 0812; was not in final game
create_map( "MonkeyHomeworldAndCroutonHomeworld.png",
[
[ -1, -1,1512],
[ -1, -1,1412],
[ -1,1112,1312],
[0612,0912,1212],
[0808,1012, -1]
]
)
method create_map( filename:String, level_numbers:Int32[][] )
local h = level_numbers.count
local w = level_numbers.first.count
local map = Bitmap( SCALED_WIDTH*w, SCALED_HEIGHT*h, Color.BLACK )
forEach (row at j in level_numbers)
forEach (number at i in row)
if (number == -1) nextIteration
local level = levels.find( $.level_number == number )
if (level.exists)
place( level.value, map, i, j )
endIf
endForEach
endForEach
println "Saving "+filename
map.save_as_png( "../../Media/Maps/"+filename )
method create_map( filename:String, level_number:Int32 )
local level = levels.find( $.level_number == level_number )
require level.exists
println "Saving "+filename
level.value.bitmap.save_as_png( "../../Media/Maps/"+filename )
method place( level:FGBLevel, destination:Bitmap, i:Int32, j:Int32 )
local x = i * SCALED_WIDTH
local y = j * SCALED_HEIGHT
level.scaled_bitmap.blit( destination, x, y, BitmapBlitFn.ALPHA )
#{
# Was used to establish standard zone size of 640x576
method calculate_sizes( levels:FGBLevel[] )
println "Calculating sizes"
# Max sizes
local max_column_width = Int32[]
local max_row_height = Int32[]
forEach (level in levels)
max_column_width.expand_to_include( level.column )
max_column_width[level.column] = max_column_width[level.column].or_larger(level.pixel_width)
max_row_height.expand_to_include( level.row )
max_row_height[level.row] = max_row_height[level.row].or_larger(level.pixel_height)
endForEach
# Max sizes help determine min sizes
local min_column_width = max_column_width.cloned
local min_row_height = max_row_height.cloned
forEach (level in levels)
min_column_width[level.column] = min_column_width[level.column].or_smaller(level.pixel_width)
min_row_height[level.row] = min_row_height[level.row].or_smaller(level.pixel_height)
endForEach
local column_width = Int32[]
local row_height = Int32[]
forEach (min_w at i in min_column_width)
column_width.add( max_column_width[i].or_smaller(min_w*2) )
endForEach
forEach (min_h at j in min_row_height)
row_height.add( max_row_height[j].or_smaller(min_h*2) )
endForEach
#column_width.add( 640 )
#row_height.add( 576 )
trace column_width.count
trace row_height.count
trace column_width.count * row_height.count
trace levels.count
@trace column_width
@trace row_height
local sum_width = 0
sum_width += (forEach in column_width)
local sum_height = 0
sum_height += (forEach in row_height)
local mb = (sum_width * sum_height * 4) / 1024^2
@trace sum_width, sum_height, mb
}#
endClass
class FGBLevel
PROPERTIES
filename : String
level_number : Int32
version : Int32
classes = Int32[]
first_character_index : Int32
first_character_id : Int32
width : Int32
pitch : Int32
height : Int32
tiles = Int32[]
bg_color : Color
bitmap : Bitmap
scaled_bitmap : Bitmap
METHODS
method init( filename )
level_number = filename.after_last('L').before_first('_')->Int32
local reader = File.reader( filename )
version = reader.read
local class_count = reader.read
classes.add( 0 ) # index 0 is always empty space
block
first_character_index = reader.read
first_character_id = reader.read
first_character_id = first_character_id | (reader.read :<<: 8)
endBlock
block
loop (class_count)
local low = reader.read : Int32
local high = reader.read : Int32
local cls = ((high:<<:8) | low)
if (cls < first_character_id) --cls
if (cls == 1532) cls = 0
classes.add( cls )
endLoop
endBlock
width = reader.read
pitch = reader.read
height = reader.read
forEach (j in 0..<height)
forEach (i in 0..<width)
local index = reader.read
require (index >= 0 and index < classes.count)
tiles.add( classes[index] )
endForEach
endForEach
forEach (cls at index in tiles)
which (cls)
case 2102, 2120, 2140, 2168, 2222, 2230, 2238, 2246, 2258, 2268, 2298, 2319, 2335,
2343, 2351, 2362, 2370, 2374, 2390, 2408, 2418, 2426, 2434, 2446
tiles[index+1] = cls+1
tiles[index+width] = cls+2
tiles[index+width+1] = cls+3
endWhich
endForEach
local color_low = reader.read : Int32
local color_high = reader.read : Int32
local color = (color_high :<<: 8) | color_low
bg_color = Graphics.color_16_to_32( color )
# Waypoint List
# TODO (investigate starting at Tools/LevelEditor/Source/Controls.cpp line 393)
# Zones
# TODO
# Exits
# TODO
# Exit Links
# TODO
bitmap = _render
local W = MapMaker.SCALED_WIDTH
local H = MapMaker.SCALED_HEIGHT
local scale = (W/Real64(bitmap.width)).or_smaller( H/Real64(bitmap.height) )
scaled_bitmap = bitmap.resized( bitmap.size*scale ).[ reframe(W,H,Anchor.CENTER,&pad_color=bg_color) ]
method column->Int32
return level_number / 100
method get( i:Int32, j:Int32 )->Int32
return tiles[ j*width + i ]
method pixel_height->Real64
return (height-2)*16
method pixel_width->Real64
return (width-2)*16
method _render->Bitmap
local result = Bitmap( (width-2)*16, (height-2)*16, bg_color )
forEach (j in 1..<height-1)
forEach (i in 1..<width-1)
local tile = this.get(i,j)
if (tile > 0)
Graphics[ this.get(i,j) ].blit( result, (i-1)*16, (j-1)*16, BitmapBlitFn.ALPHA )
endIf
endForEach
endForEach
if (level_number == 0014)
result = Bitmap( result, Box(result.width-320,0,320,result.height) )
elseIf (level_number == 0115)
result = Bitmap( result, Box(0,0,544,result.height) )
elseIf (level_number == 0215)
result = Bitmap( result, Box(0,0,320,result.height) )
endIf
return result
method row->Int32
return (level_number % 100)
endClass
class Graphics [singleton]
PROPERTIES
tiles = Bitmap[]
facings = Bitmap[][]
first_actor : Int32
METHODS
method init
tiles.add( load_with_black_as_transparent("../LevelEditor/background0001-1535.bmp").split(32,64) )
first_actor = tiles.count
tiles.add( load_with_black_as_transparent("../LevelEditor/objects2048-2303.bmp").split(32,32) )
local right = Bitmap[]
local left = Bitmap[]
local up = Bitmap[]
local down = Bitmap[]
facings.[ add(up), add(left), add(down), add(right) ]
forEach (tile in tiles from first_actor)
right.add( tile )
up.add( tile.cloned.[rotate_90(&ccw)] )
down.add( tile.cloned.[flip(&h), rotate_90(&ccw)] )
left.add( tile.cloned.[flip(&h)] )
endForEach
# Loads binary data - but tile color table is incomplete so using the pre-rendered images above instead.
#tiles.add( forEach in TileData )
#save_tileset
method color_16_to_32( c:Int32 )->Color
return Color( color_5_to_8(c), color_5_to_8(c:>>:5), color_5_to_8(c:>>:10) )
method color_5_to_8( c:Int32 )->Int32
c &= 0x1F
return ((c / Real64(0x1F)) * 255)->Int32
method get( tile_type:Int32 )->Bitmap
if (tile_type < first_actor) return tiles[ tile_type ]
if (TileData.flags[tile_type] & (TileData.FG_IS_2X2|TileData.FG_NO_ROTATE)) return tiles[ tile_type ]
return facings[Random.int32(4)][ tile_type-first_actor ]
method load_with_black_as_transparent( filename:String )->Bitmap
local bmp = Bitmap( File(filename) )
forEach (pixel at index in bmp.pixels)
if (pixel.argb == 0xff000000)
bmp.pixels[ index ] = Color(0)
endIf
endForEach
return bmp
method save_tileset
local w = 32
local h = TileData.count / 32
local bitmap = Bitmap( w*8, h*8, 0 )
local reader = tiles.reader
forEach (j in 0..<h)
forEach (i in 0..<w)
reader.read.blit( bitmap, i*8, j*8, BitmapBlitFn.ALPHA )
endForEach
endForEach
println "Saving Tileset.png"
bitmap.save_as_png( "Tileset.png" )
endClass
class TileData [singleton]
DEFINITIONS
COLOR_MASK = 7
BG_CAN_WALK_OVER = 8
BG_CAN_SHOOT_OVER = 16
BG_CAN_ATTACK = 32
FG_IS_BULLET = 16
FG_IS_2X2 = 32
FG_NO_ROTATE = 64
FG_NO_SHOVE = 128
PROPERTIES
bytes = Byte[]
tile_index = 0
reader : BitReader
palettes = Color[][]
flags = Byte[][
#0=Grey, 1=Red, 2=Blue, 3=Green, 4=Purple, 5=Yellow, 6=Brown/Orange, 7=Fuscia
#+8=can walk over
#+16=can shoot over
#+32=attackable
#1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
0, 0, 0, 4, 2, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 1- 20
0, 3, 3, 3, 3, 3,34,34,34,34,34,34,34,34,34,34,34,34,34,34, # 21- 40
34,34,34,34,34,34,34,34,34,34, 1, 1, 1, 1, 2, 2, 2, 2, 6, 6, # 41- 60
6, 6, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, # 61- 80
6, 6, 6, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 81-100
0, 0, 0, 0, 0,38,38,38,38, 2,36,36,36,36,36,36,36,36,36,36, #101-120
36,36,39, 6, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 4, 4, 4, 4, 5, #121-140
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, #141-160
2, 2, 2, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #161-180
0, 0, 0, 6, 4, 1, 5, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, #181-200
4, 4, 4, 4, 6, 6, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, #201-220
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, #221-240
3, 3, 3, 3, 3, 3, 0,16, 0, 6, 6, 3, 3, 3, 3, 0,37,37,37,37, #241-260
37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37, #261-280
37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37, #281-300
37,37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #301-320
0, 0,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, #321-340
18,18, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #341-360
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, #361-380
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, #381-400
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6, #401-420
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 5, 5, 5, 5, #421-440
5, 5, 5, 6,18,18,18,18,18,18,18,18,18,18,18,18, 0, 0, 0,18, #441-460 water
18,18,18,22,22,22,22,22,22,22,22,22,22,22,22,22,22, 7, 4, 4, #461-480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32,32,32,32,32, #1461
32,32,32,32,32,32,32,32,32,33,33,33,33,35,35,35,35,35,35,35, #1481
35,35,35,35,35,35,35,35,35,35,35,29,37,37,37,37,37,37,37,37, #1501
37,37,37,37,37,37,37,37,37,37,37,37,16,25,25,25,29,30,32,32, #1521
32,32,32,32,32,32, 4, 4, 4, 4,53,53,53,53,53,53,53,53,53,53, #1541
53,53,53,53,53,53,53,53, 0, 0, 0,30,29, 2, 2, 2, 2, 2, 2, 2, #1561
2, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, #1581
6, 6, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 0, #1601
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #1621
0, 0,32,32,32,32,32,32,32,32,32,30, 6, 6, 6, 6, 6, 6, 6, 6, #1641
6, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, #1661
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, #1681
2, 2, 2, 0, 2, 2, 2, 2, 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, #1701
6, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, #1721
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 3, 3, 3, 0, #1741
0, 3, 3, 3, 0,32,32,32,32,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #1761
0,32,32, 0, 0,32,32, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, #1781
2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, #1801
1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, #1821
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,33, 1,34, 2,33,33, #1841
1, 1,34,34, 2, 2,33,33, 1, 1,34,34, 2, 2, 6, 0, 0, 0, 0,24, #1861
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #1881
1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #1901
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #1921
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #1941
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #1961
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #1981
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #2001
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, #2021
0, 0,25, 0, 0, 5, 1, 0, #2041-2047
#0=Grey, 1=Red, 2=Blue, 3=Green, 4=Purple, 5=Yellow, 6=Brown/Orange, 7=Fuscia
# + any combination of:
#16 = is bullet
#32 = 2x2 monster
#64 = no rotate when facing N/S
#128 = can't be thrown (probably stationary)
4, 4, 2, 2, 5, 5, 1, 1, 2, 2, 3, 3, 3, 3,64, 2, 2, 6, 6,64, #2048 +0
0,197,5, 0, 0, 0, 0, 0, 0, 1, 0, 6, 6, 4, 0, 4, 0, 5, 5, 5, #2068 +20
5,195,195,0,0,65,65, 6, 6,70,70,67, 0, 0,35,35,35,35,35,35, #2088 +40
0, 0, 0, 0, 2, 2, 5, 5, 6, 6, 0, 0,38,38,38,38,38,38,38,38, #2108 +60
6, 6,16,16,16,16,16,16, 3, 3, 0, 0,165,165,165,165,2,2,1,1, #2128 +80
4, 0, 0, 0, 2, 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, #2148 +100
166,0, 0, 0, 0, 0,70,70,70,70,64,64,65,65,66,66,35,35,35,35, #2168 +120
35,35, 0, 0, 6, 6, 6, 6,66,66,70,70, 6, 6,16,16, 6, 6,16,16, #2188 +140
0, 0,16,16,16,16,16,16,16,16,16,16, 6, 6,38,38,38,38,38,38, #2208 +160
38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,37,37, #2228 +180
37,37,37,37,37,37, 3, 3, 5, 5,33,33,33,33,33,33,33,33, 1, 1, #2248 +200
34,34,34,34,34,34,34,34, 5, 5, 4, 4, 0, 0, 5, 5, 5, 5, 0, 0, #2268 +220
3, 3, 1, 1, 4, 4,16,16,34,34,34,34,19,19, 0, 0,64,64,65,65, #2288 +240
3, 3, 5, 5, 0, 0, 0, 6, 6,21,21,38,38,38,38,38,38,38,38, 3, #2308 +260
3, 7, 7, 5, 6, 6, 6,37,37,37,37,37,37,37,37,163,163,163,163, 6, #2328 +280
6, 6, 6,35,35,35,35, 0, 0, 0, 0, 1, 1, 1,32, 0, 0, 0, 0, 0, #2348 +300
0, 0,32,32,32,32,38, 0, 0, 0, 0, 0, 0, 0,16, 0, 1, 0, 2, 0, #2368 +320
3, 0,35, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0,70, 0, 0, 0, 0, 0, #2388 +340
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #2408 +360
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #2428 +380
0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 2, 0, 5, 0, 1, 0, 0, 0, 0, 0, #2448 +400
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #2468 +420
0, 0, 0, 0, 0, 0, 0, 0 #2488 +440
]
METHODS
method init
palettes.clear
add_palette( 0x0000, 0x2108, 0x4210, 0x7fff ) # Palette 0 (Grey)
add_palette( 0x0000, 0x000A, 0x001f, 0x7fff ) # Palette 1 (Red)
add_palette( 0x0000, 0x5000, 0x7e00, 0x7fff ) # Palette 2 (Blue)
add_palette( 0x0000, 0x0140, 0x03e0, 0x7fff ) # Palette 3 (Green)
add_palette( 0x0000, 0x4008, 0x5192, 0x7fff ) # Palette 4 (Purple)
add_palette( 0x0000, 0x01cd, 0x03fe, 0x7fff ) # Palette 5 (Yellow)
add_palette( 0x0000, 0x00d1, 0x09ff, 0x7fff ) # Palette 6 (Brown)
add_palette( 0x0000, 0x4412, 0x799c, 0x7fff ) # Palette 7 (Fuscia)
bytes.clear
bytes.add( File.load_as_bytes("../../Data/Tiles/bgTiles1-256.bin") )
bytes.add( File.load_as_bytes("../../Data/Tiles/bgTiles257-512.bin") )
bytes.add( File.load_as_bytes("../../Data/Tiles/bgTiles513-768.bin") )
bytes.add( File.load_as_bytes("../../Data/Tiles/bgTiles769-979.bin") )
loop (688) bytes.add( 0 ) # pad to 1023
loop (16) bytes.add( 0 ) # 1024
bytes.add( File.load_as_bytes("../../Data/Tiles/bgTiles1024-1279.bin") ) # actual fg tile indices are +1 on all these
bytes.add( File.load_as_bytes("../../Data/Tiles/bgTiles1280-1535.bin") )
bytes.add( File.load_as_bytes("../../Data/Tiles/bgTiles1536-1791.bin") )
bytes.add( File.load_as_bytes("../../Data/Tiles/bgTiles1792-2047.bin") )
loop (16) bytes.add( 0 ) # 1024
bytes.add( File.load_as_bytes("../../Data/Tiles/fgTiles2048-2302.bin") )
bytes.add( File.load_as_bytes("../../Data/Tiles/fgTiles2304-2559.bin") )
loop (32*16) bytes.add( 0 ) # pad to 2496 tiles
reset
method reset
reader = BitReader( bytes )
tile_index = 0
method add_palette( c0:Int32, c1:Int32, c2:Int32, c3:Int32 )
local palette = Color[]
palette.add( Graphics.color_16_to_32(c0) )
palette.add( Graphics.color_16_to_32(c1) )
palette.add( Graphics.color_16_to_32(c2) )
palette.add( Graphics.color_16_to_32(c3) )
palettes.add( palette )
method count->Int32
return flags.count
method has_another->Logical
return tile_index < flags.count
method read->Bitmap
local bits = Int32[]
local bitmap = Bitmap( 8, 8, Color[](64) )
local palette = palettes[ flags[tile_index] & COLOR_MASK ]
loop 8
bits.clear
loop (8) bits.add( reader.read(1) )
forEach (v in bits)
v = (reader.read(1):<<:1) | v
bitmap.pixels.add( palette[v] )
endForEach
endLoop
++tile_index
return bitmap
endClass