Advertisement
estriole

EST - SIMPLE NOTETAGS

Jan 7th, 2013
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.32 KB | None | 0 0
  1. $imported = {} if $imported.nil?
  2. $imported["EST - SIMPLE NOTETAGS"] = true
  3. =begin
  4.  
  5. EST - SIMPLE NOTETAGS
  6. v. 1.6
  7.  
  8. Author : Estriole
  9. also credit:
  10. Victor - for event comment as note code.
  11.  
  12. Version History
  13. v. 1.0 - 2013-01-07 - finish the script
  14. v. 1.1 - 2013-01-08 - fix the regexp to recognize text without ""
  15.                     - add long_note_args method.
  16. v. 1.2 - 2013-01-08 - improve the regex so now can grab any notetags format
  17.                       now can grab yanfly format, mr buble format, victor, etc
  18.                       (i hope so). rewrite the introduction and how to use
  19.                       to simplify things.
  20. v. 1.3 - 2013-01-09 - change the method to module so we can include it in any
  21.                       class as long as it have @note. to add it just add in the class:
  22.                      
  23.                         include ESTRIOLE::NOTETAGS_SYSTEM
  24.                      
  25.                       i already include the module in these following class:
  26.                       RPG::BaseItem
  27.                       RPG::Map
  28.                       RPG::Tileset
  29.                       RPG::Class::Learning
  30.                       since i think it's all the rpg class that have @note.
  31.                       also add method in game map to make it able to access the @map
  32. v. 1.4 - 2013-02-04 - fix some regexp to recognize more than 1 strings in one notetags
  33. v. 1.5 - 2013-05-26 - fix some regexp to recognize '-' example: -1321, -asdr, ase-3
  34.                       fix some regexp to recognize '.' example: 10.33, acd.331, 33.21a
  35.                       also compatibility update for dynamic note script(if any).
  36.                       also feature to grab event note (comment) (from victor code)
  37. v. 1.6 - 2013-06-07 - fix regexp to use multi line mode.
  38.                     - fix some regexp so can put array in note example: [1,2] it will saved as "1,2"
  39.                       later you could do some eval to make it array again. ex:
  40.                       note:
  41.                       <test: [1,3],[11,9]>
  42.                       then we grab it using note_args method
  43.                       a = note_args("test")
  44.                       now to transform all element in a to array. you could use collect.
  45.                       a.collect!{|x| eval("[#{x}]")}
  46.                     - fix some regexp so can put hash in note example: {1=>30,2=>2} it will saved as "1=>30,2=>2"
  47.                       now to transform all element in a to hash the same method as array above just use different eval
  48.                       a.collect!{|x| eval("{#{x}}")}
  49.  
  50. Introduction
  51. this script basically works as notetags grabbers
  52. Make your notetagging job for any database object easier (for scripter).
  53. you can easily grab any notetags value using simple method. then use that
  54. either in event script call / inside class
  55.  
  56. How to Use
  57. now we can easily grab the notetags from any RPG database object such as:
  58. RPG::Actor, RPG::Enemy, RPG::Class,
  59. RPG::Item, RPG::Weapon, RPG::Armor, RPG::Skill, RPG::State
  60. RPG::Map, RPG::Tileset, RPG::Class:Learning
  61.  
  62. basically every child class of RPG::BaseItem
  63.  
  64. this script give you two type of notetags grabber.
  65. ================================================================================
  66.  
  67. 1) rpg_instance_object.note_args("notetags name")
  68. example:
  69.   -> Actor
  70.      $game_actors[id].actor.note_args("notetags name")
  71.      $game_party.members[slot_id].actor.note_args("notetags name")
  72.   -> Enemy
  73.      $game_troops.members[slot_id].enemy.note_args("notetags name")
  74.   -> Class
  75.      $data_classes[id].note_args("notetags name")
  76.   -> Item, Weapon, Armor, Skill, State
  77.      $data_items[id].note_args("notetags name")
  78.      $data_weapons[id].note_args("notetags name")
  79.      $data_armors[id].note_args("notetags name")
  80.      $data_skills[id].note_args("notetags name")
  81.      $data_states[id].note_args("notetags name")
  82.   -> Map
  83.      $game_map.map.note_args("notetags name")
  84.   -> Tileset
  85.      i don't know how to access it yet. if anyone know pm me :D
  86.   -> Class::Learning
  87.      i don't know how to access it yet. if anyone know pm me :D
  88.  
  89. this will grab notetags of this type:
  90. <name: a b c d e f g h i ...>
  91. or
  92. <name: a, b, c, d, e, f, g, h, i,...>
  93. or
  94. combination of both (have coma or only spaces)
  95.  
  96. ... means you can have as many as you want
  97.  
  98. it then will return array
  99. [a,b,c,d,e,f,g,h,i,...]
  100.  
  101. every array member is in STRING format. so if you want to use it as integer
  102. you need to use .to_i after grabbing array[index]
  103. for true and false. it also become text. so you need to change it to boolean
  104. yourself.
  105.  
  106. and if you want to have block text in your notetags you could put it inside ""
  107. example:
  108. <testnote: "King Maker" 10 true 322>
  109. return array ["King Maker","10","true","322"]
  110.  
  111. and if all of your note value is integer and you're too lazy to use .to_i
  112. you could change .note_args to .note_args_all_int
  113. it will convert all array member to integer. (use collect method)
  114. ================================================================================
  115.  
  116. 2) rpg_instance_object.long_note_args("notetags name")
  117. example: just see number 1) above and change the method to
  118. .long_note_args("notetags name") instead.
  119.  
  120. this will grab notetags of this type:
  121. <name>
  122. key1: a b c d e f g h i ...
  123. key2: a, b, c, d, e, f, g, h, i,...
  124. key3: a b, c, d e f g h i ...
  125. </name>
  126.  
  127. note: key3 is the combination with coma and just spaces.
  128.  
  129. it then will return 2 level array
  130. [[key1,a,b,c,d,e,f,g,h,i,...],[key2,a,b,c,d,e,...],[key3,a,b,c,d,e,f,g,...]]
  131.  
  132. every level two array member is in STRING format.
  133. so if you want to use it as integer you need to use .to_i after grabbing it
  134. for true and false. it also become text. so you need to change it to boolean
  135. yourself.
  136.  
  137. and if you want to have block text in your notetags you could put it inside ""
  138. example:
  139. <testnote>
  140. can have spaces: "Dragon Slayer" "yes", true, 123
  141. w: 10 13, 33
  142. </testnote>
  143.  
  144. will return array
  145. [["can have spaces","Dragon Slayer","yes","true","123"],["w","10","13","33"]]
  146.  
  147. ================================================================================
  148. FOR GRABBING EVENT COMMENT:
  149. game_event_object.note_args("notetags name")
  150. game_event_object.long_note_args("notetags name")
  151. it will grab note from that event object ACTIVE page comment
  152. ex:
  153. $game_map.events[1].note_args("event_size")
  154. and in current map event 001 active page has comment:
  155. <event_size: 10, 4, 33, "yeah baby">
  156. it will return array
  157. ["10","4","33","yeah baby"]
  158.  
  159. ================================================================================  
  160. Author Note
  161. This script is the way i tested myself on how much i've grown in notetagging and
  162. regex in this past 6 month. i would like to see my limit.
  163. and also learn to code efficiently (making as few line as possible)
  164.  
  165. Next patch maybe adding long_note_args_eval method.
  166. for grabbing something like victor enemy action condition / some yanfly notetags...
  167. which use eval method.
  168.  
  169. i don't know but i think this script will more suited named EST - NOTETAGS GRABBER
  170. LOL...
  171.  
  172. =end
  173. module ESTRIOLE
  174.  
  175.   NO_NOTETAGS_RETURN = nil
  176.   # change above to whatever you want the function return when no note found
  177.   # nil or [] is recommended
  178.  
  179.   module NOTETAGS_SYSTEM
  180.    def note_args_all_int(str)
  181.     return NO_NOTETAGS_RETURN if !note[/<#{str}:(.*)>/i]
  182.     a = note[/<#{str}:(.*)>/im].scan(/:(.*)/m).flatten[0].scan(/(?:"(.*?)"|\{(.*?)\}|\[(.*?)\]| ([-\w.\w]+)|([-\w.\w]+),|,([-\w.\w]+))/m).flatten.compact
  183.     a.collect!{|x| x.to_i}
  184.     return noteargs = a
  185.    end
  186.  
  187.    def note_args(str)
  188.     return NO_NOTETAGS_RETURN if !note[/<#{str}:(.*)>/im]
  189.     a = note[/<#{str}:(.*)>/im].scan(/:(.*)/m).flatten[0].scan(/(?:"(.*?)"|\{(.*?)\}|\[(.*?)\]| ([-\w.\w]+)|([-\w.\w]+),|,([-\w.\w]+))/m).flatten.compact
  190.     return noteargs = a
  191.    end
  192.  
  193.    def long_note_args(str)
  194.     return NO_NOTETAGS_RETURN if !note[/<#{str}?>(?:[^<]|<[^\/])*<\/#{str}?>/i]
  195.     a = note[/<#{str}?>(?:[^<]|<[^\/])*<\/#{str}?>/i].scan(/(?:!<#{str}?>|(.*)\r)/).flatten
  196.     a.delete_at(0)
  197.     noteargs = b = []
  198.     a.each do |mem|
  199.     b = mem.scan(/(?:(.*) :|(.*):|"(.*?)"| ([-\w.\w]+)|([-\w.\w]+),|,([-\w.\w]+))/).flatten.compact
  200.     noteargs.push(b)
  201.     end
  202.     return noteargs
  203.    end
  204.  
  205.    def eval_long_note_args(str)
  206.     return NO_NOTETAGS_RETURN if !note[/<#{str}?>(?:[^<]|<[^\/])*<\/#{str}?>/i]
  207.     a = note[/<#{str}?>(?:[^<]|<[^\/])*<\/#{str}?>/i].scan(/(?:!<#{str}?>|(.*)\r)/)
  208.     a.delete_at(0)    
  209.     return noteargs = a.join("\r\n")    
  210.    end
  211.    
  212.    def have_note?(str)
  213.     return "<type x>" if note[/<#{str}:(.*)>/i]  
  214.     return "<type> x </type>" if note[/<#{str}?>(?:[^<]|<[^\/])*<\/#{str}?>/i]
  215.     return "<type>" if note[/<#{str}>/i]  
  216.     return nil
  217.    end
  218.   end
  219. end
  220.  
  221. class Game_Map
  222.   attr_reader :map
  223. end #new method to access @map
  224.  
  225. class RPG::BaseItem
  226.   include ESTRIOLE::NOTETAGS_SYSTEM
  227. end
  228.  
  229. class RPG::Map
  230.   include ESTRIOLE::NOTETAGS_SYSTEM
  231. end
  232.  
  233. class RPG::Tileset
  234.   include ESTRIOLE::NOTETAGS_SYSTEM
  235. end
  236.  
  237. class RPG::Class::Learning
  238.   include ESTRIOLE::NOTETAGS_SYSTEM
  239. end
  240. class Game_Event < Game_Character
  241.   include ESTRIOLE::NOTETAGS_SYSTEM
  242. #grabbed from victor basic module  
  243.   def note
  244.     return "" if !@page || !@page.list || @page.list.size <= 0
  245.     comment_list = []
  246.     @page.list.each do |item|
  247.       next unless item && (item.code == 108 || item.code == 408)
  248.       comment_list.push(item.parameters[0])
  249.     end
  250.     comment_list.join("\r\n")
  251.   end  
  252. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement