Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Commentary
- LOGFILE = 'Tracklog.txt'
- LIMIT_TRACKED_SWITCHES = false #true
- LIMIT_TRACKED_VARIABLES = false #true
- # Define which variable changes to track
- TRACKED_SWITCHES = []
- TRACKED_SWITCHES << 127
- TRACKED_SWITCHES << 5
- # Define which switch changes to track
- TRACKED_VARIABLES = []
- TRACKED_VARIABLES << 157
- TRACKED_VARIABLES << 17
- TRACKED_VARIABLES << 49
- BACK_COLOR = Color.new(0,0,0,200)
- OLD_TEXT_COLOR = Color.new(200,200,200,200)
- NEW_TEXT_COLOR = Color.new(255,255,255,255)
- NEW_TEXT_OPACITY = 210
- NEW_TEXT_WAIT = 60
- MIN_OPACITY = 100
- OPACITY_DIFF = NEW_TEXT_OPACITY - MIN_OPACITY
- BOX_WIDTH = 580
- module_function
- def initialize
- @sprite = Sprite.new
- @sprite.x, @sprite.y = 640 - (BOX_WIDTH + 20), 20
- @sprite.z = 0xFFFFFF
- @sprite.bitmap = Bitmap.new(BOX_WIDTH,100)
- @sprite.bitmap.font.size = 14
- @sprite.bitmap.font.bold = true
- @list = []
- add_comment('') # For multiple runs in the log file
- add_comment('Initialization done')
- end
- def add_comment(text)
- @list.unshift(text.to_s)
- @list.pop if @list.size > 5
- @need_refresh = true
- File.open(LOGFILE, 'ab') {|f|
- f.print "#{text}\r\n"
- }
- end
- def refresh
- @sprite.opacity = NEW_TEXT_OPACITY
- @sprite.bitmap.fill_rect(0, 0, BOX_WIDTH, 100, BACK_COLOR)
- @sprite.bitmap.font.color = OLD_TEXT_COLOR
- for i in 1...@list.size
- @sprite.bitmap.draw_text(8, 4+18*(4-i), BOX_WIDTH - 20, 20, @list[i], 2)
- end
- @sprite.bitmap.font.color = NEW_TEXT_COLOR
- @sprite.bitmap.draw_text(8, 76, BOX_WIDTH - 20, 20, @list[0], 2)
- @need_refresh = false
- @update_wait = NEW_TEXT_WAIT
- end
- def anim_update
- if @update_wait > 0
- @update_wait -= 1
- return
- end
- if @sprite.opacity > MIN_OPACITY
- o = (OPACITY_DIFF-(@sprite.opacity - MIN_OPACITY))/10
- o = 4 if o <= 1
- @sprite.opacity -= o
- @update_wait = 2
- end
- end
- def update
- if @sprite.nil?
- initialize
- end
- if !$game_map.nil?
- if @map.nil? || @map != $game_map.map_id
- @map = $game_map.map_id
- end
- end
- refresh if @need_refresh
- anim_update
- end
- def variable_change(variable_id, old_value, new_value)
- if (!LIMIT_TRACKED_VARIABLES || TRACKED_VARIABLES.include?(variable_id))
- add_comment("Map #{$game_map.map_id}: Variable #{variable_id} changed to #{new_value} - #{Time.now}")
- end
- end
- def switch_change(switch_id, old_value, new_value)
- if (!LIMIT_TRACKED_SWITCHES || TRACKED_SWITCHES.include?(switch_id))
- add_comment("Map #{$game_map.map_id}: Switch #{switch_id} changed to #{new_value} - #{Time.now}")
- end
- end
- end
- class Game_Switches
- def []=(switch_id, value)
- if switch_id <= 5000
- # Register change
- if (value != @data[switch_id])
- Commentary.switch_change(switch_id, @data[switch_id], value)
- end
- # Normal functionality
- @data[switch_id] = value
- end
- end
- end
- class Game_Variables
- def []=(variable_id, value)
- if variable_id <= 5000
- # Register change
- if (value != @data[variable_id])
- Commentary.variable_change(variable_id, @data[variable_id], value)
- end
- # Normal functionality
- @data[variable_id] = value
- end
- end
- end
- class << Graphics
- unless self.method_defined?(:commentary_update)
- alias :commentary_update :update
- end
- def update(*args)
- commentary_update(*args)
- Commentary.update
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement