Skip to content
This repository was archived by the owner on Aug 29, 2022. It is now read-only.

Commit 546f29f

Browse files
committed
Preliminary i18n improvements
1 parent a4de9d9 commit 546f29f

15 files changed

Lines changed: 165 additions & 58 deletions

binding-mri/binding-util.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
150150
VALUE *str = va_arg(ap, VALUE*);
151151
VALUE tmp = *arg;
152152

153-
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
154-
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
153+
tmp = rb_str_to_str(tmp);
155154

156155
*str = tmp;
157156
++argI;
@@ -169,8 +168,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
169168

170169
VALUE tmp = *arg;
171170

172-
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
173-
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
171+
tmp = rb_str_to_str(tmp);
174172

175173
*s = RSTRING_PTR(tmp);
176174
*len = RSTRING_LEN(tmp);
@@ -188,8 +186,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
188186

189187
VALUE tmp = *arg++;
190188

191-
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
192-
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
189+
tmp = rb_str_to_str(tmp);
193190

194191
*s = RSTRING_PTR(tmp);
195192
++argI;

binding-mri/oneshot-binding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void oneshotBindingInit()
4747
//Constants
4848
rb_const_set(module, rb_intern("USER_NAME"), rb_str_new2(shState->oneshot().userName().c_str()));
4949
rb_const_set(module, rb_intern("SAVE_PATH"), rb_str_new2(shState->oneshot().savePath().c_str()));
50-
rb_const_set(module, rb_intern("LANG"), ID2SYM(rb_intern(shState->oneshot().lang().c_str())));
50+
rb_const_set(module, rb_intern("LANG"), rb_str_new2(shState->oneshot().lang().c_str()));
5151
rb_const_set(msg, rb_intern("INFO"), INT2FIX(Oneshot::MSG_INFO));
5252
rb_const_set(msg, rb_intern("YESNO"), INT2FIX(Oneshot::MSG_YESNO));
5353
rb_const_set(msg, rb_intern("WARN"), INT2FIX(Oneshot::MSG_WARN));

binding-mri/steam-binding.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ void steamBindingInit()
6565
/* Constants */
6666
#ifdef STEAM
6767
rb_const_set(module, rb_intern("USER_NAME"), rb_str_new2(shState->steam().userName().c_str()));
68+
if (shState->steam().lang().empty())
69+
rb_const_set(module, rb_intern("LANG"), Qnil);
70+
else
71+
rb_const_set(module, rb_intern("LANG"), rb_str_new2(shState->steam().lang().c_str()));
6872
#else
6973
rb_const_set(module, rb_intern("USER_NAME"), Qnil);
74+
rb_const_set(module, rb_intern("LANG"), Qnil);
7075
#endif
7176

7277
/* Functions */

scripts/Ed_Message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def refresh
6161
widths = []
6262

6363
# Pre-process text
64-
text_raw = $game_temp.message_ed_text
64+
text_raw = $game_temp.message_ed_text.to_str
6565

6666
# Substitute variables, actors, player name, newlines, etc
6767
text_raw.gsub!(/\\v\[([0-9]+)\]/) do

scripts/Game_Oneshot.rb

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,13 @@ class Game_Oneshot
66
attr_accessor :plight_timer # start of plight's plight
77

88
def initialize
9-
user_name = Oneshot::USER_NAME.split(/\s+/)
9+
user_name = (Steam.enabled? ? Steam::USER_NAME : Oneshot::USER_NAME).split(/\s+/)
1010
if user_name[0].casecmp('the') == 0 || user_name[0].casecmp('a') == 0
1111
@player_name = user_name.join(' ')
1212
else
1313
@player_name = user_name[0]
1414
end
1515
@lights = {}
16-
self.lang = Oneshot::LANG
1716
@plight_timer = nil
1817
end
19-
20-
# lang
21-
def lang
22-
@lang
23-
end
24-
def lang=(val)
25-
@lang = val
26-
$tr = Translator.new(val)
27-
$language = Language.get(val)
28-
Font.default_name = $language.font
29-
Oneshot.set_yes_no(tr('Yes'), tr('No'))
30-
end
31-
32-
# MARSHAL
33-
def marshal_dump
34-
[@player_name, @lang, @plight_timer]
35-
end
36-
def marshal_load(array)
37-
@player_name, self.lang, @plight_timer = array
38-
end
3918
end

scripts/Main.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
Graphics.frame_rate = 60
99
Font.default_size = 20
1010

11+
# Load persistent data
12+
Persistent.load
13+
1114
# Prepare for transition
1215
Graphics.freeze
1316
# Make scene object (title screen)

scripts/Persistent.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Persistent data independent from save file.
2+
# Stores settings and the like.
3+
class LanguageCode
4+
attr_accessor :full
5+
attr_accessor :lang
6+
attr_accessor :region
7+
8+
def initialize(str)
9+
parts = str.split(/[_-]/)
10+
if parts.size == 1
11+
@lang, @region = parts.first.downcase.to_sym, nil
12+
@full = @lang
13+
elsif parts.size == 2
14+
@lang, @region = parts.first.downcase.to_sym, parts.last.upcase.to_sym
15+
@full = (parts.first.downcase + '_' + parts.last.upcase).to_sym
16+
else
17+
raise "malformed language code: #{str}"
18+
end
19+
end
20+
end
21+
22+
class Persistent
23+
attr_reader :lang
24+
25+
def initialize
26+
self.lang = LanguageCode.new(Steam::LANG || Oneshot::LANG)
27+
end
28+
29+
# Members
30+
def lang=(val)
31+
@lang = val
32+
$tr = Translator.new(@lang)
33+
$lang = Language.get(@lang)
34+
Font.default_name = $lang.font
35+
Oneshot.set_yes_no(tr('Yes'), tr('No'))
36+
end
37+
38+
# MARSHAL
39+
def marshal_dump
40+
[@lang]
41+
end
42+
def marshal_load(array)
43+
self.lang = array.first
44+
end
45+
46+
# Save/Load global instance of persistent
47+
FILE_NAME = Oneshot::SAVE_PATH + '/persistent.dat'
48+
def self.save
49+
File.open(FILE_NAME, 'wb') do |file|
50+
Marshal.dump($persistent, file)
51+
end
52+
end
53+
54+
def self.load
55+
if FileTest.exist?(FILE_NAME)
56+
File.open(FILE_NAME, 'rb') do |file|
57+
$persistent = Marshal.load(file)
58+
end
59+
else
60+
$persistent = Persistent.new
61+
end
62+
end
63+
end

scripts/SaveLoad.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
def save_file_name
2-
Oneshot::SAVE_PATH + '/save.dat'
3-
end
1+
SAVE_FILE_NAME = Oneshot::SAVE_PATH + '/save.dat'
42

53
def save
6-
File.open(save_file_name, 'wb') do |file|
4+
File.open(SAVE_FILE_NAME, 'wb') do |file|
75
# Wrire frame count for measuring play time
86
Marshal.dump(Graphics.frame_count, file)
97
# Increase save count by 1
@@ -27,8 +25,8 @@ def save
2725
end
2826

2927
def load
30-
return false unless FileTest.exist?(save_file_name)
31-
File.open(save_file_name, 'rb') do |file|
28+
return false unless FileTest.exist?(SAVE_FILE_NAME)
29+
File.open(SAVE_FILE_NAME, 'rb') do |file|
3230
# Read frame count for measuring play time
3331
Graphics.frame_count = Marshal.load(file)
3432
# Read each type of game object

scripts/Scene_Title.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ def main
2929
# Load save game/initialize data
3030
$game_temp = Game_Temp.new
3131
new_game unless load
32-
# Translate database items
33-
$tr.translate_database
3432
# Make system object
3533
$game_system = Game_System.new
3634
# Skip title screen if debug mode

scripts/_scripts.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ Scene_Battle 4
9696
Scene_Name
9797
Scene_Debug
9898

99+
# Persistent data
100+
Persistent
101+
99102
# Internationalization
100103
i18n_Translator
101104
i18n_Language

0 commit comments

Comments
 (0)