TheoAllen

Cidiomar - Input full

Jun 12th, 2013
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 24.11 KB | None | 0 0
  1. # ** Input
  2. #------------------------------------------------------------------------------
  3. # Created By Cidiomar R. Dias Júnior
  4. # Originally posted at http://rgss3help.cidiomar.com/?p=145
  5. #
  6. # Terms of Use: http://rgss3help.cidiomar.com/?page_id=159
  7. #------------------------------------------------------------------------------
  8. # A module that handles input data from a gamepad or keyboard.
  9. # Managed by symbols rather than button numbers in RGSS3.
  10. #==============================================================================
  11. module Input  
  12.   #--------------------------------------------------------------------------
  13.   # * Keymap in symbols
  14.   # To get a key from the keymap, you can use Input.key(sym) or Input:KEYMAP[sym]
  15.   # Or if you want to use a symbol in a input function, just pass the symbol
  16.   # as argument.
  17.   #--------------------------------------------------------------------------
  18.   KEYMAP = {
  19.     LBUTTON:              0x01,  RBUTTON:              0x02,
  20.     CANCEL:               0x03,  MBUTTON:              0x04,
  21.     XBUTTON1:             0x05,  XBUTTON2:             0x06,
  22.     BACK:                 0x08,  TAB:                  0x09,
  23.     CLEAR:                0x0c,  RETURN:               0x0d,
  24.     SHIFT:                0x10,  CONTROL:              0x11,
  25.     MENU:                 0x12,  PAUSE:                0x13,
  26.     CAPITAL:              0x14,  KANA:                 0x15,
  27.     KANA:                 0x15,  KANA:                 0x15,
  28.     JUNJA:                0x17,  FINAL:                0x18,
  29.     HANJA:                0x19,  HANJA:                0x19,
  30.     ESCAPE:               0x1b,  CONVERT:              0x1c,
  31.     NONCONVERT:           0x1d,  ACCEPT:               0x1e,
  32.     MODECHANGE:           0x1f,  SPACE:                0x20,
  33.     PRIOR:                0x21,  NEXT:                 0x22,
  34.     END:                  0x23,  HOME:                 0x24,
  35.     LEFT:                 0x25,  UP:                   0x26,
  36.     RIGHT:                0x27,  DOWN:                 0x28,
  37.     SELECT:               0x29,  PRINT:                0x2a,
  38.     EXECUTE:              0x2b,  SNAPSHOT:             0x2c,
  39.     INSERT:               0x2d,  DELETE:               0x2e,
  40.     HELP:                 0x2f,  N0:                   0x30,
  41.     KEY_1:                0x31,  KEY_2:                0x32,
  42.     KEY_3:                0x33,  KEY_4:                0x34,
  43.     KEY_5:                0x35,  KEY_6:                0x36,
  44.     KEY_7:                0x37,  KEY_8:                0x38,
  45.     KEY_9:                0x39,  colon:                0x3a,
  46.     semicolon:            0x3b,  less:                 0x3c,
  47.     equal:                0x3d,  greater:              0x3e,
  48.     question:             0x3f,  at:                   0x40,
  49.     LETTER_A:             0x41,  LETTER_B:             0x42,
  50.     LETTER_C:             0x43,  LETTER_D:             0x44,
  51.     LETTER_E:             0x45,  LETTER_F:             0x46,
  52.     LETTER_G:             0x47,  LETTER_H:             0x48,
  53.     LETTER_I:             0x49,  LETTER_J:             0x4a,
  54.     LETTER_K:             0x4b,  LETTER_L:             0x4c,
  55.     LETTER_M:             0x4d,  LETTER_N:             0x4e,
  56.     LETTER_O:             0x4f,  LETTER_P:             0x50,
  57.     LETTER_Q:             0x51,  LETTER_R:             0x52,
  58.     LETTER_S:             0x53,  LETTER_T:             0x54,
  59.     LETTER_U:             0x55,  LETTER_V:             0x56,
  60.     LETTER_W:             0x57,  LETTER_X:             0x58,
  61.     LETTER_Y:             0x59,  LETTER_Z:             0x5a,
  62.     LWIN:                 0x5b,  RWIN:                 0x5c,
  63.     APPS:                 0x5d,  asciicircum:          0x5e,
  64.     SLEEP:                0x5f,  NUMPAD0:              0x60,
  65.     NUMPAD1:              0x61,  NUMPAD2:              0x62,
  66.     NUMPAD3:              0x63,  NUMPAD4:              0x64,
  67.     NUMPAD5:              0x65,  NUMPAD6:              0x66,
  68.     NUMPAD7:              0x67,  NUMPAD8:              0x68,
  69.     NUMPAD9:              0x69,  MULTIPLY:             0x6a,
  70.     ADD:                  0x6b,  SEPARATOR:            0x6c,
  71.     SUBTRACT:             0x6d,  DECIMAL:              0x6e,
  72.     DIVIDE:               0x6f,  F1:                   0x70,
  73.     F2:                   0x71,  F3:                   0x72,
  74.     F4:                   0x73,  F5:                   0x74,
  75.     F6:                   0x75,  F7:                   0x76,
  76.     F8:                   0x77,  F9:                   0x78,
  77.     F10:                  0x79,  F11:                  0x7a,
  78.     F12:                  0x7b,  F13:                  0x7c,
  79.     F14:                  0x7d,  F15:                  0x7e,
  80.     F16:                  0x7f,  F17:                  0x80,
  81.     F18:                  0x81,  F19:                  0x82,
  82.     F20:                  0x83,  F21:                  0x84,
  83.     F22:                  0x85,  F23:                  0x86,
  84.     F24:                  0x87,  NUMLOCK:              0x90,
  85.     SCROLL:               0x91,  LSHIFT:               0xa0,
  86.     RSHIFT:               0xa1,  LCONTROL:             0xa2,
  87.     RCONTROL:             0xa3,  LMENU:                0xa4,
  88.     RMENU:                0xa5,  BROWSER_BACK:         0xa6,
  89.     BROWSER_FORWARD:      0xa7,  BROWSER_REFRESH:      0xa8,
  90.     BROWSER_STOP:         0xa9,  BROWSER_SEARCH:       0xaa,
  91.     BROWSER_FAVORITES:    0xab,  BROWSER_HOME:         0xac,
  92.     VOLUME_MUTE:          0xad,  VOLUME_DOWN:          0xae,
  93.     VOLUME_UP:            0xaf,  MEDIA_NEXT_TRACK:     0xb0,
  94.     MEDIA_PREV_TRACK:     0xb1,  MEDIA_STOP:           0xb2,
  95.     MEDIA_PLAY_PAUSE:     0xb3,  LAUNCH_MAIL:          0xb4,
  96.     LAUNCH_MEDIA_SELECT:  0xb5,  LAUNCH_APP1:          0xb6,
  97.     LAUNCH_APP2:          0xb7,  cedilla:              0xb8,
  98.     onesuperior:          0xb9,  masculine:            0xba,
  99.     guillemotright:       0xbb,  onequarter:           0xbc,
  100.     onehalf:              0xbd,  threequarters:        0xbe,
  101.     questiondown:         0xbf,  Agrave:               0xc0,
  102.     Aacute:               0xc1,  Acircumflex:          0xc2,
  103.     Atilde:               0xc3,  Adiaeresis:           0xc4,
  104.     Aring:                0xc5,  AE:                   0xc6,
  105.     Ccedilla:             0xc7,  Egrave:               0xc8,
  106.     Eacute:               0xc9,  Ecircumflex:          0xca,
  107.     Ediaeresis:           0xcb,  Igrave:               0xcc,
  108.     Iacute:               0xcd,  Icircumflex:          0xce,
  109.     Idiaeresis:           0xcf,  ETH:                  0xd0,
  110.     Ntilde:               0xd1,  Ograve:               0xd2,
  111.     Oacute:               0xd3,  Ocircumflex:          0xd4,
  112.     Otilde:               0xd5,  Odiaeresis:           0xd6,
  113.     multiply:             0xd7,  Oslash:               0xd8,
  114.     Ugrave:               0xd9,  Uacute:               0xda,
  115.     Ucircumflex:          0xdb,  Udiaeresis:           0xdc,
  116.     Yacute:               0xdd,  THORN:                0xde,
  117.     ssharp:               0xdf,  agrave:               0xe0,
  118.     aacute:               0xe1,  acircumflex:          0xe2,
  119.     atilde:               0xe3,  adiaeresis:           0xe4,
  120.     PROCESSKEY:           0xe5,  ae:                   0xe6,
  121.     PACKET:               0xe7,  egrave:               0xe8,
  122.     eacute:               0xe9,  ecircumflex:          0xea,
  123.     ediaeresis:           0xeb,  igrave:               0xec,
  124.     iacute:               0xed,  icircumflex:          0xee,
  125.     idiaeresis:           0xef,  eth:                  0xf0,
  126.     ntilde:               0xf1,  ograve:               0xf2,
  127.     oacute:               0xf3,  ocircumflex:          0xf4,
  128.     otilde:               0xf5,  ATTN:                 0xf6,
  129.     CRSEL:                0xf7,  EXSEL:                0xf8,
  130.     EREOF:                0xf9,  PLAY:                 0xfa,
  131.     ZOOM:                 0xfb,  NONAME:               0xfc,
  132.     PA1:                  0xfd,  thorn:                0xfe,
  133.     ydiaeresis:           0xff
  134.   }
  135.   KEYMAP[:WIN]  = [KEYMAP[:LWIN], KEYMAP[:RWIN]]
  136.  
  137.   #--------------------------------------------------------------------------
  138.   # * Default Keys, you can configure here instead of by pressing F1.
  139.   #--------------------------------------------------------------------------
  140.   UP    = [KEYMAP[:UP]]
  141.   DOWN  = [KEYMAP[:DOWN]]
  142.   LEFT  = [KEYMAP[:LEFT]]
  143.   RIGHT = [KEYMAP[:RIGHT]]
  144.   A     = [KEYMAP[:SHIFT]]
  145.   B     = [KEYMAP[:LETTER_X]]
  146.   C     = [KEYMAP[:LETTER_Z]]
  147.   X     = []
  148.   Y     = []
  149.   Z     = []
  150.   L     = [KEYMAP[:PRIOR]]
  151.   R     = [KEYMAP[:NEXT]]
  152.   F5    = [KEYMAP[:F5]]
  153.   F6    = [KEYMAP[:F6]]
  154.   F7    = [KEYMAP[:F7]]
  155.   F8    = [KEYMAP[:F8]]
  156.   F9    = [KEYMAP[:F9]]
  157.   SHIFT = [KEYMAP[:SHIFT]]
  158.   CTRL  = [KEYMAP[:CONTROL]]
  159.   ALT   = [KEYMAP[:MENU]]
  160.   I     = [KEYMAP[:LETTER_I]]
  161.   E     = [KEYMAP[:LETTER_E]]
  162.   S     = [KEYMAP[:LETTER_S]]
  163.   T     = [KEYMAP[:LETTER_T]]
  164.  
  165.   #--------------------------------------------------------------------------
  166.   # * Symbol version of default keys.
  167.   #--------------------------------------------------------------------------
  168.   SYM_KEYS = {
  169.     :UP     => UP,
  170.     :LEFT   => LEFT,
  171.     :DOWN   => DOWN,
  172.     :RIGHT  => RIGHT,
  173.     :A      => A,
  174.     :B      => B,
  175.     :C      => C,
  176.     :X      => X,
  177.     :Y      => Y,
  178.     :Z      => Z,
  179.     :L      => L,
  180.     :R      => R,
  181.     :F5     => F5,
  182.     :F6     => F6,
  183.     :F7     => F7,
  184.     :F8     => F8,
  185.     :F9     => F9,
  186.     :SHIFT  => SHIFT,
  187.     :CTRL   => CTRL,
  188.     :ALT    => ALT,
  189.     :I      => I,
  190.     :E      => E,
  191.     :S      => S,
  192.     :T      => T
  193.   }
  194.   #--------------------------------------------------------------------------
  195.   # * Key Codes Used in Events Conditional Branchs
  196.   #--------------------------------------------------------------------------
  197.   EventsKeyCodes = {
  198.      2 => :DOWN,
  199.      4 => :LEFT,
  200.      6 => :RIGHT,
  201.      8 => :UP,
  202.     11 => :A,
  203.     12 => :B,
  204.     13 => :C,
  205.     14 => :X,
  206.     15 => :Y,
  207.     16 => :Z,
  208.     17 => :L,
  209.     18 => :R
  210.   }
  211.   #--------------------------------------------------------------------------
  212.   # * Internal APIs to handle keyboard functions
  213.   #--------------------------------------------------------------------------
  214.   GetKeyboardState  = Win32API.new('user32.dll', 'GetKeyboardState',  'I', 'I')
  215.   MapVirtualKeyEx   = Win32API.new('user32.dll', 'MapVirtualKeyEx', 'IIL', 'I')
  216.   ToUnicodeEx       = Win32API.new('user32.dll', 'ToUnicodeEx', 'LLPPILL', 'L')
  217.   #----------
  218.   @language_layout  = Win32API.new('user32.dll', 'GetKeyboardLayout', 'L', 'L').call(0)
  219.   DOWN_STATE_MASK   = (0x8 << 0x04)
  220.   DEAD_KEY_MASK     = (0x8 << 0x1C)
  221.   #-----
  222.   UNICODE_TO_UTF8   = Encoding::Converter.new(Encoding.list[2], Encoding.list[1])
  223.  
  224.   #--------------------------------------------------------------------------
  225.   # * States of keys
  226.   #--------------------------------------------------------------------------
  227.   @state            = DL::CPtr.new(DL.malloc(256), 256)
  228.   @triggered        = Array.new(256, false)
  229.   @pressed          = Array.new(256, false)
  230.   @released         = Array.new(256, false)
  231.   @repeated         = Array.new(256, 0)
  232.  
  233.   #--------------------------------------------------------------------------
  234.   # * Singleton attrs of states
  235.   #--------------------------------------------------------------------------
  236.   class << self
  237.     attr_reader :triggered, :pressed, :released, :repeated, :state
  238.   end
  239.  
  240.   #--------------------------------------------------------------------------
  241.   # * Get a key code by simbol
  242.   #--------------------------------------------------------------------------
  243.   def self.key(sym)
  244.     KEYMAP[sym] || 0
  245.   end
  246.  
  247.   #--------------------------------------------------------------------------
  248.   # * Updates input data.
  249.   # As a general rule, this method is called once per frame.
  250.   #--------------------------------------------------------------------------
  251.   def self.update
  252.     GetKeyboardState.call(@state.to_i)
  253.     #-----
  254.     0.upto(255) do |key|
  255.       if @state[key] & DOWN_STATE_MASK == DOWN_STATE_MASK
  256.         @released[key] = false
  257.         @pressed[key]  = true if (@triggered[key] = !@pressed[key])
  258.         @repeated[key] < 17 ? @repeated[key] += 1 : @repeated[key] = 15
  259.       elsif !@released[key] and @pressed[key]
  260.         @triggered[key] = false
  261.         @pressed[key]   = false
  262.         @repeated[key]  = 0
  263.         @released[key]  = true
  264.       else
  265.         @released[key]  = false
  266.       end
  267.     end
  268.   end
  269.  
  270.   #--------------------------------------------------------------------------
  271.   # * Checks the status of the directional buttons, translates the data into
  272.   # a specialized 4-direction input format, and returns the number pad
  273.   # equivalent (2, 4, 6, 8).
  274.   #
  275.   # If no directional buttons are being pressed (or the equivalent), returns 0.
  276.   #--------------------------------------------------------------------------
  277.   def self.dir4
  278.     return 2 if self.press?(DOWN)
  279.     return 4 if self.press?(LEFT)
  280.     return 6 if self.press?(RIGHT)
  281.     return 8 if self.press?(UP)
  282.     return 0
  283.   end
  284.  
  285.   #--------------------------------------------------------------------------
  286.   # * Checks the status of the directional buttons, translates the data into
  287.   # a specialized 8-direction input format, and returns the number pad
  288.   # equivalent (1, 2, 3, 4, 6, 7, 8, 9).
  289.   #
  290.   #If no directional buttons are being pressed (or the equivalent), returns 0.
  291.   #--------------------------------------------------------------------------
  292.   def self.dir8
  293.     down = self.press?(DOWN)
  294.     left = self.press?(LEFT)
  295.     return 1 if down and left
  296.     right = self.press?(RIGHT)
  297.     return 3 if down and right
  298.     up = self.press?(UP)
  299.     return 7 if up and left
  300.     return 9 if up and right
  301.     return 2 if down
  302.     return 4 if left
  303.     return 6 if right
  304.     return 8 if up
  305.     return 0
  306.   end
  307.  
  308.   #--------------------------------------------------------------------------
  309.   # * Determines whether the button corresponding to the symbol sym is
  310.   # currently being pressed.
  311.   #
  312.   # If the button is being pressed, returns TRUE. If not, returns FALSE.
  313.   #
  314.   #   if Input.press?(:C)
  315.   #     do_something
  316.   #   end
  317.   #--------------------------------------------------------------------------
  318.   def self.press?(keys)
  319.     if keys.is_a?(Numeric)
  320.       k = keys.to_i
  321.       return (@pressed[k] and !@triggered[k])
  322.     elsif keys.is_a?(Array)
  323.       return keys.any? {|key| self.press?(key) }
  324.     elsif keys.is_a?(Symbol)
  325.       if SYM_KEYS.key?(keys)
  326.         return SYM_KEYS[keys].any? {|key| (@pressed[key]  and !@triggered[key]) }
  327.       elsif (KEYMAP.key?(keys))
  328.         k = KEYMAP[keys]
  329.         return (@pressed[k] and !@triggered[k])
  330.       else
  331.         return false
  332.       end
  333.     end
  334.   end
  335.  
  336.   #--------------------------------------------------------------------------
  337.   # * Determines whether the button corresponding to the symbol sym is
  338.   # currently being pressed again.
  339.   # "Pressed again" is seen as time having passed between the button being
  340.   # not pressed and being pressed.
  341.   #
  342.   # If the button is being pressed, returns TRUE. If not, returns FALSE.
  343.   #--------------------------------------------------------------------------
  344.   def self.trigger?(keys)
  345.     if keys.is_a?(Numeric)
  346.       return @triggered[keys.to_i]
  347.     elsif keys.is_a?(Array)
  348.       return keys.any? {|key| @triggered[key]}
  349.     elsif keys.is_a?(Symbol)
  350.       if SYM_KEYS.key?(keys)
  351.         return SYM_KEYS[keys].any? {|key| @triggered[key]}
  352.       elsif KEYMAP.key?(keys)
  353.         return @triggered[KEYMAP[keys]]
  354.       else
  355.         return false
  356.       end
  357.     end
  358.   end
  359.  
  360.   #--------------------------------------------------------------------------
  361.   # * Determines whether the button corresponding to the symbol sym is
  362.   # currently being pressed again.
  363.   # Unlike trigger?, takes into account the repeated input of a button being
  364.   # held down continuously.
  365.   #
  366.   # If the button is being pressed, returns TRUE. If not, returns FALSE.
  367.   #--------------------------------------------------------------------------
  368.   def self.repeat?(keys)
  369.     if keys.is_a?(Numeric)
  370.       key = keys.to_i
  371.       return @repeated[key] == 1 || @repeated[key] == 16
  372.     elsif keys.is_a?(Array)
  373.       return keys.any? {|key| @repeated[key] == 1 || @repeated[key] == 16}
  374.     elsif keys.is_a?(Symbol)
  375.       if SYM_KEYS.key?(keys)
  376.         return SYM_KEYS[keys].any? {|key| @repeated[key] == 1 || @repeated[key] == 16}
  377.       elsif KEYMAP.key?(keys)
  378.         return @repeated[KEYMAP[keys]] == 1 || @repeated[KEYMAP[keys]] == 16
  379.       else
  380.         return false
  381.       end
  382.     end
  383.   end
  384.  
  385.   #--------------------------------------------------------------------------
  386.   # * Determines whether the button corresponding to the symbol sym
  387.   # was released.
  388.   #
  389.   # If the button was released, returns TRUE. If not, returns FALSE.
  390.   #--------------------------------------------------------------------------
  391.   def self.release?(keys)
  392.     if keys.is_a?(Numeric)
  393.       return @released[keys.to_i]
  394.     elsif keys.is_a?(Array)
  395.       return keys.any? {|key| @released[key]}
  396.     elsif keys.is_a?(Symbol)
  397.       if SYM_KEYS.key?(keys)
  398.         return SYM_KEYS[keys].any? {|key| @released[key]}
  399.       elsif KEYMAP.key?(keys)
  400.         return @released[KEYMAP[keys]]
  401.       else
  402.         return false
  403.       end
  404.     end
  405.   end
  406.  
  407.   #--------------------------------------------------------------------------
  408.   # * Gets the character that correspond to vk using the keyboard layout
  409.   #--------------------------------------------------------------------------
  410.   def self.get_character(vk)
  411.     c = MapVirtualKeyEx.call(vk, 2, @language_layout)
  412.     return '' if c < 32 && (c & DEAD_KEY_MASK != DEAD_KEY_MASK)
  413.     #-----
  414.     result = "\0" * 2
  415.     length = ToUnicodeEx.call(vk, MapVirtualKeyEx.call(vk, 0, @language_layout),
  416.                               @state, result, 2, 0, @language_layout)
  417.     #-----
  418.     return (length == 0 ? '' : result)
  419.   end
  420.  
  421.   #--------------------------------------------------------------------------
  422.   # * Accents Table, to bo used in conversion from ASCII to UTF8
  423.   #--------------------------------------------------------------------------
  424.   AccentsCharsConv = {
  425.     'A' =>  ['À', 'Á', 'Â', 'Ã', 'Ä'],
  426.     'E' =>  ['È', 'É', 'Ê',  0,  'Ë'],
  427.     'I' =>  ['Ì', 'Í', 'Î',  0,  'Ï'],
  428.     'O' =>  ['Ò', 'Ó', 'Ô', 'Õ', 'Ö'],
  429.     'U' =>  ['Ù', 'Ú', 'Û',  0,  'Ü'],
  430.     'C' =>  [ 0 , 'Ç',  0 ,  0,  0 ],
  431.     'N' =>  [ 0 ,  0,  0 , 'Ñ',  0 ],
  432.     'Y' =>  [ 0 , 'Ý',  0 ,  0,  'Ÿ'],
  433.     'a' =>  ['à', 'á', 'â', 'ã', 'ä'],
  434.     'e' =>  ['è', 'é', 'ê',  0 , 'ë'],
  435.     'i' =>  ['ì', 'í', 'î',  0 , 'ï'],
  436.     'o' =>  ['ò', 'ó', 'ô', 'õ', 'ö'],
  437.     'u' =>  ['ù', 'ú', 'û',  0 , 'ü'],
  438.     'c' =>  [ 0 , 'ç',  0 ,  0 ,  0 ],
  439.     'n' =>  [ 0 ,  0 ,  0 , 'ñ',  0 ],
  440.     'y' =>  [ 0 , 'ý',  0 ,  0 , 'ÿ'],
  441.   }
  442.   # Letters that can have accent
  443.   PssbLetters    = 'AEIOUCNYaeioucny'
  444.   # Accents, in ASCII, configured at runtime to avoid encoding troubles
  445.   Accents        = [96.chr, 180.chr, 94.chr, 126.chr, 168.chr].join
  446.   NonCompatChars = [180, 168]
  447.   @last_accent  = nil
  448.  
  449.   #--------------------------------------------------------------------------
  450.   # * Get inputed string transcoded to UTF8
  451.   #--------------------------------------------------------------------------
  452.   def self.UTF8String
  453.     result = ''
  454.     31.upto(255) {|key|
  455.         if self.repeat?(key)
  456.           c = self.get_character(key)
  457.           if (cc = c.unpack('C')[0]) and NonCompatChars.include?(cc)
  458.             result += cc.chr
  459.           else
  460.             result += UNICODE_TO_UTF8.convert(c) if c != ''
  461.           end
  462.         end
  463.     }
  464.     return '' if result == ''
  465.     #-----
  466.     if @last_accent
  467.       result      = @last_accent + result
  468.       @last_accent = nil
  469.     end
  470.     f_result = ''
  471.     jump    = false
  472.     for i in 0 ... result.length
  473.       c = result[i]
  474.       if jump
  475.         jump = false
  476.         next
  477.       end
  478.       #-----
  479.       if Accents.include?(c)
  480.         if (nc = result[i+1]) != nil
  481.           if PssbLetters.include?(nc)
  482.             if (ac = AccentsCharsConv[nc][Accents.index(c)]) != 0
  483.               f_result << ac
  484.               jump = true
  485.             else
  486.               f_result << c
  487.               f_result << nc
  488.               jump = true
  489.             end
  490.           elsif Accents.include?(nc)
  491.             f_result << c
  492.             f_result << nc
  493.             jump = true
  494.           else
  495.             f_result << c
  496.             f_result << nc
  497.             jump = true
  498.           end
  499.         else
  500.           @last_accent = c
  501.         end
  502.       else
  503.         f_result << c
  504.       end
  505.     end
  506.     #-----
  507.     return f_result
  508.   end
  509.   #----------
  510. end
  511.  
  512. #
  513. # Game_Interpreter
  514. # def command_111 modification to work properly with my Input System
  515. #
  516. class Game_Interpreter
  517.   #--------------------------------------------------------------------------
  518.   # * Conditional Branch
  519.   #--------------------------------------------------------------------------
  520.   def command_111
  521.     result = false
  522.     case @params[0]
  523.     when 0  # Switch
  524.       result = ($game_switches[@params[1]] == (@params[2] == 0))
  525.     when 1  # Variable
  526.       value1 = $game_variables[@params[1]]
  527.       if @params[2] == 0
  528.         value2 = @params[3]
  529.       else
  530.         value2 = $game_variables[@params[3]]
  531.       end
  532.       case @params[4]
  533.       when 0  # value1 is equal to value2
  534.         result = (value1 == value2)
  535.       when 1  # value1 is greater than or equal to value2
  536.         result = (value1 >= value2)
  537.       when 2  # value1 is less than or equal to value2
  538.         result = (value1 <= value2)
  539.       when 3  # value1 is greater than value2
  540.         result = (value1 > value2)
  541.       when 4  # value1 is less than value2
  542.         result = (value1 < value2)
  543.       when 5  # value1 is not equal to value2
  544.         result = (value1 != value2)
  545.       end
  546.     when 2  # Self switch
  547.       if @event_id > 0
  548.         key = [@map_id, @event_id, @params[1]]
  549.         result = ($game_self_switches[key] == (@params[2] == 0))
  550.       end
  551.     when 3  # Timer
  552.       if $game_timer.working?
  553.         if @params[2] == 0
  554.           result = ($game_timer.sec >= @params[1])
  555.         else
  556.           result = ($game_timer.sec <= @params[1])
  557.         end
  558.       end
  559.     when 4  # Actor
  560.       actor = $game_actors[@params[1]]
  561.       if actor
  562.         case @params[2]
  563.         when 0  # in party
  564.           result = ($game_party.members.include?(actor))
  565.         when 1  # name
  566.           result = (actor.name == @params[3])
  567.         when 2  # Class
  568.           result = (actor.class_id == @params[3])
  569.         when 3  # Skills
  570.           result = (actor.skill_learn?($data_skills[@params[3]]))
  571.         when 4  # Weapons
  572.           result = (actor.weapons.include?($data_weapons[@params[3]]))
  573.         when 5  # Armors
  574.           result = (actor.armors.include?($data_armors[@params[3]]))
  575.         when 6  # States
  576.           result = (actor.state?(@params[3]))
  577.         end
  578.       end
  579.     when 5  # Enemy
  580.       enemy = $game_troop.members[@params[1]]
  581.       if enemy
  582.         case @params[2]
  583.         when 0  # appear
  584.           result = (enemy.alive?)
  585.         when 1  # state
  586.           result = (enemy.state?(@params[3]))
  587.         end
  588.       end
  589.     when 6  # Character
  590.       character = get_character(@params[1])
  591.       if character
  592.         result = (character.direction == @params[2])
  593.       end
  594.     when 7  # Gold
  595.       case @params[2]
  596.       when 0  # Greater than or equal to
  597.         result = ($game_party.gold >= @params[1])
  598.       when 1  # Less than or equal to
  599.         result = ($game_party.gold <= @params[1])
  600.       when 2  # Less than
  601.         result = ($game_party.gold < @params[1])
  602.       end
  603.     when 8  # Item
  604.       result = $game_party.has_item?($data_items[@params[1]])
  605.     when 9  # Weapon
  606.       result = $game_party.has_item?($data_weapons[@params[1]], @params[2])
  607.     when 10  # Armor
  608.       result = $game_party.has_item?($data_armors[@params[1]], @params[2])
  609.     when 11  # Button
  610.       key = Input::EventsKeyCodes[@params[1]]
  611.       result = Input.press?(key) if key
  612.     when 12  # Script
  613.       result = eval(@params[1])
  614.     when 13  # Vehicle
  615.       result = ($game_player.vehicle == $game_map.vehicles[@params[1]])
  616.     end
  617.     @branch[@indent] = result
  618.     command_skip if !@branch[@indent]
  619.   end
  620. end
Advertisement
Add Comment
Please, Sign In to add comment