rvpacker-txt 1.2.1 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 366c510ab91e885534a8dd5d3c7421b3b6c68f03beaad2bcc7e5e160ba05bbf8
4
- data.tar.gz: 6d93ab447d98bd285d738b0e5183ffadd8c59bb0e078a8b2a42db8fc3c463153
3
+ metadata.gz: be60b9ca7d30b5ba65f22b5c71b2051cddc357d0793e5040bddddb4b940f7aec
4
+ data.tar.gz: a62fc90e814c94a9eeb0d56299c6a9211311263589d6d55b0ef5367a74a281ae
5
5
  SHA512:
6
- metadata.gz: ba4567fab07d8d079b9a5b60663c9a45ed006edba0006c48dfebf7d4bef70ad5fa5f338f7bd6ed8211530c8f69861c309d14d8f07a59b747e65d21d5227b2f12
7
- data.tar.gz: cb0d9fe0cab421d58c0d6d867b6602974d5b94191b0fa421171ccf0d87ea5a93ef821838ece9f4d6990dd50542ccd0d82d566f184c2e5b66d180f6462e3f6e0a
6
+ metadata.gz: 58e86a866916217af89835096794ecdcaef8803eadc695f24347790179e5e3fda42510d5ce968a904e6d86e84c88602cbbd7fdf7411d2294b253c2a4d225b63b
7
+ data.tar.gz: 4a6b9e66cc383defab76c9d6216afdfcc45f16de09530ebec498b2401faf4fac16dd3d1aa1843ecc6992585116f22f750f123a9df4d76dd1e1cacbede6ca2705
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rvpacker-txt.gemspec
4
- gemspec
4
+ gemspec
5
+ gem 'rubocop', group: 'development', require: false
data/Rakefile CHANGED
@@ -1,2 +1 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require 'bundler/gem_tasks'
data/bin/rvpacker-txt CHANGED
@@ -1,90 +1,88 @@
1
1
  #!/usr/bin/env ruby
2
- require 'RGSS'
2
+ require 'classes'
3
3
  require 'optparse'
4
4
 
5
5
  $logging = false
6
6
  $shuffle = 0
7
- $no = [true, true, true, true] # 0 is whether to process maps, 1 is other, 2 is system, 3 is scripts
7
+ $no = [false, false, false, false] # 0 is whether to NOT process maps, 1 is other, 2 is system, 3 is scripts
8
+ $disable_custom_parsing = false
8
9
 
9
- opts = {}
10
- OptionParser.new do |options|
11
- options.banner = "This tool allows to parse RPG Maker project to .txt files and back.\n\nUsage: rvpacker-txt COMMAND [options]\n\nCOMMANDS:\n read - Parses RPG Maker game files to .txt\n write - Writes parsed files back to their initial form\nOPTIONS:\n"
10
+ options = {}
11
+ OptionParser.new do |command|
12
+ command.banner = "This tool allows to parse RPG Maker project to .txt files and back.\n\nUsage: rvpacker-txt COMMAND [options]\n\nCOMMANDS:\n read - Parses RPG Maker game files to .txt\n write - Writes parsed files back to their initial form\nOPTIONS:\n"
12
13
 
13
- options.on('-d', '--input-dir DIRECTORY', 'Input directory of RPG Maker project.',
14
+ command.on('-d',
15
+ '--input-dir DIRECTORY',
16
+ 'Input directory of RPG Maker project.',
14
17
  'Must contain "Data" or "original" folder to read,',
15
- 'and additionally "translation" with "maps" and "other" subdirectories to write.') do |dir|
16
- opts[:input_dir] = dir
17
- end
18
+ 'and additionally "translation" with "maps" and "other" subdirectories to write.') { |dir| options[:input_dir] = dir }
18
19
 
19
- options.on('--no', "Don't process specified files.", 'Takes multiple values separated by a comma.', 'Allowed values: maps, other, system, plugins') do |files|
20
+ command.on('--no',
21
+ "Don't process specified files.",
22
+ 'Takes multiple values separated by a comma.',
23
+ 'Allowed values: maps, other, system, plugins') do |files|
20
24
  actual_files = files.split(',')
21
25
 
22
26
  actual_files.each do |file|
23
27
  case file
24
28
  when "maps"
25
- $no[0] = false
29
+ $no[0] = true
26
30
  when "other"
27
- $no[1] = false
31
+ $no[1] = true
28
32
  when "system"
29
- $no[2] = false
33
+ $no[2] = true
30
34
  when "scripts"
31
- $no[3] = false
35
+ $no[3] = true
32
36
  else
33
- nil
37
+ puts "Wrong value for no argument: #{file}.\nAllowed values: maps, other, system, plugins"
38
+ exit
34
39
  end
35
40
  end
36
41
  end
37
42
 
38
- options.on('-s', '--shuffle NUMBER', 'At value 1: Shuffles all lines in strings, at value 2: shuffles all lines and words in strings.') do |number|
39
- $shuffle = number
40
- end
43
+ command.on('-s',
44
+ '--shuffle NUMBER',
45
+ 'At value 1: Shuffles all lines in strings, at value 2: shuffles all lines and words in strings.') { |number| $shuffle = number }
41
46
 
42
- options.on('-l', '--log', 'Log information while processing.') do
43
- $logging = true
44
- end
47
+ command.on('--disable-custom-parsing',
48
+ 'Disables built-in custom parsing for some games, which may improperly parse/write some games.')
45
49
 
46
- options.on_tail('-h', '--help', 'Show help message.') do
47
- puts options
48
- exit
49
- end
50
+ command.on('-l',
51
+ '--log',
52
+ 'Log information while processing.') { $logging = true }
53
+
54
+ command.on_tail('-h',
55
+ '--help',
56
+ 'Show help message.') { puts command; exit }
50
57
  end.parse!(ARGV)
51
58
 
52
59
  if ARGV.empty?
53
- puts 'COMMAND argument is required.'
60
+ puts 'COMMAND argument is required. Use rvpacker-txt -h for help.'
54
61
  exit
55
62
  end
56
63
 
57
- opts[:action] = ARGV.shift
64
+ options[:action] = ARGV.shift
58
65
 
59
- unless %w[read write].include?(opts[:action])
66
+ unless %w[read write].include?(options[:action])
60
67
  puts 'Invalid command. Allowed commands are: read, write.'
61
68
  exit
62
69
  end
63
70
 
64
- project_types = { 'vx' => :vx, 'ace' => :ace, 'xp' => :xp }
65
-
66
- directory = opts[:input_dir]
71
+ directory = options[:input_dir]
67
72
  raise "#{directory} not found" unless File.exist?(directory)
73
+ directory = File.realpath(directory)
68
74
 
69
- original_directory = Dir.foreach(directory).find { |filename| filename.downcase == 'original' } ||
70
- Dir.foreach(directory).find { |filename| filename.downcase == 'data' }
75
+ original_directory = Dir.foreach(directory).find { |dirname| dirname.downcase == 'original' || dirname.downcase == 'data' }
71
76
  raise '"Data" or "original" directory not found within input directory.' if original_directory.nil?
72
77
 
73
- types = %w[vx ace xp]
74
-
75
- type = types.find do |type_|
76
- case type_
77
- when 'xp'
78
- break project_types[type_] if File.exist?(File.join(directory, original_directory, 'System.rxdata'))
79
- when 'vx'
80
- break project_types[type_] if File.exist?(File.join(directory, original_directory, 'System.rvdata'))
81
- when 'ace'
82
- break project_types[type_] if File.exist?(File.join(directory, original_directory, 'System.rvdata2'))
83
- else
84
- break nil
85
- end
86
- end
87
-
88
- raise 'Couldn\'t determine project engine.' if type.nil?
89
-
90
- RGSS.serialize(type, opts[:action], directory, original_directory)
78
+ engine = if File.exist?(File.join(directory, original_directory, 'System.rxdata'))
79
+ :xp
80
+ elsif File.exist?(File.join(directory, original_directory, 'System.rvdata'))
81
+ :vx
82
+ elsif File.exist?(File.join(directory, original_directory, 'System.rvdata2'))
83
+ :ace
84
+ else
85
+ raise "Couldn't determine project engine."
86
+ end
87
+
88
+ RGSS.serialize(engine, options[:action], directory, original_directory,)
data/lib/classes.rb ADDED
@@ -0,0 +1,150 @@
1
+ =begin
2
+ Copyright (c) 2013 Howard Jeng
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
5
+ software and associated documentation files (the "Software"), to deal in the Software
6
+ without restriction, including without limitation the rights to use, copy, modify, merge,
7
+ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8
+ to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or
11
+ substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
+ DEALINGS IN THE SOFTWARE.
19
+ =end
20
+
21
+ class Table
22
+ def initialize(bytes)
23
+ @dim, @x, @y, @z, items, *@data = bytes.unpack('L5 S*')
24
+
25
+ unless items == @data.length && @x * @y * @z == items
26
+ raise 'Size mismatch loading Table from data'
27
+ end
28
+ end
29
+
30
+ def _dump(*_ignored)
31
+ [@dim, @x, @y, @z, @x * @y * @z, *@data].pack('L5 S*')
32
+ end
33
+
34
+ def self._load(bytes)
35
+ Table.new(bytes)
36
+ end
37
+ end
38
+
39
+ class Color
40
+ def initialize(bytes)
41
+ @r, @g, @b, @a = *bytes.unpack('D4')
42
+ end
43
+
44
+ def _dump(*_ignored)
45
+ [@r, @g, @b, @a].pack('D4')
46
+ end
47
+
48
+ def self._load(bytes)
49
+ Color.new(bytes)
50
+ end
51
+ end
52
+
53
+ class Tone
54
+ def initialize(bytes)
55
+ @r, @g, @b, @a = *bytes.unpack('D4')
56
+ end
57
+
58
+ def _dump(*_ignored)
59
+ [@r, @g, @b, @a].pack('D4')
60
+ end
61
+
62
+ def self._load(bytes)
63
+ Tone.new(bytes)
64
+ end
65
+ end
66
+
67
+ class Rect
68
+ def initialize(bytes)
69
+ @x, @y, @width, @height = *bytes.unpack('i4')
70
+ end
71
+
72
+ def _dump(*_ignored)
73
+ [@x, @y, @width, @height].pack('i4')
74
+ end
75
+
76
+ def self._load(bytes)
77
+ Rect.new(bytes)
78
+ end
79
+ end
80
+
81
+ module RPG
82
+ end
83
+
84
+ module RGSS
85
+ # creates an empty class in a potentially nested scope
86
+ def self.process(root, name, *args)
87
+ if args.empty?
88
+ root.const_set(name, Class.new) unless root.const_defined?(name, false)
89
+ else
90
+ process(root.const_get(name), *args)
91
+ end
92
+ end
93
+
94
+ classes_nested_array = [
95
+ # RGSS data structures
96
+ %i[RPG Actor],
97
+ %i[RPG Animation],
98
+ %i[RPG Animation Frame],
99
+ %i[RPG Animation Timing],
100
+ %i[RPG Area],
101
+ %i[RPG Armor],
102
+ %i[RPG AudioFile],
103
+ %i[RPG BaseItem],
104
+ %i[RPG BaseItem Feature],
105
+ %i[RPG BGM],
106
+ %i[RPG BGS],
107
+ %i[RPG Class],
108
+ %i[RPG Class Learning],
109
+ %i[RPG CommonEvent],
110
+ %i[RPG Enemy],
111
+ %i[RPG Enemy Action],
112
+ %i[RPG Enemy DropItem],
113
+ %i[RPG EquipItem],
114
+ %i[RPG Event],
115
+ %i[RPG Event Page],
116
+ %i[RPG Event Page Condition],
117
+ %i[RPG Event Page Graphic],
118
+ %i[RPG EventCommand],
119
+ %i[RPG Item],
120
+ %i[RPG Map],
121
+ %i[RPG Map Encounter],
122
+ %i[RPG MapInfo],
123
+ %i[RPG ME],
124
+ %i[RPG MoveCommand],
125
+ %i[RPG MoveRoute],
126
+ %i[RPG SE],
127
+ %i[RPG Skill],
128
+ %i[RPG State],
129
+ %i[RPG System],
130
+ %i[RPG System Terms],
131
+ %i[RPG System TestBattler],
132
+ %i[RPG System Vehicle],
133
+ %i[RPG System Words],
134
+ %i[RPG Tileset],
135
+ %i[RPG Troop],
136
+ %i[RPG Troop Member],
137
+ %i[RPG Troop Page],
138
+ %i[RPG Troop Page Condition],
139
+ %i[RPG UsableItem],
140
+ %i[RPG UsableItem Damage],
141
+ %i[RPG UsableItem Effect],
142
+ %i[RPG Weapon]
143
+ ].freeze
144
+
145
+ classes_nested_array.each do |symbol_array|
146
+ process(Object, *symbol_array)
147
+ end
148
+ end
149
+
150
+ require 'serialize'
@@ -18,41 +18,40 @@
18
18
 
19
19
  require 'zlib'
20
20
 
21
+ # Fuck using an array with set, that's just straight dumb and not efficient
21
22
  class IndexedSet
22
23
  def initialize
23
- @set = Set.new
24
- @index = []
24
+ @hash = Hash.new
25
25
  end
26
26
 
27
27
  def add(item)
28
- return if @set.include?(item)
29
-
30
- @set.add(item)
31
- @index << item
28
+ return if @hash.include?(item)
29
+ @hash[item] = hash.size
30
+ @hash
32
31
  end
33
32
 
34
33
  def include?(item)
35
- @set.include?(item)
34
+ @hash.include?(item)
36
35
  end
37
36
 
38
37
  def each(&block)
39
- @index.each(&block)
38
+ @hash.each_key(&block)
40
39
  end
41
40
 
42
41
  def to_a
43
- @index.dup
42
+ @hash.dup
44
43
  end
45
44
 
46
45
  def join(delimiter = '')
47
- @index.join(delimiter)
46
+ @hash.keys.join(delimiter)
48
47
  end
49
48
 
50
49
  def length
51
- @index.length
50
+ @hash.size
52
51
  end
53
52
 
54
53
  def empty?
55
- @index.empty?
54
+ @hash.empty?
56
55
  end
57
56
  end
58
57
 
@@ -61,12 +60,12 @@ module RGSS
61
60
  object = Marshal.load(File.read(system_file_path, mode: 'rb'))
62
61
  game_title = object.instance_variable_get(:@game_title)
63
62
 
64
- return nil if !game_title.is_a?(String) || game_title.empty?
63
+ return nil if $disable_custom_parsing || (!game_title.is_a?(String) || game_title.empty?)
65
64
 
66
65
  game_title.downcase!
67
66
 
68
- if game_title.include?("lisa")
69
- return "lisa"
67
+ if game_title.include?('lisa')
68
+ return 'lisa'
70
69
  end
71
70
 
72
71
  nil
@@ -76,8 +75,8 @@ module RGSS
76
75
  case code
77
76
  when 401, 405
78
77
  case $game_type
79
- when "lisa"
80
- match = parameter.scan(/^\\et\[[0-9]+\]|\\nbt/)
78
+ when 'lisa'
79
+ match = parameter.scan(/^(\\et\[[0-9]+\]|\\nbt)/)
81
80
  parameter = parameter.slice((match[0].length)..) if match
82
81
  else
83
82
  nil
@@ -98,8 +97,8 @@ module RGSS
98
97
  variable = variable.gsub(/\r?\n/, '\#')
99
98
 
100
99
  case $game_type
101
- when "lisa"
102
- unless variable.split('\#').all? { |line| line.match?(/^<.*>\.?$/) || line.length.nil? }
100
+ when 'lisa'
101
+ unless variable.split('\#').all? { |line| line.match?(/^<.*>\.?$/) || line.empty? }
103
102
  return nil
104
103
  end
105
104
  else
@@ -119,7 +118,7 @@ module RGSS
119
118
 
120
119
  object_map.each do |filename, object|
121
120
  display_name = object.instance_variable_get(:@display_name)
122
- lines[1].add(display_name) unless display_name.nil? || display_name.empty?
121
+ lines[1].add(display_name) if display_name.is_a?(String) && !display_name.empty?
123
122
 
124
123
  events = object.instance_variable_get(:@events)
125
124
  next if events.nil?
@@ -174,9 +173,9 @@ module RGSS
174
173
  end
175
174
 
176
175
  File.write("#{output_path}/maps.txt", lines[0].join("\n"))
177
- File.write("#{output_path}/maps_trans.txt", "\n" * (!lines[0].empty? ? lines[0].length - 1 : 0))
176
+ File.write("#{output_path}/maps_trans.txt", "\n" * (lines[0].empty? ? 0 : lines[0].length - 1))
178
177
  File.write("#{output_path}/names.txt", lines[1].join("\n"))
179
- File.write("#{output_path}/names_trans.txt", "\n" * (!lines[1].empty? ? lines[1].length - 1 : 0))
178
+ File.write("#{output_path}/names_trans.txt", "\n" * (lines[1].empty? ? 0 : lines[1].length - 1))
180
179
  end
181
180
 
182
181
  def self.read_other(original_other_files, output_path)
@@ -256,7 +255,7 @@ module RGSS
256
255
  puts "Parsed #{filename}" if $logging
257
256
 
258
257
  File.write("#{output_path}/#{processed_filename}.txt", lines.join("\n"))
259
- File.write("#{output_path}/#{processed_filename}_trans.txt", "\n" * (!lines.empty? ? lines.length - 1 : 0))
258
+ File.write("#{output_path}/#{processed_filename}_trans.txt", "\n" * (lines.empty? ? 0 : lines.length - 1))
260
259
  end
261
260
  end
262
261
 
@@ -277,10 +276,10 @@ module RGSS
277
276
 
278
277
  [elements, skill_types, weapon_types, armor_types].each do |array|
279
278
  next if array.nil?
280
- array.each { |string| lines.add(string) unless string.is_a?(String) && string.empty? }
279
+ array.each { |string| lines.add(string) if string.is_a?(String) && !string.empty? }
281
280
  end
282
281
 
283
- lines.add(currency_unit) unless currency_unit.is_a?(String) && currency_unit.empty?
282
+ lines.add(currency_unit) if currency_unit.is_a?(String) && !currency_unit.empty?
284
283
 
285
284
  terms.instance_variables.each do |variable|
286
285
  value = terms.instance_variable_get(variable)
@@ -290,15 +289,15 @@ module RGSS
290
289
  next
291
290
  end
292
291
 
293
- value.each { |string| lines.add(string) unless string.is_a?(String) && string.empty? }
292
+ value.each { |string| lines.add(string) if string.is_a?(String) && !string.empty? }
294
293
  end
295
294
 
296
- lines.add(game_title) unless game_title.is_a?(String) && game_title.empty?
295
+ lines.add(game_title) if game_title.is_a?(String) && !game_title.empty?
297
296
 
298
297
  puts "Parsed #{filename}" if $logging
299
298
 
300
299
  File.write("#{output_path}/#{basename}.txt", lines.join("\n"), mode: 'wb')
301
- File.write("#{output_path}/#{basename}_trans.txt", "\n" * (!lines.empty? ? lines.length - 1 : 0),
300
+ File.write("#{output_path}/#{basename}_trans.txt", "\n" * (lines.empty? ? 0 : lines.length - 1),
302
301
  mode: 'wb')
303
302
  end
304
303
 
@@ -306,19 +305,17 @@ module RGSS
306
305
  array.map do |string|
307
306
  re = /\S+/
308
307
  words = string.scan(re)
309
- words.shuffle
310
-
311
- result = nil
308
+ shuffled = words.shuffle
312
309
 
313
310
  (0..(words.length)).each do |i|
314
- result = string.sub(string[i], words[i])
311
+ string.sub!(words[i], shuffled[i])
315
312
  end
316
313
 
317
- result
314
+ string
318
315
  end
319
316
  end
320
317
 
321
- def self.extract_quoted_strings(input)
318
+ def self.extract_quoted_strings(string)
322
319
  result = []
323
320
 
324
321
  skip_block = false
@@ -326,12 +323,12 @@ module RGSS
326
323
  quote_type = nil
327
324
  buffer = []
328
325
 
329
- input.each_line(chomp: true) do |line|
326
+ string.each_line(chomp: true) do |line|
330
327
  line.strip!
331
328
  next if line[0] == '#' || line.start_with?(/(Win|Lose)|_Fanfare/)
332
329
 
333
- skip_block = true if line.start_with?("=begin")
334
- skip_block = false if line.start_with?("=end")
330
+ skip_block = true if line.start_with?('=begin')
331
+ skip_block = false if line.start_with?('=end')
335
332
 
336
333
  next if skip_block
337
334
 
@@ -339,7 +336,7 @@ module RGSS
339
336
 
340
337
  line.each_char do |char|
341
338
  if char == "'" || char == '"'
342
- if !quote_type.nil? && char != quote_type
339
+ unless quote_type.nil? || char == quote_type
343
340
  buffer.push(char)
344
341
  next
345
342
  end
@@ -372,14 +369,14 @@ module RGSS
372
369
  extract_quoted_strings(code).each do |string|
373
370
  string.strip!
374
371
 
375
- next if string.empty? || string.delete('  ').empty?
372
+ next if string.empty? || string.gsub(' ', '').empty?
376
373
 
377
374
  # Maybe this mess will remove something that mustn't be removed, but it needs to be tested
378
- next if string.start_with?(/(#|!?\$|@|(\.\/)?(Graphics|Data|Audio|CG|Movies|Save)\/)/) ||
375
+ next if string.start_with?(/([#!?$@]|(\.\/)?(Graphics|Data|Audio|CG|Movies|Save)\/)/) ||
379
376
  string.match?(/^\d+$/) ||
380
377
  string.match?(/^(.)\1{2,}$/) ||
381
378
  string.match?(/^(false|true)$/) ||
382
- string.match?(/^(wb|rb)$/) ||
379
+ string.match?(/^[wr]b$/) ||
383
380
  string.match?(/^(?=.*\d)[A-Za-z0-9\-]+$/) ||
384
381
  string.match?(/^[A-Z\-()\/ +'&]*$/) ||
385
382
  string.match?(/^[a-z\-()\/ +'&]*$/) ||
@@ -388,15 +385,34 @@ module RGSS
388
385
  string.match?(/^Tile.*[A-Z]$/) ||
389
386
  string.match?(/^:?%.*[ds][:%]*?$/) ||
390
387
  string.match?(/^[a-zA-Z]+([A-Z][a-z]*)+$/) ||
388
+ string.match?(/^Cancel Action$|^Invert$|^End$|^Individual$|^Missed File$|^Bitmap$|^Audio$/) ||
391
389
  string.match?(/\.(mp3|ogg|jpg|png|ini)$/) ||
390
+ string.match?(/\/(\d.*)?$/) ||
391
+ string.match?(/FILE$/) ||
392
392
  string.match?(/#\{/) ||
393
393
  string.match?(/\\(?!#)/) ||
394
394
  string.match?(/\+?=?=/) ||
395
395
  string.match?(/[}{_<>]/) ||
396
396
  string.match?(/r[vx]data/) ||
397
- string.match?(/\/(\d.*)?$/) ||
398
- string.match?(/FILE$/) ||
399
- string.match?(/No such file or directory|level \*\*|Courier New|Comic Sans|Lucida|Verdana|Tahoma|Arial|Player start location|Common event call has exceeded|se-|Start Pos|An error has occurred|Define it first|Process Skill|Wpn Only|Don't Wait|Clear image|Can Collapse|^Cancel Action$|^Invert$|^End$|^Individual$|^Missed File$|^Bitmap$|^Audio$/)
397
+ string.match?(/No such file or directory/) ||
398
+ string.match?(/level \*\*/) ||
399
+ string.match?(/Courier New/) ||
400
+ string.match?(/Comic Sans/) ||
401
+ string.match?(/Lucida/) ||
402
+ string.match?(/Verdana/) ||
403
+ string.match?(/Tahoma/) ||
404
+ string.match?(/Arial/) ||
405
+ string.match?(/Player start location/) ||
406
+ string.match?(/Common event call has exceeded/) ||
407
+ string.match?(/se-/) ||
408
+ string.match?(/Start Pos/) ||
409
+ string.match?(/An error has occurred/) ||
410
+ string.match?(/Define it first/) ||
411
+ string.match?(/Process Skill/) ||
412
+ string.match?(/Wpn Only/) ||
413
+ string.match?(/Don't Wait/) ||
414
+ string.match?(/Clear image/) ||
415
+ string.match?(/Can Collapse/)
400
416
 
401
417
  strings.add(string)
402
418
  end
@@ -404,7 +420,7 @@ module RGSS
404
420
 
405
421
  File.write("#{output_path}/scripts_plain.txt", codes.join("\n"), mode: 'wb')
406
422
  File.write("#{output_path}/scripts.txt", strings.join("\n"), mode: 'wb')
407
- File.write("#{output_path}/scripts_trans.txt", "\n" * (!strings.empty? ? strings.length - 1 : 0), mode: 'wb')
423
+ File.write("#{output_path}/scripts_trans.txt", "\n" * (strings.empty? ? 0 : strings.length - 1), mode: 'wb')
408
424
  end
409
425
 
410
426
  def self.merge_seq(object_array)
@@ -428,7 +444,7 @@ module RGSS
428
444
  elsif i.positive? && in_sequence && !first.nil? && !number.negative?
429
445
  parameters = object_array[first].instance_variable_get(:@parameters)
430
446
  parameters[0] = string_array.join("\n")
431
- object_array[first].instance_variable_set(parameters)
447
+ object_array[first].instance_variable_set(:@parameters, parameters)
432
448
 
433
449
  start_index = first + 1
434
450
  items_to_delete = start_index + number
@@ -496,8 +512,8 @@ module RGSS
496
512
  case code
497
513
  when 401, 356, 405
498
514
  case $game_type
499
- when "lisa"
500
- match = parameter.scan(/^\\et\[[0-9]+\]/) || parameter.scan(/^\\nbt/)
515
+ when 'lisa'
516
+ match = parameter.scan(/^(\\et\[[0-9]+\]|\\nbt)/)
501
517
  lisa_start = match[0]
502
518
  parameter = parameter.slice((match[0].length)..) unless match.nil?
503
519
  else
@@ -512,7 +528,7 @@ module RGSS
512
528
  gotten = hashmap[parameter]
513
529
 
514
530
  case $game_type
515
- when "lisa"
531
+ when 'lisa'
516
532
  gotten = lisa_start + gotten unless lisa_start.nil?
517
533
  else
518
534
  nil
@@ -563,7 +579,8 @@ module RGSS
563
579
 
564
580
  object_map.each do |filename, object|
565
581
  display_name = object.instance_variable_get(:@display_name)
566
- object.instance_variable_set(:@display_name, names_translation_map[display_name]) if names_translation_map.key?(display_name)
582
+ display_name_gotten = names_translation_map[display_name]
583
+ object.instance_variable_set(:@display_name, display_name_gotten) unless display_name_gotten.nil?
567
584
 
568
585
  events = object.instance_variable_get(:@events)
569
586
  next if events.nil?
@@ -623,16 +640,14 @@ module RGSS
623
640
  object_array_map.each do |filename, object_array|
624
641
  processed_filename = File.basename(filename, '.*').downcase
625
642
 
626
- other_original_text = File.read("#{File.join(other_path, processed_filename)}.txt").split("\n").map do
627
- |line|
628
- line.gsub('\#', "\n")
629
- end
643
+ other_original_text = File.read("#{File.join(other_path, processed_filename)}.txt")
644
+ .split("\n")
645
+ .map { |line| line.gsub('\#', "\n") }
646
+ .freeze
630
647
 
631
- other_translated_text = File.read("#{File.join(other_path, processed_filename)}_trans.txt").split("\n")
632
- .map do
633
- |line|
634
- line.gsub('\#', "\n")
635
- end
648
+ other_translated_text = File.read("#{File.join(other_path, processed_filename)}_trans.txt")
649
+ .split("\n")
650
+ .map { |line| line.gsub('\#', "\n") }
636
651
 
637
652
  if $shuffle > 0
638
653
  other_translated_text.shuffle!
@@ -642,13 +657,13 @@ module RGSS
642
657
  end
643
658
  end
644
659
 
645
- other_translation_map = Hash[other_original_text.zip(other_translated_text)]
660
+ other_translation_map = Hash[other_original_text.zip(other_translated_text)].freeze
646
661
 
647
662
  if !filename.start_with?(/Common|Troops/)
648
663
  object_array.each do |object|
649
664
  next if object.nil?
650
665
 
651
- variables_symbols = %i[@name @nickname @description @note]
666
+ variables_symbols = %i[@name @nickname @description @note].freeze
652
667
 
653
668
  name = object.instance_variable_get(variables_symbols[0])
654
669
  nickname = object.instance_variable_get(variables_symbols[1])
@@ -686,7 +701,7 @@ module RGSS
686
701
  parameters[i] = translated unless translated.nil?
687
702
  end
688
703
  elsif parameter.is_a?(Array)
689
- parameter.each_with_index.map do |subparameter, j|
704
+ parameter.each_with_index do |subparameter, j|
690
705
  if subparameter.is_a?(String) && !subparameter.empty?
691
706
  translated = get_translated(code, subparameter, other_translation_map)
692
707
  parameters[i][j] = translated unless translated.nil?
@@ -711,8 +726,11 @@ module RGSS
711
726
  basename = File.basename(system_file_path)
712
727
  object = Marshal.load(File.read(system_file_path, mode: 'rb'))
713
728
 
714
- system_original_text = File.read("#{other_path}/system.txt").split("\n")
715
- system_translated_text = File.read("#{other_path}/system_trans.txt").split("\n")
729
+ system_original_text = File.read("#{other_path}/system.txt")
730
+ .split("\n")
731
+ .freeze
732
+ system_translated_text = File.read("#{other_path}/system_trans.txt")
733
+ .split("\n")
716
734
 
717
735
  if $shuffle > 0
718
736
  system_translated_text.shuffle!
@@ -722,30 +740,28 @@ module RGSS
722
740
  end
723
741
  end
724
742
 
725
- system_translation_map = Hash[system_original_text.zip(system_translated_text)]
743
+ system_translation_map = Hash[system_original_text.zip(system_translated_text)].freeze
726
744
 
727
- symbols = %i[@elements @skill_types @weapon_types @armor_types]
728
- elements = object.instance_variable_get(:@elements)
729
- skill_types = object.instance_variable_get(:@skill_types)
730
- weapon_types = object.instance_variable_get(:@weapon_types)
731
- armor_types = object.instance_variable_get(:@armor_types)
732
- currency_unit = object.instance_variable_get(:@currency_unit)
733
- terms = object.instance_variable_get(:@terms) || object.instance_variable_get(:@words)
734
- game_title = object.instance_variable_get(:@game_title)
745
+ symbols = %i[@elements @skill_types @weapon_types @armor_types @currency_unit @terms @words @game_title].freeze
735
746
 
736
- [elements, skill_types, weapon_types, armor_types].each_with_index.each do |array, i|
737
- next if array.nil?
747
+ elements = object.instance_variable_get(symbols[0])
748
+ skill_types = object.instance_variable_get(symbols[1])
749
+ weapon_types = object.instance_variable_get(symbols[2])
750
+ armor_types = object.instance_variable_get(symbols[3])
751
+ currency_unit = object.instance_variable_get(symbols[4])
752
+ terms = object.instance_variable_get(symbols[5]) || object.instance_variable_get(symbols[6])
753
+ game_title = object.instance_variable_get(symbols[7])
738
754
 
739
- array.each_with_index do |string, j|
740
- translated = system_translation_map[string]
741
- array[j] = translated unless translated.nil?
742
- end
755
+ [elements, skill_types, weapon_types, armor_types].each_with_index.each do |array, i|
756
+ next unless array.is_a?(Array)
743
757
 
758
+ array.map! { |string| system_translation_map[string] || string }
744
759
  object.instance_variable_set(symbols[i], array)
745
760
  end
746
761
 
747
- instance_variable_set(:@currency_unit, system_translation_map[currency_unit]) if !currency_unit.nil? &&
748
- system_translation_map.key?(currency_unit)
762
+ currency_unit_translated = system_translation_map[currency_unit]
763
+ object.instance_variable_set(symbols[4], currency_unit_translated) if currency_unit.is_a?(String) &&
764
+ !currency_unit_translated.nil?
749
765
 
750
766
  terms.instance_variables.each do |variable|
751
767
  value = terms.instance_variable_get(variable)
@@ -754,21 +770,18 @@ module RGSS
754
770
  translated = system_translation_map[value]
755
771
  value = translated unless translated.nil?
756
772
  elsif value.is_a?(Array)
757
- value.each_with_index do |string, i|
758
- translated = system_translation_map[string]
759
- value[i] = translated unless translated.nil?
760
- end
773
+ value.map! { |string| system_translation_map[string] || string }
761
774
  end
762
775
 
763
776
  terms.instance_variable_set(variable, value)
764
777
  end
765
778
 
766
- object.instance_variable_defined?(:@terms) ? object.instance_variable_set(:@terms, terms) : object
767
- .instance_variable_set(:@words, terms)
779
+ object.instance_variable_defined?(symbols[5]) ?
780
+ object.instance_variable_set(symbols[5], terms) :
781
+ object.instance_variable_set(symbols[6], terms)
768
782
 
769
- object.instance_variable_set(:@game_title, system_translation_map[game_title]) if !currency_unit.nil? &&
770
- system_translation_map
771
- .key?(game_title)
783
+ game_title_translated = system_translation_map[game_title]
784
+ object.instance_variable_set(symbols[7], game_title_translated) if currency_unit.is_a?(String) && !game_title_translated.nil?
772
785
 
773
786
  puts "Written #{basename}" if $logging
774
787
 
@@ -777,22 +790,27 @@ module RGSS
777
790
 
778
791
  def self.write_scripts(scripts_file, other_path, output_path)
779
792
  script_entries = Marshal.load(File.read(scripts_file, mode: 'rb'))
780
- original_strings = File.read("#{other_path}/scripts.txt", mode: 'rb')
781
- .force_encoding('UTF-8')
782
- .split("\n")
783
- .map { |line| line.gsub('\#', "\r\n") }
784
793
 
785
- translation_strings = File.read("#{other_path}/scripts_trans.txt", mode: 'rb')
786
- .force_encoding('UTF-8')
787
- .split("\n")
788
- .map { |line| line.gsub('\#', "\r\n") }
794
+ scripts_original_text = File.read("#{other_path}/scripts.txt", mode: 'rb')
795
+ .force_encoding('UTF-8')
796
+ .split("\n")
797
+ .map { |line| line.gsub('\#', "\r\n") }
798
+ .freeze
799
+
800
+ scripts_translated_text = File.read("#{other_path}/scripts_trans.txt", mode: 'rb')
801
+ .force_encoding('UTF-8')
802
+ .split("\n")
803
+ .map { |line| line.gsub('\#', "\r\n") }
804
+ .freeze
789
805
 
790
806
  # Shuffle can possibly break the game in scripts, so no shuffling
791
807
 
792
808
  script_entries.each do |script|
793
809
  code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
794
810
 
795
- original_strings.zip(translation_strings).each do |original, translated|
811
+ scripts_original_text.zip(scripts_translated_text).each do |original, translated|
812
+ # That may possibly break something, but until it does, who cares
813
+ # Honestly, it needs to be changed to find quoted strings like in `extract_quoted_strings` method
796
814
  code.gsub!(original, translated) unless translated.nil?
797
815
  end
798
816
 
@@ -805,35 +823,29 @@ module RGSS
805
823
  def self.serialize(engine, action, directory, original_directory)
806
824
  start_time = Time.now
807
825
 
808
- setup_classes(engine)
809
-
810
- absolute_path = File.realpath(directory)
811
-
812
826
  paths = {
813
- original_path: File.join(absolute_path, original_directory),
814
- translation_path: File.join(absolute_path, 'translation'),
815
- maps_path: File.join(absolute_path, 'translation/maps'),
816
- other_path: File.join(absolute_path, 'translation/other'),
817
- output_path: File.join(absolute_path, 'output')
827
+ original_path: File.join(directory, original_directory),
828
+ translation_path: File.join(directory, 'translation'),
829
+ maps_path: File.join(directory, 'translation/maps'),
830
+ other_path: File.join(directory, 'translation/other'),
831
+ output_path: File.join(directory, 'output')
818
832
  }
819
833
 
820
834
  paths.each_value { |path| FileUtils.mkdir_p(path) }
821
835
 
822
- extensions = { ace: '.rvdata2', vx: '.rvdata', xp: '.rxdata' }
836
+ extensions = { ace: '.rvdata2', vx: '.rvdata', xp: '.rxdata' }.freeze
823
837
 
824
- files = (
825
- Dir
826
- .children(paths[:original_path])
827
- .select { |filename| File.extname(filename) == extensions[engine] }
828
- .map { |filename| "#{paths[:original_path]}/#{filename}" }
829
- )
838
+ files = Dir.children(paths[:original_path])
839
+ .select { |filename| File.extname(filename) == extensions[engine] }
840
+ .map { |filename| "#{paths[:original_path]}/#{filename}" }
841
+ .freeze
830
842
 
831
843
  maps_files = []
832
844
  other_files = []
833
- system_file = "#{paths[:original_path]}/System#{extensions[engine]}"
834
- scripts_file = "#{paths[:original_path]}/Scripts#{extensions[engine]}"
845
+ system_file = "#{paths[:original_path]}/System#{extensions[engine]}".freeze
846
+ scripts_file = "#{paths[:original_path]}/Scripts#{extensions[engine]}".freeze
835
847
 
836
- $game_type = get_game_type(system_file)
848
+ $game_type = get_game_type(system_file).freeze
837
849
 
838
850
  files.each do |file|
839
851
  basename = File.basename(file)
@@ -846,17 +858,17 @@ module RGSS
846
858
  end
847
859
 
848
860
  if action == 'read'
849
- read_map(maps_files, paths[:maps_path]) if $no[0]
850
- read_other(other_files, paths[:other_path]) if $no[1]
851
- read_system(system_file, paths[:other_path]) if $no[2]
852
- read_scripts(scripts_file, paths[:other_path]) if $no[3]
861
+ read_map(maps_files, paths[:maps_path]) unless $no[0]
862
+ read_other(other_files, paths[:other_path]) unless $no[1]
863
+ read_system(system_file, paths[:other_path]) unless $no[2]
864
+ read_scripts(scripts_file, paths[:other_path]) unless $no[3]
853
865
  else
854
- write_map(maps_files, paths[:maps_path], paths[:output_path]) if $no[0]
855
- write_other(other_files, paths[:other_path], paths[:output_path]) if $no[1]
856
- write_system(system_file, paths[:other_path], paths[:output_path]) if $no[2]
857
- write_scripts(scripts_file, paths[:other_path], paths[:output_path]) if $no[3]
866
+ write_map(maps_files, paths[:maps_path], paths[:output_path]) unless $no[0]
867
+ write_other(other_files, paths[:other_path], paths[:output_path]) unless $no[1]
868
+ write_system(system_file, paths[:other_path], paths[:output_path]) unless $no[2]
869
+ write_scripts(scripts_file, paths[:other_path], paths[:output_path]) unless $no[3]
858
870
  end
859
871
 
860
- puts "Done in #{(Time.now - start_time)}"
872
+ puts "Done in #{Time.now - start_time}"
861
873
  end
862
874
  end
data/rvpacker-txt.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'rvpacker-txt'
3
- spec.version = '1.2.1'
3
+ spec.version = '1.3.1'
4
4
  spec.authors = ['Howard Jeng', 'Andrew Kesterson', 'Solistra', 'Darkness9724', 'savannstm']
5
5
  spec.email = ['savannstm@gmail.com']
6
6
  spec.summary = 'Reads or writes RPG Maker XP/VX/VXAce game text to .txt files'
@@ -8,11 +8,12 @@ Gem::Specification.new do |spec|
8
8
  spec.license = 'MIT'
9
9
  spec.required_ruby_version = Gem::Requirement.new('>= 3.0.0')
10
10
 
11
+ spec.metadata = { 'homepage_uri' => 'https://github.com/savannstm/rvpacker-txt' }
12
+
11
13
  spec.files = `git ls-files -z`.split("\x0")
12
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.executables = ['rvpacker-txt']
14
15
  spec.require_paths = ['lib']
15
16
 
16
- spec.add_development_dependency 'bundler', '>= 2.5.14'
17
- spec.add_development_dependency 'rake', '>= 13.0.6'
17
+ spec.add_development_dependency 'bundler', '~> 2.5'
18
+ spec.add_development_dependency 'rake', '~> 13.0'
18
19
  end
@@ -0,0 +1,5 @@
1
+ $logging: bool
2
+ $shuffle: Integer
3
+ $no: Array[bool]
4
+ $game_type: String | nil
5
+ $disable_custom_parsing: bool
data/sig/rgss.rbs CHANGED
@@ -1,14 +1,18 @@
1
1
  module RGSS
2
+ def self.extract_quoted_strings: (String) -> Array[String]
3
+
2
4
  def self.get_game_type: (String) -> (String | nil)
3
5
 
4
6
  def self.get_translated: (Integer, String, Hash[String, String]) -> (String | nil)
5
7
 
6
- def self.get_variable_translated: (String) -> (String | nil)
8
+ def self.get_variable_translated: (String, Hash[String, String]) -> (String | nil)
7
9
 
8
10
  def self.merge_map: (Object) -> Object
9
11
 
10
12
  def self.merge_other: (Array[Object]) -> Array[Object]
11
13
 
14
+ def self.merge_seq: (Array[Object]) -> Array[Object]
15
+
12
16
  def self.parse_parameter: (Integer, String) -> (String | nil)
13
17
 
14
18
  def self.parse_variable: (String) -> (String | nil)
@@ -23,6 +27,8 @@ module RGSS
23
27
 
24
28
  def self.serialize: (Symbol, String, String, String) -> void
25
29
 
30
+ def self.shuffle_words: (Array[String]) -> Array[String]
31
+
26
32
  def self.write_map: (Array[String], String, String) -> void
27
33
 
28
34
  def self.write_other: (Array[String], String, String) -> void
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rvpacker-txt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Howard Jeng
@@ -12,36 +12,36 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2024-07-04 00:00:00.000000000 Z
15
+ date: 2024-07-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - "~>"
22
22
  - !ruby/object:Gem::Version
23
- version: 2.5.14
23
+ version: '2.5'
24
24
  type: :development
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - ">="
28
+ - - "~>"
29
29
  - !ruby/object:Gem::Version
30
- version: 2.5.14
30
+ version: '2.5'
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: rake
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - ">="
35
+ - - "~>"
36
36
  - !ruby/object:Gem::Version
37
- version: 13.0.6
37
+ version: '13.0'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - ">="
42
+ - - "~>"
43
43
  - !ruby/object:Gem::Version
44
- version: 13.0.6
44
+ version: '13.0'
45
45
  description:
46
46
  email:
47
47
  - savannstm@gmail.com
@@ -55,16 +55,16 @@ files:
55
55
  - README.md
56
56
  - Rakefile
57
57
  - bin/rvpacker-txt
58
- - lib/RGSS.rb
59
- - lib/RGSS/BasicCoder.rb
60
- - lib/RGSS/serialize.rb
61
- - lib/RPG.rb
58
+ - lib/classes.rb
59
+ - lib/serialize.rb
62
60
  - rvpacker-txt.gemspec
61
+ - sig/global_variables.rbs
63
62
  - sig/rgss.rbs
64
63
  homepage: https://github.com/savannstm/rvpacker-txt
65
64
  licenses:
66
65
  - MIT
67
- metadata: {}
66
+ metadata:
67
+ homepage_uri: https://github.com/savannstm/rvpacker-txt
68
68
  post_install_message:
69
69
  rdoc_options: []
70
70
  require_paths:
@@ -1,31 +0,0 @@
1
- module RGSS
2
- module BasicCoder
3
- def ivars
4
- instance_variables
5
- end
6
-
7
- INCLUDED_CLASSES = []
8
-
9
- def self.included(module_)
10
- INCLUDED_CLASSES.push(module_)
11
- end
12
-
13
- def self.ivars_methods_set(version)
14
- INCLUDED_CLASSES.each do |class_|
15
- if version == :ace
16
- RGSS.reset_method(
17
- class_,
18
- :ivars,
19
- -> { instance_variables }
20
- )
21
- else
22
- RGSS.reset_method(
23
- class_,
24
- :ivars,
25
- -> { instance_variables.sort }
26
- )
27
- end
28
- end
29
- end
30
- end
31
- end
data/lib/RGSS.rb DELETED
@@ -1,280 +0,0 @@
1
- =begin
2
- Copyright (c) 2013 Howard Jeng
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this
5
- software and associated documentation files (the "Software"), to deal in the Software
6
- without restriction, including without limitation the rights to use, copy, modify, merge,
7
- publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8
- to whom the Software is furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all copies or
11
- substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15
- PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16
- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17
- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
- DEALINGS IN THE SOFTWARE.
19
- =end
20
-
21
- class Table
22
- def initialize(bytes)
23
- @dim, @x, @y, @z, items, *@data = bytes.unpack('L5 S*')
24
-
25
- unless items == @data.length && @x * @y * @z == items
26
- raise 'Size mismatch loading Table from data'
27
- end
28
- end
29
-
30
- def _dump(*_ignored)
31
- [@dim, @x, @y, @z, @x * @y * @z, *@data].pack('L5 S*')
32
- end
33
-
34
- def self._load(bytes)
35
- Table.new(bytes)
36
- end
37
- end
38
-
39
- class Color
40
- def initialize(bytes)
41
- @r, @g, @b, @a = *bytes.unpack('D4')
42
- end
43
-
44
- def _dump(*_ignored)
45
- [@r, @g, @b, @a].pack('D4')
46
- end
47
-
48
- def self._load(bytes)
49
- Color.new(bytes)
50
- end
51
- end
52
-
53
- class Tone
54
- def initialize(bytes)
55
- @r, @g, @b, @a = *bytes.unpack('D4')
56
- end
57
-
58
- def _dump(*_ignored)
59
- [@r, @g, @b, @a].pack('D4')
60
- end
61
-
62
- def self._load(bytes)
63
- Tone.new(bytes)
64
- end
65
- end
66
-
67
- class Rect
68
- def initialize(bytes)
69
- @x, @y, @width, @height = *bytes.unpack('i4')
70
- end
71
-
72
- def _dump(*_ignored)
73
- [@x, @y, @width, @height].pack('i4')
74
- end
75
-
76
- def self._load(bytes)
77
- Rect.new(bytes)
78
- end
79
- end
80
-
81
- module RGSS
82
- def self.remove_defined_method(scope, name)
83
- if scope.instance_methods(false).include?(name)
84
- scope.send(:remove_method, name)
85
- end
86
- end
87
-
88
- def self.reset_method(scope, name, method)
89
- remove_defined_method(scope, name)
90
- scope.send(:define_method, name, method)
91
- end
92
-
93
- def self.reset_const(scope, symbol, value)
94
- scope.send(:remove_const, symbol) if scope.const_defined?(symbol)
95
- scope.send(:const_set, symbol, value)
96
- end
97
-
98
- def self.array_to_hash(array, &block)
99
- hash = {}
100
-
101
- array.each_with_index do |value, index|
102
- r = block_given? ? block.call(value) : value
103
- hash[index] = r unless r.nil?
104
- end
105
-
106
- unless array.empty?
107
- last = array.length - 1
108
- hash[last] = nil unless hash.has_key?(last)
109
- end
110
-
111
- hash
112
- end
113
-
114
- def self.hash_to_array(hash)
115
- array = []
116
- hash.each { |key, value| array[key] = value }
117
- array
118
- end
119
-
120
- require 'RGSS/BasicCoder'
121
- require 'RPG'
122
-
123
- # creates an empty class in a potentially nested scope
124
- def self.process(root, name, *args)
125
- if !args.empty?
126
- process(root.const_get(name), *args)
127
- else
128
- unless root.const_defined?(name, false)
129
- root.const_set(name, Class.new)
130
- end
131
- end
132
- end
133
-
134
- # other classes that don't need definitions
135
- [
136
- # RGSS data structures
137
- %i[RPG Actor],
138
- %i[RPG Animation],
139
- %i[RPG Animation Frame],
140
- %i[RPG Animation Timing],
141
- %i[RPG Area],
142
- %i[RPG Armor],
143
- %i[RPG AudioFile],
144
- %i[RPG BaseItem],
145
- %i[RPG BaseItem Feature],
146
- %i[RPG BGM],
147
- %i[RPG BGS],
148
- %i[RPG Class],
149
- %i[RPG Class Learning],
150
- %i[RPG CommonEvent],
151
- %i[RPG Enemy],
152
- %i[RPG Enemy Action],
153
- %i[RPG Enemy DropItem],
154
- %i[RPG EquipItem],
155
- %i[RPG Event],
156
- %i[RPG Event Page],
157
- %i[RPG Event Page Condition],
158
- %i[RPG Event Page Graphic],
159
- %i[RPG Item],
160
- %i[RPG Map],
161
- %i[RPG Map Encounter],
162
- %i[RPG MapInfo],
163
- %i[RPG ME],
164
- %i[RPG MoveCommand],
165
- %i[RPG MoveRoute],
166
- %i[RPG SE],
167
- %i[RPG Skill],
168
- %i[RPG State],
169
- %i[RPG System Terms],
170
- %i[RPG System TestBattler],
171
- %i[RPG System Vehicle],
172
- %i[RPG System Words],
173
- %i[RPG Tileset],
174
- %i[RPG Troop],
175
- %i[RPG Troop Member],
176
- %i[RPG Troop Page],
177
- %i[RPG Troop Page Condition],
178
- %i[RPG UsableItem],
179
- %i[RPG UsableItem Damage],
180
- %i[RPG UsableItem Effect],
181
- %i[RPG Weapon],
182
- # Script classes serialized in save game files
183
- [:Game_ActionResult],
184
- [:Game_Actor],
185
- [:Game_Actors],
186
- [:Game_BaseItem],
187
- [:Game_BattleAction],
188
- [:Game_CommonEvent],
189
- [:Game_Enemy],
190
- [:Game_Event],
191
- [:Game_Follower],
192
- [:Game_Followers],
193
- [:Game_Interpreter],
194
- [:Game_Map],
195
- [:Game_Message],
196
- [:Game_Party],
197
- [:Game_Picture],
198
- [:Game_Pictures],
199
- [:Game_Player],
200
- [:Game_System],
201
- [:Game_Timer],
202
- [:Game_Troop],
203
- [:Game_Screen],
204
- [:Game_Vehicle],
205
- [:Interpreter]
206
- ].each { |symbol_array| process(Object, *symbol_array) }
207
-
208
- def self.setup_classes(version)
209
- # change version_id to fixed number
210
- reset_method(
211
- RPG::System,
212
- :reduce_string,
213
- ->(string) do
214
- return nil if string.nil?
215
-
216
- stripped = string.strip
217
- stripped.empty? ? nil : stripped
218
- end
219
- )
220
-
221
- # These magic numbers should be different. If they are the same, the saved version
222
- # of the map in save files will be used instead of any updated version of the map
223
- reset_method(
224
- RPG::System,
225
- :map_version,
226
- ->(_ignored) { 12_345_678 }
227
- )
228
-
229
- reset_method(
230
- Game_System,
231
- :map_version,
232
- ->(_ignored) { 87_654_321 }
233
- )
234
-
235
- # Game_Interpreter is marshalled differently in VX Ace
236
- if version == :ace
237
- reset_method(Game_Interpreter, :marshal_dump, -> { @data })
238
- reset_method(
239
- Game_Interpreter,
240
- :marshal_load,
241
- ->(obj) { @data = obj }
242
- )
243
- else
244
- remove_defined_method(Game_Interpreter, :marshal_dump)
245
- remove_defined_method(Game_Interpreter, :marshal_load)
246
- end
247
-
248
- reset_method(
249
- RPG::EventCommand,
250
- :clean,
251
- -> { @parameters[0].rstrip! if @code == 401 }
252
- )
253
-
254
- reset_const(
255
- RPG::EventCommand,
256
- :MOVE_LIST_CODE,
257
- version == :xp ? 209 : 205
258
- )
259
-
260
- BasicCoder.ivars_methods_set(version)
261
- end
262
-
263
- class Game_Switches
264
- include RGSS::BasicCoder
265
- end
266
-
267
- class Game_Variables
268
- include RGSS::BasicCoder
269
- end
270
-
271
- class Game_SelfSwitches
272
- include RGSS::BasicCoder
273
- end
274
-
275
- class Game_System
276
- include RGSS::BasicCoder
277
- end
278
-
279
- require 'RGSS/serialize'
280
- end
data/lib/RPG.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'RGSS'
2
- module RPG
3
- class System
4
- include RGSS::BasicCoder
5
- end
6
-
7
- class EventCommand
8
- end
9
- end