Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: Wecoc on September 12, 2013, 05:32:05 pm

Title: [XP][VX] Improved Scene_Debug
Post by: Wecoc on September 12, 2013, 05:32:05 pm
Debug Eval
Authors: Wecoc
Version: 1.0
Type: Debug AddOn
Key Term: Game Utility



Introduction

Are you tired of the limited default Scene_Debug and you want one a little more personalized to further test your project?
Well I did one where you can write an eval and get it done :D



Features




Screenshots

Spoiler: ShowHide
(http://s17.postimg.org/ca605biun/evalscript_xp.png)

(http://s17.postimg.org/lj86ffrqn/evalscript_vx.png)



Script

Put the script over main. To call it use F9 as always only in debug mode. It's that simple :)
Spoiler: ShowHide

#==============================================================================
# [XP/VX] Debug Eval (Scene_Debug Edit) v1.0
#------------------------------------------------------------------------------
# By: Wecoc
#------------------------------------------------------------------------------
# Please do not judge me for this, I'm really not that crazy.
#==============================================================================


#==============================================================================
# ** Modules configuration
#==============================================================================

# EVAL_HELP ) Shortcuts [ Add as many as you want ]

module EVAL_HELP
 def var
   return $game_variables
 end
 
 def stch
   return $game_switches
 end
 
 def debug
   $scene = Scene_Debug.new
 end
 
 def help
   print EVAL_HELP.instance_methods.join("\n")
 end
end

# EVAL_FEATURES ) VX Compatibility

$debug_eval_vx = defined?(Game_Interpreter)

module EVAL_FEATURES # VX compatibility
 WIDTH =  $debug_eval_vx ? 544 : 640
 HEIGHT = $debug_eval_vx ? 416 : 480
 
 def play_cursor
   if $debug_eval_vx
     Sound.play_cursor
   else
     $game_system.se_play($data_system.cursor_se)
   end
 end
 def play_decision
   if $debug_eval_vx
     Sound.play_decision
   else
     $game_system.se_play($data_system.decision_se)
   end
 end
 def play_cancel
   if $debug_eval_vx
     Sound.play_cancel
   else
     $game_system.se_play($data_system.cancel_se)
   end
 end
 def play_buzzer
   if $debug_eval_vx
     Sound.play_buzzer
   else
     $game_system.se_play($data_system.buzzer_se)
   end
 end
end

# WecocInput ) Keyboard Features

module WecocInput
 Teclas = {
 # index => [ key, mayúsculas, minúsculas, shift, AltGr]
 1 =>   [0x01, "", ""], # Click L
 2 =>   [0x02, "", ""], # Click R
 3 =>   [0x04, "", ""], # Click M
 4 =>   [0x08, "", ""], # Back
 5 =>   [0x09, " ", " "], # Tab
 6 =>   [0x0C, "", ""], # Bloq Numpad 5
 7 =>   [0x0D, "", ""], # Enter
 8 =>   [0x11, "", ""], # Ctrl (0xA2 + 0x11)
 9 =>   [0x12, "", ""], # Alt
 10 =>  [0x13, "", ""], # Pause
 11 =>  [0x14, "", ""], # Cap Lock
 12 =>  [0x1B, "", ""], # Esc
 13 =>  [0x20, " ", " "], # Backspace
 14 =>  [0x21, "", ""], # Next Page
 15 =>  [0x22, "", ""], # Prev Page
 16 =>  [0x23, "", ""], # End
 17 =>  [0x24, "", ""], # Start
 18 =>  [0x25, "", ""], # Left arrow
 19 =>  [0x26, "", ""], # Up arrow
 20 =>  [0x27, "", ""], # Right arrow
 21 =>  [0x28, "", ""], # Down arrow
 22 =>  [0x2C, "", ""], # Print Screen
 23 =>  [0x2D, "", ""], # Insert
 24 =>  [0x2E, "", ""], # Del
 25 =>  [0x30, "0", "0", "=", "="],
 26 =>  [0x31, "1", "1", "!", "|"],
 27 =>  [0x32, "2", "2", '"', "@"],
 28 =>  [0x33, "3", "3", "·", '#'],
 29 =>  [0x34, "4", "4", "$", "~"],
 30 =>  [0x35, "5", "5", "%"],
 31 =>  [0x36, "6", "6", "&", "¬"],
 32 =>  [0x37, "7", "7", "/"],
 33 =>  [0x38, "8", "8", "("],
 34 =>  [0x39, "9", "9", ")"],
 35 =>  [0x41, "A", "a", true],
 36 =>  [0x42, "B", "b", true],
 37 =>  [0x43, "C", "c", true],
 38 =>  [0x44, "D", "d", true],
 39 =>  [0x45, "E", "e", true],
 40 =>  [0x46, "F", "f", true],
 41 =>  [0x47, "G", "g", true],
 42 =>  [0x48, "H", "h", true],
 43 =>  [0x49, "I", "i", true],
 44 =>  [0x4A, "J", "j", true],
 45 =>  [0x4B, "K", "k", true],
 46 =>  [0x4C, "L", "l", true],
 47 =>  [0x4D, "M", "m", true],
 48 =>  [0x4E, "N", "n", true],
 49 =>  [0x4F, "O", "o", true],
 50 =>  [0x50, "P", "p", true],
 51 =>  [0x51, "Q", "q", true],
 52 =>  [0x52, "R", "r", true],
 53 =>  [0x53, "S", "s", true],
 54 =>  [0x54, "T", "t", true],
 55 =>  [0x55, "U", "u", true],
 56 =>  [0x56, "V", "v", true],
 57 =>  [0x57, "W", "w", true],
 58 =>  [0x58, "X", "x", true],
 59 =>  [0x59, "Y", "y", true],
 60 =>  [0x5A, "Z", "z", true],
 61 =>  [0x5B, "", ""], # Windows
 62 =>  [0x5C, "", ""], # R-Windows
 63 =>  [0x5D, "", ""], # Scroll Fix
 64 =>  [0x60, "0", "0"], # Numpad
 65 =>  [0x61, "1", "1"], # Numpad
 66 =>  [0x62, "2", "2"], # Numpad
 67 =>  [0x63, "3", "3"], # Numpad
 68 =>  [0x64, "4", "4"], # Numpad
 69 =>  [0x65, "5", "5"], # Numpad
 70 =>  [0x66, "6", "6"], # Numpad
 71 =>  [0x67, "7", "7"], # Numpad
 72 =>  [0x68, "8", "8"], # Numpad
 73 =>  [0x69, "9", "9"], # Numpad
 74 =>  [0x6A, "*", "*"], # Numpad
 75 =>  [0x6B, "+", "+"], # Numpad
 76 =>  [0x6C, "", ""],   # Numpad
 77 =>  [0x6D, "-", "-"], # Numpad
 78 =>  [0x6E, ".", "."], # Numpad
 79 =>  [0x6F, "/", "/"], # Numpad
 80 =>  [0x70, "", ""], # F1
 81 =>  [0x71, "", ""], # F2
 82 =>  [0x72, "", ""], # F3
 83 =>  [0x73, "", ""], # F4
 84 =>  [0x74, "", ""], # F5
 85 =>  [0x75, "", ""], # F6
 86 =>  [0x76, "", ""], # F7
 87 =>  [0x77, "", ""], # F8
 88 =>  [0x78, "", ""], # F9
 89 =>  [0x79, "", ""], # F10
 90 =>  [0x7A, "", ""], # F11
 91 =>  [0x7B, "", ""], # F12
 92 =>  [0x90, "", ""], # BloqNum
 93 =>  [0x91, "", ""], # BloqDespl
 94 =>  [0xA0, "", ""], # Shift
 95 =>  [0xA1, "", ""], # R-Shift
 96 =>  [0xA2, "", ""], # Ctrl (0xA2 + 0x11)
 97 =>  [0xA3, "", ""], # R-Ctrl
 98 =>  [0xA4, "", ""], # Alt
 99 =>  [0xA5, "", ""], # R-Alt
 100 => [0xBA, "`", "`", "^", "["],
 101 => [0xBB, "+", "+", "*", "]"],
 102 => [0xBC, ",", ",", ";"],
 103 => [0xBD, "-", "-","_"],
 104 => [0xBE, ".", ".", ":"],
# 105 => [0xBF, "Ç", "ç", true, "}"],
 105 => [0xBF, "}", "}", true, "}"],
# 106 => [0xC0, "Ñ", "ñ", true],
 107 => [0xDB, "'", "'", "?"],
# 108 => [0xDC, "º", "º", "ª", 92.chr], # \
 108 => [0xDC, 92.chr, 92.chr, 92.chr, 92.chr], # \
# 109 => [0xDD, "¡", "¡", "¿"],
# 110 => [0xDE, "´", "´", "¨", "{"],
 111 => [0xE2, "<", "<", ">"]
 }
 
 Keyboard_Acces = Win32API.new("user32","GetAsyncKeyState",['i'],'i')

def self.get_key(key)
   Keyboard_Acces.call(key) & 0x01 == 1
 end
end


#==============================================================================
# ** Window_Eval
#==============================================================================

class Window_Eval < Window_Base
 
 include EVAL_FEATURES
 include EVAL_HELP
 
 attr_accessor :text
 attr_accessor :down
 attr_accessor :cursor
 
 def initialize
   super(0, 0, WIDTH, HEIGHT-64)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.color = normal_color
   self.contents.font.name = "Courier New"
   self.contents.font.size = 18
   self.contents.font.bold = true
   $falcao_apply = false
   $testing = true
   @text = ""
   @cursor = [0, 0]
   @lines = 0
   @caps_lock = 2
   @shift = false
   @altgr = false
   @down = -1
   refresh
 end
 
 def refresh
   self.contents.clear
   draw_back
   draw_eval
   draw_cursor
 end
 
 def draw_back
   rect0 = Rect.new(10, 10, WIDTH-32-20, HEIGHT-64-32-20)
   rect1 = Rect.new(10, 10, WIDTH-32-20, 2)
   rect2 = Rect.new(10, HEIGHT-64-32-20+8, WIDTH-32-20, 2)
   rect3 = Rect.new(10, 10, 2, HEIGHT-64-32-20)
   rect4 = Rect.new(WIDTH-32-20+8, 10, 2, HEIGHT-64-32-20)
   
   self.contents.fill_rect(rect0, Color.new(8,8,8,160))
   self.contents.fill_rect(rect1, Color.new(200,200,200,255))
   self.contents.fill_rect(rect2, Color.new(200,200,200,255))
   self.contents.fill_rect(rect3, Color.new(200,200,200,255))
   self.contents.fill_rect(rect4, Color.new(200,200,200,255))
   self.contents.font.color = normal_color
 end
 
 def draw_eval
   for i in WecocInput::Teclas.values
     if WecocInput.get_key(i[0])
       if @down == -1
         if i[0] == 0x14 # Caps
           @caps_lock = @caps_lock == 1 ? 2 : 1
         end
         unless i[1] == ""
           if @shift
             case i[3]
             when nil
               @text.insert get_cursor_pos, i[@caps_lock]
             when true
               @text.insert get_cursor_pos, i[@caps_lock == 1 ? 2 : 1]
             else
               @text.insert get_cursor_pos, i[3]
             end
             @shift = false
             @altgr = false
           else
             if @altgr
               if i[4] != nil
                 @text.insert get_cursor_pos, i[4]
               end
               @shift = false
               @altgr = false
             else
               @text.insert get_cursor_pos, i[@caps_lock]
             end
           end
           @cursor[0] += 1
         end
         if i[0] == 0x78 # F9
           play_cancel
           $scene = Scene_Map.new
         end
         if i[0] == 0xA0 or i[0] == 0xA1 # Shift
           @shift = true
         end
         if i[0] == 0xA4 or i[0] == 0xA2 or i[0] == 0x11 # AltGr
           @altgr = true
         end
         if i[0] == 0x0D # Enter
           @text.insert get_cursor_pos, ";"
           @cursor[1] += 1
           @lines += 1
           @cursor[0] = 0
         end
         if i[0] == 0x09 # Tab
           @text.insert get_cursor_pos, " "
           @cursor[0] += 1
         end
         if i[0] == 0x25 # Left
           if @cursor[0] == 0
             unless @cursor[1] == 0
               @cursor[1] -= 1
               @cursor[0] = get_txt[@cursor[1]].size
             end
           else
             @cursor[0] -= 1
           end
         end
         if i[0] == 0x27 # Right
           if @cursor[1] != @lines
             if @cursor[0] == get_txt[@cursor[1]].size
               @cursor[1] += 1
               @cursor[0] = 0
             else
               @cursor[0] += 1
             end
           else
             @cursor[0] += 1 if @cursor[0] != get_txt[@cursor[1]].size - 1
           end
         end
         if i[0] == 0x26 # Up
           if @cursor[1] != 0
             @cursor[1] -= 1
             @cursor[0] = [@cursor[0], get_txt[@cursor[1]].size].min
           end
         end
         if i[0] == 0x28 # Down
           if @lines == @cursor[1]
             play_cursor
             @down = 0
           else
             @cursor[1] += 1
             @cursor[0] = [@cursor[0], get_txt[@cursor[1]].size - 1].min
           end
         end
         if i[0] == 0x2E # Del
           if @lines == @cursor[1]
             del_txt unless @cursor[0] == (get_txt[@cursor[1]].size - 1)
           else
             @lines -= 1 if @cursor[0] == (get_txt[@cursor[1]].size)
             del_txt
           end
         end
         if i[0] == 0x08 # Backspace
           if @text.size <= 1
             @text = ""
             @cursor[0] = 0
           else
             if @text[get_cursor_pos-1].chr == ";"
               @cursor[1] -= 1
               @cursor[0] = get_txt[@cursor[1]].size - 1
               @lines -= 1
               del_txt
             else
               @cursor[0] -= 1
             end
             del_txt
           end
         end
       end
     end
   end
   write_eval
 end
 
 def get_txt
   txt = ""
   txt.concat(@text)
   txt << " "
   return txt.include?(";") ? txt = txt.split(";") : [txt]
 end
 
 def del_txt
   text = @text.split(//)
   text.delete_at(get_cursor_pos)
   @text = text.join
   @text = "" if @text.nil?
 end
 
 def get_cursor_pos
   pos = 0
   for i in 0...@cursor[1]
     pos += get_txt[i].size+1
   end
   pos += @cursor[0]
   return pos
 end
 
 def write_eval
   if @text != nil and @text != ""
     txt = get_txt
     for i in 0...txt.size
      self.contents.draw_text(20, 20 + i*24, 620, 32, txt[i])
     end
   end
   return
 end
 
 def get_eval_code
   return begin
     eval(@text).to_s
   rescue Exception
     "Exception"
   end
 end
 
 def draw_cursor
   rect = Rect.new(@cursor[0]*10+20, 28 + @cursor[1]*24, 2, 16)
   self.contents.fill_rect(rect, Color.new(128,128,128,255))
 end
end


#==============================================================================
# ** Window_DebugCommand
#==============================================================================

class Window_DebugCommand < Window_Selectable
 
 include EVAL_FEATURES
 
 def initialize
   super(0, HEIGHT-64, WIDTH, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   @item_max = 2
   @column_max = 2
   @commands = ["Confirm", "Cancel"]
   refresh
   self.index = 0
 end

 def refresh
   self.contents.clear
   for i in 0...@item_max
     draw_item(i)
   end
 end

 def draw_item(index)
   width = (WIDTH-32)/2
   self.contents.draw_text(width * index, 0, width, 32, @commands[index], 1)
 end
 
 def update_cursor
   super
   self.cursor_rect.height = 32
 end
end


#==============================================================================
# ** Scene_DebugEval
#==============================================================================

class Scene_DebugEval
 
 include EVAL_FEATURES
 
 def main
   @eval_window = Window_Eval.new
   @command_window = Window_DebugCommand.new
   @command_window.index = -1
   Graphics.transition
   loop do
     Graphics.update
     update
     if $scene != self
       break
     end
   end
   $game_map.refresh
   Graphics.freeze
   @eval_window.dispose
   @command_window.dispose
 end
 
 def update
   if @eval_window.down == -1
     @command_window.index = -1
   else
     @command_window.index = [@command_window.index, 0].max
   end
   if @command_window.index != -1
     update_command
   end
   @eval_window.refresh
   @command_window.update
 end
 
 def update_command
   for i in WecocInput::Teclas.values
     if WecocInput.get_key(i[0])
       if i[0] == 0x25 # Left
         play_cursor
         @command_window.index = 0
       end
       if i[0] == 0x27 # Right
         play_cursor
         @command_window.index = 1
       end
       if i[0] == 0x26 # Up
         play_cursor
         @eval_window.down = -1
       end
       if i[0] == 0x20 or i[0] == 0x0D or i[0] == 0x78 # Space, Enter or F9
         case @command_window.index
         when 0 # Confirm
           $scene = Scene_Map.new if @eval_window.text != "help"
           eval = @eval_window.get_eval_code
           eval == "Exception" ? play_buzzer : play_decision
         when 1 # Cancel
           play_cancel
           $scene = Scene_Map.new
         end
         $testing = false
       end
       if i[0] == 0x78 # F9
         play_cancel
         $scene = Scene_Map.new
       end
     end
   end
 end
end


#==============================================================================
# ** [Others]
#==============================================================================

if $debug_eval_vx

 class Scene_Map < Scene_Base
   def call_debug
     Sound.play_decision
     $game_temp.next_scene = nil
     $scene = Scene_DebugEval.new
   end
 end

else

 class Scene_Map
   def call_debug
     $game_temp.debug_calling = false
     $game_system.se_play($data_system.decision_se)
     $game_player.straighten
     $scene = Scene_DebugEval.new
   end
 end

end

class SystemStackError < Exception
 alias testing_exception initialize unless $@
 def initialize
   return if $testing
   testing_exception
 end
end



Instructions

To set new shortcuts go on the very beginning of the script inside module EVAL_HELP and write there all you want.
If when you are on game you forget it you can write help on the eval and a print with the shortcuts will appear.
You can control the cursor with direction arrows. To activate the command window you just have to press down arrow, only if you are on the last line.


Compatibility

No incompatibilities known. It uses only one alias (SystemStackError initialize)


Credits and Thanks




Author's Notes

I have to drink less. If you have any question don't hestitate to ask.
Enjoy ~