Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ § Note Replacement (v1.0) by Solistra [License: CC BY-SA 3.0]
- # ║ <RMVX Ace>
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Change Log
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ v1.0 (January 5th, 2013) - Initial release
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Summary
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ This is a simple script that allows you to replace any text that you define
- # ║ with another set of text in any note box. You may use strings, symbols, or
- # ║ even regular expressions as tags, then define the text that replaces them
- # ║ with a string or a block of Ruby code that returns a string (for the truly
- # ║ insane). If you need to access the original state of the note box before
- # ║ replacements are done, you can use the "original_note" method on the object.
- # ║
- # ║ By default, this works with maps, actors, classes, skills, items, weapons,
- # ║ armors, enemies, states, and tilesets -- basically, anything with notes.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Installation
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ For best compatibility, place this script below Materials, but above all
- # ║ other custom scripts.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ ▼ module SES::Notes
- #═╩═════════════════════════════════════════════════════════════════════════════
- module SES module Notes
- # Define the tags you want to use and their replacements here.
- TAGS = {
- # An example tag -- replaces <example> with "This is a simple example tag."
- # "<tag>" => "replacement text"
- "<example>" => "This is a simple example tag.",
- # A more advanced example using regular expressions and a Proc object to
- # create the replacement text. Ignore this if you don't know how it works.
- # /\<tag\>/ => Proc.new{"Make sure this always returns a string."}
- /\<example (\d+)\>/ => Proc.new do
- # $~ and its relatives aren't actually global, so use them this way if you
- # want to make use of them for match groups.
- @note =~ /\<example (\d+)\>/ ? "This is example number #{$1}." : ""
- end
- }
- # Used to define the note() method in the RPG data structures. This basically
- # overwrites the default reader method for @note in each class.
- def self.note() Proc.new{SES::Notes.replace(@note.clone) if !@note.nil?} end
- # Performs the substitutions. The @note instance variable is defined here so
- # that the tags above can access the content of the note (if using a Proc).
- def self.replace(note)
- @note = note
- TAGS.each{|k, v| note.gsub!(k, v.is_a?(Proc) ? v.call : v)}
- return note
- end
- end end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ module SES::Notes
- #═╩═════════════════════════════════════════════════════════════════════════════
- ($imported ||= {})["SES - Notes"] = 1.0
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▼ module RPG
- #═╩═════════════════════════════════════════════════════════════════════════════
- module RPG
- # Add the methods note() and original_note() to all of the RPG data structures
- # that make use of note boxes.
- [Map, BaseItem, Tileset].each do |base_class|
- base_class.send(:define_method, :note, &SES::Notes.note)
- base_class.send(:define_method, :original_note, &Proc.new{@note})
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ module RPG
- #═╩═════════════════════════════════════════════════════════════════════════════
Advertisement
Add Comment
Please, Sign In to add comment