Module: Converter

Defined in:
scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/01500 Converter.rb

Overview

Module that helps to convert stuff

Constant Summary collapse

Autotiles =

The autotile builder data

[
  [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
    [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12] ],
  [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
    [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12] ],
  [ [25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
    [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
  [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
    [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46] ],
  [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
    [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
  [ [37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
    [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8] ]
]
SRC =

The source rect (to draw autotiles)

Rect.new(0, 0, 16, 16)

Class Method Summary collapse

Class Method Details

.convert_autotile(filename)

Convert an autotile file to a specific autotile file

Examples:

Converter.convert_autotile(“Graphics/autotiles/eauca.png”)

Parameters:



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/01500 Converter.rb', line 46

def convert_autotile(filename)
  autotiles = [Image.new(filename)]
  bmp_arr = Array.new(48) { |i| generate_autotile_bmp(i + 48, autotiles) }
  bmp = Image.new(48 * 32, bmp_arr.first.height)
  bmp_arr.each_with_index do |sub_bmp, i|
    bmp.blt(32 * i, 0, sub_bmp, sub_bmp.rect)
  end
  bmp.to_png_file(new_filename = filename.gsub('.png', '_._tiled.png'))
  bmp.dispose
  bmp_arr.each(&:dispose)
  autotiles.first.dispose
  log_info("#{filename} converted to #{new_filename}!")
end

.convert_tileset(filename, max_size = 4096, min_size = 1024)

Convert a tileset to a PSDK readable PSDK tileset (if required)

Examples:

Converter.convert_tileset(“Graphics/tilesets/tileset.png”)

Parameters:

  • filename (String)
  • max_size (Integer) (defaults to: 4096)

    Maximum Size of the texture in the Graphic Card

  • min_size (Integer) (defaults to: 1024)

    Minimum Size of the texture for weak Graphic Card



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/01500 Converter.rb', line 10

def convert_tileset(filename, max_size = 4096, min_size = 1024)
  return unless File.exist?(filename.downcase)

  img = Image.new(filename.downcase)
  new_filename = filename.downcase.gsub('.png', '_._ingame.png')

  if img.height > (min_size / 256 * min_size)
    log_error("#{filename} is too big for weak Graphic Card !")
    min_size = max_size
  end

  if img.height > (max_size / 256 * max_size)
    log_error("#{filename} is too big for most Graphic Card !")
    return
  end
  nb_col = (img.height / min_size.to_f).ceil
  # return img.dispose if nb_col == 1 # Removed to get better loading.
  if nb_col > 32
    log_error("#{filename} cannot be converted to #{new_filename}, there's too much tiles.")
    return
  end
  new_image = Image.new(256 * nb_col, min_size)
  nb_col.times do |i|
    height = min_size
    height = img.height - (i * min_size) if (i * min_size + height) > img.height
    new_image.blt(256 * i, 0, img, Rect.new(0, i * min_size, 256, height))
  end
  new_image.to_png_file(new_filename)
  log_info("#{filename} converted to #{new_filename}!")
  img.dispose
  new_image.dispose
end

.generate_autotile_bmp(id, autotiles) ⇒ Texture

Generate one tile of an autotile

Parameters:

  • id (Integer)

    id of the tile

  • autotiles (Array<Texture>)

    autotiles bitmaps

Returns:

  • (Texture)

    the calculated bitmap



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/01500 Converter.rb', line 81

def generate_autotile_bmp(id, autotiles)
  autotile = autotiles[id / 48 - 1]
  return Image.new(32, 32) if !autotile or autotile.width < 96

  src = SRC
  id %= 48
  tiles = Autotiles[id >> 3][id & 7]
  frames = autotile.width / 96
  bmp = Image.new(32, frames * 32)
  frames.times do |x|
    anim = x * 96
    4.times do |i|
      tile_position = tiles[i] - 1
      src.set(tile_position % 6 * 16 + anim, tile_position / 6 * 16, 16, 16)
      bmp.blt(i % 2 * 16, i / 2 * 16 + x * 32, autotile, src)
    end
  end
  return bmp
end