Advertisement
Dark_Paladin

Cachext

May 7th, 2013
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.22 KB | None | 0 0
  1. module Cachext
  2.   #--------------------------------------------------------------------------
  3.   # DKP Cachext
  4.   # Do not edit unless you really know what your doing!
  5.   # Platform: VX Ace
  6.   # Author: Dark paladin
  7.   # Description: Just an update to the Cache module for use with scripts
  8.   # created by me.
  9.   # -------------------------------------------------------------------------
  10.  
  11.  
  12.   #--------------------------------------------------------------------------
  13.   # *Graphics
  14.   #--------------------------------------------------------------------------  
  15.   #You can edit the stuff in purple between the "" to change folder location.  
  16.   #--------------------------------------------------------------------------
  17.   # *Logo Folder
  18.   #--------------------------------------------------------------------------
  19.   def self.logo(filename)
  20.     load_bitmap("Graphics/Logo/", filename)
  21.   end
  22.  
  23.   #--------------------------------------------------------------------------
  24.   # *Menu Graphics Folder
  25.   #--------------------------------------------------------------------------
  26.   def self.dpmenu(filename)
  27.     load_bitmap("Graphics/DPmenu/Main/", filename)
  28.   end
  29.   def self.dpjournal(filename)
  30.     load_bitmap("Graphics/DPmenu/Journal/", filename)
  31.   end
  32.   def self.dphud(filename)
  33.     load_bitmap("Graphics/DPmenu/Hud/", filename)
  34.   end
  35.  
  36.   #--------------------------------------------------------------------------
  37.   # * Load Bitmap
  38.   #--------------------------------------------------------------------------
  39.   def self.load_bitmap(folder_name, filename, hue = 0)
  40.     @cachext ||= {}
  41.     if filename.empty?
  42.       empty_bitmap
  43.     elsif hue == 0
  44.       normal_bitmap(folder_name + filename)
  45.     else
  46.       hue_changed_bitmap(folder_name + filename, hue)
  47.     end
  48.   end
  49.   #--------------------------------------------------------------------------
  50.   # * Create Empty Bitmap
  51.   #--------------------------------------------------------------------------
  52.   def self.empty_bitmap
  53.     Bitmap.new(32, 32)
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # * Create/Get Normal Bitmap
  57.   #--------------------------------------------------------------------------
  58.   def self.normal_bitmap(path)
  59.     @cachext[path] = Bitmap.new(path) unless include?(path)
  60.     @cachext[path]
  61.   end
  62.   #--------------------------------------------------------------------------
  63.   # * Create/Get Hue-Changed Bitmap
  64.   #--------------------------------------------------------------------------
  65.   def self.hue_changed_bitmap(path, hue)
  66.     key = [path, hue]
  67.     unless include?(key)
  68.       @cachext[key] = normal_bitmap(path).clone
  69.       @cachext[key].hue_change(hue)
  70.     end
  71.     @cachext[key]
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * Check Cache Existence
  75.   #--------------------------------------------------------------------------
  76.   def self.include?(key)
  77.     @cachext[key] && !@cachext[key].disposed?
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * Clear Cache
  81.   #--------------------------------------------------------------------------
  82.   def self.clear
  83.     @cachext ||= {}
  84.     @cachext.clear
  85.     GC.start
  86.   end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement