Partagez
Aller en bas
avatar
crackerwood
Membre

Nombre de messages : 343
Age : 33
Localisation : Derrière son pc y parait
Distinction : aucune
Date d'inscription : 03/08/2008

Organiser sa base de donnée

le Jeu 26 Nov 2015 - 20:43
Bonjour, bonsoir,
il y a quelques temps j'avais demandé de l'aide pour un script. Ce script devait servir à modifier toutes les variables. C'est à dire mixer deux projets qui utilisent les mêmes variables et je voulaient toutes les conserver. J'ai donc trouvé un script de Gambit qui, au démarrage d'un projet, permet de les déplacer dans la BDD mais qui sera également pris en compte.

Code:
#==============================================================================
# GAMBIT DATABASE ORGANIZER
#------------------------------------------------------------------------------
# WRITTEN BY: Gambit
#------------------------------------------------------------------------------
# VERSION: 1.50
#------------------------------------------------------------------------------
# CHANGELOG:
#  v 1.50 - June 6, 2014 > Added support for variables
#                        > Added support for self switches
#  v 1.15 - June 5, 2014 > Significant performance improvements
#                        > Added support for switches
#  v 1.10 - June 4, 2014 > Added Database Organizer scene
#  v 1.00 - June 4, 2014 > Initial release
#------------------------------------------------------------------------------
# DESCRIPTION AND FEATURES:
#   This script allows a user to modify the order of objects in most databases
#   while preserving all game references to the original objects. In the project
#   editor, if you attempt to swap two Items by cutting and pasting, all
#   references to the items would be reversed. The references are tied to the ID
#   instead of the object itself. This script allows you to manipulate the
#   databases while preserving all references to the original objects.
#
#   A message will appear when the tasks you have specified are completed
#   successfully. CLOSE AND REOPEN THE PROJECT for the changes to finalize and
#   appear in the editor. If you save the project after running the script but
#   before closing and reopening it, the Organizer tasks will be REVERTED.
#
#   The script will print out a note to the console as each task is completed.
#   If you encounter an error and would like to revert all the tasks that were
#   performed prior to the error, just save your project. Again, saving the
#   project after running the script will revert the changes. To finalize the
#   changes, you must close the project after running the script then reopen it.
#
#  Features:
#   - Swap, move, insert, and delete database objects without ruining all of the
#     references in your game
#   - Update and redirect object references
#   - User-friendly Database Organizer scene to facilitate organization
#   - Optional task queue is available which will automatically perform the
#     specified tasks in the order they are provided
#   - Most objects are supported:
#     - Actors
#     - Animations
#     - Armors
#     - Classes
#     - Common Events
#     - Enemies
#     - Items
#     - Self Switches
#     - Skills
#     - States
#     - Switches
#     - Tilesets
#     - Troops
#     - Variables
#     - Weapons
#------------------------------------------------------------------------------
# REQUIRES:
# - None
#------------------------------------------------------------------------------
# INSTRUCTIONS AND SETUP:
#  Place this script below Materials and above Main Process.
#
#  Setup for this script is below. Please read explanations in comments.
#------------------------------------------------------------------------------
# Terms of Use:
# - Credit if used
# - Free for use in non-commercial projects
# - Please do not repost elsewhere, convert, or translate this script without
#   permission.
# - If seeking to use in commercial projects (projects that are generating money
#   in any way, including advertisements), please contact me via PM at:
#   http://www.rpgmakervxace.net/user/14194-gambit/
# - When using third-party scripts, the terms and conditions of those scripts
#   also apply. Please be aware of them prior to using.
# - Not for use in any project involving any form of nudity, commercial or not
#==============================================================================

module Gambit
 module DatabaseOrganizer
   
   # Determines whether Database Organizer will run when your game starts.
   Enabled = true
   
   # Determines whether to use the Database Organizer scene.
   # If set to true, you do not need to set up Tasks below.
   UseGUI = true
   
   # Only needed if UseGUI is set to false.
   # This allows you to queue tasks if you prefer creating them manually and
   # bypassing the Database Organizer scene.
   #       -------------------------------------------------------------
   # Tasks that you want to perform. The tasks are performed in the order
   # listed, one after the other. So feel free to chain tasks by using the IDs
   # that would result from the previous tasks.
   #       -------------------------------------------------------------
   # Each entry should have this format:
   # [task type, object type, old ID, new ID(, map ID)],
   #       -------------------------------------------------------------
   # task type =
   #   :swap   = swaps old ID object with new ID object and updates the
   #             references to both.
   #   :move   = moves old ID object to new ID, overwriting object that was
   #             previously at new ID. References to old ID will be changed to
   #             new ID so references to both the old and new IDs will point at
   #             new ID. The old ID will be a blank object.
   #   :insert = inserts old ID object at new ID. If old ID is less than new
   #             ID, all objects in between are shifted up one. If old ID is
   #             greater than new ID, all objects in between are shifted down
   #             one. All references are updated accordingly.
   #   :delete = deletes old ID object and shifts the IDs of all the following
   #             objects up one. All references are updated accordingly.
   #             References to the old ID will be redirected to the last ID.
   #             The last ID will be a blank object. A new ID is not needed.
   #   :update = updates and redirects old ID references to new ID.
   #
   # object type = :actor, :animation, :armor, :class, :common_event, :enemy,
   #               :item, :self_switch, :skill, :state, :switch, :tileset,
   #               :troop, :variable, :weapon
   # old ID      = original ID
   # new ID      = target ID (not needed for :delete task type)
   #       -------------------------------------------------------------
   # For Self Switches only:
   # map ID      = map ID
   #
   # Only the :swap and :update task types can be used.
   # Use strings for the IDs ('A', 'B', 'C', 'D').
   #       -------------------------------------------------------------
   Tasks = [
     [:swap,   :actor,   5,  6],
     [:move,   :class,  10,  4],
     [:insert, :weapon, 23, 34],
     [:delete, :skill,   7    ],
     [:update, :armor,  10, 12],
   ]
   
 end
end

###############################################################################
###############################################################################
###############################################################################
###############################################################################
### END OF SETTING UP ###### ONLY EDIT BELOW IF YOU KNOW WHAT YOU ARE DOING ###
###############################################################################
###############################################################################
###############################################################################
###############################################################################


($imported ||={})["GambitDatabaseOrganizer"] = true

#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
#  This module manages the database and game objects. Almost all of the
# global variables used by the game are initialized by this module.
#==============================================================================

module DataManager
 class <<self
   alias gam_dborganizer_load_normal_database load_normal_database
 end
 #--------------------------------------------------------------------------
 # * Load Normal Database
 #--------------------------------------------------------------------------
 def self.load_normal_database
   gam_dborganizer_load_normal_database
   if Gambit::DatabaseOrganizer::Enabled && !Gambit::DatabaseOrganizer::UseGUI
     Gambit::DatabaseOrganizer::Tasks.each_with_index do |task, index|
       organize_database(task, index)
     end
     database_organizer_done
   end
 end
 #--------------------------------------------------------------------------
 # * Perform Database Organizer Tasks
 #--------------------------------------------------------------------------
 def self.organize_database(task, index = nil)
   task_type, type, old_id, new_id, map_id = task
   case task_type
   when :swap
     separator = '↔'
     database_swap(*task.drop(1))
     update_references(*task)
   when :move
     separator = '→'
     database_move(*task.drop(1))
     update_references(*task)
   when :insert
     separator = '↓'
     database_insert(*task.drop(1))
     update_references(*task)
   when :delete
     new_id = determine_type(type)[0].drop(1).size
     task.size == 3 ? task << new_id : task[-1] = new_id
     database_delete(type, old_id)
     update_references(*task)
   when :update
     separator = '↑'
     update_references(*task)
   else
     error = true
     puts "XTask #{index + 1}: Skipped - #{task_type}: invalid task type"
   end unless type == :self_switch
   if type == :self_switch
     case task_type
     when :swap
       separator = '↔'
       update_references(*task)
     when :update
       separator = '→'
       update_references(*task)
     else
       error = true
       puts "XTask #{index + 1}: Skipped - #{task_type}: invalid task type " +
         'for self switch object type'
     end
   else
     save_data(*determine_type(type, true)) unless error
   end
   if task_type == :delete
     puts "✓Task #{index + 1}: Completed - #{task_type}: #{type} #{old_id}"
   elsif !error
     puts "✓Task #{index + 1}: Completed - #{task_type}: #{type} #{old_id} " +
       "#{separator} #{new_id}"
   end
 end
 #--------------------------------------------------------------------------
 # * Present Database Organizer Completion Message
 #--------------------------------------------------------------------------
 def self.database_organizer_done
   message = "Database organization has been performed successfully! Close and
              reopen your project for the changes to show in the database. You
              can now disable the Gambit Database Organizer script or change
              the tasks to prevent them from being repeated."
   title   = "Gambit Database Organizer: Successful"
   message.gsub!(/\s+/," ").gsub!(/! C/,"!\n\nC").gsub!(/. Y/,".\n\nY")
   win32 = Win32API.new("user32", "MessageBox", ['i', 'p', 'p', 'i'], 'i')
   win32.call(0, message, title, 64)
   exit
 end
 #--------------------------------------------------------------------------
 # * Delete Database Object
 #--------------------------------------------------------------------------
 def self.database_delete(type, old_id)
   array = determine_type(type)[0]
   array.delete_at(old_id)
   array << array[-1].class.new
   return if type == :switch || type == :variable
   array[old_id..array.size - 1].each_with_index do |object, index|
     object.id = index + old_id
   end
 end
 #--------------------------------------------------------------------------
 # * Insert Database Object
 #--------------------------------------------------------------------------
 def self.database_insert(type, old_id, new_id)
   array = determine_type(type)[0]
   array.insert(new_id, array.delete_at(old_id))
   return if type == :switch || type == :variable
   array[[old_id, new_id].min..[old_id, new_id].max].each_with_index do
     |object, index|
     object.id = index + [old_id, new_id].min
   end
 end
 #--------------------------------------------------------------------------
 # * Move Database Object
 #--------------------------------------------------------------------------
 def self.database_move(type, old_id, new_id)
   return if old_id == new_id
   array = determine_type(type)[0]
   array[new_id] = array[old_id]
   array[new_id].id = new_id unless type == :switch || type == :variable
   array[old_id] = array[old_id].class.new unless type == :self_switch
   return if type == :switch || type == :variable
   array[old_id].id = old_id
 end
 #--------------------------------------------------------------------------
 # * Swap Database Objects
 #--------------------------------------------------------------------------
 def self.database_swap(type, old_id, new_id)
   array = determine_type(type)[0]
   array.swap!(old_id, new_id)
   return if type == :switch || type == :variable
   array[old_id].id = old_id
   array[new_id].id = new_id
 end
 #--------------------------------------------------------------------------
 # * Get Data and File Name of Type
 #--------------------------------------------------------------------------
 def self.determine_type(type, save = false)
   case type
   when :actor
     array = $data_actors
     file = "Data/Actors.rvdata2"
   when :animation
     array = $data_animations
     file = "Data/Animations.rvdata2"
   when :armor
     array = $data_armors
     file = "Data/Armors.rvdata2"
   when :class
     array = $data_classes
     file = "Data/Classes.rvdata2"
   when :common_event
     array = $data_common_events
     file = "Data/CommonEvents.rvdata2"
   when :enemy
     array = $data_enemies
     file = "Data/Enemies.rvdata2"
   when :item
     array = $data_items
     file = "Data/Items.rvdata2"
   when :self_switch
     array = [*'A'..'D']
     file = false
   when :skill
     array = $data_skills
     file = "Data/Skills.rvdata2"
   when :state
     array = $data_states
     file = "Data/States.rvdata2"
   when :switch
     array = save ? $data_system : $data_system.switches
     file = "Data/System.rvdata2"
   when :tileset
     array = $data_tilesets
     file = "Data/Tilesets.rvdata2"
   when :troop
     array = $data_troops
     file = "Data/Troops.rvdata2"
   when :variable
     array = save ? $data_system : $data_system.variables
     file = "Data/System.rvdata2"
   when :weapon
     array = $data_weapons
     file = "Data/Weapons.rvdata2"
   end
   [array, file]
 end
 #--------------------------------------------------------------------------
 # * Update References to Object IDs and Save Data
 #--------------------------------------------------------------------------
 def self.update_references(*args)
   type = args[1]
   #------------------------------------------------------------------------
   # * Modify Map References to Self Switches
   #------------------------------------------------------------------------
   if type == :self_switch
     file = sprintf("Data/Map%03d.rvdata2", args[-1])
     map = load_data(file)
     map.events.values.each do |event|
       event.pages.each do |page|
         page.condition.self_switch_ch.dborg!(*args)
         change_event_references(*args, page)
       end
     end
     save_data(map, file)
     return
   end
   #------------------------------------------------------------------------
   # * Modify Common Event References to IDs
   #------------------------------------------------------------------------
   $data_common_events.drop(1).each do |page|
     page.switch_id = page.switch_id.dborg(*args) if type == :switch
     change_event_references(*args, page)
   end
   save_data($data_common_events, "Data/CommonEvents.rvdata2")
   #------------------------------------------------------------------------
   # * Modify Map References to IDs
   #------------------------------------------------------------------------
   $data_mapinfos.keys.each do |map_id|
     file = sprintf("Data/Map%03d.rvdata2", map_id)
     map = load_data(file)
     map.tileset_id = map.tileset_id.dborg(*args) if type == :tileset
     map.encounter_list.each do |encounter|
       encounter.troop_id = encounter.troop_id.dborg(*args)
     end if type == :troop
     map.events.values.each do |event|
       event.pages.each do |page|
         case type
         when :actor
           page.condition.actor_id = page.condition.actor_id.dborg(*args)
         when :item
           page.condition.item_id = page.condition.item_id.dborg(*args)
         when :switch
           page.condition.switch1_id = page.condition.switch1_id.dborg(*args)
           page.condition.switch2_id = page.condition.switch2_id.dborg(*args)
           page.move_route.list.each do |move_command|
             next unless move_command.code == 27 || move_command.code == 28
             move_command.parameters[0] =
               move_command.parameters[0].dborg(*args)
           end
         when :variable
           page.condition.variable_id = page.condition.variable_id.dborg(*args)
         end
         change_event_references(*args, page)
       end
     end
     save_data(map, file)
   end
   #------------------------------------------------------------------------
   # * Modify Troop References to IDs
   #------------------------------------------------------------------------
   $data_troops.drop(1).each do |troop|
     troop.members.each do |member|
       member.enemy_id = member.enemy_id.dborg(*args)
     end if type == :enemy
     troop.pages.each do |page|
       page.condition.actor_id = page.condition.actor_id.dborg(*args) if
         type == :actor
       page.condition.switch_id = page.condition.switch_id.dborg(*args) if
         type == :switch
       change_event_references(*args, page)
     end
   end
   save_data($data_troops, "Data/Troops.rvdata2")
   #------------------------------------------------------------------------
   # * Modify System References to Actor IDs
   #------------------------------------------------------------------------
   if type == :actor
     $data_system.party_members.map! {|id| id.dborg(*args) }
     $data_system.test_battlers.each do |battler|
       battler.actor_id = battler.actor_id.dborg(*args)
     end
     save_data($data_system, "Data/System.rvdata2")
   end
   #------------------------------------------------------------------------
   # * Modify Item, Skill, and Weapon References to Animation IDs
   #------------------------------------------------------------------------
   if type == :animation
     ($data_skills | $data_items | $data_weapons).compact.each do |object|
       object.animation_id = object.animation_id.dborg(*args)
     end
     save_data($data_skills,  "Data/Skills.rvdata2")
     save_data($data_items,   "Data/Items.rvdata2")
     save_data($data_weapons, "Data/Weapons.rvdata2")
   end
   #------------------------------------------------------------------------
   # * Modify Actor References to Class IDs
   #------------------------------------------------------------------------
   if type == :class
     $data_actors.drop(1).each do |actor|
       actor.class_id = actor.class_id.dborg(*args)
     end
     save_data($data_actors, "Data/Actors.rvdata2")
   end
   #------------------------------------------------------------------------
   # * Modify Class References to Skill IDs
   #------------------------------------------------------------------------
   if type == :skill
     $data_classes.drop(1).each do |class_object|
       class_object.learnings.each do |learning|
         learning.skill_id = learning.skill_id.dborg(*args)
       end
     end
   end
   #------------------------------------------------------------------------
   # * Modify Skill and Item References to Variable IDs
   #------------------------------------------------------------------------
   if type == :variable
     ($data_skills | $data_items).compact.map {|obj| obj.damage.formula }.
       each do |formula|
       formula.gsub!(/v\[(\d+)\]/) { "v[#{$1.to_i.dborg(*args)}]" }
     end
     save_data($data_skills, "Data/Skills.rvdata2")
     save_data($data_items,  "Data/Items.rvdata2")
   end
   #------------------------------------------------------------------------
   # * Modify Enemy References to Armor, Item, and Weapon IDs
   #------------------------------------------------------------------------
   if [:armor, :item, :weapon].include?(type)
     $data_enemies.drop(1).each do |enemy|
       enemy.drop_items.each do |item|
         case type
         when :armor
           next unless item.kind == 3
           item.data_id = item.data_id.dborg(*args)
         when :item
           next unless item.kind == 1
           item.data_id = item.data_id.dborg(*args)
         when :weapon
           next unless item.kind == 2
           item.data_id = item.data_id.dborg(*args)
         end
       end
     end
     save_data($data_enemies, "Data/Enemies.rvdata2")
   end
   #------------------------------------------------------------------------
   # * Modify Actor and System References to Armor and Weapon IDs
   #------------------------------------------------------------------------
   if type == :armor || type == :weapon
     $data_actors.drop(1).each do |actor|
       case type
       when :armor
         [*2..4].each do |index|
           actor.equips[index] = actor.equips[index].dborg(*args)
         end
         actor.equips[1] = actor.equips[1].dborg(*args) if (actor.features |
           $data_classes[actor.class_id].features).none? {|feature|
           feature.code == 55 }
       when :weapon
         actor.equips[0] = actor.equips[0].dborg(*args)
         actor.equips[1] = actor.equips[1].dborg(*args) if (actor.features |
           $data_classes[actor.class_id].features).any? {|feature|
           feature.code == 55 }
       end
     end
     save_data($data_actors, "Data/Actors.rvdata2")
     $data_system.test_battlers.each do |battler|
       case type
       when :armor
         [*2..4].each do |index|
           battler.equips[index] = battler.equips[index].dborg(*args)
         end
         battler.equips[1] = battler.equips[1].dborg(*args) if
           ($data_actors[battler.actor_id].features |
           $data_classes[$data_actors[battler.actor_id].class_id].features).
           none? {|feature| feature.code == 55 }
       when :weapon
         battler.equips[0] = battler.equips[0].dborg(*args)
         battler.equips[1] = battler.equips[1].dborg(*args) if
           ($data_actors[battler.actor_id].features |
           $data_classes[$data_actors[battler.actor_id].class_id].features).
           any? {|feature| feature.code == 55 }
       end
     end
     save_data($data_system, "Data/System.rvdata2")
   end
   #------------------------------------------------------------------------
   # * Modify Effect References to Common Event, Skill, and State IDs
   #------------------------------------------------------------------------
   if [:common_event, :skill, :state].include?(type)
     ($data_skills | $data_items).compact.map {|obj| obj.effects }.flatten.
       each do |effect|
       case type
       when :common_event
         next unless effect.code == 44
         effect.data_id = effect.data_id.dborg(*args)
       when :skill
         next unless effect.code == 43
         effect.data_id = effect.data_id.dborg(*args)
       when :state
         next unless effect.code == 21 || effect.code == 22
         effect.data_id = effect.data_id.dborg(*args)
       end
     end
     save_data($data_skills, "Data/Skills.rvdata2")
     save_data($data_items,  "Data/Items.rvdata2")
   end
   #------------------------------------------------------------------------
   # * Modify Feature References to Skill and State IDs
   #------------------------------------------------------------------------
   if type == :skill || type == :state
     ($data_actors | $data_classes | $data_weapons | $data_armors |
       $data_enemies | $data_states).compact.map {|obj| obj.features }.flatten.
       each do |feature|
       case type
       when :skill
         next unless feature.code == 43 || feature.code == 44
         feature.data_id = feature.data_id.dborg(*args)
       when :state
         next unless [13, 14, 32].include?(feature.code)
         feature.data_id = feature.data_id.dborg(*args)
       end
     end
     save_data($data_actors,  "Data/Actors.rvdata2")
     save_data($data_classes, "Data/Classes.rvdata2")
     save_data($data_weapons, "Data/Weapons.rvdata2")
     save_data($data_armors,  "Data/Armors.rvdata2")
     save_data($data_enemies, "Data/Enemies.rvdata2")
     save_data($data_states,  "Data/States.rvdata2")
   end
   #------------------------------------------------------------------------
   # * Modify Enemy References to Skill, State, and Switch IDs
   #------------------------------------------------------------------------
   if [:skill, :state, :switch].include?(type)
     $data_enemies.drop(1).each do |enemy|
       enemy.actions.each do |action|
         case type
         when :skill
           action.skill_id = action.skill_id.dborg(*args)
         when :state
           next unless action.condition_type == 4
           action.condition_param1 = action.condition_param1.dborg(*args)
         when :switch
           next unless action.condition_type == 6
           action.condition_param1 = action.condition_param1.dborg(*args)
         end
       end
     end
     save_data($data_enemies, "Data/Enemies.rvdata2")
   end
 end
 #--------------------------------------------------------------------------
 # * Determine Type to Modify in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_references(*args)
   case args[1]
   when :actor
     change_event_actors(*args)
   when :animation
     change_event_animations(*args)
   when :armor
     change_event_armors(*args)
   when :class
     change_event_classes(*args)
   when :common_event
     change_event_common_events(*args)
   when :enemy
     change_event_enemies(*args)
   when :item
     change_event_items(*args)
   when :self_switch
     change_event_self_switches(*args)
   when :skill
     change_event_skills(*args)
   when :switch
     change_event_switches(*args)
   when :state
     change_event_states(*args)
   when :tileset
     change_event_tilesets(*args)
   when :troop
     change_event_troops(*args)
   when :variable
     change_event_variables(*args)
   when :weapon
     change_event_weapons(*args)
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Actor IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_actors(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 111
       next unless command.parameters[0] == 4
       command.parameters[1] = command.parameters[1].dborg(*args)
     when 122
       next unless command.parameters[3..4] == [3, 3]
       command.parameters[5] = command.parameters[5].dborg(*args)
     when 129, 303, 319..322, 324
       command.parameters[0] = command.parameters[0].dborg(*args)
     when 311..318
       next unless command.parameters[0] == 0
       command.parameters[1] = command.parameters[1].dborg(*args)
     when 339
       next unless command.parameters[0] == 1
       command.parameters[1] = command.parameters[1].dborg(*args)
     when 401, 405
       command.parameters[0].gsub!(/\\(N)\[(\d+)\]/i) {
         "\\#{$1}[#{$2.to_i.dborg(*args)}]" }
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Animation IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_animations(*args)
   page = args.pop
   page.list.each do |command|
     next unless command.code == 212 || command.code == 337
     command.parameters[1] = command.parameters[1].dborg(*args)
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Armor IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_armors(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 111
       next unless command.parameters.values_at(*[0, 2]) == [4, 5] ||
         command.parameters[0] == 10
       if command.parameters[0] == 10
         command.parameters[1] = command.parameters[1].dborg(*args)
       else
         command.parameters[3] = command.parameters[3].dborg(*args)
       end
     when 122
       next unless command.parameters[3..4] == [3, 2]
       command.parameters[5] = command.parameters[5].dborg(*args)
     when 128
       command.parameters[0] = command.parameters[0].dborg(*args)
     when 302, 605
       next unless command.parameters[0] == 2
       command.parameters[1] = command.parameters[1].dborg(*args)
     when 319
       next unless command.parameters[1] > 0
       command.parameters[2] = command.parameters[2].dborg(*args)
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Class IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_classes(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 111
       next unless command.parameters.values_at(*[0, 2]) == [4, 2]
       command.parameters[3] = command.parameters[3].dborg(*args)
     when 321
       command.parameters[1] = command.parameters[1].dborg(*args)
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Common Event IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_common_events(*args)
   page = args.pop
   page.list.each do |command|
     next unless command.code == 117
     command.parameters[0] = command.parameters[0].dborg(*args)
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Enemy IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_enemies(*args)
   page = args.pop
   page.list.each do |command|
     next unless command.code == 336
     command.parameters[1] = command.parameters[1].dborg(*args)
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Item IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_items(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 111
       next unless command.parameters[0] == 8
       command.parameters[1] = command.parameters[1].dborg(*args)
     when 122
       next unless command.parameters[3..4] == [3, 0]
       command.parameters[5] = command.parameters[5].dborg(*args)
     when 126
       command.parameters[0] = command.parameters[0].dborg(*args)
     when 302, 605
       next unless command.parameters[0] == 0
       command.parameters[1] = command.parameters[1].dborg(*args)
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Self Switches in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_self_switches(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 111
       next unless command.parameters[0] == 2
       command.parameters[1].dborg!(*args)
     when 123
       command.parameters[0].dborg!(*args)
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Skill IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_skills(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 111
       next unless command.parameters.values_at(*[0, 2]) == [4, 3]
       command.parameters[3] = command.parameters[3].dborg(*args)
     when 318
       command.parameters[3] = command.parameters[3].dborg(*args)
     when 339
       command.parameters[2] = command.parameters[2].dborg(*args)
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Switch IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_switches(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 111
       next unless command.parameters[0] == 0
       command.parameters[1] = command.parameters[1].dborg(*args)
     when 121
       command.parameters[0] = command.parameters[0].dborg(*args)
       command.parameters[1] = command.parameters[1].dborg(*args)
     when 205
       command.parameters[1].list.each do |move_command|
         next unless move_command.code == 27 || move_command.code == 28
         move_command.parameters[0] = move_command.parameters[0].dborg(*args)
       end
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Modify State IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_states(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 111
       next unless command.parameters.values_at(*[0, 2]) == [4, 6] ||
         command.parameters.values_at(*[0, 2]) == [5, 1]
       command.parameters[3] = command.parameters[3].dborg(*args)
     when 313
       command.parameters[3] = command.parameters[3].dborg(*args)
     when 333
       command.parameters[2] = command.parameters[2].dborg(*args)
     end
   end
 end


Dernière édition par crackerwood le Jeu 26 Nov 2015 - 20:45, édité 1 fois
avatar
crackerwood
Membre

Nombre de messages : 343
Age : 33
Localisation : Derrière son pc y parait
Distinction : aucune
Date d'inscription : 03/08/2008

Re: Organiser sa base de donnée

le Jeu 26 Nov 2015 - 20:44
Suite du script :
Code:
 #--------------------------------------------------------------------------
 # * Modify Tileset IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_tilesets(*args)
   page = args.pop
   page.list.each do |command|
     next unless command.code == 282
     command.parameters[0] = command.parameters[0].dborg(*args)
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Troop IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_troops(*args)
   page = args.pop
   page.list.each do |command|
     next unless command.code == 301 && command.parameters[0] == 0
     command.parameters[1] = command.parameters[1].dborg(*args)
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Variable IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_variables(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 103, 104
       command.parameters[0] = command.parameters[0].dborg(*args)
     when 111
       next unless command.parameters[0] == 1
       command.parameters[1] = command.parameters[1].dborg(*args)
       next unless command.parameters[2] == 1
       command.parameters[3] = command.parameters[3].dborg(*args)
     when 122
       command.parameters[0] = command.parameters[0].dborg(*args)
       command.parameters[1] = command.parameters[1].dborg(*args)
       next unless command.parameters[3] == 1
       command.parameters[4] = command.parameters[4].dborg(*args)
     when 125
       next unless command.parameters[1] == 1
       command.parameters[2] = command.parameters[2].dborg(*args)
     when 126..128, 331, 332
       next unless command.parameters[2] == 1
       command.parameters[3] = command.parameters[3].dborg(*args)
     when 201
       next unless command.parameters[0] == 1
       command.parameters[1] = command.parameters[1].dborg(*args)
       command.parameters[2] = command.parameters[2].dborg(*args)
       command.parameters[3] = command.parameters[3].dborg(*args)
     when 202
       next unless command.parameters[1] == 1
       command.parameters[2] = command.parameters[2].dborg(*args)
       command.parameters[3] = command.parameters[3].dborg(*args)
       command.parameters[4] = command.parameters[4].dborg(*args)
     when 203
       next unless command.parameters[1] == 1
       command.parameters[2] = command.parameters[2].dborg(*args)
       command.parameters[3] = command.parameters[3].dborg(*args)
     when 231, 232
       next unless command.parameters[3] == 1
       command.parameters[4] = command.parameters[4].dborg(*args)
       command.parameters[5] = command.parameters[5].dborg(*args)
     when 285
       command.parameters[0] = command.parameters[0].dborg(*args)
       next unless command.parameters[2] == 1
       command.parameters[3] = command.parameters[3].dborg(*args)
       command.parameters[4] = command.parameters[4].dborg(*args)
     when 301, 313, 314, 318
       next unless command.parameters[0] == 1
       command.parameters[1] = command.parameters[1].dborg(*args)
     when 311, 312, 315, 316
       command.parameters[1] = command.parameters[1].dborg(*args) if
         command.parameters[0] == 1
       command.parameters[4] = command.parameters[4].dborg(*args) if
         command.parameters[3] == 1
     when 317
       command.parameters[1] = command.parameters[1].dborg(*args) if
         command.parameters[0] == 1
       command.parameters[5] = command.parameters[5].dborg(*args) if
         command.parameters[4] == 1
     when 401, 405
       command.parameters[0].gsub!(/\\(V)\[(\d+)\]/i) {
         "\\#{$1}[#{$2.to_i.dborg(*args)}]" }
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Modify Weapon IDs in Event Commands
 #--------------------------------------------------------------------------
 def self.change_event_weapons(*args)
   page = args.pop
   page.list.each do |command|
     case command.code
     when 111
       next unless command.parameters.values_at(*[0, 2]) == [4, 4] ||
         command.parameters[0] == 9
       if command.parameters[0] == 9
         command.parameters[1] = command.parameters[1].dborg(*args)
       else
         command.parameters[3] = command.parameters[3].dborg(*args)
       end
     when 122
       next unless command.parameters[3..4] == [3, 1]
       command.parameters[5] = command.parameters[5].dborg(*args)
     when 127
       command.parameters[0] = command.parameters[0].dborg(*args)
     when 302, 605
       next unless command.parameters[0] == 1
       command.parameters[1] = command.parameters[1].dborg(*args)
     when 319
       next unless command.parameters[1] == 0
       command.parameters[2] = command.parameters[2].dborg(*args)
     end
   end
 end
end

#==============================================================================
# ** SceneManager
#------------------------------------------------------------------------------
#  This module manages scene transitions. For example, it can handle
# hierarchical structures such as calling the item screen from the main menu
# or returning from the item screen to the main menu.
#==============================================================================

module SceneManager
 class <<self
   alias gam_dborganizer_first_scene_class first_scene_class
 end
 #--------------------------------------------------------------------------
 # * Get First Scene Class
 #--------------------------------------------------------------------------
 def self.first_scene_class
   Gambit::DatabaseOrganizer::Enabled && !$BTEST ? Scene_DatabaseOrganizer :
     gam_dborganizer_first_scene_class
 end
end

#==============================================================================
# ** Window_DatabaseControls
#------------------------------------------------------------------------------
#  This window shows the control explanations on the database organizer screen.
#==============================================================================

class Window_DatabaseControls < Window_Base
 #--------------------------------------------------------------------------
 # * Set Category Controls Text
 #--------------------------------------------------------------------------
 def set_category
   contents.clear
   change_color(system_color)
   draw_text(0, 0, contents_width, line_height, 'Select a database to')
   draw_text(0, line_height, contents_width, line_height,
     'organize.')
 end
 #--------------------------------------------------------------------------
 # * Set Database Controls Text
 #--------------------------------------------------------------------------
 def set_database(old_id)
   contents.clear
   cw = contents_width
   change_color(system_color)
   draw_text(0, line_height * 2, cw / 5 * 3, line_height, "Select #{old_id}:",
     2)
   draw_text(0, line_height * 3, cw / 5 * 3, line_height, "Delete #{old_id}:",
     2)
   draw_text(0, contents_height - line_height, cw / 2, line_height, 'Cancel:',
     2)
   change_color(normal_color)
   draw_text(cw / 5 * 3, line_height * 2, cw, line_height, ' Z / Enter')
   draw_text(cw / 5 * 3, line_height * 3, cw, line_height, ' D')
   draw_text(cw / 2, contents_height - line_height, cw / 2, line_height,
     ' X / Esc')
 end
 #--------------------------------------------------------------------------
 # * Set Pending Database Controls Text
 #--------------------------------------------------------------------------
 def set_pending(old_id, new_id)
   contents.clear
   cw = contents_width
   change_color(system_color)
   draw_text(0, line_height * 2, cw / 5 * 3, line_height,
     "Swap with #{new_id}:", 2)
   draw_text(0, line_height * 3, cw / 5 * 3, line_height,
     "Move to #{new_id}:", 2)
   draw_text(0, line_height * 4, cw / 5 * 3, line_height,
     "Insert at #{new_id}:", 2)
   draw_text(0, line_height * 5, cw / 5 * 3, line_height,
     "Update to #{new_id}:", 2)
   draw_text(0, contents_height - line_height, cw / 2, line_height, 'Cancel:',
     2)
   change_color(normal_color)
   draw_text(0, line_height * 0, cw, line_height, "Original ID: #{old_id}", 1)
   draw_text(cw / 5 * 3, line_height * 2, cw, line_height, ' Z / Enter')
   draw_text(cw / 5 * 3, line_height * 3, cw, line_height, ' S')
   draw_text(cw / 5 * 3, line_height * 4, cw, line_height, ' Shift')
   draw_text(cw / 5 * 3, line_height * 5, cw, line_height, ' A')
   draw_text(cw / 2, contents_height - line_height, cw / 2, line_height,
     ' X / Esc')
 end
 #--------------------------------------------------------------------------
 # * Set Map Database Controls Text
 #--------------------------------------------------------------------------
 def set_map
   contents.clear
   change_color(system_color)
   draw_text(0, 0, contents_width, line_height, 'Select a map to organize.')
 end
 #--------------------------------------------------------------------------
 # * Set Self Switch Database Controls Text
 #--------------------------------------------------------------------------
 def set_self_switch_database(map, old_id)
   contents.clear
   cw = contents_width
   change_color(system_color)
   draw_text(0, line_height * 2, cw / 5 * 3, line_height, "Select #{old_id}:",
     2)
   draw_text(0, contents_height - line_height, cw / 2, line_height, 'Cancel:',
     2)
   change_color(normal_color)
   draw_text(0, line_height * 0, cw, line_height, "Map: #{map}", 1)
   draw_text(cw / 5 * 3, line_height * 2, cw, line_height, ' Z / Enter')
   draw_text(cw / 2, contents_height - line_height, cw / 2, line_height,
     ' X / Esc')
 end
 #--------------------------------------------------------------------------
 # * Set Pending Self Switch Database Controls Text
 #--------------------------------------------------------------------------
 def set_pending_self_switch_database(map, old_id, new_id)
   contents.clear
   cw = contents_width
   change_color(system_color)
   draw_text(0, line_height * 3, cw / 5 * 3, line_height,
     "Swap with #{new_id}:", 2)
   draw_text(0, line_height * 4, cw / 5 * 3, line_height,
     "Update to #{new_id}:", 2)
   draw_text(0, contents_height - line_height, cw / 2, line_height, 'Cancel:',
     2)
   change_color(normal_color)
   draw_text(0, line_height * 0, cw, line_height, "Map: #{map}", 1)
   draw_text(0, line_height * 1, cw, line_height, "Original Switch: #{old_id}",
     1)
   draw_text(cw / 5 * 3, line_height * 3, cw, line_height, ' Z / Enter')
   draw_text(cw / 5 * 3, line_height * 4, cw, line_height, ' A')
   draw_text(cw / 2, contents_height - line_height, cw / 2, line_height,
     ' X / Esc')
 end
end

#==============================================================================
# ** Window_DatabaseList
#------------------------------------------------------------------------------
#  This window displays a list of database objects on the database organizer
# screen.
#==============================================================================

class Window_DatabaseList < Window_Selectable
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader   :pending_index            # Pending position
 attr_accessor :map                      # selected map id
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize(x, y, width, height)
   super
   @category = :none
   @map = false
   @pending_index = -1
 end
 #--------------------------------------------------------------------------
 # * Set Category
 #--------------------------------------------------------------------------
 def category=(category)
   return if @category == category
   @category = category
   refresh unless @category == :none
   self.oy = 0
 end
 #--------------------------------------------------------------------------
 # * Set Controls Window
 #--------------------------------------------------------------------------
 def controls_window=(controls_window)
   @controls_window = controls_window
   call_update_help
 end
 #--------------------------------------------------------------------------
 # * Set Pending Position
 #--------------------------------------------------------------------------
 def pending_index=(index)
   last_pending_index = @pending_index
   @pending_index = index
   redraw_item(@pending_index)
   redraw_item(last_pending_index)
 end
 #--------------------------------------------------------------------------
 # * Get Number of Items
 #--------------------------------------------------------------------------
 def item_max
   @data ? @data.size : 1
 end
 #--------------------------------------------------------------------------
 # * Get Item Height
 #--------------------------------------------------------------------------
 def item_height
   @category == :actor ? 34 : line_height
 end
 #--------------------------------------------------------------------------
 # * Get Item
 #--------------------------------------------------------------------------
 def item
   @data && index >= 0 ? @data[index] : nil
 end
 #--------------------------------------------------------------------------
 # * Create Item List
 #--------------------------------------------------------------------------
 def make_item_list
   if @category == :self_switch && @map
     @data = DataManager::determine_type(@category)[0]
   elsif @category == :self_switch
     @data = $data_mapinfos.map do |map_id, info|
       map = RPG::BaseItem.new
       map.id = map_id
       map.name = info.name
       map
     end
   else
     @data = DataManager::determine_type(@category)[0].drop(1)
   end
 end
 #--------------------------------------------------------------------------
 # * Draw Item
 #--------------------------------------------------------------------------
 def draw_item(index)
   item = @data[index]
   if item
     rect = item_rect(index)
     rect.x += 2
     rect.width -= 4
     draw_item_background(index)
     draw_item_id(rect, item, index)
     draw_item_name(item, rect.x + 38, rect.y, rect.height)
   end
 end
 #--------------------------------------------------------------------------
 # * Draw Background for Item
 #--------------------------------------------------------------------------
 def draw_item_background(index)
   if index == @pending_index
     contents.fill_rect(item_rect(index), pending_color)
   end
 end
 #--------------------------------------------------------------------------
 # * Draw ID of Item
 #--------------------------------------------------------------------------
 def draw_item_id(rect, item, index)
   return if @map
   if @category == :switch || @category == :variable
     draw_text(rect, sprintf("%03d:", index + 1))
   else
     draw_text(rect, sprintf("%03d:", item.id))
   end
 end
 #--------------------------------------------------------------------------
 # * Draw Item Name
 #--------------------------------------------------------------------------
 def draw_item_name(item, x, y, height)
   return unless item
   case @category
   when :actor
     draw_actor_graphic(item, x + 12, y + 33)
     offset = 26
   when :skill, :item, :weapon, :armor, :state
     draw_icon(item.icon_index, x, y)
     offset = 24
   else
     offset = 0
   end
   width = contents_width - x - offset
   if @category == :switch || @category == :variable || @map
     draw_text(x + offset, y, width, height, item)
   else
     draw_text(x + offset, y, width, height, item.name)
   end
 end
 #--------------------------------------------------------------------------
 # * Update Help Text
 #--------------------------------------------------------------------------
 def update_help
   @help_window.set_item(item) if item.respond_to?(:description)
   if @map && @pending_index >= 0
     @controls_window.set_pending_self_switch_database(@map.name,
       @data[@pending_index], item)
   elsif @pending_index >= 0
     @controls_window.set_pending(@pending_index + 1, index + 1)
   elsif @category == :self_switch && !map
     @controls_window.set_map
   elsif @map
     @controls_window.set_self_switch_database(@map.name, item)
   else
     @controls_window.set_database(index + 1)
   end
 end
 #--------------------------------------------------------------------------
 # * Redraw Item
 #--------------------------------------------------------------------------
 def redraw_item(index)
   @data[index] = DataManager::determine_type(@category)[0].drop(1)[index] if
     @category != :self_switch
   super
 end
 #--------------------------------------------------------------------------
 # * Redraw Range of Items
 #--------------------------------------------------------------------------
 def refresh_range(first, last)
   for number in [*[first, last].min..[first, last].max]
     redraw_item(number)
   end
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   make_item_list
   create_contents
   draw_all_items
 end
 #--------------------------------------------------------------------------
 # * Handling Processing for OK and Cancel Etc.
 #--------------------------------------------------------------------------
 def process_handling
   super
   return unless open? && active
   return process_delete if Input.trigger?(:Z) && @category != :self_switch
   return unless @pending_index >= 0
   return process_move   if Input.trigger?(:Y) && @category != :self_switch
   return process_insert if Input.trigger?(:A) && @category != :self_switch
   return process_update if Input.trigger?(:X)
 end
 #--------------------------------------------------------------------------
 # * Processing When OK Button Is Pressed
 #--------------------------------------------------------------------------
 def process_ok(task_type = :ok)
   Sound.play_ok
   Input.update
   deactivate
   call_handler(task_type)
 end
 #--------------------------------------------------------------------------
 # * Processing When Move Button Is Pressed
 #--------------------------------------------------------------------------
 def process_move
   process_ok(:move)
 end
 #--------------------------------------------------------------------------
 # * Processing When Insert Button Is Pressed
 #--------------------------------------------------------------------------
 def process_insert
   process_ok(:insert)
 end
 #--------------------------------------------------------------------------
 # * Processing When Delete Button Is Pressed
 #--------------------------------------------------------------------------
 def process_delete
   @pending_index >= 0 ? process_cancel : process_ok(:delete)
 end
 #--------------------------------------------------------------------------
 # * Processing When Update Button Is Pressed
 #--------------------------------------------------------------------------
 def process_update
   process_ok(:update)
 end
end

#==============================================================================
# ** Window_DatabaseCategory
#------------------------------------------------------------------------------
#  This window is for selecting a category from a list of databases on the
# database organizer screen.
#==============================================================================

class Window_DatabaseCategory < Window_Command
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader   :database_window
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(0, 0)
 end
 #--------------------------------------------------------------------------
 # * Get Window Width
 #--------------------------------------------------------------------------
 def window_width
   Graphics.width
 end
 #--------------------------------------------------------------------------
 # * Get Number of Lines to Show
 #--------------------------------------------------------------------------
 def visible_line_number
   3
 end
 #--------------------------------------------------------------------------
 # * Get Digit Count
 #--------------------------------------------------------------------------
 def col_max
   return 5
 end
 #--------------------------------------------------------------------------
 # * Get Spacing for Items Arranged Side by Side
 #--------------------------------------------------------------------------
 def spacing
   return 0
 end
 #--------------------------------------------------------------------------
 # * Get Rectangle for Drawing Items (for Text)
 #--------------------------------------------------------------------------
 def item_rect_for_text(index)
   item_rect(index)
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   super
   @database_window.category = current_symbol if @database_window
 end
 #--------------------------------------------------------------------------
 # * Create Command List
 #--------------------------------------------------------------------------
 def make_command_list
   add_command('Actors',        :actor)
   add_command('Classes',       :class)
   add_command('Skills',        :skill)
   add_command('Items',         :item)
   add_command('Weapons',       :weapon)
   add_command('Armors',        :armor)
   add_command('Enemies',       :enemy)
   add_command('Troops',        :troop)
   add_command('States',        :state)
   add_command('Animations',    :animation)
   add_command('Tilesets',      :tileset)
   add_command('Common Events', :common_event)
   add_command('Switches',      :switch)
   add_command('Variables',     :variable)
   add_command('Self Switches', :self_switch)
 end
 #--------------------------------------------------------------------------
 # * Get Alignment
 #--------------------------------------------------------------------------
 def alignment
   return 1
 end
 #--------------------------------------------------------------------------
 # * Set Database Window
 #--------------------------------------------------------------------------
 def database_window=(database_window)
   @database_window = database_window
   update
 end
end

#==============================================================================
# ** Scene_DatabaseOrganizer
#------------------------------------------------------------------------------
#  This class performs the database organizer screen processing.
#==============================================================================

class Scene_DatabaseOrganizer < Scene_Base
 #--------------------------------------------------------------------------
 # * Start Processing
 #--------------------------------------------------------------------------
 def start
   Graphics.resize_screen(640, 480)
   super
   @task_count = 0
   create_help_window
   create_category_window
   create_database_window
   create_controls_window
 end
 #--------------------------------------------------------------------------
 # * Create Help Window
 #--------------------------------------------------------------------------
 def create_help_window
   @help_window = Window_Help.new
   @help_window.y = Graphics.height - @help_window.height
   @help_window.viewport = @viewport
 end
 #--------------------------------------------------------------------------
 # * Create Category Window
 #--------------------------------------------------------------------------
 def create_category_window
   @category_window = Window_DatabaseCategory.new
   @category_window.viewport = @viewport
   @category_window.help_window = @help_window
   @category_window.set_handler(:ok,     method(:on_category_ok))
   @category_window.set_handler(:cancel, method(:on_category_cancel))
 end
 #--------------------------------------------------------------------------
 # * Create Database Window
 #--------------------------------------------------------------------------
 def create_database_window
   wy = @category_window.height
   wh = Graphics.height - wy - @help_window.height
   @database_window = Window_DatabaseList.new(0, wy, Graphics.width / 2, wh)
   @database_window.viewport = @viewport
   @database_window.help_window = @help_window
   @database_window.set_handler(:ok,     method(:on_database_ok))
   @database_window.set_handler(:move,   method(:on_database_move))
   @database_window.set_handler(:insert, method(:on_database_insert))
   @database_window.set_handler(:delete, method(:on_database_delete))
   @database_window.set_handler(:update, method(:on_database_update))
   @database_window.set_handler(:cancel, method(:on_database_cancel))
   @category_window.database_window = @database_window
 end
 #--------------------------------------------------------------------------
 # * Create Controls Window
 #--------------------------------------------------------------------------
 def create_controls_window
   wx = @database_window.width
   wy = @category_window.height
   wh = @database_window.height
   @controls_window = Window_DatabaseControls.new(wx, wy, wx, wh)
   @controls_window.viewport = @viewport
   @controls_window.set_category
   @database_window.controls_window = @controls_window
 end
 #--------------------------------------------------------------------------
 # * Category [OK]
 #--------------------------------------------------------------------------
 def on_category_ok
   @database_window.activate
   @database_window.select(0)
 end
 #--------------------------------------------------------------------------
 # * Category [Cancel]
 #--------------------------------------------------------------------------
 def on_category_cancel
   DataManager::database_organizer_done
 end
 #--------------------------------------------------------------------------
 # * Database [OK]
 #--------------------------------------------------------------------------
 def on_database_ok(task_type = :swap)
   if @database_window.pending_index >= 0
     DataManager::organize_database(task(task_type), @task_count)
     @task_count += 1
     @database_window.refresh_range(@database_window.pending_index,
       @database_window.index) if task_type == :insert
     @database_window.pending_index = -1
     @database_window.redraw_item(@database_window.index) unless
       @category_window.current_symbol == :self_switch
   elsif task_type == :delete
     DataManager::organize_database(task(task_type), @task_count)
     @task_count += 1
     @database_window.refresh_range(@database_window.index,
       @database_window.item_max - 1)
   elsif @category_window.current_symbol == :self_switch &&
     !@database_window.map
     @database_window.map = @database_window.item
     @database_window.select(0)
     @database_window.refresh
   else
     @database_window.pending_index = @database_window.index
   end
   @database_window.activate
 end
 #--------------------------------------------------------------------------
 # * Database [Move]
 #--------------------------------------------------------------------------
 def on_database_move
   on_database_ok(:move)
 end
 #--------------------------------------------------------------------------
 # * Database [Insert]
 #--------------------------------------------------------------------------
 def on_database_insert
   on_database_ok(:insert)
 end
 #--------------------------------------------------------------------------
 # * Database [Delete]
 #--------------------------------------------------------------------------
 def on_database_delete
   on_database_ok(:delete)
 end
 #--------------------------------------------------------------------------
 # * Database [Update]
 #--------------------------------------------------------------------------
 def on_database_update
   on_database_ok(:update)
 end
 #--------------------------------------------------------------------------
 # * Database [Cancel]
 #--------------------------------------------------------------------------
 def on_database_cancel
   if @database_window.pending_index >= 0
     @database_window.pending_index = -1
     @database_window.activate
   elsif @database_window.map
     @database_window.select(@database_window.map.id - 1)
     @database_window.map = false
     @database_window.refresh
     @database_window.activate
   else
     @controls_window.set_category
     @database_window.unselect
     @category_window.activate
   end
 end
 #--------------------------------------------------------------------------
 # * Get Task Array
 #--------------------------------------------------------------------------
 def task(task_type)
   if task_type == :delete
     task = [task_type, @category_window.current_symbol,
        @database_window.index + 1]
   elsif @category_window.current_symbol == :self_switch
     array = DataManager::determine_type(:self_switch)[0]
     task = [task_type, @category_window.current_symbol,
       array[@database_window.pending_index], array[@database_window.index],
       @database_window.map.id]
   else
     task = [task_type, @category_window.current_symbol,
        @database_window.pending_index + 1, @database_window.index + 1]
   end
 end
end

class Array
 #--------------------------------------------------------------------------
 # * Swap Two Elements by Indices
 #--------------------------------------------------------------------------
 def swap!(a, b)
   self[a], self[b] = self[b], self[a]
   self
 end
end

class Integer
 #--------------------------------------------------------------------------
 # * Determine Database Organizer Reference ID
 #--------------------------------------------------------------------------
 def dborg(task_type, type, old_id, new_id)
   value = self
   case task_type
   when :swap
     if self == old_id
       value = new_id
     elsif self == new_id
       value = old_id
     end
   when :move, :update
     value = new_id if self == old_id
   when :insert
     unless self < [old_id, new_id].min || self > [old_id, new_id].max
       if self == old_id
         value = new_id
       elsif old_id < new_id
         value -= 1
       elsif old_id > new_id
         value += 1
       end
     end
   when :delete
     unless self < old_id
       if self == old_id
         value = new_id
       else
         value -= 1
       end
     end
   end
   value
 end
end

class String
 #--------------------------------------------------------------------------
 # * Determine Database Organizer Reference Self Switch
 #--------------------------------------------------------------------------
 def dborg!(task_type, type, old_id, new_id, map_id)
   value = self
   case task_type
   when :swap
     if self == old_id
       value = new_id
     elsif self == new_id
       value = old_id
     end
   when :update
     value = new_id if self == old_id
   end
   self.replace(value)
 end
end
avatar
Wulffen
Membre

Nombre de messages : 246
Age : 29
Distinction : Enflure de service mais on l'aime comme ça [Gel']
Date d'inscription : 02/11/2015
http://r-qsfriends.blogspot.com

Re: Organiser sa base de donnée

le Jeu 26 Nov 2015 - 20:48
traduction s'il te plait. Je n'ai rien compris.

avatar
crackerwood
Membre

Nombre de messages : 343
Age : 33
Localisation : Derrière son pc y parait
Distinction : aucune
Date d'inscription : 03/08/2008

Re: Organiser sa base de donnée

le Ven 27 Nov 2015 - 16:48
Pour faire simple tu as mon tuto n°1 (PHS) qui prends l'interrupteur 01, les variables 1 à 22 et l'événement commun 01.
Mon tuto n°2 (blackjack) utilise les interrupteur 1 à 56, variable 1 à 9 et commun 1 à 4.

Si je veux mixer les deux les interrupteurs et les variables vont "s'écraser" et surtout il y a un risque de bug.

Le script permet de deplacer les interrupteurs, variables et événements communs du tuto n°2 par exemple pour les insérer à la suite du tuto n°1. Le projet prendra les échange y compris dans les événements.
Contenu sponsorisé

Re: Organiser sa base de donnée

Revenir en haut
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum