gbtiles 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +19 -0
  3. data/README.md +48 -0
  4. data/bin/gbm +27 -0
  5. data/bin/gbr +27 -0
  6. data/lib/gbtiles/data_type.rb +73 -0
  7. data/lib/gbtiles/gbm/cli/convert.rb +56 -0
  8. data/lib/gbtiles/gbm/export/asm/asm.h.erb +19 -0
  9. data/lib/gbtiles/gbm/export/asm/asm.rb +52 -0
  10. data/lib/gbtiles/gbm/export/asm/asm.s.erb +30 -0
  11. data/lib/gbtiles/gbm/import/gbm_file.rb +82 -0
  12. data/lib/gbtiles/gbm/map/map_set.rb +55 -0
  13. data/lib/gbtiles/gbm/map/object.rb +21 -0
  14. data/lib/gbtiles/gbm/map/object_type.rb +14 -0
  15. data/lib/gbtiles/gbm/map/objects/map.rb +49 -0
  16. data/lib/gbtiles/gbm/map/objects/map_export_settings.rb +77 -0
  17. data/lib/gbtiles/gbm/map/objects/map_settings.rb +73 -0
  18. data/lib/gbtiles/gbm/map/objects/map_tile_data.rb +40 -0
  19. data/lib/gbtiles/gbm/map/objects/map_tile_data_record.rb +40 -0
  20. data/lib/gbtiles/gbm/map/objects/producer.rb +33 -0
  21. data/lib/gbtiles/gbm/map/objects/unknown.rb +14 -0
  22. data/lib/gbtiles/gbr/cli/convert.rb +58 -0
  23. data/lib/gbtiles/gbr/export/asm/asm.h.erb +15 -0
  24. data/lib/gbtiles/gbr/export/asm/asm.rb +52 -0
  25. data/lib/gbtiles/gbr/export/asm/asm.s.erb +17 -0
  26. data/lib/gbtiles/gbr/import/gbr_file.rb +70 -0
  27. data/lib/gbtiles/gbr/tile_set/color_set.rb +12 -0
  28. data/lib/gbtiles/gbr/tile_set/export_type.rb +13 -0
  29. data/lib/gbtiles/gbr/tile_set/object.rb +18 -0
  30. data/lib/gbtiles/gbr/tile_set/object_type.rb +16 -0
  31. data/lib/gbtiles/gbr/tile_set/objects/palettes.rb +41 -0
  32. data/lib/gbtiles/gbr/tile_set/objects/producer.rb +33 -0
  33. data/lib/gbtiles/gbr/tile_set/objects/tile_data.rb +82 -0
  34. data/lib/gbtiles/gbr/tile_set/objects/tile_export.rb +105 -0
  35. data/lib/gbtiles/gbr/tile_set/objects/tile_import.rb +57 -0
  36. data/lib/gbtiles/gbr/tile_set/objects/tile_pal.rb +41 -0
  37. data/lib/gbtiles/gbr/tile_set/objects/tile_settings.rb +65 -0
  38. data/lib/gbtiles/gbr/tile_set/objects/unknown.rb +14 -0
  39. data/lib/gbtiles/gbr/tile_set/sgb_palettes.rb +13 -0
  40. data/lib/gbtiles/gbr/tile_set/split_order.rb +13 -0
  41. data/lib/gbtiles/gbr/tile_set/tile_set.rb +57 -0
  42. data/lib/gbtiles/helpers/fixnum.rb +6 -0
  43. data/lib/gbtiles/version.rb +3 -0
  44. metadata +104 -0
@@ -0,0 +1,55 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ class MapSet
5
+
6
+ attr_accessor :objects
7
+ @objects
8
+
9
+ def initialize
10
+ @objects = []
11
+ end
12
+
13
+ def maps master_id = nil
14
+ @objects.select{ |a|
15
+ a.is_a? GBTiles::GBM::Map::Objects::Map
16
+ }.select{ |a|
17
+ master_id.nil? || a.object_id = master_id
18
+ }
19
+ end
20
+
21
+ def map_export_settings master_id = nil
22
+ @objects.select{ |a|
23
+ a.is_a? GBTiles::GBM::Map::Objects::MapExportSettings
24
+ }.select{ |a|
25
+ master_id.nil? || a.object_id = master_id
26
+ }
27
+ end
28
+
29
+ def map_settings master_id = nil
30
+ @objects.select{ |a|
31
+ a.is_a? GBTiles::GBM::Map::Objects::MapSettings
32
+ }.select{ |a|
33
+ master_id.nil? || a.object_id = master_id
34
+ }
35
+ end
36
+
37
+ def map_tile_data master_id = nil
38
+ @objects.select{ |a|
39
+ a.is_a? GBTiles::GBM::Map::Objects::MapTileData
40
+ }.select{ |a|
41
+ master_id.nil? || a.object_id = master_id
42
+ }
43
+ end
44
+
45
+ def producers master_id = nil
46
+ @objects.select{ |a|
47
+ a.is_a? GBTiles::GBM::Map::Objects::Producer
48
+ }.select{ |a|
49
+ master_id.nil? || a.object_id = master_id
50
+ }
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ class Object
5
+
6
+ attr_accessor :object_type
7
+ @object_type
8
+
9
+ attr_accessor :object_id
10
+ @object_id
11
+
12
+ attr_accessor :master_id
13
+ @master_id
14
+
15
+ def initialize object_type
16
+ @object_type = object_type
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ module ObjectType
5
+ PRODUCER = 0x01
6
+ MAP = 0x02
7
+ MAP_TILE_DATA = 0x03
8
+ MAP_SETTINGS = 0x07
9
+ MAP_EXPORT_SETTINGS = 0x09
10
+ DELETED = 0xFF
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ module Objects
5
+ class Map < GBTiles::GBM::Map::Object
6
+
7
+ attr_accessor :name
8
+ @name
9
+
10
+ attr_accessor :width
11
+ @width
12
+
13
+ attr_accessor :height
14
+ @height
15
+
16
+ attr_accessor :prop_count
17
+ @prop_count
18
+
19
+ attr_accessor :tile_file
20
+ @tile_file
21
+
22
+ attr_accessor :tile_count
23
+ @tile_count
24
+
25
+ attr_accessor :prop_color_count
26
+ @prop_color_count
27
+
28
+ def initialize
29
+ super GBTiles::GBM::Map::ObjectType::MAP
30
+ end
31
+
32
+ def self.initFromBitString src
33
+ object = GBTiles::GBM::Map::Objects::Map.new
34
+
35
+ object.name = GBTiles::DataType.string!(src, 128)
36
+ object.width = GBTiles::DataType.long!(src)
37
+ object.height = GBTiles::DataType.long!(src)
38
+ object.prop_count = GBTiles::DataType.long!(src)
39
+ object.tile_file = GBTiles::DataType.string!(src, 256)
40
+ object.tile_count = GBTiles::DataType.long!(src)
41
+ object.prop_color_count = GBTiles::DataType.long!(src)
42
+
43
+ object
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,77 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ module Objects
5
+ class MapExportSettings < GBTiles::GBM::Map::Object
6
+
7
+ attr_accessor :file_name
8
+ @file_name
9
+
10
+ attr_accessor :file_type
11
+ @file_type
12
+
13
+ attr_accessor :section_name
14
+ @section_name
15
+
16
+ attr_accessor :label_name
17
+ @label_name
18
+
19
+ attr_accessor :bank
20
+ @bank
21
+
22
+ attr_accessor :plane_count
23
+ @plane_count
24
+
25
+ attr_accessor :plane_order
26
+ @plane_order
27
+
28
+ attr_accessor :map_layout
29
+ @map_layout
30
+
31
+ attr_accessor :split
32
+ @split
33
+
34
+ attr_accessor :split_size
35
+ @split_size
36
+
37
+ attr_accessor :split_bank
38
+ @split_bank
39
+
40
+ attr_accessor :sel_tab
41
+ @sel_tab
42
+
43
+ attr_accessor :prop_count
44
+ @prop_count
45
+
46
+ attr_accessor :tile_offset
47
+ @tile_offset
48
+
49
+ def initialize
50
+ super GBTiles::GBM::Map::ObjectType::MAP_EXPORT_SETTINGS
51
+ end
52
+
53
+ def self.initFromBitString src
54
+ object = GBTiles::GBM::Map::Objects::MapExportSettings.new
55
+
56
+ object.file_name = GBTiles::DataType.string!(src, 255)
57
+ object.file_type = GBTiles::DataType.byte!(src)
58
+ object.section_name = GBTiles::DataType.string!(src, 40)
59
+ object.label_name = GBTiles::DataType.string!(src, 40)
60
+ object.bank = GBTiles::DataType.byte!(src)
61
+ object.plane_count = GBTiles::DataType.word!(src)
62
+ object.plane_order = GBTiles::DataType.word!(src)
63
+ object.map_layout = GBTiles::DataType.word!(src)
64
+ object.split = GBTiles::DataType.boolean!(src)
65
+ object.split_size = GBTiles::DataType.long!(src)
66
+ object.split_bank = GBTiles::DataType.boolean!(src)
67
+ object.sel_tab = GBTiles::DataType.byte!(src)
68
+ object.prop_count = GBTiles::DataType.word!(src)
69
+ object.tile_offset = GBTiles::DataType.word!(src)
70
+
71
+ object
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,73 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ module Objects
5
+ class MapSettings < GBTiles::GBM::Map::Object
6
+
7
+ attr_accessor :form_width
8
+ @form_width
9
+
10
+ attr_accessor :form_height
11
+ @form_height
12
+
13
+ attr_accessor :form_maximized
14
+ @form_maximized
15
+
16
+ attr_accessor :info_panel
17
+ @info_panel
18
+
19
+ attr_accessor :grid
20
+ @grid
21
+
22
+ attr_accessor :double_markers
23
+ @double_markers
24
+
25
+ attr_accessor :prop_colors
26
+ @prop_colors
27
+
28
+ attr_accessor :zoom
29
+ @zoom
30
+
31
+ attr_accessor :color_set
32
+ @color_set
33
+
34
+ attr_accessor :bookmarks
35
+ @bookmarks
36
+
37
+ attr_accessor :block_fill_pattern
38
+ @block_fill_pattern
39
+
40
+ attr_accessor :block_fill_width
41
+ @block_fill_width
42
+
43
+ attr_accessor :block_fill_height
44
+ @block_fill_height
45
+
46
+ def initialize
47
+ super GBTiles::GBM::Map::ObjectType::MAP_SETTINGS
48
+ end
49
+
50
+ def self.initFromBitString src
51
+ object = GBTiles::GBM::Map::Objects::MapSettings.new
52
+
53
+ object.form_width = GBTiles::DataType.long!(src)
54
+ object.form_height = GBTiles::DataType.long!(src)
55
+ object.form_maximized = GBTiles::DataType.boolean!(src)
56
+ object.info_panel = GBTiles::DataType.boolean!(src)
57
+ object.grid = GBTiles::DataType.boolean!(src)
58
+ object.double_markers = GBTiles::DataType.boolean!(src)
59
+ object.prop_colors = GBTiles::DataType.boolean!(src)
60
+ object.zoom = GBTiles::DataType.word!(src)
61
+ object.color_set = GBTiles::DataType.word!(src)
62
+ object.bookmarks = src.slice!(3)
63
+ object.block_fill_pattern = GBTiles::DataType.long!(src)
64
+ object.block_fill_width = GBTiles::DataType.long!(src)
65
+ object.block_fill_height = GBTiles::DataType.long!(src)
66
+
67
+ object
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,40 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ module Objects
5
+ class MapTileData < GBTiles::GBM::Map::Object
6
+
7
+ attr_accessor :records
8
+ @records
9
+
10
+ def initialize
11
+ super GBTiles::GBM::Map::ObjectType::MAP_TILE_DATA
12
+
13
+ @records = []
14
+ end
15
+
16
+ def self.initFromBitString src
17
+ object = GBTiles::GBM::Map::Objects::MapTileData.new
18
+
19
+ while !src.empty?
20
+ # Get the record
21
+ number = src.slice!(0..2) # Get 24-bits (3 bytes)
22
+ number = 0.chr + number # Convert from 24-bit to 32-bit
23
+ number = number.unpack("N").first # Unpack integer
24
+
25
+ object.records.push(
26
+ GBTiles::GBM::Map::Objects::MapTileDataRecord.initFromBitString(number)
27
+ )
28
+ end
29
+
30
+ object
31
+ end
32
+
33
+ def row width, row
34
+ @records[(width * (row - 1))..((width * row) - 1)]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ module Objects
5
+ class MapTileDataRecord
6
+
7
+ attr_accessor :tile_number
8
+ @tile_number
9
+
10
+ attr_accessor :gbc_palette
11
+ @gbc_palette
12
+
13
+ attr_accessor :sgb_palette
14
+ @sgb_palette
15
+
16
+ attr_accessor :flipped_horizontally
17
+ @flipped_horizontally
18
+
19
+ attr_accessor :flipped_vertically
20
+ @flipped_vertically
21
+
22
+ def initialize
23
+ end
24
+
25
+ def self.initFromBitString number
26
+ record = GBTiles::GBM::Map::Objects::MapTileDataRecord.new
27
+
28
+ record.tile_number = number.bits(0..9)
29
+ record.gbc_palette = number.bits(10..14)
30
+ record.sgb_palette = number.bits(16..18)
31
+ record.flipped_horizontally = number.bits(22..22)
32
+ record.flipped_vertically = number.bits(23..23)
33
+
34
+ record
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ module Objects
5
+ class Producer < GBTiles::GBM::Map::Object
6
+
7
+ attr_accessor :name
8
+ @name
9
+
10
+ attr_accessor :version
11
+ @version
12
+
13
+ attr_accessor :info
14
+ @info
15
+
16
+ def initialize
17
+ super GBTiles::GBM::Map::ObjectType::PRODUCER
18
+ end
19
+
20
+ def self.initFromBitString(src)
21
+ object = GBTiles::GBM::Map::Objects::Producer.new
22
+
23
+ object.name = GBTiles::DataType.string!(src, 128)
24
+ object.version = GBTiles::DataType.string!(src, 10)
25
+ object.info = GBTiles::DataType.string!(src, 128)
26
+
27
+ object
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ module GBTiles
2
+ module GBM
3
+ module Map
4
+ module Objects
5
+ class Unknown < GBTiles::GBM::Map::Object
6
+
7
+ attr_accessor :object_data
8
+ @object_data
9
+
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,58 @@
1
+ require "gbtiles/data_type"
2
+
3
+ require "gbtiles/gbr/tile_set/tile_set"
4
+ require "gbtiles/gbr/tile_set/object"
5
+ require "gbtiles/gbr/tile_set/object_type"
6
+ require "gbtiles/gbr/tile_set/split_order"
7
+ require "gbtiles/gbr/tile_set/color_set"
8
+
9
+ require "gbtiles/gbr/tile_set/objects/palettes"
10
+ require "gbtiles/gbr/tile_set/objects/producer"
11
+ require "gbtiles/gbr/tile_set/objects/tile_data"
12
+ require "gbtiles/gbr/tile_set/objects/tile_export"
13
+ require "gbtiles/gbr/tile_set/objects/tile_import"
14
+ require "gbtiles/gbr/tile_set/objects/tile_pal"
15
+ require "gbtiles/gbr/tile_set/objects/tile_settings"
16
+ require "gbtiles/gbr/tile_set/objects/unknown"
17
+
18
+ require "gbtiles/gbr/import/gbr_file"
19
+
20
+ require "gbtiles/gbr/export/asm/asm"
21
+
22
+ desc "Convert a file from GBR format"
23
+ arg_name "input"
24
+ command :convert do |c|
25
+
26
+ c.desc "Output filename (*.s)"
27
+ c.flag :output
28
+
29
+ c.action do |global_options,options,args|
30
+ # Prepare input file
31
+ if !args[0].nil? then
32
+ # Use file
33
+ input_file = File.open(args[0], "rb")
34
+ else
35
+ # Use STDIN
36
+ input_file = $stdin
37
+ end
38
+
39
+ # Prepare output file
40
+ if !options[:output].nil? then
41
+ # Use file
42
+ output_file = File.open(options[:output], "w")
43
+ else
44
+ # Use STDOUT
45
+ output_file = $stdout
46
+ end
47
+
48
+ # Do import
49
+ import = GBTiles::GBR::Import::GBRFile.open(input_file)
50
+ input_file.close
51
+
52
+ # Do export
53
+ export = GBTiles::GBR::Export::ASM::ASM.new
54
+ export.tile_set = import.tile_set
55
+ export.write(output_file)
56
+ output_file.close
57
+ end
58
+ end