adiktuzmiko

Custom Note Files v1.0

Dec 15th, 2014
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.59 KB | None | 0 0
  1. =begin
  2. ======================================================
  3.  
  4.   Custom Note Files v1.0
  5.   by Adiktuzmiko                  
  6.  
  7.   Date Created: 12/16/2014
  8.   Date Last Updated: 12/16/2014
  9.   Requires: N/A
  10.   Difficulty: Easy
  11.  
  12. ======================================================
  13.  Overview
  14. ======================================================
  15.  
  16.  This script allows you to create text files from
  17.  where you want to load the notetags for the database
  18.  entries in your game.
  19.  
  20.  Allows you to make different files so that you can
  21.  segregate the notes.
  22.  
  23. ======================================================
  24.  Usage
  25. ======================================================
  26.  
  27.  Put this script into your scripts editor and modify
  28.  the settings below
  29.  
  30.  Create your note files where you want them to be and
  31.  just modify the FILES hash on the set-up part below.
  32.  
  33.  Start tagging your database objects with
  34.  
  35.  <note:key:index>
  36.  
  37.  Where key determines which file to open and index
  38.  is the index of the tag on the file.
  39.  
  40.  Example notetag text file:
  41.  
  42.  It is important to not put any spaces after the : part
  43.  
  44.  <note:1>
  45.    notetags here
  46.  </note>
  47.  
  48.  Let's say this note is in a file that is registered
  49.  using the symbol :items, this is how the note in the database
  50.  should look like:
  51.  
  52.  <note:items:1>
  53.  
  54.  Note: index can be any string
  55. ======================================================
  56.  Compatibility
  57. ======================================================
  58.  
  59.  Aliases RPG::BaseItem's note method
  60.  
  61.  Aliases DataManager's load_database method
  62.  
  63.  This would work for all database entries that uses the RPG::BaseItem
  64.  and/or it's subclasses as it's parent class
  65.  
  66.  This would work for any script that uses notetags as long as they use
  67.  the .note call instead of using @note directly from inside the
  68.  RPG::BaseItem class
  69.  
  70. ======================================================
  71.  Terms and Conditions
  72. ======================================================
  73.  
  74.  View it here: http://lescripts.wordpress.com/terms-and-conditions/
  75.  
  76. ======================================================
  77. =end
  78.  
  79. module CUSTOM_NOTE
  80.  
  81.   #======================================================
  82.   #Collection of paths and symbol used
  83.   #for different note files
  84.  
  85.   #Format: FILES[symbol] = Path
  86.  
  87.   #The symbol you use here will also be the symbol that you will
  88.   #use in your database notetags
  89.  
  90.   #Make sure you create the files before testing
  91.   #======================================================
  92.   FILES = {}
  93.   FILES[:items] = "System\\Items.txt"
  94.  
  95.   #======================================================
  96.   #  Do not edit below this line    
  97.   #======================================================
  98.  
  99.   def self.load_notes
  100.     return if @note != nil
  101.     @note = {}
  102.     FILES.each do |key,value|
  103.       File.open(value,"rb") do |file|
  104.         @note[key] = file.read
  105.       end
  106.     end
  107.   end
  108.  
  109.   def self.note(key)
  110.     return @note[key]
  111.   end
  112.  
  113. end
  114.  
  115. #======================================================
  116. #  Do not edit below this line    
  117. #======================================================
  118.  
  119. module DataManager
  120.  
  121.   class << self;alias load_database_custom_notes load_database;end;
  122.   def self.load_database
  123.     load_database_custom_notes
  124.     CUSTOM_NOTE.load_notes
  125.   end
  126. end
  127.  
  128. class RPG::BaseItem
  129.  
  130.   REGEX = /<note:(.*):(.*)>/
  131.  
  132.   alias note_adik_custom note
  133.   def note
  134.     index = "none"
  135.     key = :none
  136.     if @note =~ REGEX
  137.       return $1 if CUSTOM_NOTE.note($1.to_sym) =~ /<note:#{$2}>(.*)<end_note>/m
  138.     else
  139.       return @note
  140.     end
  141.   end
  142.  
  143. end
Advertisement
Add Comment
Please, Sign In to add comment