Class: TextConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/gen3_pokeedit/TextConverter.rb

Class Method Summary collapse

Class Method Details

.convert_text_to_ascii(text, options = {gen: 3}) ⇒ Object



55
56
57
58
59
# File 'lib/gen3_pokeedit/TextConverter.rb', line 55

def self.convert_text_to_ascii(text, options = {gen: 3})
  finished_text = ""
  text.each_char { |char| finished_text += translate_char(char, options) }
  finished_text
end

.convert_text_to_game(text, options = {gen: 3}) ⇒ Object



61
62
63
64
65
# File 'lib/gen3_pokeedit/TextConverter.rb', line 61

def self.convert_text_to_game(text, options = {gen: 3})
  finished_text = ""
  text.each_char { |char| finished_text += translate_ascii_char(char, options) }
  finished_text
end

.translate_ascii_char(char, options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/gen3_pokeedit/TextConverter.rb', line 44

def self.translate_ascii_char(char, options)
  case options[:gen]
  when 1
    translate_gen1_to_ascii_char(char)
  when 2
    translate_gen1_to_ascii_char(char)
  when 3
    translate_gen3_to_ascii_char(char)
  end
end

.translate_char(char, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/gen3_pokeedit/TextConverter.rb', line 19

def self.translate_char(char, options)
  case options[:gen]
  when 1
    translate_gen1_char(char)
  when 2
    translate_gen1_char(char)
  when 3
    translate_gen3_char(char)
  end
end

.translate_gen1_char(char) ⇒ Object



3
4
5
# File 'lib/gen3_pokeedit/TextConverter.rb', line 3

def self.translate_gen1_char(char)
  
end

.translate_gen1_to_ascii_char(char) ⇒ Object



30
31
32
# File 'lib/gen3_pokeedit/TextConverter.rb', line 30

def self.translate_gen1_to_ascii_char(char)

end

.translate_gen3_char(char) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gen3_pokeedit/TextConverter.rb', line 7

def self.translate_gen3_char(char)
  if char[0].ord >= 0xBB && char[0].ord <= 0xD4
    return ((char[0].ord - 0xBB) + 65).chr
  end
  
  if char[0].ord >= 0xD5 && char[0].ord <= 0xEE
    return ((char[0].ord - 0xD5) + 97).chr
  end
  
  
end

.translate_gen3_to_ascii_char(char) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/gen3_pokeedit/TextConverter.rb', line 34

def self.translate_gen3_to_ascii_char(char)
  if char[0].ord >= 65 && char[0].ord <= 89
    return ((char[0].ord - 65) + 0xBB).chr
  end
  
  if char[0].ord >= 0xD5 && char[0].ord <= 0xEE
    return ((char[0].ord - 0xD5) + 97).chr
  end
end