Advertisement
diamondandplatinum3

DP Core ~ Tutorial Version ~ RGSS3

Oct 2nd, 2013
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.12 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #             DP Core
  3. #             Version: 1.0
  4. #             Author: DiamondandPlatinum3
  5. #             Date: October 2, 2013
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. #  Description:
  8. #
  9. #    This Core Script adds extra classes and additions to existing classes for
  10. #    use by future DiamondandPlatinum3 scripts and/or any other scripter who
  11. #    finds these additions useful.
  12. #
  13. #   New Additions Include:
  14. #     Module:   DPCore:               A Module which houses the new Classes.
  15. #     Class:    ScreenFilledSprite:   A Sprite which automatically fits to screen.
  16. #     Class:    TimeTracker:          A Class Which Keeps Track of Real-Time once Activated.
  17. #     Edited:   Window_MenuCommand:   Now Allows for quicker menu option creation.
  18. #     Module:   GameEvents:           A Module to Contain Code for interaction with GameEvents.
  19. #
  20. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21. ($diamondandplatinum3_scripts ||= {})[:DPCore] = true
  22. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23.  
  24.  
  25.  
  26.  
  27. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  28. # **  New Class:   Screen Filled Sprite
  29. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  30. # Creates a sprite which automatically fills the screen and can be disposed
  31. # without needing to dispose of the included bitmap.
  32. # Everything beyond initialisation is still accessed the way a normal
  33. # Sprite is accessed.
  34. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  35. module DPCore
  36.   class ScreenFilledSprite < Sprite
  37.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  38.     # * New Method:   Object Initialisation
  39.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40.     # Filename:   Filename of the Sprite Image, includes path if necessary.
  41.     # Visible:    Will be visible? : true by default
  42.     # Z:          The Z Value of this sprite on initialisation : 1 by default
  43.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44.     def initialize(filename, visible = true, z = 1)
  45.       super()
  46.       self.bitmap   = Bitmap.new(filename)
  47.       self.x        = 0
  48.       self.y        = 0
  49.       self.z        = z
  50.       self.zoom_x   = (Graphics.width.to_f / self.bitmap.width)
  51.       self.zoom_y   = (Graphics.height.to_f / self.bitmap.height)
  52.       self.visible  = visible
  53.     end
  54.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55.     # * New Method:   Dispose
  56.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  57.     def dispose()
  58.       self.bitmap.dispose()       unless self.bitmap.disposed?
  59.       super()
  60.     end
  61.   end
  62. end
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  71. # **  New Class:   Time Tracker
  72. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. # Once initialised, this class keeps track of time in seconds.
  74. # All instances of the TimeTracker class are updated automatically if you
  75. # have chosen to allow themselves to be added to the list (true by default).
  76. #
  77. # Once initialised, simply call the ' time_up? ' method to see if the time
  78. # is up for this TimeTracker.
  79. # Call ' dispose ' once finished.
  80. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  81. module DPCore
  82.   class TimeTracker
  83.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  84.     # *+ Public Instance Variables
  85.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86.     attr_reader :current_frame  # Current Frame the Tracker is on: Use to Reset Tracker.
  87.     attr_reader :seconds        # Seconds until TimeUp: Change to Increase/Decrease the Wait Time.
  88.     attr_reader :scenetype      # Scenetype: If not nil, this TimeTracker will only Update if SceneManager is in that Specified Scene.
  89.    
  90.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91.     # *- Private Static Variables
  92.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93.     @@timetracker_list = []     # Static Variable List/Array containing active instances of TimeTrackers
  94.    
  95.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  96.     # * New Method:   Object Initialisation
  97.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98.     # Time:             How long (in seconds) until this TimeTracker has been successful
  99.     # Scene Class:      Which Scene Can this TimeTracker be updated in : nil by default, which means it can always be updated no matter what scene it is.
  100.     # Add Self To List: Add Self to the Automatic Update List? : true by default. If not true, you need to update the TimeTracker manually
  101.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  102.     def initialize(time, scene_class = nil, add_self_to_list = true)
  103.       @current_frame  = 0.0
  104.       @seconds        = time.to_f
  105.       @scenetype      = scene_class
  106.      
  107.       @@timetracker_list.push(self) if add_self_to_list
  108.     end
  109.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110.     # * New Method:   Dispose
  111.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  112.     def dispose()
  113.       @@timetracker_list.reject! { |tracker| tracker == self }
  114.     end
  115.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  116.     # * New Method:   Update
  117.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118.     def update()
  119.       @current_frame += 1.0
  120.     end
  121.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122.     # * New Method:   Reset
  123.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124.     def reset()
  125.       @current_frame = 0.0
  126.     end
  127.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  128.     # * New Method:   Get Current Time (in seconds)
  129.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  130.     def get_current_time()
  131.       return (@current_frame / Graphics.frame_rate)
  132.     end
  133.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  134.     # * New Method:   Is Time Up?
  135.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  136.     def time_up?()
  137.       return (get_current_time() > @seconds)
  138.     end
  139.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140.     # * New Method:   Get TimeTracker List
  141.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142.     def self.get_timetracker_list()
  143.       return @@timetracker_list
  144.     end
  145.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  146.     # * New Method:   Update TimeTrackers
  147.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  148.     def self.update_timetrackers()
  149.       @@timetracker_list.each do |tracker|
  150.         if tracker.scenetype
  151.           if SceneManager.scene_is?(tracker.scenetype)
  152.             tracker.update()
  153.           end
  154.         else
  155.           tracker.update()
  156.         end
  157.       end
  158.     end
  159.   end
  160. end
  161.  
  162.  
  163. class Scene_Base
  164.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165.   # * Aliased Method:   Update
  166.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167.   alias dp3_dpcore_scenebase_update_axxz                          update
  168.   def update(*args)
  169.     dp3_dpcore_scenebase_update_axxz(*args)
  170.     DPCore::TimeTracker.update_timetrackers()
  171.   end
  172. end
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  180. # **  Edited Classes:   Scene Menu Quick Option Creation
  181. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  182. # This edit allows for quick Scene Menu Command Creation.
  183. # alias ' dp3_dpcore_get_original_commands ' and follow the instructions
  184. # of that method.
  185. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  186. class Window_MenuCommand < Window_Command
  187.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188.   # * Aliased Listings
  189.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  190.   alias dp3_dpcore_addorigcomnd_axxz               add_original_commands
  191.   alias dp3_dpcore_activate_axxz                   activate
  192.  
  193.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  194.   # * New Method:   Get Original Commands
  195.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  196.   #   hash = alias
  197.   #   hash[ "label" ] = {
  198.   #     :enabled    => true/false,
  199.   #     :method_ref => method(:method_name),
  200.   #   }
  201.   #   return hash
  202.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  203.   def dp3_dpcore_get_original_commands()
  204.     return {}
  205.   end
  206.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  207.   # * Aliased Method: For Adding Original Commands
  208.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209.   def add_original_commands(*args)
  210.     dp3_dpcore_addorigcomnd_axxz(*args) # Call Original Method
  211.    
  212.     original_commands = dp3_dpcore_get_original_commands()
  213.     original_commands.each_key do |key|
  214.       add_command(key, key.to_sym, original_commands[key][:enabled])
  215.     end
  216.   end
  217.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218.   # * Aliased Method: Activate
  219.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  220.   def activate(*args)
  221.     dp3_dpcore_activate_axxz(*args) # Call Original Command
  222.    
  223.     original_commands = dp3_dpcore_get_original_commands()
  224.     original_commands.each_key do |key|
  225.       set_handler(key.to_sym, original_commands[key][:method_ref])
  226.     end
  227.   end
  228. end
  229.  
  230.  
  231.  
  232.  
  233.  
  234. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  235. # **  New Module:   GameEvents
  236. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  237. # This Module Will interact with GameEvents. For now the only code here is:
  238. #     * Get First Comment in Event Page
  239. #     * Get All Comments in Event Page
  240. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  241. module DPCore
  242.   module GameEvents
  243.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  244.     # * New Method: Get Event First Comment
  245.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  246.     def self.get_event_first_comment( event_id )
  247.       comments = get_event_all_comments( event_id )
  248.       return comments[0]  unless comments.empty?
  249.       return ""
  250.     end
  251.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  252.     # * New Method: Get Event All Comments
  253.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  254.     def self.get_event_all_comments( event_id )
  255.       comments = []
  256.       event = $game_map.events[ event_id ]
  257.       if event.list
  258.         event.list.each do |command|
  259.           if command.code == 108
  260.             comments.push( command.parameters[0] )
  261.           end
  262.         end
  263.       end
  264.       return comments
  265.     end
  266.   end
  267. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement