Enelvon

SES Core

Dec 13th, 2012
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.81 KB | None | 0 0
  1. #═╦═════════════════════════════════════════════════════════════════════════════
  2. # ║ § SES Core (v1.2) by Solistra and Enelvon            [License: CC BY-SA 3.0]
  3. # ║                                                            <RMVX Ace>
  4. #═╬═════════════════════════════════════════════════════════════════════════════
  5. # ║ § Change Log
  6. #─╫─────────────────────────────────────────────────────────────────────────────
  7. # ║ v1.0 (December ???, 2012) - Initial release
  8. # ║ v1.1 (February 26th, 2013) - Enelvon fixed an issue with scanning comments,
  9. # ║                              but took forever to remember to upload it
  10. # ║ v1.2 (March 15, 2013) - Ditto the above
  11. # ║
  12. #═╬═════════════════════════════════════════════════════════════════════════════
  13. # ║ § Summary
  14. #─╫─────────────────────────────────────────────────────────────────────────────
  15. # ║ This serves as a base script required by some SES scripts released by both
  16. # ║ Solistra and Enelvon. It contains some utility methods and methods to help
  17. # ║ facilitate the use of tags in note boxes and event comments.
  18. # ║
  19. #═╬═════════════════════════════════════════════════════════════════════════════
  20. # ║ § Installation
  21. #─╫─────────────────────────────────────────────────────────────────────────────
  22. # ║ For best compatibility, place this script below Materials, but above all
  23. # ║ other custom scripts (especially SES scripts).
  24. # ║
  25. #═╬═════════════════════════════════════════════════════════════════════════════
  26. # ║ § New Methods
  27. #─╫─────────────────────────────────────────────────────────────────────────────
  28. # ║ ● Game_Event
  29. # ║     comments
  30. # ║ ● Game_Interpreter
  31. # ║     this
  32. # ║     event
  33. # ║     comments
  34. # ║
  35. #═╬═════════════════════════════════════════════════════════════════════════════
  36. # ║ ▼ module SES
  37. #═╩═════════════════════════════════════════════════════════════════════════════
  38. module SES
  39.   # Includes SES in the data structures used by RMVX Ace by default.
  40.   def self.insert
  41.     RPG.constants.each do |s|
  42.       (s = RPG.const_get(s)).send(:include, self)
  43.       s.constants.each{|c| s.const_get(c).send(:include, self)}
  44.     end
  45.   end
  46.  
  47.   # Used in Game_Event and Game_Interpreter to collect comments.
  48.   def self.comment_proc
  49.     Proc.new do
  50.       @list.select{|c| c.code == 108 || c.code == 408}.map{|c|c.parameters[0]}
  51.     end
  52.   end
  53.  
  54.   # An extended version of Kernel.rand. Also takes ranges, arrays, or hashes.
  55.   def self.rand(arg = nil)
  56.     if arg.is_a?(Range) then Kernel.rand(1 + arg.max - arg.min) + arg.min
  57.     elsif arg.kind_of?(Array) then arg[Kernel.rand(arg.size)]
  58.     elsif arg.is_a?(Hash) then self.rand(arg.values)
  59.     else Kernel.rand(arg) end
  60.   end
  61.  
  62.   # Note tag scanning method.
  63.   def scan_ses_notes(tags = {})
  64.     return unless defined?(self.note)
  65.     self.note.split(/[\r\n+]/).each do |line|
  66.       tags.each{|regex, code| eval(code) if line =~ regex}
  67.     end
  68.   end
  69.  
  70.   # Allows scan_ses_comments to work.
  71.   def comments
  72.     com = []
  73.     if self.is_a?(RPG::Event::Page) || self.is_a?(RPG::CommonEvent)
  74.       @list.each{|c|com.push(c.parameters[0]) if c.code == 108 || c.code == 408}
  75.     end
  76.     com
  77.   end
  78.  
  79.   # Event comment scanning method. May be used in common events as well.
  80.   def scan_ses_comments(tags = {})
  81.     self.comments.each do |comment|
  82.       tags.each{|regex, code| eval(code) if comment =~ regex}
  83.     end
  84.   end
  85.  
  86.   # Method definitions are complete; include SES in the RPG data structures.
  87.   self.insert
  88. end
  89. #═╦═════════════════════════════════════════════════════════════════════════════
  90. # ║ ▲ module SES
  91. #═╩═════════════════════════════════════════════════════════════════════════════
  92.                      ($imported ||= {})["SES - Core"] = 1.1
  93. #═╦═════════════════════════════════════════════════════════════════════════════
  94. # ║ ▼ class Game_Event
  95. #═╩═════════════════════════════════════════════════════════════════════════════
  96. class Game_Event < Game_Character
  97.   def comments() self.instance_eval(&SES.comment_proc) end
  98. end
  99. #═╦═════════════════════════════════════════════════════════════════════════════
  100. # ║ ▲ class Game_Event
  101. #─╫─────────────────────────────────────────────────────────────────────────────
  102. # ║ ▼ class Game_Interpreter
  103. #═╩═════════════════════════════════════════════════════════════════════════════
  104. class Game_Interpreter
  105.   def event(id) $game_map.events[id] end
  106.   def this() @event_id > 0 ? $game_map.events[@event_id] : self end
  107.   def comments() this.page ? self.instance_eval(&SES.comment_proc) : [] end
  108. end
  109. #═╦═════════════════════════════════════════════════════════════════════════════
  110. # ║ ▲ class Game_Interpreter
  111. #═╩═════════════════════════════════════════════════════════════════════════════
Advertisement
Add Comment
Please, Sign In to add comment