Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Iavra Game Localization - Database Module 1.00
- # -----------------------------------------------------------------------------
- # Description:
- # Allows the localization of database entries. Supports the following entries:
- # - Actors, classes, skills, items, weapons, armors, enemies, states
- # - System, terms, vocab
- # - map display names
- # -----------------------------------------------------------------------------
- # Prerequisites:
- # Iavra Game Localization - Core Engine
- # -----------------------------------------------------------------------------
- # How to Use:
- # Language files are built after the following formats:
- #
- # - Actors, classes, skills, items, weapons, armors, enemies, states
- #
- # {
- # :actors => {
- # 1 => {
- # :name => "Name of actor 1"
- # }
- # }
- # }
- #
- # - System, terms, vocab:
- #
- # {
- # :system => {
- # :game_title => "Game title"
- # }
- # }
- #
- # - Map display names:
- #
- # {
- # :maps => {
- # 1 => "Name of map 1"
- # }
- # }
- #
- # If an entry is not localized, it will be set to its default value, instead.
- # The default value is whatever was set in VX Ace.
- # -----------------------------------------------------------------------------
- # Terms of Use:
- # Free to use for both commercial and non-commercial games. Please give credit.
- # -----------------------------------------------------------------------------
- # Credits:
- # Iavra
- # -----------------------------------------------------------------------------
- # Changelog:
- # - 1.00: Release version.
- #==============================================================================
- ($imported ||= {})[:iavra_i18n_database] = true
- fail "This module needs the core engine to function." unless $imported[:iavra_i18n_core]
- #==============================================================================
- # ▼ IAVRA::I18N::DATABASE
- #==============================================================================
- module IAVRA
- module I18N
- module DATABASE
- #========================================================================
- # ■ ■ ■ ■ ■ CONFIGURATION ■ ■ ■ ■ ■
- #========================================================================
- #========================================================================
- # Since actors are cached, we have to localize the values directly inside
- # of $game_actors. Setting this to true will revert those entries back
- # to default before saving and re-localize them afterwards, leaving no
- # traces in your savefiles.
- #========================================================================
- CLEAN_ACTORS = false
- #========================================================================
- # ■ ■ ■ ■ ■ CONFIGURATION ■ ■ ■ ■ ■
- #========================================================================
- #========================================================================
- # The attributes of $data_actors, $data_classes, $data_skills, $data_items,
- # $data_weapons, $data_armors, $data_enemies and $data_states, that should
- # be localized.
- #========================================================================
- CONFIG_DATA = {
- :actors => {
- :@name => :name,
- :@nickname => :nickname,
- :@description => :description
- },
- :classes => {
- :@name => :name
- },
- :skills => {
- :@name => :name,
- :@description => :description,
- :@message1 => :message1,
- :@message2 => :message2
- },
- :items => {
- :@name => :name,
- :@description => :description
- },
- :weapons => {
- :@name => :name,
- :@description => :description
- },
- :armors => {
- :@name => :name,
- :@description => :description
- },
- :enemies => {
- :@name => :name
- },
- :states => {
- :@name => :name,
- :@description => :description,
- :@message1 => :message1,
- :@message2 => :message2,
- :@message3 => :message3,
- :@message4 => :message4
- }
- }
- #========================================================================
- # The attributes of $data_system, that should be localized.
- #========================================================================
- CONFIG_SYSTEM_CAT = :system
- CONFIG_SYSTEM = {
- :@game_title => :game_title,
- :@currency_unit => :currency_unit,
- :@elements => :elements,
- :@skill_types => :skill_types,
- :@weapon_types => :weapon_types,
- :@armor_types => :armor_types
- }
- #========================================================================
- # The attributes of $data_system.terms, that should be localized.
- #========================================================================
- CONFIG_TERMS_CAT = :terms
- CONFIG_TERMS = {
- :@basic => {
- 0 => :basic_level,
- 1 => :basic_level_short,
- 2 => :basic_hp,
- 3 => :basic_hp_short,
- 4 => :basic_mp,
- 5 => :basic_mp_short,
- 6 => :basic_tp,
- 7 => :basic_tp_short
- },
- :@params => {
- 0 => :param_mhp,
- 1 => :param_mmp,
- 2 => :param_atk,
- 3 => :param_def,
- 4 => :param_matk,
- 5 => :param_mdef,
- 6 => :param_agi,
- 7 => :param_luck
- },
- :@etypes => {
- 0 => :etype_weapon,
- 1 => :etype_shield,
- 2 => :etype_head,
- 3 => :etype_body,
- 4 => :etype_accessory
- },
- :@commands => {
- 0 => :command_fight,
- 1 => :command_escape,
- 2 => :command_attack,
- 3 => :command_guard,
- 4 => :command_item,
- 5 => :command_skill,
- 6 => :command_equip,
- 7 => :command_status,
- 8 => :command_formation,
- 9 => :command_save,
- 10 => :command_game_end,
- 12 => :command_weapon,
- 13 => :command_armor,
- 14 => :command_key_item,
- 15 => :command_change_equip,
- 16 => :command_optimize_equip,
- 17 => :command_clear_equip,
- 18 => :command_new_game,
- 19 => :command_continue,
- 20 => :command_shutdown,
- 21 => :command_to_title,
- 22 => :command_cancel
- }
- }
- #========================================================================
- # The constants inside the Vocab module, that should be localized.
- #========================================================================
- CONFIG_VOCAB_CAT = :vocab
- CONFIG_VOCAB = {
- :ShopBuy => :shop_buy,
- :ShopSell => :shop_sell,
- :ShopCancel => :shop_cancel,
- :Possession => :possession,
- :ExpTotal => :exp_total,
- :ExpNext => :exp_next,
- :SaveMessage => :save_message,
- :LoadMessage => :load_message,
- :File => :file,
- :PartyName => :party_name,
- :Emerge => :emerge,
- :Preemptive => :preemptive,
- :Surprise => :surprise,
- :EscapeStart => :escape_start,
- :EscapeFailure => :escape_failure,
- :Victory => :victory,
- :Defeat => :defeat,
- :ObtainExp => :obtain_exp,
- :ObtainGold => :obtain_gold,
- :ObtainItem => :obtain_item,
- :LevelUp => :level_up,
- :ObtainSkill => :obtain_skill,
- :UseItem => :use_item,
- :CriticalToEnemy => :critical_to_enemy,
- :CriticalToActor => :critical_to_actor,
- :ActorDamage => :actor_damage,
- :ActorRecovery => :actor_recovery,
- :ActorGain => :actor_gain,
- :ActorLoss => :actor_loss,
- :ActorDrain => :actor_drain,
- :ActorNoDamage => :actor_no_damage,
- :ActorNoHit => :actor_no_hit,
- :EnemyDamage => :enemy_damage,
- :EnemyRecovery => :enemy_recovery,
- :EnemyGain => :enemy_gain,
- :EnemyLoss => :enemy_loss,
- :EnemyDrain => :enemy_drain,
- :EnemyNoDamage => :enemy_no_damage,
- :EnemyNoHit => :enemy_no_hit,
- :Evasion => :evasion,
- :MagicEvasion => :magic_evasion,
- :MagicReflection => :magic_reflection,
- :CounterAttack => :counter_attack,
- :Substitute => :substitute,
- :BuffAdd => :buff_add,
- :DebuffAdd => :debuff_add,
- :BuffRemove => :buff_remove,
- :ActionFailure => :action_failure
- }
- #========================================================================
- # The category for map ids whose display names should be localized.
- #========================================================================
- CONFIG_MAPS_CAT = :maps
- #========================================================================
- # Creates backups of the values values to use if no localized value can
- # be found.
- #========================================================================
- def self.initialize_base_values
- CONFIG_DATA.each{|name, attrs|
- eval("$data_#{name}").compact.each{|data|
- base = Hash[attrs.keys.map{|attr| [attr, data.instance_variable_get(attr)]}]
- data.iavra_i18n_database_base = base
- }
- }
- base = {}
- CONFIG_SYSTEM.each{|k, v|
- base[k] = $data_system.instance_variable_get(k) || ""
- }
- $data_system.iavra_i18n_database_base = base
- base = Hash[CONFIG_TERMS.keys.map{|name| [name, $data_system.terms.instance_variable_get(name)]}]
- $data_system.terms.iavra_i18n_database_base = base
- @vocab_base = Hash[CONFIG_VOCAB.keys.map{|symbol| [symbol, Vocab.const_get(symbol)]}]
- end
- #========================================================================
- # Updates all localized values whenever the current language is changed.
- #========================================================================
- def self.update_data
- CONFIG_DATA.each{|name, attrs|
- eval("$data_#{name}").compact.each{|data|
- attrs.each{|attr, symbol|
- value = (IAVRA::I18N[name][data.id] || {})[symbol] || data.iavra_i18n_database_base[attr]
- data.instance_variable_set(attr, value)
- }
- }
- }
- end
- def self.update_system
- CONFIG_SYSTEM.each{|k, v|
- base = $data_system.iavra_i18n_database_base[k].clone
- config = IAVRA::I18N[CONFIG_SYSTEM_CAT][v]
- if(base.is_a?(Array))
- base = base.map.with_index{|data, id| (config || {})[id] || data}
- else
- base = config || base
- end
- $data_system.instance_variable_set(k, base)
- }
- end
- def self.update_terms
- CONFIG_TERMS.each{|name, attrs|
- value = $data_system.terms.instance_variable_get(name).each_index.map{|id|
- IAVRA::I18N[CONFIG_TERMS_CAT][attrs[id]] || $data_system.terms.iavra_i18n_database_base[name][id]
- }
- $data_system.terms.instance_variable_set(name, value)
- }
- end
- def self.update_vocab
- CONFIG_VOCAB.each{|name, symbol|
- Vocab.send(:remove_const, name) if Vocab.const_defined?(name)
- Vocab.const_set(name, IAVRA::I18N[CONFIG_VOCAB_CAT][symbol] || @vocab_base[name])
- }
- end
- def self.update_actors
- $data_actors.each_with_index{|actor, id|
- next if $game_actors[id].nil?
- (CONFIG_DATA[:actors] || {}).each {|k, v|
- $game_actors[id].instance_variable_set(k, actor.instance_variable_get(k))
- }
- } unless $game_actors.nil?
- end
- end
- #==========================================================================
- # Registering our initialize and update methods with the core engine.
- #==========================================================================
- class << self
- alias :iavra_i18n_database_initialize :initialize
- alias :iavra_i18n_database_update :update
- end
- def self.initialize
- iavra_i18n_database_initialize
- DATABASE.initialize_base_values
- end
- def self.update
- iavra_i18n_database_update
- DATABASE.update_data
- DATABASE.update_system
- DATABASE.update_terms
- DATABASE.update_vocab
- DATABASE.update_actors
- end
- end
- end
- #==============================================================================
- # ▼ RPG::BaseItem, RPG::System, RPG::System::Terms
- #==============================================================================
- ["RPG::BaseItem", "RPG::System", "RPG::System::Terms"].each{|cls| eval %Q{
- class #{cls}; attr_accessor :iavra_i18n_database_base; end
- }}
- #==============================================================================
- # ▼ DataManager
- #==============================================================================
- module DataManager
- class << self
- alias :iavra_i18n_database_extract_save_contents :extract_save_contents
- end
- #============================================================================
- # If the language is changed before a game is loaded, the change wouldn't
- # carry over to $game_actors. This call fixes that.
- #============================================================================
- def self.extract_save_contents(*args)
- iavra_i18n_database_extract_save_contents(*args)
- IAVRA::I18N::DATABASE.update_actors
- end
- #============================================================================
- # If CLEAN_ACTORS is set to true, this will revert the localizing done to
- # $game_actors before saving and immediately relocalize it afterwards.
- #============================================================================
- if(IAVRA::I18N::DATABASE::CLEAN_ACTORS)
- class << self
- alias :iavra_i18n_database_save_game :save_game
- end
- def self.save_game(*args)
- $data_actors.each_with_index{|actor, id|
- next if $game_actors[id].nil?
- (IAVRA::I18N::DATABASE::CONFIG_DATA[:actors] || {}).each {|k, v|
- $game_actors[id].instance_variable_set(k, actor.iavra_i18n_database_base[k])
- }
- }
- iavra_i18n_database_save_game(*args)
- IAVRA::I18N::DATABASE.update_actors
- end
- end
- end
- #==============================================================================
- # ▼ Game_Map
- #==============================================================================
- class Game_Map
- alias :iavra_i18n_database_display_name :display_name
- def display_name
- IAVRA::I18N[IAVRA::I18N::DATABASE::CONFIG_MAPS_CAT][@map_id] || iavra_i18n_database_display_name
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement