SHOW:
|
|
- or go back to the newest paste.
| 1 | #============================================================================== | |
| 2 | # * Dax Core | |
| 3 | #============================================================================== | |
| 4 | # Autor : Dax Aquatic X | |
| 5 | - | # Versão : Core i3.5 |
| 5 | + | # Versão : Core i3.7 |
| 6 | # Site : www.dax-soft.weebly.com | |
| 7 | # Suporte : [email protected] | |
| 8 | #============================================================================== | |
| 9 | # Um Core com vários módulos e métodos que facilitará na hora de programar os | |
| 10 | # seus scripts, bom proveito. | |
| 11 | #============================================================================== | |
| 12 | # Conteúdo : | |
| 13 | #============================================================================== | |
| 14 | # i : | |
| 15 | # - API | |
| 16 | # - String | |
| 17 | # - Integer | |
| 18 | # - Float | |
| 19 | # - Color | |
| 20 | # - ColorBasic | |
| 21 | # - DMath | |
| 22 | # - Key | |
| 23 | # - Mouse | |
| 24 | # - Entries | |
| 25 | # - Rpg Module | |
| 26 | # - Read | |
| 27 | # - DRGSS | |
| 28 | # - Rect | |
| 29 | # - Sprite | |
| 30 | # - Bitmap : method (save) by Gab! | |
| 31 | # - Object | |
| 32 | # - Touch_Picture | |
| 33 | # - Simple_Touch_Picture | |
| 34 | # - Sprite_Text | |
| 35 | # - Text_Base | |
| 36 | # - Touch_Icon | |
| 37 | # - Simple_Touch_Icon | |
| 38 | # - Touch_Text | |
| 39 | # - Simple_Touch_Text | |
| 40 | # - Opacity | |
| 41 | # - DString | |
| 42 | # - Background | |
| 43 | # - Background | |
| 44 | # - Window_Base | |
| 45 | # - Map | |
| 46 | # - VS | |
| 47 | # - Sound Base | |
| 48 | # - Disable Script | |
| 49 | # - Regexp Symbols | |
| 50 | # - Enumerables | |
| 51 | # - Cache | |
| 52 | # - Sprite_Icon | |
| 53 | # - Module | |
| 54 | # - Window_CommandEx | |
| 55 | # - Crypt | |
| 56 | # - Vector | |
| 57 | # - Matrix | |
| 58 | # - Animation(BASE para estudos.) | |
| 59 | # - Sprite_Anime_Horz(BASE para estudos.) | |
| 60 | # - Sprite_Anime_Vert(BASE para estudos.) | |
| 61 | # - KeyStringSprite(BASE para estudos.) | |
| 62 | # - Clipboard | |
| 63 | # - Array | |
| 64 | # - MessageBox | |
| 65 | #============================================================================== | |
| 66 | # • Adicionado comentário padrão. Veja o modo que agora os comentários dos | |
| 67 | # métodos estão. | |
| 68 | #============================================================================== | |
| 69 | # • [Classe do Retorno] : Explicação. | |
| 70 | # * Exemplo. | |
| 71 | #============================================================================== | |
| 72 | # • TAGS : Para facilitar a localização dos códigos e explicações. Para acessar | |
| 73 | # o comando para localizar, basta apertar Ctrl+F. | |
| 74 | #============================================================================== | |
| 75 | # :api -> Ir até módulos das API; | |
| 76 | # :enumerables -> Ir até add-ons para Enumerables. | |
| 77 | # :string -> Ir até add-ons para a classe String. | |
| 78 | # :integer -> Ir até add-ons para a classe Integer. | |
| 79 | # :float -> Ir até add-ons para a classe Float. | |
| 80 | # :color -> Ir até add-ons para a classe Color. | |
| 81 | # :rect -> Ir até add-ons para a classe Rect. | |
| 82 | # :dmath -> Ir até o módulo DMath. | |
| 83 | # :colorbasic -> Ir até o módulo ColorBasic. | |
| 84 | # :key -> Ir até o módulo Key. | |
| 85 | # :sprite -> Ir até add-ons para a classe Sprite. | |
| 86 | # :bitmap -> Ir até add-ons para a classe Bitmap. | |
| 87 | # :mouse -> Ir até o módulo Mouse. | |
| 88 | # :object -> Ir até add-ons para a classe Object. | |
| 89 | # :entries -> Ir até a classe Entries. | |
| 90 | # :text_base -> Ir até a classe Text Base. | |
| 91 | # :drgss -> Ir até o módulo DRGSS. | |
| 92 | # :outline_fill_rect -> Ir até a classe OutlineFillRect | |
| 93 | # :backupsystem -> Ir até o método de backup. Para fazer backup só chamar o | |
| 94 | # método backup. | |
| 95 | # :dstring -> Ir até o módulo DString. | |
| 96 | # :scenemanager -> Ir até add-ons para o módulo SceneManager. | |
| 97 | # :sprite_text -> Ir até a classe Sprite_Text. | |
| 98 | # :opacity -> Ir até o módulo Opacity. | |
| 99 | # :rpg -> Ir até o módulo Rpg. | |
| 100 | # :shortcut -> Ir até o método Shortcut. | |
| 101 | # :read -> Ir até o módulo Read. | |
| 102 | # :background -> Ir até o módulo Background. | |
| 103 | # :window_base -> Ir até add-ons para a classe Window_Base. | |
| 104 | # :map -> Ir até o módulo Map. | |
| 105 | # :vs -> Ir até o módulo VS. | |
| 106 | # :sound_base -> Ir até o módulo Sound_Base. | |
| 107 | # :position -> Ir até a classe Positions. | |
| 108 | # :cache -> Ir até add-ons para o módulo Cache. | |
| 109 | # :sprite_icon -> Ir até a classe Sprite_Icon. | |
| 110 | # :wcEx -> Ir até a classe Window_CommandEx | |
| 111 | # :crypt -> Ir até o módulo Crypt. | |
| 112 | # :vector -> Ir até a classe Vector | |
| 113 | # :matrix -> Ir até a classe Matrix. | |
| 114 | # :animation -> Ir até o módulo de Animation. | |
| 115 | # :sprite_anime_horz -> Ir até a classe Sprite_Anime_Horz | |
| 116 | # :sprite_anime_vert -> Ir até a classe Sprite_Anime_Vert | |
| 117 | # :key_string_sprite -> Ir até a classe KeyStringSprite | |
| 118 | # :array -> Ir até os Add-ons da classe Array. | |
| 119 | #============================================================================== | |
| 120 | module Dax | |
| 121 | extend self | |
| 122 | #---------------------------------------------------------------------------- | |
| 123 | # Ajuste aqui as configurações básicas da fonte padrão do jogo. | |
| 124 | #---------------------------------------------------------------------------- | |
| 125 | Font.default_name = "Trebuchet MS" # Nome padrão da fonte do jogo. | |
| 126 | Font.default_size = 22 # Tamanho padrão da fonte do jogo. | |
| 127 | Font.default_bold = true # true - Para usar negrito | false - para não usar. | |
| 128 | Font.default_italic = false # true - Para usar italico | false - para não usar. | |
| 129 | Font.default_shadow = false # true - Para usar sombra na fonte | false - para não usar. | |
| 130 | Font.default_outline = false # true - Para usar borda da fonte | false - para não usar. | |
| 131 | Font.default_out_color = Color.new(0, 0, 0) # Cor da fonte padrão da borda da fonte. | |
| 132 | Font.default_color = Color.new(255, 255, 255) # Cor da fonte padrão. | |
| 133 | FontArray = ["name", "size", "bold", "italic", "shadow", "outline", "color"] | |
| 134 | #---------------------------------------------------------------------------- | |
| 135 | # * Constantes e variáveis | |
| 136 | #---------------------------------------------------------------------------- | |
| 137 | @register = {} # Armazena os scripts criados que foram registrados.
| |
| 138 | @benchmark = "" # Armazena os testes conclusos de benchmark. | |
| 139 | # A imagem do ícone do Mouse tem que estar na pasta System. Basta você | |
| 140 | # por o nome da imagem dentro das áspas. Caso você queira usar um ícone | |
| 141 | # do Rpg Maker no lugar de uma imagem, basta você por o id do ícone no lugar | |
| 142 | # das áspas. | |
| 143 | Mouse_Name = "" | |
| 144 | - | # Constante base para ponteiros números em formato Float. Regexp |
| 144 | + | |
| 145 | # * Somente executará o bloco caso estiver registrado o script. | |
| 146 | #---------------------------------------------------------------------------- | |
| 147 | - | PARAM_RE = /^-(-|\.$|[^\d\.])/ |
| 147 | + | |
| 148 | # Dax.required_script(:teste) { # Só irá executar caso estiver registrado.
| |
| 149 | # methods... | |
| 150 | # } | |
| 151 | #---------------------------------------------------------------------------- | |
| 152 | def required_script(symbol, &block) | |
| 153 | block.call if @register.has_key?(symbol) and block_given? | |
| 154 | end | |
| 155 | #---------------------------------------------------------------------------- | |
| 156 | # * Método de registrar scripts : | |
| 157 | #---------------------------------------------------------------------------- | |
| 158 | # ** Este método tem de ser definido alguns valores como : | |
| 159 | # symbol - nome do script, que é posto em símbolo : Ex - :arrow | |
| 160 | # name - nome do autor do script, que é posto em áspas | |
| 161 | # version - versão do script; | |
| 162 | # data - data do script; | |
| 163 | # Dax.register(symbol, name, version, data) | |
| 164 | # ** Você pode usá-lo para somente registrar o nome do script. | |
| 165 | # Dax.register(symbol) | |
| 166 | #---------------------------------------------------------------------------- | |
| 167 | def register(*args) | |
| 168 | if @register.has_key?(args[0]) | |
| 169 | @register[args[0]][:version] = args[1] | |
| 170 | @register[args[0]][:data] = args[2] | |
| 171 | else | |
| 172 | @register[args[0]] = {name: args[1], version: args[2], data: args[3], script: nil}
| |
| 173 | end | |
| 174 | end | |
| 175 | #---------------------------------------------------------------------------- | |
| 176 | # * Método de verificar se o objeto existe. | |
| 177 | #---------------------------------------------------------------------------- | |
| 178 | # Dax.required_class("Objeto") { }
| |
| 179 | # Dentro das chaves você poem o script. | |
| 180 | # * Exemplo : | |
| 181 | # Dax.required_class("Window_Base") {
| |
| 182 | # class Window_Base < Window | |
| 183 | # def example | |
| 184 | # self.x = self.x + self.width | |
| 185 | # end | |
| 186 | # end | |
| 187 | # } | |
| 188 | #---------------------------------------------------------------------------- | |
| 189 | # Executa o bloco se o objeto existir. | |
| 190 | #---------------------------------------------------------------------------- | |
| 191 | def required_class(name, &block) | |
| 192 | return unless defined?(name) | |
| 193 | eval("block.call if defined?(name)")
| |
| 194 | end | |
| 195 | #---------------------------------------------------------------------------- | |
| 196 | # • Fazer benchmark de um bloco. O resultado será impresso no Console do | |
| 197 | # Maker. | |
| 198 | #---------------------------------------------------------------------------- | |
| 199 | # Dax.benchmark(name(opcional)) { BLOCO }
| |
| 200 | #---------------------------------------------------------------------------- | |
| 201 | def benchmark(name="", &block) | |
| 202 | time = Time.now | |
| 203 | block.call | |
| 204 | print "Benchmark: #{(time - Time.now).abs.to_f} segundos!\r\n"
| |
| 205 | @benchmark += "#{name} : #{(time - Time.now).to_f} segundos!\r\n"
| |
| 206 | end | |
| 207 | #---------------------------------------------------------------------------- | |
| 208 | # • Salva os testes de benchmark num arquivo chamado 'Benchmark' de extensão | |
| 209 | # .txt. | |
| 210 | #---------------------------------------------------------------------------- | |
| 211 | def benchmark_save | |
| 212 | self.required_file("Benchmark.txt") { File.delete("Benchmark.txt") }
| |
| 213 | File.open("Benchmark.txt", "a+") do |file|
| |
| 214 | file.write(@benchmark) | |
| 215 | file.close | |
| 216 | end | |
| 217 | end | |
| 218 | #---------------------------------------------------------------------------- | |
| 219 | # • Requirir um arquivo. | |
| 220 | # arquivo : Arquivo... | |
| 221 | #---------------------------------------------------------------------------- | |
| 222 | def require(arquivo) | |
| 223 | $: << "./" | |
| 224 | Kernel.send(:require, arquivo) | |
| 225 | end | |
| 226 | #---------------------------------------------------------------------------- | |
| 227 | # * Somente executa um bloco case existir um arquivo. | |
| 228 | #---------------------------------------------------------------------------- | |
| 229 | # Dax.required_file("arquivo.tipo") { # Exemplo.
| |
| 230 | # Métodos; | |
| 231 | # } | |
| 232 | #---------------------------------------------------------------------------- | |
| 233 | def required_file(filename, &block) | |
| 234 | return unless FileTest.exist?(filename) | |
| 235 | block.call | |
| 236 | end | |
| 237 | # Requer a existência de uma pasta para executar tal bloco. | |
| 238 | def required_directory(directory, &block) | |
| 239 | return unless File.directory?(directory) and block_given? | |
| 240 | block.call | |
| 241 | end | |
| 242 | #---------------------------------------------------------------------------- | |
| 243 | # * Remove uma [Classe], exemplo: Dax.remove(:Scene_Menu) | |
| 244 | #---------------------------------------------------------------------------- | |
| 245 | def remove(symbol_name) | |
| 246 | Object.send(:remove_const, symbol_name) | |
| 247 | end | |
| 248 | #---------------------------------------------------------------------------- | |
| 249 | # * Tela chéia | |
| 250 | #---------------------------------------------------------------------------- | |
| 251 | def full_screen | |
| 252 | res = Win32API.new 'user32', 'keybd_event', %w(l l l l), '' | |
| 253 | - | # * Retorna a variável [$RGSS_SCRIPT] |
| 253 | + | |
| 254 | res.call(13,0,0,0) | |
| 255 | - | def rgss_script |
| 255 | + | |
| 256 | - | return $RGSS_SCRIPTS |
| 256 | + | |
| 257 | end | |
| 258 | end | |
| 259 | #============================================================================== | |
| 260 | # • Module | |
| 261 | #============================================================================== | |
| 262 | Dax.register(:module) | |
| 263 | class Module | |
| 264 | #---------------------------------------------------------------------------- | |
| 265 | # • [NilClass] Permite definir uma variável de instância com um valor definido. | |
| 266 | # Exemplo: | |
| 267 | # Test = Class.new {
| |
| 268 | # attr_value :gold, 0 | |
| 269 | # } | |
| 270 | # msgbox Test.new.gold #=> 0 | |
| 271 | #---------------------------------------------------------------------------- | |
| 272 | def attr_value(symbol, value=nil) | |
| 273 | attr_accessor(symbol) | |
| 274 | module_eval("def #{symbol}
| |
| 275 | @#{symbol} = #{value} unless defined?(@#{symbol})
| |
| 276 | return @#{symbol}
| |
| 277 | end") | |
| 278 | return nil | |
| 279 | end | |
| 280 | end | |
| 281 | Dax.register(:dax) | |
| 282 | #============================================================================== | |
| 283 | # • Array | |
| 284 | #============================================================================== | |
| 285 | Dax.register :array | |
| 286 | class Array | |
| 287 | #---------------------------------------------------------------------------- | |
| 288 | # • [Array] Retorna ao elemento da array que condiz com a condição | |
| 289 | # definida no bloco. | |
| 290 | # Exemplo: | |
| 291 | # [2, 4, 5, 6, 8].rIf { |element| element >= 4 }
| |
| 292 | # # 5, 6, 8 | |
| 293 | #---------------------------------------------------------------------------- | |
| 294 | def rIf | |
| 295 | return unless block_given? | |
| 296 | getResult ||= [] | |
| 297 | self.each_with_index{ |arrays|
| |
| 298 | getResult << arrays if yield(arrays) | |
| 299 | } | |
| 300 | return getResult | |
| 301 | end | |
| 302 | end | |
| 303 | #============================================================================== | |
| 304 | # * API : Módulo que armazena informações de algumas APIS. | |
| 305 | #============================================================================== | |
| 306 | Dax.register(:api) | |
| 307 | module API | |
| 308 | extend self | |
| 309 | #---------------------------------------------------------------------------- | |
| 310 | # • [String] : Tipos e seus retornos.. Pegado da internet.. Autor desconhecido | |
| 311 | #---------------------------------------------------------------------------- | |
| 312 | TYPES = {
| |
| 313 | struct: "p", | |
| 314 | int: "i", | |
| 315 | long: "l", | |
| 316 | INTERNET_PORT: "l", | |
| 317 | SOCKET: "p", | |
| 318 | C: "p", #– 8-bit unsigned character (byte) | |
| 319 | c: "p", # 8-bit character (byte) | |
| 320 | # "i"8 – 8-bit signed integer | |
| 321 | # "i"8 – 8-bit unsigned integer | |
| 322 | - | TYPES = {
|
| 322 | + | |
| 323 | s: "n", # – 16-bit signed integer | |
| 324 | # "i"16 – 16-bit unsigned integer | |
| 325 | # "i"16 – 16-bit signed integer | |
| 326 | I: "I", # 32-bit unsigned integer | |
| 327 | i: "i", # 32-bit signed integer | |
| 328 | # "i"32 – 32-bit unsigned integer | |
| 329 | # "i"32 – 32-bit signed integer | |
| 330 | L: "L", # unsigned long int – platform-specific size | |
| 331 | l: "l", # long int – platform-specific size. For discussion of platforms, see: | |
| 332 | # (http://groups.google.com/group/ruby-ffi/browse_thread/thread/4762fc77130339b1) | |
| 333 | # "i"64 – 64-bit signed integer | |
| 334 | # "i"64 – 64-bit unsigned integer | |
| 335 | # "l"_long – 64-bit signed integer | |
| 336 | # "l"_long – 64-bit unsigned integer | |
| 337 | F: "L", # 32-bit floating point | |
| 338 | D: "L", # 64-bit floating point (double-precision) | |
| 339 | P: "P", # pointer – platform-specific size | |
| 340 | p: "p", # C-style (NULL-terminated) character string (Win32API: S) | |
| 341 | B: "i", # (?? 1 byte in C++) | |
| 342 | V: "V", # For functions that return nothing (return type void). | |
| 343 | v: "v", # For functions that return nothing (return type void). | |
| 344 | # For function argument type only: | |
| 345 | # :buffer_in – Similar to "l", but optimized for Buffers that the function can only read (not write). | |
| 346 | # :buffer_out – Similar to "l", but optimized for Buffers that the function can only write (not read). | |
| 347 | # :buffer_inout – Similar to "l", but may be optimized for Buffers. | |
| 348 | # :varargs – Variable arguments | |
| 349 | # :enum - Enumerable type (should be defined) | |
| 350 | # "p"_array - ?? | |
| 351 | ||
| 352 | # Windows-specific type defs (ms-help://MS.MSDNQTR.v90.en/winprog/winprog/windows_data_types.htm): | |
| 353 | ATOM: "I", # Atom ~= Symbol: Atom table stores strings and corresponding identifiers. Application | |
| 354 | # places a string in an atom table and receives a 16-bit integer, called an atom, that | |
| 355 | # can be used to access the string. Placed string is called an atom name. | |
| 356 | # See: http://msdn.microsoft.com/en-us/library/ms648708%28VS.85%29.aspx | |
| 357 | BOOL: "i", | |
| 358 | BOOLEAN: "i", | |
| 359 | BYTE: "p", # Byte (8 bits). Declared as unsigned char | |
| 360 | #CALLBACK: K, # Win32.API gem-specific ?? MSDN: #define CALLBACK __stdcall | |
| 361 | CHAR: "p", # 8-bit Windows (ANSI) character. See http://msdn.microsoft.com/en-us/library/dd183415%28VS.85%29.aspx | |
| 362 | COLORREF: "i", # Red, green, blue (RGB) color value (32 bits). See COLORREF for more info. | |
| 363 | DWORD: "i", # 32-bit unsigned integer. The range is 0 through 4,294,967,295 decimal. | |
| 364 | DWORDLONG: "i", # 64-bit unsigned integer. The range is 0 through 18,446,744,073,709,551,615 decimal. | |
| 365 | DWORD_PTR: "l", # Unsigned long type for pointer precision. Use when casting a pointer to a long type | |
| 366 | # to perform pointer arithmetic. (Also commonly used for general 32-bit parameters that have | |
| 367 | # been extended to 64 bits in 64-bit Windows.) BaseTsd.h: #typedef ULONG_PTR DWORD_PTR; | |
| 368 | DWORD32: "I", | |
| 369 | DWORD64: "I", | |
| 370 | HALF_PTR: "i", # Half the size of a pointer. Use within a structure that contains a pointer and two small fields. | |
| 371 | # BaseTsd.h: #ifdef (_WIN64) typedef int HALF_PTR; #else typedef short HALF_PTR; | |
| 372 | HACCEL: "i", # (L) Handle to an accelerator table. WinDef.h: #typedef HANDLE HACCEL; | |
| 373 | # See http://msdn.microsoft.com/en-us/library/ms645526%28VS.85%29.aspx | |
| 374 | HANDLE: "l", # (L) Handle to an object. WinNT.h: #typedef PVOID HANDLE; | |
| 375 | # todo: Platform-dependent! Need to change to "i"64 for Win64 | |
| 376 | HBITMAP: "l", # (L) Handle to a bitmap: http://msdn.microsoft.com/en-us/library/dd183377%28VS.85%29.aspx | |
| 377 | HBRUSH: "l", # (L) Handle to a brush. http://msdn.microsoft.com/en-us/library/dd183394%28VS.85%29.aspx | |
| 378 | HCOLORSPACE: "l", # (L) Handle to a color space. http://msdn.microsoft.com/en-us/library/ms536546%28VS.85%29.aspx | |
| 379 | HCURSOR: "l", # (L) Handle to a cursor. http://msdn.microsoft.com/en-us/library/ms646970%28VS.85%29.aspx | |
| 380 | HCONV: "l", # (L) Handle to a dynamic data exchange (DDE) conversation. | |
| 381 | HCONVLIST: "l", # (L) Handle to a DDE conversation list. HANDLE - L ? | |
| 382 | HDDEDATA: "l", # (L) Handle to DDE data (structure?) | |
| 383 | HDC: "l", # (L) Handle to a device context (DC). http://msdn.microsoft.com/en-us/library/dd183560%28VS.85%29.aspx | |
| 384 | HDESK: "l", # (L) Handle to a desktop. http://msdn.microsoft.com/en-us/library/ms682573%28VS.85%29.aspx | |
| 385 | HDROP: "l", # (L) Handle to an internal drop structure. | |
| 386 | HDWP: "l", # (L) Handle to a deferred window position structure. | |
| 387 | HENHMETAFILE: "l", #(L) Handle to an enhanced metafile. http://msdn.microsoft.com/en-us/library/dd145051%28VS.85%29.aspx | |
| 388 | HFILE: "i", # (I) Special file handle to a file opened by OpenFile, not CreateFile. | |
| 389 | # WinDef.h: #typedef int HFILE; | |
| 390 | HFONT: "l", # (L) Handle to a font. http://msdn.microsoft.com/en-us/library/dd162470%28VS.85%29.aspx | |
| 391 | HGDIOBJ: "l", # (L) Handle to a GDI object. | |
| 392 | HGLOBAL: "l", # (L) Handle to a global memory block. | |
| 393 | HHOOK: "l", # (L) Handle to a hook. http://msdn.microsoft.com/en-us/library/ms632589%28VS.85%29.aspx | |
| 394 | HICON: "l", # (L) Handle to an icon. http://msdn.microsoft.com/en-us/library/ms646973%28VS.85%29.aspx | |
| 395 | HINSTANCE: "l", # (L) Handle to an instance. This is the base address of the module in memory. | |
| 396 | # HMODULE and HINSTANCE are the same today, but were different in 16-bit Windows. | |
| 397 | HKEY: "l", # (L) Handle to a registry key. | |
| 398 | HKL: "l", # (L) Input locale identifier. | |
| 399 | HLOCAL: "l", # (L) Handle to a local memory block. | |
| 400 | HMENU: "l", # (L) Handle to a menu. http://msdn.microsoft.com/en-us/library/ms646977%28VS.85%29.aspx | |
| 401 | HMETAFILE: "l", # (L) Handle to a metafile. http://msdn.microsoft.com/en-us/library/dd145051%28VS.85%29.aspx | |
| 402 | HMODULE: "l", # (L) Handle to an instance. Same as HINSTANCE today, but was different in 16-bit Windows. | |
| 403 | HMONITOR: "l", # (L) Рandle to a display monitor. WinDef.h: if(WINVER >= 0x0500) typedef HANDLE HMONITOR; | |
| 404 | HPALETTE: "l", # (L) Handle to a palette. | |
| 405 | HPEN: "l", # (L) Handle to a pen. http://msdn.microsoft.com/en-us/library/dd162786%28VS.85%29.aspx | |
| 406 | HRESULT: "l", # Return code used by COM interfaces. For more info, Structure of the COM Error Codes. | |
| 407 | # To test an HRESULT value, use the FAILED and SUCCEEDED macros. | |
| 408 | HRGN: "l", # (L) Handle to a region. http://msdn.microsoft.com/en-us/library/dd162913%28VS.85%29.aspx | |
| 409 | HRSRC: "l", # (L) Handle to a resource. | |
| 410 | HSZ: "l", # (L) Handle to a DDE string. | |
| 411 | HWINSTA: "l", # (L) Handle to a window station. http://msdn.microsoft.com/en-us/library/ms687096%28VS.85%29.aspx | |
| 412 | HWND: "l", # (L) Handle to a window. http://msdn.microsoft.com/en-us/library/ms632595%28VS.85%29.aspx | |
| 413 | INT: "i", # 32-bit signed integer. The range is -2147483648 through 2147483647 decimal. | |
| 414 | INT_PTR: "i", # Signed integer type for pointer precision. Use when casting a pointer to an integer | |
| 415 | # to perform pointer arithmetic. BaseTsd.h: | |
| 416 | #if defined(_WIN64) typedef __int64 INT_PTR; #else typedef int INT_PTR; | |
| 417 | INT32: "i", # 32-bit signed integer. The range is -2,147,483,648 through +...647 decimal. | |
| 418 | INT64: "i", # 64-bit signed integer. The range is –9,223,372,036,854,775,808 through +...807 | |
| 419 | LANGID: "n", # Language identifier. For more information, see Locales. WinNT.h: #typedef WORD LANGID; | |
| 420 | # See http://msdn.microsoft.com/en-us/library/dd318716%28VS.85%29.aspx | |
| 421 | LCID: "i", # Locale identifier. For more information, see Locales. | |
| 422 | LCTYPE: "i", # Locale information type. For a list, see Locale Information Constants. | |
| 423 | LGRPID: "i", # Language group identifier. For a list, see EnumLanguageGroupLocales. | |
| 424 | LONG: "l", # 32-bit signed integer. The range is -2,147,483,648 through +...647 decimal. | |
| 425 | LONG32: "i", # 32-bit signed integer. The range is -2,147,483,648 through +...647 decimal. | |
| 426 | LONG64: "i", # 64-bit signed integer. The range is –9,223,372,036,854,775,808 through +...807 | |
| 427 | LONGLONG: "i", # 64-bit signed integer. The range is –9,223,372,036,854,775,808 through +...807 | |
| 428 | LONG_PTR: "l", # Signed long type for pointer precision. Use when casting a pointer to a long to | |
| 429 | # perform pointer arithmetic. BaseTsd.h: | |
| 430 | #if defined(_WIN64) typedef __int64 LONG_PTR; #else typedef long LONG_PTR; | |
| 431 | LPARAM: "l", # Message parameter. WinDef.h as follows: #typedef LONG_PTR LPARAM; | |
| 432 | LPBOOL: "i", # Pointer to a BOOL. WinDef.h as follows: #typedef BOOL far *LPBOOL; | |
| 433 | LPBYTE: "i", # Pointer to a BYTE. WinDef.h as follows: #typedef BYTE far *LPBYTE; | |
| 434 | LPCSTR: "p", # Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. | |
| 435 | # See Character Sets Used By Fonts. http://msdn.microsoft.com/en-us/library/dd183415%28VS.85%29.aspx | |
| 436 | LPCTSTR: "p", # An LPCWSTR if UNICODE is defined, an LPCSTR otherwise. | |
| 437 | LPCVOID: "v", # Pointer to a constant of any type. WinDef.h as follows: typedef CONST void *LPCVOID; | |
| 438 | LPCWSTR: "P", # Pointer to a constant null-terminated string of 16-bit Unicode characters. | |
| 439 | LPDWORD: "p", # Pointer to a DWORD. WinDef.h as follows: typedef DWORD *LPDWORD; | |
| 440 | LPHANDLE: "l", # Pointer to a HANDLE. WinDef.h as follows: typedef HANDLE *LPHANDLE; | |
| 441 | LPINT: "I", # Pointer to an INT. | |
| 442 | LPLONG: "L", # Pointer to an LONG. | |
| 443 | LPSTR: "p", # Pointer to a null-terminated string of 8-bit Windows (ANSI) characters. | |
| 444 | LPTSTR: "p", # An LPWSTR if UNICODE is defined, an LPSTR otherwise. | |
| 445 | LPVOID: "v", # Pointer to any type. | |
| 446 | LPWORD: "p", # Pointer to a WORD. | |
| 447 | LPWSTR: "p", # Pointer to a null-terminated string of 16-bit Unicode characters. | |
| 448 | LRESULT: "l", # Signed result of message processing. WinDef.h: typedef LONG_PTR LRESULT; | |
| 449 | PBOOL: "i", # Pointer to a BOOL. | |
| 450 | PBOOLEAN: "i", # Pointer to a BOOL. | |
| 451 | PBYTE: "i", # Pointer to a BYTE. | |
| 452 | PCHAR: "p", # Pointer to a CHAR. | |
| 453 | PCSTR: "p", # Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. | |
| 454 | PCTSTR: "p", # A PCWSTR if UNICODE is defined, a PCSTR otherwise. | |
| 455 | PCWSTR: "p", # Pointer to a constant null-terminated string of 16-bit Unicode characters. | |
| 456 | PDWORD: "p", # Pointer to a DWORD. | |
| 457 | PDWORDLONG: "L", # Pointer to a DWORDLONG. | |
| 458 | PDWORD_PTR: "L", # Pointer to a DWORD_PTR. | |
| 459 | PDWORD32: "L", # Pointer to a DWORD32. | |
| 460 | PDWORD64: "L", # Pointer to a DWORD64. | |
| 461 | PFLOAT: "L", # Pointer to a FLOAT. | |
| 462 | PHALF_PTR: "L", # Pointer to a HALF_PTR. | |
| 463 | PHANDLE: "L", # Pointer to a HANDLE. | |
| 464 | PHKEY: "L", # Pointer to an HKEY. | |
| 465 | PINT: "i", # Pointer to an INT. | |
| 466 | PINT_PTR: "i", # Pointer to an INT_PTR. | |
| 467 | PINT32: "i", # Pointer to an INT32. | |
| 468 | PINT64: "i", # Pointer to an INT64. | |
| 469 | PLCID: "l", # Pointer to an LCID. | |
| 470 | PLONG: "l", # Pointer to a LONG. | |
| 471 | PLONGLONG: "l", # Pointer to a LONGLONG. | |
| 472 | PLONG_PTR: "l", # Pointer to a LONG_PTR. | |
| 473 | PLONG32: "l", # Pointer to a LONG32. | |
| 474 | PLONG64: "l", # Pointer to a LONG64. | |
| 475 | POINTER_32: "l", # 32-bit pointer. On a 32-bit system, this is a native pointer. On a 64-bit system, this is a truncated 64-bit pointer. | |
| 476 | POINTER_64: "l", # 64-bit pointer. On a 64-bit system, this is a native pointer. On a 32-bit system, this is a sign-extended 32-bit pointer. | |
| 477 | POINTER_SIGNED: "l", # A signed pointer. | |
| 478 | HPSS: "l", | |
| 479 | POINTER_UNSIGNED: "l", # An unsigned pointer. | |
| 480 | PSHORT: "l", # Pointer to a SHORT. | |
| 481 | PSIZE_T: "l", # Pointer to a SIZE_T. | |
| 482 | PSSIZE_T: "l", # Pointer to a SSIZE_T. | |
| 483 | PSS_CAPTURE_FLAGS: "l", | |
| 484 | PSTR: "p", # Pointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts. | |
| 485 | PTBYTE: "p", # Pointer to a TBYTE. | |
| 486 | PTCHAR: "p", # Pointer to a TCHAR. | |
| 487 | PTSTR: "p", # A PWSTR if UNICODE is defined, a PSTR otherwise. | |
| 488 | PUCHAR: "p", # Pointer to a UCHAR. | |
| 489 | PUINT: "i", # Pointer to a UINT. | |
| 490 | PUINT_PTR: "i", # Pointer to a UINT_PTR. | |
| 491 | PUINT32: "i", # Pointer to a UINT32. | |
| 492 | PUINT64: "i", # Pointer to a UINT64. | |
| 493 | PULONG: "l", # Pointer to a ULONG. | |
| 494 | PULONGLONG: "l", # Pointer to a ULONGLONG. | |
| 495 | PULONG_PTR: "l", # Pointer to a ULONG_PTR. | |
| 496 | PULONG32: "l", # Pointer to a ULONG32. | |
| 497 | PULONG64: "l", # Pointer to a ULONG64. | |
| 498 | PUSHORT: "l", # Pointer to a USHORT. | |
| 499 | PVOID: "v", # Pointer to any type. | |
| 500 | PWCHAR: "p", # Pointer to a WCHAR. | |
| 501 | PWORD: "p", # Pointer to a WORD. | |
| 502 | PWSTR: "p", # Pointer to a null- terminated string of 16-bit Unicode characters. | |
| 503 | # For more information, see Character Sets Used By Fonts. | |
| 504 | SC_HANDLE: "l", # (L) Handle to a service control manager database. | |
| 505 | SERVICE_STATUS_HANDLE: "l", # (L) Handle to a service status value. See SCM Handles. | |
| 506 | SHORT: "i", # A 16-bit integer. The range is –32768 through 32767 decimal. | |
| 507 | SIZE_T: "l", # The maximum number of bytes to which a pointer can point. Use for a count that must span the full range of a pointer. | |
| 508 | SSIZE_T: "l", # Signed SIZE_T. | |
| 509 | TBYTE: "p", # A WCHAR if UNICODE is defined, a CHAR otherwise.TCHAR: | |
| 510 | # http://msdn.microsoft.com/en-us/library/c426s321%28VS.80%29.aspx | |
| 511 | TCHAR: "p", # A WCHAR if UNICODE is defined, a CHAR otherwise.TCHAR: | |
| 512 | UCHAR: "p", # Unsigned CHAR (8 bit) | |
| 513 | UHALF_PTR: "i", # Unsigned HALF_PTR. Use within a structure that contains a pointer and two small fields. | |
| 514 | UINT: "i", # Unsigned INT. The range is 0 through 4294967295 decimal. | |
| 515 | UINT_PTR: "i", # Unsigned INT_PTR. | |
| 516 | UINT32: "i", # Unsigned INT32. The range is 0 through 4294967295 decimal. | |
| 517 | UINT64: "i", # Unsigned INT64. The range is 0 through 18446744073709551615 decimal. | |
| 518 | ULONG: "l", # Unsigned LONG. The range is 0 through 4294967295 decimal. | |
| 519 | ULONGLONG: "l", # 64-bit unsigned integer. The range is 0 through 18446744073709551615 decimal. | |
| 520 | ULONG_PTR: "l", # Unsigned LONG_PTR. | |
| 521 | ULONG32: "i", # Unsigned INT32. The range is 0 through 4294967295 decimal. | |
| 522 | ULONG64: "i", # Unsigned LONG64. The range is 0 through 18446744073709551615 decimal. | |
| 523 | UNICODE_STRING: "P", # Pointer to some string structure?? | |
| 524 | USHORT: "i", # Unsigned SHORT. The range is 0 through 65535 decimal. | |
| 525 | USN: "l", # Update sequence number (USN). | |
| 526 | WCHAR: "i", # 16-bit Unicode character. For more information, see Character Sets Used By Fonts. | |
| 527 | # In WinNT.h: typedef wchar_t WCHAR; | |
| 528 | #WINAPI: K, # Calling convention for system functions. WinDef.h: define WINAPI __stdcall | |
| 529 | WORD: "i", # 16-bit unsigned integer. The range is 0 through 65535 decimal. | |
| 530 | WPARAM: "i", # Message parameter. WinDef.h as follows: typedef UINT_PTR WPARAM; | |
| 531 | VOID: "v", # Any type ? Only use it to indicate no arguments or no return value | |
| 532 | vKey: "i", | |
| 533 | LPRECT: "p", | |
| 534 | } | |
| 535 | #---------------------------------------------------------------------------- | |
| 536 | # • [Array] : Pega os valores especificados no método.. depois verifica | |
| 537 | # cada um se é String ou Symbol. Se for Symbol retorna ao valor especificado | |
| 538 | # na Constante TYPES. | |
| 539 | # Exemplo: types([:BOOL, :WCHAR]) # ["i", "i"] | |
| 540 | #---------------------------------------------------------------------------- | |
| 541 | def types(import) | |
| 542 | import2 = [] | |
| 543 | import.each { |i|
| |
| 544 | next if i.is_a?(NilClass) or i.is_a?(String) | |
| 545 | import2 << TYPES[i] | |
| 546 | } | |
| 547 | return import2 | |
| 548 | end | |
| 549 | #---------------------------------------------------------------------------- | |
| 550 | # • [Dll]// : Especifica uma função, com o valor da importação é a DLL.. | |
| 551 | # Por padrão a DLL é a "user32". O valor de exportação será "i" | |
| 552 | #---------------------------------------------------------------------------- | |
| 553 | def int(function, import, dll="user32") | |
| 554 | Win32API.new(dll, function, types(import), "i") rescue nil | |
| 555 | end | |
| 556 | #---------------------------------------------------------------------------- | |
| 557 | # • [Dll]// : Especifica uma função, com o valor da importação é a DLL.. | |
| 558 | # Por padrão a DLL é a "user32". O valor de exportação será "l" | |
| 559 | #---------------------------------------------------------------------------- | |
| 560 | def long(function, import, dll="user32") | |
| 561 | Win32API.new(dll, function.to_s, types(import), "l") rescue nil | |
| 562 | end | |
| 563 | #---------------------------------------------------------------------------- | |
| 564 | # • [Dll]// : Especifica uma função, com o valor da importação é a DLL.. | |
| 565 | # Por padrão a DLL é a "user32". O valor de exportação será "v" | |
| 566 | #---------------------------------------------------------------------------- | |
| 567 | def void(function, import, dll="user32") | |
| 568 | Win32API.new(dll, function.to_s, types(import), "v") rescue nil | |
| 569 | end | |
| 570 | #---------------------------------------------------------------------------- | |
| 571 | # • [Dll]// : Especifica uma função, com o valor da importação é a DLL.. | |
| 572 | # Por padrão a DLL é a "user32". O valor de exportação será "p" | |
| 573 | #---------------------------------------------------------------------------- | |
| 574 | def char(function, import, dll="user32") | |
| 575 | Win32API.new(dll, function.to_s, types(import), "p") rescue nil | |
| 576 | end | |
| 577 | #---------------------------------------------------------------------------- | |
| 578 | # • [Dll]// : Com esse método você pode especificar uma função de uma Dll. | |
| 579 | # function(export, function, import, dll) | |
| 580 | # export : Valor da exportação. Formato [Symbol] | |
| 581 | # function : Função da Dll. | |
| 582 | # import : Valor da importação. | |
| 583 | # dll : Dll. Por padrão é a User32 | |
| 584 | # Esconder o Mouse. | |
| 585 | # Exemplo: function(:int, "ShowCursor", [:BOOL]).call(0) | |
| 586 | #---------------------------------------------------------------------------- | |
| 587 | def function(export, function, import, dll="user32") | |
| 588 | eval("#{export}(function, import, dll)")
| |
| 589 | end | |
| 590 | #---------------------------------------------------------------------------- | |
| 591 | # • Especificando o método protegido. | |
| 592 | #---------------------------------------------------------------------------- | |
| 593 | # Métodos privados. | |
| 594 | private :long, :int, :char, :void, :types | |
| 595 | #---------------------------------------------------------------------------- | |
| 596 | - | protected :function |
| 596 | + | |
| 597 | # CopyFile.call(filename_to_copy, filename_copied, replace) | |
| 598 | - | private :long, :int, :char, :void, :char, :types |
| 598 | + | |
| 599 | # filename_copied : Formato [String] | |
| 600 | # replace : Formato [Integer] 0 - false 1 - true | |
| 601 | # Exemplo: CopyFile.call("System/RGSS300.dll", "./RGSS300.dll", 1)
| |
| 602 | #---------------------------------------------------------------------------- | |
| 603 | CopyFile = Win32API.new('kernel32', 'CopyFile', 'ppl', 'l')
| |
| 604 | #---------------------------------------------------------------------------- | |
| 605 | # • [Beep]/Dll : Emitir uma frequência de um som do sistema com duração. | |
| 606 | # Beep.call(freq, duration) | |
| 607 | # freq : Formato [Integer\Hexadécimal] | |
| 608 | # duration : Formato [Integer\Hexadécimal] | |
| 609 | # Exemplo: Beep.call(2145, 51) | |
| 610 | #---------------------------------------------------------------------------- | |
| 611 | Beep = Win32API.new('kernel32', 'Beep', 'LL', 'L')
| |
| 612 | #---------------------------------------------------------------------------- | |
| 613 | # • [keybd_event]/Dll : Ela é usada para sintentizar uma combinação de teclas. | |
| 614 | # KEYBD_EVENT.call(vk, scan, fdwFlags, dwExtraInfo) | |
| 615 | # vk : Formato [Integer/Hexadécimal]. | |
| 616 | # scan : Formato [Integer] | |
| 617 | # fdwFlags : Formato [Integer] | |
| 618 | # dwExtraInfo : Formato [Integer] | |
| 619 | # Exemplo: KEYBD_EVENT.call(0x01, 0, 0, 0) | |
| 620 | #---------------------------------------------------------------------------- | |
| 621 | KEYBD_EVENT = Win32API.new('user32', 'keybd_event', 'LLLL', '')
| |
| 622 | #---------------------------------------------------------------------------- | |
| 623 | # • [GetKeyState]/Dll : Pega o status da chave. | |
| 624 | # GetKeyState.call(vk) | |
| 625 | # vk : Formato [Integer/Hexadécimal]. | |
| 626 | # Exemplo: GetKeyState.call(0x01) | |
| 627 | #---------------------------------------------------------------------------- | |
| 628 | GetKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
| |
| 629 | #---------------------------------------------------------------------------- | |
| 630 | # • [MouseShowCursor]/Dll : Mostrar ou desativar o cusor do Mouse. | |
| 631 | # MouseShowCursor.call(value) | |
| 632 | # value : Formato [Integer] 0 - false 1 - true | |
| 633 | # Exemplo: MouseShowCursor.call(0) | |
| 634 | #---------------------------------------------------------------------------- | |
| 635 | MouseShowCursor = Win32API.new("user32", "ShowCursor", "i", "i")
| |
| 636 | #---------------------------------------------------------------------------- | |
| 637 | # • [CursorPosition]/Dll : Obtem a posição do cursor do Mouse na tela. | |
| 638 | # CursorPosition.call(lpPoint) | |
| 639 | # lpPoint : Formato [Array] | |
| 640 | # Ex: CursorPosition.call([0, 0].pack('ll'))
| |
| 641 | #---------------------------------------------------------------------------- | |
| 642 | CursorPosition = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
| |
| 643 | #---------------------------------------------------------------------------- | |
| 644 | # • [ScreenToClient]/Dll : Converte as coordenadas da tela para um ponto | |
| 645 | # em especifico da área da tela do cliente. | |
| 646 | # ScreenToClient.call(hWnd, lpPoint) | |
| 647 | #---------------------------------------------------------------------------- | |
| 648 | ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
| |
| 649 | #---------------------------------------------------------------------------- | |
| 650 | # • [ReadIni]/Dll : */Ainda não explicado./* | |
| 651 | #---------------------------------------------------------------------------- | |
| 652 | ReadIni = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
| |
| 653 | #---------------------------------------------------------------------------- | |
| 654 | # • [FindWindow]/Dll : Recupera o identificador da janela superior. Cujo | |
| 655 | # o nome da janela é o nome da classe da janela se combina com as cadeias | |
| 656 | # especificas. | |
| 657 | # FindWindow.call(lpClassName, lpWindowName) | |
| 658 | # lpClassName : Formato [String] | |
| 659 | # lpWindowName : Formato [String] | |
| 660 | #---------------------------------------------------------------------------- | |
| 661 | FindWindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
| |
| 662 | #---------------------------------------------------------------------------- | |
| 663 | # • [Handle]/Dll : Retorna ao Handle da janela. | |
| 664 | #---------------------------------------------------------------------------- | |
| 665 | def hWND | |
| 666 | return API::FindWindow.call('RGSS Player', load_data("./Data/System.rvdata2").game_title.to_s)
| |
| 667 | end | |
| 668 | #---------------------------------------------------------------------------- | |
| 669 | # • [Handle]/Dll : Retorna ao Handle da janela. Método protegido. | |
| 670 | #---------------------------------------------------------------------------- | |
| 671 | def hwnd | |
| 672 | hWND | |
| 673 | end | |
| 674 | #---------------------------------------------------------------------------- | |
| 675 | # • [GetPrivateProfileString]/Dll : */Ainda não explicado./* | |
| 676 | #---------------------------------------------------------------------------- | |
| 677 | GetPrivateProfileString = Win32API.new('kernel32', 'GetPrivateProfileStringA',%w(p p p p l p),'l')
| |
| 678 | - | protected :hwnd |
| 678 | + | |
| 679 | # • [SetWindowPos]/Dll : Modifica os elementos da janela como, posição, tamanho. | |
| 680 | #---------------------------------------------------------------------------- | |
| 681 | SetWindowPos = Win32API.new("user32", "SetWindowPos", "lliiiii", "i")
| |
| 682 | #---------------------------------------------------------------------------- | |
| 683 | # • [GetWindowRect]/Dll : Obtem as dimensões do retângulo da janela. | |
| 684 | # GetWindowRect.call(hWnd, lpRect) | |
| 685 | #---------------------------------------------------------------------------- | |
| 686 | GetWindowRect = Win32API.new('user32','GetWindowRect',%w(l p),'i')
| |
| 687 | #---------------------------------------------------------------------------- | |
| 688 | # • [StateKey]/Dll : Retorna ao status específico da chave. | |
| 689 | # StateKey.call(VK) | |
| 690 | # VK : Formato [Integer/Hexadécimal]. | |
| 691 | #---------------------------------------------------------------------------- | |
| 692 | StateKey = Win32API.new("user32", "GetKeyState", ["i"], "i")
| |
| 693 | #---------------------------------------------------------------------------- | |
| 694 | # • [SetCursorPos]/Dll : Move o cursor do Mouse para um ponto específico | |
| 695 | # da tela. | |
| 696 | # SetCursorPos.call(x, y) | |
| 697 | # x, y : Formato [Integer/Float] | |
| 698 | #---------------------------------------------------------------------------- | |
| 699 | SetCursorPos = Win32API.new("user32", "SetCursorPos", "ll", "i")
| |
| 700 | #---------------------------------------------------------------------------- | |
| 701 | # • [GetKeyboardState]/Dll : Cópia o status das 256 chaves para um | |
| 702 | # buffer especificado. | |
| 703 | #---------------------------------------------------------------------------- | |
| 704 | GetKeyboardState = Win32API.new('user32', 'GetKeyboardState', ['P'], 'V')
| |
| 705 | #---------------------------------------------------------------------------- | |
| 706 | # • [GetAsyncKeyState]/Dll : Determina o estado da chave no momento em que a | |
| 707 | # função é chamada. | |
| 708 | # GetAsyncKeyState.call(Vk) | |
| 709 | # VK : Formato [Integer/Hexadécimal]. | |
| 710 | #---------------------------------------------------------------------------- | |
| 711 | GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
| |
| 712 | #---------------------------------------------------------------------------- | |
| 713 | # • [WideCharToMultiByte] : [MultiByteToWideChar] // Comentários | |
| 714 | # não adicionados. | |
| 715 | #---------------------------------------------------------------------------- | |
| 716 | WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
| |
| 717 | MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
| |
| 718 | #---------------------------------------------------------------------------- | |
| 719 | # • [ZeroMemoy]/Dll : Enche um bloco da memória com zeros. | |
| 720 | #---------------------------------------------------------------------------- | |
| 721 | ZeroMemory = Win32API.new("kernel32", "RtlZeroMemory", "pl", "")
| |
| 722 | #---------------------------------------------------------------------------- | |
| 723 | # • [AdjustWindowRect] : Calcula o tamanho requerido do retângulo da Janela. | |
| 724 | #---------------------------------------------------------------------------- | |
| 725 | AdjustWindowRect = int("AdjustWindowRect", [:LPRECT, :DWORD, :BOOL])
| |
| 726 | #---------------------------------------------------------------------------- | |
| 727 | # • Constantes [SetWindowPos] | |
| 728 | #---------------------------------------------------------------------------- | |
| 729 | SWP_ASYNCWINDOWPOS = 0x4000 | |
| 730 | # Desenha os frames (definidos na classe da janela descrita) em torno na janela. | |
| 731 | SWP_DRAWFRAME = 0x0020 | |
| 732 | # Esconde a janela. | |
| 733 | SWP_HIDEWINDOW = 0x0080 | |
| 734 | # Não pode ser ativada nem movida | |
| 735 | SWP_NOACTIVATE = 0x0010 | |
| 736 | # Não permite mover | |
| 737 | SWP_NOMOVE = 0x0002 | |
| 738 | # Não permite redimensionar | |
| 739 | SWP_NOSIZE = 0x0001 | |
| 740 | # Mostra a Janela | |
| 741 | SWP_SHOWWINDOW = 0x0040 | |
| 742 | # Coloca a janela na parte inferior na ordem de Z. Se identificar uma janela | |
| 743 | # superior ela perde os seus status. | |
| 744 | HWND_BOTTOM = 1 | |
| 745 | # Coloca a janela acima de todas as janelas que não estão em primeiro plano. | |
| 746 | HWND_NOTOPMOST = -2 | |
| 747 | # Poem a janela no Topo na ordem de Z. | |
| 748 | HWND_TOP = 0 | |
| 749 | # Poem a janela acima de todas que não estão em primeiro plano. Mantendo a | |
| 750 | # posição. | |
| 751 | HWND_TOPMOST = -1 | |
| 752 | #---------------------------------------------------------------------------- | |
| 753 | # • [SetActiveWindow]/ Dll : Ativa a Window. | |
| 754 | #---------------------------------------------------------------------------- | |
| 755 | SetActiveWindow = long("SetActiveWindow", [:HWND])
| |
| 756 | #---------------------------------------------------------------------------- | |
| 757 | # • WindowFromPoint : Retorna ao handle da janela, que contém um ponto | |
| 758 | # específico. | |
| 759 | #---------------------------------------------------------------------------- | |
| 760 | WindowFromPoint = long("WindowFromPoint", [:HWND])
| |
| 761 | #---------------------------------------------------------------------------- | |
| 762 | # • ShowWindow : Mostra a janela em um estado específico. | |
| 763 | #---------------------------------------------------------------------------- | |
| 764 | ShowWindow = long("ShowWindow", [:HWND, :LONG])
| |
| 765 | # Força a janela a minimizar | |
| 766 | SW_FORCEMINIMIZE = 11 | |
| 767 | # Esconde a janela, ativa outra. | |
| 768 | SW_HIDE = 0 | |
| 769 | # Maximiza a janela. | |
| 770 | SW_MAXIMIZE = 3 | |
| 771 | # Minimiza a janela | |
| 772 | SW_MINIMIZE = 6 | |
| 773 | # Restaura o estado da janela. | |
| 774 | SW_RESTORE = 9 | |
| 775 | # Ativa a janela a mostrando na posição original. | |
| 776 | SW_SHOW = 5 | |
| 777 | #---------------------------------------------------------------------------- | |
| 778 | # • [SetWindowText] : Permite modificar o título da janela. | |
| 779 | #---------------------------------------------------------------------------- | |
| 780 | SetWindowText = int("SetWindowText", [:HWND, :LPCTSTR])
| |
| 781 | #---------------------------------------------------------------------------- | |
| 782 | # • [GetDesktopWindow] : Retorna ao handle da janela em relação ao Desktop. | |
| 783 | #---------------------------------------------------------------------------- | |
| 784 | GetDesktopWindow = long("GetDesktopWindow", [:HWND])
| |
| 785 | #---------------------------------------------------------------------------- | |
| 786 | # • [GetSystemMetric] : Obtem um sistema métrico específico ou a configuração | |
| 787 | # do sistema. As dimensões retornadas são em pixel. | |
| 788 | #---------------------------------------------------------------------------- | |
| 789 | GetSystemMetric = int("GetSystemMetric", [:int])
| |
| 790 | #---------------------------------------------------------------------------- | |
| 791 | # • [GetSystemMetric]/Constantes: | |
| 792 | #---------------------------------------------------------------------------- | |
| 793 | # Obtem a flag que especifica como o sistema está organizando as janelas | |
| 794 | # minimizadas. | |
| 795 | SM_ARRANGE = 56 | |
| 796 | # Obtem o tamanho da borda da Janela em pixel. | |
| 797 | SM_CXBORDER = 5 | |
| 798 | # Valor do tamanho da área do cliente pra uma Janela em modo de tela-chéia. | |
| 799 | # em pixel. | |
| 800 | SM_CXFULLSCREEN = 16 | |
| 801 | # Para mais informações dos valores, visite : | |
| 802 | # http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385(v=vs.85).aspx | |
| 803 | #---------------------------------------------------------------------------- | |
| 804 | # • [GetClientRect] : Retorna ao rect da área da Janela. | |
| 805 | # Uses : | |
| 806 | # lpRect = [0,0,0,0].pack("L*")
| |
| 807 | # GetClientRect.(hwnd, lpRect) | |
| 808 | # lpRect = lpRect.unpack("L*")
| |
| 809 | #---------------------------------------------------------------------------- | |
| 810 | GetClientRect = int("GetClientRect", [:HWND, :LPRECT])
| |
| 811 | #---------------------------------------------------------------------------- | |
| 812 | # • [GetModuleHandle] : Retorna ao Handle do módulo, do módulo específicado. | |
| 813 | # Pode ser aquivo '.dll' ou '.exe'. Exemplo: | |
| 814 | # GetModuleHandle.call('System/RGSS300.dll')
| |
| 815 | #---------------------------------------------------------------------------- | |
| 816 | GetModuleHandle = long("GetModuleHandle", [:LPCTSTR], "kerne32")
| |
| 817 | #---------------------------------------------------------------------------- | |
| 818 | # • [FreeLibrary] : Libera o módulo que está carregado na DLL específica. | |
| 819 | #---------------------------------------------------------------------------- | |
| 820 | FreeLibrary = long("FreeLibrary", [:HMODULE], "kernel32")
| |
| 821 | #---------------------------------------------------------------------------- | |
| 822 | # • [LoadLibrary] : Carrega um endereço de um módulo em específico. | |
| 823 | # LoadLibrary.call(Nome da Libraria(dll/exe)) | |
| 824 | # [Handle] : Retorna ao valor do Handle do módulo caso der certo. | |
| 825 | #---------------------------------------------------------------------------- | |
| 826 | LoadLibrary = long("LoadLibrary", [:LPCTSTR], "kernel32")
| |
| 827 | #---------------------------------------------------------------------------- | |
| 828 | # • [GetProcAddress] : Retorna ao endereço da função exportada ou a variável | |
| 829 | # de uma DLL específica. | |
| 830 | # GetProcAddress.call(hModule, lpProcName) | |
| 831 | # hModule : É o valor do handle. Você pode pega-lo usando o LoadLibrary | |
| 832 | # lpProcName : A função ou o nome da variável. | |
| 833 | #---------------------------------------------------------------------------- | |
| 834 | GetProcAddress = long("GetProcAddress", [:HMODULE, :LPCSTR], "kernel32")
| |
| 835 | #---------------------------------------------------------------------------- | |
| 836 | # • [GetSystemMetrics] : Retorna á uma configuração específica do sistema | |
| 837 | # métrico. | |
| 838 | #---------------------------------------------------------------------------- | |
| 839 | GetSystemMetrics = int("GetSystemMetrics", [:int])
| |
| 840 | #---------------------------------------------------------------------------- | |
| 841 | # • [GetSystemMetrics]::Constantes. #Para mais visite: | |
| 842 | # http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385(v=vs.85).aspx | |
| 843 | #---------------------------------------------------------------------------- | |
| 844 | SM_CXSCREEN = 0 # O tamanho(width/largura) da janela em pixel. | |
| 845 | SM_CYSCREEN = 1 # O tamanho(height/comprimento) da janela em pixel. | |
| 846 | SM_CXFULLSCREEN = 16 # O tamanho da largura da tela chéia da janela. | |
| 847 | SM_CYFULLSCREEN = 17 # O tamanho do comprimento da tela chéia da janela. | |
| 848 | #---------------------------------------------------------------------------- | |
| 849 | # • [Método protegido] : Método usado para chamar a função LoadLibrary. | |
| 850 | #---------------------------------------------------------------------------- | |
| 851 | def dlopen(name, fA=nil) | |
| 852 | l = LoadLibrary.(String(name)) | |
| 853 | return l if fA.nil? | |
| 854 | return GetProcAddress.(l, String(fA)) | |
| 855 | end | |
| 856 | #---------------------------------------------------------------------------- | |
| 857 | # • Converte um texto para o formato UTF-8 | |
| 858 | # textUTF(text) | |
| 859 | # * text : Texto. | |
| 860 | #---------------------------------------------------------------------------- | |
| 861 | def textUTF(text) | |
| 862 | wC = API::MultiByteToWideChar.call(65001, 0, text, -1, "", 0) | |
| 863 | API::MultiByteToWideChar.call(65001, 0, text, -1, text = "\0\0" * wC, wC) | |
| 864 | return text | |
| 865 | end | |
| 866 | #---------------------------------------------------------------------------- | |
| 867 | # • [TrueClass/FalseClass] : Retorna verdadeiro caso o Caps Lock esteja | |
| 868 | # ativo e retorna Falso caso não esteja ativo. | |
| 869 | #---------------------------------------------------------------------------- | |
| 870 | def get_caps_lock | |
| 871 | return int("GetKeyState", [:vKey]).call(20) == 1
| |
| 872 | end | |
| 873 | #---------------------------------------------------------------------------- | |
| 874 | # • Abre a URL de um site o direcionado para o navegador padrão do usuário. | |
| 875 | #---------------------------------------------------------------------------- | |
| 876 | def open_site(url) | |
| 877 | c = Win32API.new("Shell32", "ShellExecute", "pppppl", "l")
| |
| 878 | c.call(nil, "open", url, nil, nil, 0) | |
| 879 | end | |
| 880 | #============================================================================== | |
| 881 | # • Clipboard | |
| 882 | #============================================================================== | |
| 883 | module Clipboard | |
| 884 | extend self | |
| 885 | #---------------------------------------------------------------------------- | |
| 886 | # • Constantes do módulo: | |
| 887 | #---------------------------------------------------------------------------- | |
| 888 | Close = Win32API.new("user32", "CloseClipboard", "v", "l")
| |
| 889 | GetData = Win32API.new("user32", "GetClipboardData", "n", "l")
| |
| 890 | Open = Win32API.new('user32', 'OpenClipboard', "N", "L")
| |
| 891 | FormatAvailable = Win32API.new('user32', 'IsClipboardFormatAvailable', "i", "i")
| |
| 892 | GlobalAlloc = Win32API.new('kernel32', 'GlobalAlloc', 'll', 'l')
| |
| 893 | GlobalLock = Win32API.new('kernel32', 'GlobalLock', 'l', 'l')
| |
| 894 | GlobalSize = Win32API.new('kernel32', 'GlobalSize', 'l', 'l')
| |
| 895 | GlobalUnlock = Win32API.new('kernel32', 'GlobalUnlock', 'l', '')
| |
| 896 | MemCpy = Win32API.new('ntdll', 'memcpy', 'ppl', 'l')
| |
| 897 | FORMATS = {text: 1, dib: 2, bitmap: 8}
| |
| 898 | #---------------------------------------------------------------------------- | |
| 899 | # • Data. Retorna a Data do clipboard. Especificar o formato para receber | |
| 900 | # o retorno do formato especifico. Formato padrão é o texto. | |
| 901 | #---------------------------------------------------------------------------- | |
| 902 | def data(format=FORMATS[:text]) | |
| 903 | begin | |
| 904 | self.open | |
| 905 | if FormatAvailable.call(format) | |
| 906 | handle = GetData.call(format) | |
| 907 | case format | |
| 908 | when 1 | |
| 909 | clip_data = 0.chr * GlobalSize.call(handle) | |
| 910 | MemCpy.call(clip_data, handle, clip_data.size) | |
| 911 | clip_data = clip_data[ /^[^\0]*/ ] | |
| 912 | when 2, 8 then clip_data = get_image_data(handle) | |
| 913 | else | |
| 914 | raise Error, 'format not supported' | |
| 915 | end | |
| 916 | else | |
| 917 | clip_data = '' | |
| 918 | end | |
| 919 | ensure | |
| 920 | self.close | |
| 921 | end | |
| 922 | clip_data | |
| 923 | end | |
| 924 | #---------------------------------------------------------------------------- | |
| 925 | # • Singleton Class | |
| 926 | #---------------------------------------------------------------------------- | |
| 927 | class << self | |
| 928 | alias :get_data :data | |
| 929 | end | |
| 930 | #---------------------------------------------------------------------------- | |
| 931 | # • Formato aceito. | |
| 932 | #---------------------------------------------------------------------------- | |
| 933 | def formatAvailable?(format) | |
| 934 | FormatAvailable.call(format).boolean | |
| 935 | end | |
| 936 | private | |
| 937 | #---------------------------------------------------------------------------- | |
| 938 | # • Abrir clipboard | |
| 939 | #---------------------------------------------------------------------------- | |
| 940 | def open | |
| 941 | Open.call(0) | |
| 942 | end | |
| 943 | #---------------------------------------------------------------------------- | |
| 944 | # • Fechar | |
| 945 | #---------------------------------------------------------------------------- | |
| 946 | def close | |
| 947 | Close.call | |
| 948 | end | |
| 949 | #---------------------------------------------------------------------------- | |
| 950 | # • Obter a data de uma imagem, bitmap. | |
| 951 | #---------------------------------------------------------------------------- | |
| 952 | def get_image_data(handle) | |
| 953 | buf = nil | |
| 954 | bmi = 0.chr * 44 # BITMAPINFO | |
| 955 | begin | |
| 956 | address = GlobalLock.call(handle) | |
| 957 | buf_size = GlobalSize.call(handle) | |
| 958 | MemCpy.call(bmi, address, bmi.length) | |
| 959 | bit_count = bmi[14,2].unpack('S').first # biBitCount
| |
| 960 | compression = bmi[16,4].unpack('L').first # biCompression
| |
| 961 | size_image = bmi[20,4].unpack('L').first # biSizeImage
| |
| 962 | clr_used = bmi[32,4].unpack('L').first # biClrUsed
| |
| 963 | size_image = buf_size + 16 if size_image == 0 | |
| 964 | # Calculate the header size | |
| 965 | case bit_count | |
| 966 | when 1 then table_size = 2 | |
| 967 | when 4 then table_size = 16 | |
| 968 | when 8 then table_size = 256 | |
| 969 | when 16, 32 | |
| 970 | if compression == 0 | |
| 971 | table_size = clr_used | |
| 972 | elsif compression == 3 | |
| 973 | table_size = 3 | |
| 974 | else | |
| 975 | msgbox "ERROR: invalid bit/compression combination" | |
| 976 | end | |
| 977 | when 24 then table_size = crl_used | |
| 978 | else | |
| 979 | msgbox "ERROR: invalid bit count" | |
| 980 | end | |
| 981 | offset = 0x36 + (table_size * 4) | |
| 982 | buf = 0.chr * buf_size | |
| 983 | MemCpy.call(buf, address, buf.size) | |
| 984 | buf = "\x42\x4D" + [size_image].pack('L') + 0.chr * 4 + [offset].pack('L') + buf
| |
| 985 | ensure | |
| 986 | GlobalUnlock.call(handle) | |
| 987 | end | |
| 988 | buf | |
| 989 | end | |
| 990 | end | |
| 991 | #============================================================================ | |
| 992 | # • MessageBox | |
| 993 | #============================================================================ | |
| 994 | module MessageBox | |
| 995 | extend self | |
| 996 | # handle, string, title, format. | |
| 997 | FunctionMessageBox = Win32API.new("user32", "MessageBoxW", "lppl", "l")
| |
| 998 | #-------------------------------------------------------------------------- | |
| 999 | # • [Constantes] Botões: | |
| 1000 | #-------------------------------------------------------------------------- | |
| 1001 | # Adiciona três botões a mensagem: Anular, Repetir e Ignorar. | |
| 1002 | ABORTRETRYIGNORE = 0x00000002 | |
| 1003 | # Adiciona três botões a mensagem: Cancelar, Tentar e Continuar. | |
| 1004 | CANCELTRYCONTINUE = 0x00000006 | |
| 1005 | # Adiciona o botão de ajuda. | |
| 1006 | HELP = 0x00004000 | |
| 1007 | # Adiciona o botão Ok. | |
| 1008 | OK = 0x00000000 | |
| 1009 | # Adiciona o botão OK e Cancelar. | |
| 1010 | OKCANCEL = 0x00000001 | |
| 1011 | # Adiciona os botões: Repetir e Cancelar. | |
| 1012 | RETRYCANCEL = 0x00000005 | |
| 1013 | # Adiciona os botões: Sim e Não | |
| 1014 | YESNO = 0x00000004 | |
| 1015 | # Adiciona os botões: Sim, Não e Cancelar | |
| 1016 | YESNOCANCEL = 0x00000003 | |
| 1017 | #-------------------------------------------------------------------------- | |
| 1018 | # • [Constantes] Ícones: | |
| 1019 | #-------------------------------------------------------------------------- | |
| 1020 | # Adiciona um ícone de exclamação | |
| 1021 | ICONEXCLAMATION = 0x00000030 | |
| 1022 | # Adiciona um ícone de informação. | |
| 1023 | ICONINFORMATION = 0x00000040 | |
| 1024 | # Adiciona um ícone de um círculo com um ponto de interrogação. | |
| 1025 | ICONQUESTION = 0x00000020 | |
| 1026 | # Adiciona um íconde parar na mensagem. | |
| 1027 | ICONSTOP = 0x00000010 | |
| 1028 | #-------------------------------------------------------------------------- | |
| 1029 | # • [Constantes] Valores de retorno dos botões: | |
| 1030 | #-------------------------------------------------------------------------- | |
| 1031 | ABORT = 3 # Retorno do valor do botão de Anular | |
| 1032 | CANCEL = 2 # Retorno do valor do botão de Cancelar. | |
| 1033 | CONTINUE = 11 # Retorno do valor do botão de Continuar. | |
| 1034 | IGNORE = 5 # Retorno do valor de ignonar. | |
| 1035 | NO = 7 # Retorno do valor do botão de Não. | |
| 1036 | OK = 1 # Retorno do valor do botão de Ok. | |
| 1037 | RETRY = 4 # Retorno do valor de repetir. | |
| 1038 | TRYAGAIN = 10 # Retorno do valor de Repetir. | |
| 1039 | YES = 6 # Retorno do valor do botão de Sim. | |
| 1040 | #-------------------------------------------------------------------------- | |
| 1041 | # • [Constantes] Valores adicionais. | |
| 1042 | #-------------------------------------------------------------------------- | |
| 1043 | RIGHT = 0x00080000 # Os textos ficarão justificados a direita. | |
| 1044 | TOPMOST = 0x00040000 # O estilo da mensagem é criado como WB_EX_TOPMOST | |
| 1045 | #-------------------------------------------------------------------------- | |
| 1046 | # • [call] : Retorna aos valores dos botões. Para serem usados | |
| 1047 | # como condição, de que se ao clicar. | |
| 1048 | # API::MessageBox.call(title, string, format) | |
| 1049 | # title -> Título da caixa. | |
| 1050 | # string -> Conteúdo da caixa. | |
| 1051 | # format -> Formato, no caso seria os botões e ícones. | |
| 1052 | #-------------------------------------------------------------------------- | |
| 1053 | def call(title, string, format) | |
| 1054 | return FunctionMessageBox.call(API.hWND, API.textUTF(string), API.textUTF(title), format) | |
| 1055 | end | |
| 1056 | #-------------------------------------------------------------------------- | |
| 1057 | # • [messageBox] : Mesma função do Call a diferença é que e protegido. | |
| 1058 | #-------------------------------------------------------------------------- | |
| 1059 | def messageBox(*args) | |
| 1060 | self.call(*args) | |
| 1061 | end | |
| 1062 | protected :messageBox | |
| 1063 | end | |
| 1064 | #============================================================================ | |
| 1065 | # • Sock | |
| 1066 | #============================================================================ | |
| 1067 | @dll = "ws2_32" | |
| 1068 | #-------------------------------------------------------------------------- | |
| 1069 | # • [accept] : Permite uma tentativa de entrada na conexão da internet | |
| 1070 | # atráves do socket. | |
| 1071 | #-------------------------------------------------------------------------- | |
| 1072 | Accept = long("accept", [:SOCKET, :struct, :int], @dll)
| |
| 1073 | #-------------------------------------------------------------------------- | |
| 1074 | # • [bind] : Associa um endereço local com o socket. | |
| 1075 | #-------------------------------------------------------------------------- | |
| 1076 | Bind = long("bind", [:SOCKET, :struct, :int], @dll)
| |
| 1077 | #-------------------------------------------------------------------------- | |
| 1078 | # • [closesocket] : Fecha uma conexão socket existente. | |
| 1079 | #-------------------------------------------------------------------------- | |
| 1080 | CloseSocket = long("closesocket", [:SOCKET], @dll)
| |
| 1081 | #-------------------------------------------------------------------------- | |
| 1082 | # • [connect] : Estabeliza uma conexão com um socket específico. | |
| 1083 | #-------------------------------------------------------------------------- | |
| 1084 | Connect = int("connect", [:SOCKET, :struct, :int], @dll)
| |
| 1085 | #-------------------------------------------------------------------------- | |
| 1086 | # • [gethostbyaddr] : Essa função retorna a informação do host | |
| 1087 | # que corresponde ao endereço network. | |
| 1088 | #-------------------------------------------------------------------------- | |
| 1089 | GetHostByAddr = long("gethostbyaddr", [:c, :int, :int], @dll)
| |
| 1090 | #-------------------------------------------------------------------------- | |
| 1091 | # • [gethostbyname] : Essa função retorna a informação do host | |
| 1092 | # correspondente ao nome do host. | |
| 1093 | #-------------------------------------------------------------------------- | |
| 1094 | GetHostByName = long("gethostbyname", [:c], @dll)
| |
| 1095 | #-------------------------------------------------------------------------- | |
| 1096 | # • [gethostname] : Essa função retorna ao nome do host padrão do computador | |
| 1097 | # local. | |
| 1098 | #-------------------------------------------------------------------------- | |
| 1099 | GetHostName = void("gethostname", [:c, :int], @dll)
| |
| 1100 | #-------------------------------------------------------------------------- | |
| 1101 | # • [getservbyname] : Essa função retorna as informações do sistema | |
| 1102 | # correspondente ao nome do serviço é do protocolo. | |
| 1103 | #-------------------------------------------------------------------------- | |
| 1104 | GetServByName = char("getservbyname", [:c, :c], @dll)
| |
| 1105 | protected :hwnd, :open, :function | |
| 1106 | end | |
| 1107 | #============================================================================== | |
| 1108 | # • Enumerables; | |
| 1109 | #============================================================================== | |
| 1110 | Dax.register(:enumerables) | |
| 1111 | module Enumerables | |
| 1112 | #---------------------------------------------------------------------------- | |
| 1113 | # • Retorna a uma nova array com todos os resultados retirando os vazio. | |
| 1114 | #---------------------------------------------------------------------------- | |
| 1115 | def select_map(&aProc) | |
| 1116 | map(&aProc).reject { |e| e.nil? }
| |
| 1117 | end | |
| 1118 | end | |
| 1119 | #============================================================================== | |
| 1120 | # * String | |
| 1121 | #============================================================================== | |
| 1122 | Dax.register(:string) | |
| 1123 | class String | |
| 1124 | #-------------------------------------------------------------------------- | |
| 1125 | # * [String] : converter a String em UTF8 | |
| 1126 | #-------------------------------------------------------------------------- | |
| 1127 | def to_utf8 | |
| 1128 | API.textUTF(self) | |
| 1129 | end | |
| 1130 | #-------------------------------------------------------------------------- | |
| 1131 | # * [String] : Extrai os números. | |
| 1132 | #-------------------------------------------------------------------------- | |
| 1133 | def extract_numbers | |
| 1134 | self.scan(/-*\d+/).collect{|n|n.to_i}
| |
| 1135 | end | |
| 1136 | #---------------------------------------------------------------------------- | |
| 1137 | # • [String] : Aplicando Case Sensitive | |
| 1138 | # "Exemplo 2" => "Exemplo_2" | |
| 1139 | #---------------------------------------------------------------------------- | |
| 1140 | def case_sensitive | |
| 1141 | return self.gsub(" ", "_")
| |
| 1142 | end | |
| 1143 | #---------------------------------------------------------------------------- | |
| 1144 | # • [String] : Transormar em símbolo. | |
| 1145 | #---------------------------------------------------------------------------- | |
| 1146 | def symbol | |
| 1147 | return self.case_sensitive.downcase.to_sym | |
| 1148 | end | |
| 1149 | #---------------------------------------------------------------------------- | |
| 1150 | # • [String] : Converte para Windows Unicode | |
| 1151 | #---------------------------------------------------------------------------- | |
| 1152 | def to_w | |
| 1153 | (self+"\x00").encode('utf-16LE')
| |
| 1154 | end | |
| 1155 | #---------------------------------------------------------------------------- | |
| 1156 | # • Método Xor. Realiza byte per byte. [Actor Desconhecido] | |
| 1157 | #---------------------------------------------------------------------------- | |
| 1158 | def ^(string) | |
| 1159 | bytes.map.with_index{|byte, index|
| |
| 1160 | byte ^ string[index % other.size].ord | |
| 1161 | }.pack("C*")
| |
| 1162 | end | |
| 1163 | end | |
| 1164 | #============================================================================== | |
| 1165 | # • DString | |
| 1166 | #============================================================================== | |
| 1167 | Dax.register :dstring | |
| 1168 | module DString | |
| 1169 | extend self | |
| 1170 | #---------------------------------------------------------------------------- | |
| 1171 | # • [String] : Deletar a útlima letra de uma string.. | |
| 1172 | # Exemplo: DString.backslash("ok!") #=> ok
| |
| 1173 | #---------------------------------------------------------------------------- | |
| 1174 | def backslash(text) | |
| 1175 | text2 ||= "" | |
| 1176 | text = text.to_s.split(//) | |
| 1177 | text[text.size-1] = "" unless text[0].to_s.empty? | |
| 1178 | for i in 0..text.size-1 | |
| 1179 | text2 += text[i].to_s | |
| 1180 | end | |
| 1181 | return text2 | |
| 1182 | end | |
| 1183 | end | |
| 1184 | #============================================================================== | |
| 1185 | # * Integer | |
| 1186 | #============================================================================== | |
| 1187 | Dax.register(:integer) | |
| 1188 | class Integer | |
| 1189 | #---------------------------------------------------------------------------- | |
| 1190 | # • [TrueClass/FalseClass] : Verifica-se e par. | |
| 1191 | #---------------------------------------------------------------------------- | |
| 1192 | def is_evan? | |
| 1193 | return (self & 1) == 0 | |
| 1194 | end | |
| 1195 | #---------------------------------------------------------------------------- | |
| 1196 | # • [TrueClass/FalseClass] : Verifica-se e impar. | |
| 1197 | #---------------------------------------------------------------------------- | |
| 1198 | def is_odd? | |
| 1199 | return (self & 1) == 1 | |
| 1200 | end | |
| 1201 | #---------------------------------------------------------------------------- | |
| 1202 | # * [Integer] : Transformar o valor em porcentagem : Útil para fazer barras | |
| 1203 | # como por exemplo barras de HP. | |
| 1204 | # a : Valor atual. | |
| 1205 | # b : Valor máximo. | |
| 1206 | #---------------------------------------------------------------------------- | |
| 1207 | def to_p(a, b) | |
| 1208 | self * a / b | |
| 1209 | end | |
| 1210 | #---------------------------------------------------------------------------- | |
| 1211 | # * [Integer] : Multiplica o número pelo tamanho de uma grid. | |
| 1212 | #---------------------------------------------------------------------------- | |
| 1213 | def grid_on(grid_size=32) | |
| 1214 | return self * grid_size | |
| 1215 | end | |
| 1216 | #---------------------------------------------------------------------------- | |
| 1217 | # * [Integer] : Divide o número pelo tamanho de uma grid. | |
| 1218 | #---------------------------------------------------------------------------- | |
| 1219 | def grid_off(grid_size=32) | |
| 1220 | return self / grid_size | |
| 1221 | end | |
| 1222 | #---------------------------------------------------------------------------- | |
| 1223 | # • [Array] : Retorna aos divisores primos. | |
| 1224 | #---------------------------------------------------------------------------- | |
| 1225 | def primeDivision | |
| 1226 | raise ZeroDivisionError if self == 0 | |
| 1227 | ps = DMath::Prime.new | |
| 1228 | value = self | |
| 1229 | pv = [] | |
| 1230 | for prime in ps | |
| 1231 | count = 0 | |
| 1232 | while (value1, mod = value.divmod(prime) | |
| 1233 | mod) == 0 | |
| 1234 | value = value1 | |
| 1235 | count += 1 | |
| 1236 | end | |
| 1237 | pv.push [prime, count] unless count == 0 | |
| 1238 | - | (self.red == color.red and self.green == color.green and self.blue == color.blue and |
| 1238 | + | |
| 1239 | end | |
| 1240 | pv.push [value, 1] if value > 1 | |
| 1241 | return pv | |
| 1242 | end | |
| 1243 | end | |
| 1244 | #============================================================================== | |
| 1245 | # * Float | |
| 1246 | #============================================================================== | |
| 1247 | Dax.register(:float) | |
| 1248 | class Float | |
| 1249 | #---------------------------------------------------------------------------- | |
| 1250 | # * [Float] : Transformar em porcentagem | |
| 1251 | # a : Valor atual. | |
| 1252 | # b : Valor máximo. | |
| 1253 | #---------------------------------------------------------------------------- | |
| 1254 | def to_p(a, b) | |
| 1255 | self * a / b | |
| 1256 | end | |
| 1257 | end | |
| 1258 | #============================================================================== | |
| 1259 | # • Crypt | |
| 1260 | #============================================================================== | |
| 1261 | Dax.register(:crypt) | |
| 1262 | module Crypt | |
| 1263 | #============================================================================ | |
| 1264 | # • Cesar : Criptográfia de Cesar. | |
| 1265 | #============================================================================ | |
| 1266 | module Cesar | |
| 1267 | extend self | |
| 1268 | #-------------------------------------------------------------------------- | |
| 1269 | # • Constantes. | |
| 1270 | #-------------------------------------------------------------------------- | |
| 1271 | AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(//) | |
| 1272 | DC = "DEFGHIJKLMNOPQRSTUVWXYZABC".split(//) | |
| 1273 | #-------------------------------------------------------------------------- | |
| 1274 | # • [String] : Codificar. | |
| 1275 | # Crypt::Cesar.codify("AMA", 1) : #=> dpd
| |
| 1276 | #-------------------------------------------------------------------------- | |
| 1277 | def codify(string, ty=0) | |
| 1278 | string = string.split(//) | |
| 1279 | ns = "" | |
| 1280 | dc = [] | |
| 1281 | string.each { |i|
| |
| 1282 | next dc << "" if i == "" | |
| 1283 | next dc << " " if i == " " | |
| 1284 | AZ.each_with_index { |v, id|
| |
| 1285 | next dc << DC[id] if i == v | |
| 1286 | }} | |
| 1287 | dc.size.times { |i| ns += dc[i] }
| |
| 1288 | return ty == 0 ? ns : ns.downcase! | |
| 1289 | end | |
| 1290 | #-------------------------------------------------------------------------- | |
| 1291 | # • [String] : Decodificar. | |
| 1292 | # Crypt::Cesar.decodify("dpd", 0) #=> AMA
| |
| 1293 | #-------------------------------------------------------------------------- | |
| 1294 | def decodify(string, ty=0) | |
| 1295 | string = string.split(//) | |
| 1296 | ns = "" | |
| 1297 | az = [] | |
| 1298 | string.each { |i|
| |
| 1299 | next az << "" if i == "" | |
| 1300 | next az << " " if i == " " | |
| 1301 | DC.each_with_index { |v,id|
| |
| 1302 | next az << AZ[id] if i == v | |
| 1303 | } | |
| 1304 | } | |
| 1305 | az.size.times { |i| ns += az[i] }
| |
| 1306 | return ty == 0 ? ns : ns.downcase! | |
| 1307 | end | |
| 1308 | end | |
| 1309 | end | |
| 1310 | #============================================================================== | |
| 1311 | # * Color | |
| 1312 | #============================================================================== | |
| 1313 | Dax.register(:color) | |
| 1314 | class Color | |
| 1315 | #---------------------------------------------------------------------------- | |
| 1316 | # • [Color] : Diminui a opacidade da cor, deixando-a opaca. | |
| 1317 | # Color.new(r, g, b).opacity([alpha]) | |
| 1318 | # O valor padrão do alpha e 128.. não é preciso espeficar. | |
| 1319 | #---------------------------------------------------------------------------- | |
| 1320 | def opacity(alpha=nil) | |
| 1321 | self.set(self.red, self.green, self.blue, alpha || 128) | |
| 1322 | end | |
| 1323 | #---------------------------------------------------------------------------- | |
| 1324 | # • [Color] : Inverte as cores. | |
| 1325 | # Color.new(r, g, b[, a).invert! | |
| 1326 | #---------------------------------------------------------------------------- | |
| 1327 | def invert! | |
| 1328 | self.set(255-self.red, 255-self.green, 255-self.blue, self.alpha) | |
| 1329 | end | |
| 1330 | #---------------------------------------------------------------------------- | |
| 1331 | # • [Color] : Reverte as cores. | |
| 1332 | # Color.new(r, g, b[, a).revert | |
| 1333 | #---------------------------------------------------------------------------- | |
| 1334 | def revert | |
| 1335 | colors = [self.red, self.green, self.blue, self.alpha].reverse! | |
| 1336 | self.set(*colors) | |
| 1337 | end | |
| 1338 | #---------------------------------------------------------------------------- | |
| 1339 | # • [String] : Converte para string as informações dos valores das cores. | |
| 1340 | # Color.new(0, 0, 0).to_s | |
| 1341 | # red: 0 | |
| 1342 | # blue: 0 | |
| 1343 | # green: 0 | |
| 1344 | # alpha: 255 | |
| 1345 | #---------------------------------------------------------------------------- | |
| 1346 | def to_s | |
| 1347 | "red: #{self.red}\nblue: #{self.blue}\ngreen: #{self.green}\nalpha: #{self.alpha}"
| |
| 1348 | end | |
| 1349 | #---------------------------------------------------------------------------- | |
| 1350 | # • [TrueClass/FalseClass] : Comparar cores, retorna a [true] se for igual.. | |
| 1351 | # retorna a [false] se não for igual. | |
| 1352 | #---------------------------------------------------------------------------- | |
| 1353 | def ==(color) | |
| 1354 | return (self.red == color.red and self.green == color.green and self.blue == color.blue and | |
| 1355 | self.alpha == color.alpha) ? true : false | |
| 1356 | end | |
| 1357 | #---------------------------------------------------------------------------- | |
| 1358 | # • [Hash] : Retorna aos valores das cores em formato de Hash. | |
| 1359 | # Color.new(0, 0, 0).to_h | |
| 1360 | # {:red => 0, :green => 0, :blue => 0, :alpha => 255}
| |
| 1361 | #---------------------------------------------------------------------------- | |
| 1362 | def to_h | |
| 1363 | return {
| |
| 1364 | red: self.red, green: self.green, blue: self.blue, alpha: self.alpha, | |
| 1365 | } | |
| 1366 | end | |
| 1367 | #---------------------------------------------------------------------------- | |
| 1368 | # • [Array] : Retorna aos valores das cores em formato de Array. | |
| 1369 | # Color.new(0, 0, 0).to_a | |
| 1370 | # [0, 0, 0, 255] | |
| 1371 | #---------------------------------------------------------------------------- | |
| 1372 | def to_a | |
| 1373 | return [self.red, self.green, self.blue, self.alpha] | |
| 1374 | end | |
| 1375 | - | return Color.new(rand(256), rand(256), rand(256)) |
| 1375 | + | |
| 1376 | # • [Color] Soma os valores das cores com os valores de outras cores. | |
| 1377 | # Ex: color + Color.new(21,54,255) | |
| 1378 | #---------------------------------------------------------------------------- | |
| 1379 | def +(color) | |
| 1380 | return unless color.is_a?(Color) | |
| 1381 | red = self.red + color.red | |
| 1382 | green = self.green + color.green | |
| 1383 | blue = self.blue + color.blue | |
| 1384 | self.set(red, green, blue) | |
| 1385 | end | |
| 1386 | #---------------------------------------------------------------------------- | |
| 1387 | # • [Color] Subtrai os valores das cores com os valores de outras cores. | |
| 1388 | # Ex: color - Color.new(21,54,255) | |
| 1389 | #---------------------------------------------------------------------------- | |
| 1390 | def -(color) | |
| 1391 | return unless color.is_a?(Color) | |
| 1392 | red = self.red - color.red | |
| 1393 | green = self.green - color.green | |
| 1394 | blue = self.blue - color.blue | |
| 1395 | self.set(red, green, blue) | |
| 1396 | end | |
| 1397 | #---------------------------------------------------------------------------- | |
| 1398 | # • [Color] Multiplica os valores das cores com os valores de outras cores. | |
| 1399 | # Ex: color * Color.new(21,54,255) | |
| 1400 | #---------------------------------------------------------------------------- | |
| 1401 | def *(color) | |
| 1402 | return unless color.is_a?(Color) | |
| 1403 | red = (self.red * color.red) / 255.0 | |
| 1404 | green = (self.green * color.green) / 255.0 | |
| 1405 | blue = (self.blue * color.blue) / 255.0 | |
| 1406 | self.set(red, green, blue) | |
| 1407 | end | |
| 1408 | #---------------------------------------------------------------------------- | |
| 1409 | # • Métodos Privados. | |
| 1410 | #---------------------------------------------------------------------------- | |
| 1411 | private | |
| 1412 | def max | |
| 1413 | [red, green, blue].max | |
| 1414 | end | |
| 1415 | def min | |
| 1416 | [red, green, blue].min | |
| 1417 | end | |
| 1418 | end | |
| 1419 | #============================================================================== | |
| 1420 | # * ColorBasic | |
| 1421 | #============================================================================== | |
| 1422 | Dax.register(:colorbasic) | |
| 1423 | module ColorBasic | |
| 1424 | extend self | |
| 1425 | #---------------------------------------------------------------------------- | |
| 1426 | # • [Color] : Cores no formato de hexadécimal. | |
| 1427 | # * ColorBasic.hex("ffffff") #=> 255, 255, 255 | Branco.
| |
| 1428 | #---------------------------------------------------------------------------- | |
| 1429 | def hex(color) | |
| 1430 | Color.new(*color.scan(/../).map { |color| color.to_i(16)})
| |
| 1431 | end | |
| 1432 | #---------------------------------------------------------------------------- | |
| 1433 | # • [Color] : Cores do índice. Veja abaixo. | |
| 1434 | #---------------------------------------------------------------------------- | |
| 1435 | def [](id) | |
| 1436 | case id | |
| 1437 | when -1 then Color.new(255, 255, 255) # White | |
| 1438 | when 0 then Color.new(240, 248, 255) # Alice Blue | |
| 1439 | when 1 then Color.new(250, 235, 215) # Antique_White | |
| 1440 | when 2 then Color.new(0, 255, 255) # Aqua | |
| 1441 | when 3 then Color.new(127, 255, 255) # Aqua Marine | |
| 1442 | when 4 then Color.new(240, 255, 255) # Azure | |
| 1443 | when 5 then Color.new(245, 245, 220) # Beige | |
| 1444 | when 6 then Color.new(255, 228, 196) # Bisque | |
| 1445 | when 7 then Color.new(0, 0, 0) # Black | |
| 1446 | when 8 then Color.new(255, 235, 205) # Blanchedalmond | |
| 1447 | when 9 then Color.new(0, 0, 255) # Blue | |
| 1448 | when 10 then Color.new(138, 43, 226) # Blue Violet | |
| 1449 | when 11 then Color.new(165, 42, 42) # Brown | |
| 1450 | when 12 then Color.new(222, 184, 135) # Burly Wood | |
| 1451 | when 13 then Color.new(93, 158, 160) # Cadet Blue | |
| 1452 | when 14 then Color.new(127, 255, 0) # Chatreuse | |
| 1453 | when 15 then Color.new(210, 105, 30) # Chocolate | |
| 1454 | when 16 then Color.new(255, 127, 80) # Coral | |
| 1455 | when 17 then Color.new(100, 149, 237) # Corn Flower Blue | |
| 1456 | when 18 then Color.new(255, 248, 220) # CornSilk | |
| 1457 | when 19 then Color.new(220, 20, 60) # Crimson | |
| 1458 | when 20 then Color.new(0, 255, 255) # Cyan | |
| 1459 | when 21 then Color.new(0, 0, 139) # DarkBlue | |
| 1460 | when 22 then Color.new(0, 139, 139) # DarkCyan | |
| 1461 | when 23 then Color.new(184, 134, 11) # DarkGoldEnrod | |
| 1462 | when 24 then Color.new(169, 169, 169) # Dark Gray | |
| 1463 | when 25 then Color.new(0, 100, 0) # Dark Green | |
| 1464 | when 26 then Color.new(189, 183, 107) # Dark Khaki | |
| 1465 | when 27 then Color.new(139, 0, 139) # Dark Magenta | |
| 1466 | when 28 then Color.new(85, 107, 47) # Dark Oliver Green | |
| 1467 | when 29 then Color.new(255, 140, 0) # Dark Orange | |
| 1468 | when 30 then Color.new(153, 50, 204) # Dark orchid | |
| 1469 | when 31 then Color.new(139, 0, 0) # Dark Red | |
| 1470 | when 32 then Color.new(233, 150, 120) # Dark Salmon | |
| 1471 | when 33 then Color.new(143, 188, 143) # Dark Sea Green | |
| 1472 | when 34 then Color.new(72, 61, 139) # Dark Slate Blue | |
| 1473 | when 35 then Color.new(255, 255, 0) # Yellow | |
| 1474 | when 36 then Color.new(255, 0, 0) # Red | |
| 1475 | when 37 then Color.new(0, 255, 0) # Green | |
| 1476 | when 38 then Color.new(255, 128, 0) # Orange | |
| 1477 | else | |
| 1478 | self.default | |
| 1479 | end | |
| 1480 | end | |
| 1481 | #---------------------------------------------------------------------------- | |
| 1482 | # • [Color] : Cor padrão. | |
| 1483 | #---------------------------------------------------------------------------- | |
| 1484 | def default | |
| 1485 | return self.hex "ffffff" | |
| 1486 | end | |
| 1487 | #---------------------------------------------------------------------------- | |
| 1488 | # • [Color] : Retorna a uma cor padrão. | |
| 1489 | #---------------------------------------------------------------------------- | |
| 1490 | def rand | |
| 1491 | Color.new(rand(256), rand(256), rand(256)) | |
| 1492 | end | |
| 1493 | end | |
| 1494 | #============================================================================== | |
| 1495 | # • Rect | |
| 1496 | #============================================================================== | |
| 1497 | Dax.register(:rect) | |
| 1498 | class Rect | |
| 1499 | #---------------------------------------------------------------------------- | |
| 1500 | # • [TrueClass/FalseClass] : Verificar se está na área. | |
| 1501 | #---------------------------------------------------------------------------- | |
| 1502 | def in?(x, y) | |
| 1503 | x.between?(self.x, self.x + self.width) && | |
| 1504 | y.between?(self.y, self.y + self.height) | |
| 1505 | end | |
| 1506 | #---------------------------------------------------------------------------- | |
| 1507 | # • [NilClass] : Cada elemento em um bloco. | |
| 1508 | # rect.each { |x, y, w, h| }
| |
| 1509 | #---------------------------------------------------------------------------- | |
| 1510 | def each | |
| 1511 | yield(self.x, self.y, self.width, self.height) | |
| 1512 | return nil | |
| 1513 | end | |
| 1514 | end | |
| 1515 | #============================================================================== | |
| 1516 | # • DMath | |
| 1517 | #============================================================================== | |
| 1518 | Dax.register(:dmath, 'Dax', 1.5, '04/05/13') | |
| 1519 | module DMath | |
| 1520 | extend self | |
| 1521 | #---------------------------------------------------------------------------- | |
| 1522 | # • [TrueClass/FalseClass] : Clamp | Delimitar o inteiro | |
| 1523 | # num : Número. | |
| 1524 | # low : Número minímo. Sê o 'num' for menor que min retorna a low. | |
| 1525 | # high : Número máximo. Sê o 'num' for maior que hight retorna a high. | |
| 1526 | #---------------------------------------------------------------------------- | |
| 1527 | def clamp(num, low, high) | |
| 1528 | return num < low ? low : num > high ? high : low | |
| 1529 | end | |
| 1530 | #---------------------------------------------------------------------------- | |
| 1531 | # • [Array] : Centralizar um objeto n'outro. | |
| 1532 | # object : Objeto, tem que ser do tipo [Sprite] ou [Window_Base] | |
| 1533 | # object_for_centralize : Objeto que irá se centralizar no 'object', tem | |
| 1534 | # que ser do tipo [Sprite] ou [Window_Base] | |
| 1535 | # * Retorna a uma Array contendo as informações das novas posições em X e Y. | |
| 1536 | #---------------------------------------------------------------------------- | |
| 1537 | def centralize_object(object, object_for_centralize) | |
| 1538 | x = object.x + (object.width - object_for_centralize.width) / 2 | |
| 1539 | y = object.y + (object.height - object_for_centralize.height) / 2 | |
| 1540 | return x, y | |
| 1541 | end | |
| 1542 | #---------------------------------------------------------------------------- | |
| 1543 | # • [Numeric] : Centralizar um objeto n'outro, obtendo somente a posição X. | |
| 1544 | # objectx : Valor da posição X do objeto número 1. | |
| 1545 | # objectwidth : Valor da largura do objeto número 1. | |
| 1546 | # object_for_centralizewidth : Valor da largura do objeto que irá se | |
| 1547 | # centralizar no objeto número 1. | |
| 1548 | # * Retorna ao valor da posição X. | |
| 1549 | #---------------------------------------------------------------------------- | |
| 1550 | def centralize_x(objectx, objectwidth, object_for_centralizewidth) | |
| 1551 | return objectx + (objectwidth - object_for_centralizewidth) / 2 | |
| 1552 | end | |
| 1553 | #---------------------------------------------------------------------------- | |
| 1554 | # • [Numeric] : Centralizar um objeto n'outro, obtendo somente a posição Y. | |
| 1555 | # objecty : Valor da posição Y do objeto número 1. | |
| 1556 | # objectheight : Valor da altura do objeto número 1. | |
| 1557 | # object_for_centralizeheight : Valor da altura do objeto que irá se | |
| 1558 | # centralizar no objeto número 1. | |
| 1559 | # * Retorna ao valor da posição Y. | |
| 1560 | #---------------------------------------------------------------------------- | |
| 1561 | def centralize_y(objecty, objectheight, object_for_centralizeheight) | |
| 1562 | return objecty + (objectheight - object_for_centralizeheight) / 2 | |
| 1563 | end | |
| 1564 | #---------------------------------------------------------------------------- | |
| 1565 | # • [Numeric] : Obter a posição X do centro da tela referente a largura do objeto X. | |
| 1566 | # Exemplo: get_x_center_screen(sprite.width) : Irá retornar ao valor da posição | |
| 1567 | # X para que o objeto fique no centro da tela. | |
| 1568 | # Exemplo: sprite.x = get_x_center_screen(sprite.width) | |
| 1569 | #---------------------------------------------------------------------------- | |
| 1570 | def get_x_center_screen(width) | |
| 1571 | return (Graphics.width - width) / 2 | |
| 1572 | end | |
| 1573 | #---------------------------------------------------------------------------- | |
| 1574 | # • [Numeric] : Obter a posição Y do centro da tela referente a altura do objeto X. | |
| 1575 | # Exemplo: get_y_center_screen(sprite.height) : Irá retornar ao valor da posição | |
| 1576 | # Y para que o objeto fique no centro da tela. | |
| 1577 | # Exemplo: sprite.y = get_y_center_screen(sprite.height) | |
| 1578 | #---------------------------------------------------------------------------- | |
| 1579 | def get_y_center_screen(height) | |
| 1580 | return (Graphics.height - height) / 2 | |
| 1581 | end | |
| 1582 | #-------------------------------------------------------------------------- | |
| 1583 | # • [TrueClass/FalseClass] : Verifica se um objeto está na área de um círculo. | |
| 1584 | # object : Objeto do tipo da classe [Sprite]. | |
| 1585 | # object2 : Objeto do tipo da classe [Sprite]. | |
| 1586 | # size : Tamanho geral do círculo. | |
| 1587 | #-------------------------------------------------------------------------- | |
| 1588 | def circle(object, object2, size) | |
| 1589 | ( (object.x - object2.x) ** 2) + ( (object.y - object2.y) ** 2) <= (size ** 2) | |
| 1590 | end | |
| 1591 | #---------------------------------------------------------------------------- | |
| 1592 | # • [Numeric] : Converter o valor em graus. | |
| 1593 | #---------------------------------------------------------------------------- | |
| 1594 | def graus | |
| 1595 | 360 / (2 * Math::PI) | |
| 1596 | end | |
| 1597 | #---------------------------------------------------------------------------- | |
| 1598 | # • [Numeric] : Converte o valor em radiano. | |
| 1599 | #---------------------------------------------------------------------------- | |
| 1600 | def radian(degree) | |
| 1601 | return (degree.to_f/180) * Math::PI | |
| 1602 | end | |
| 1603 | #---------------------------------------------------------------------------- | |
| 1604 | # • [Numeric] : Converte o valor em grau. | |
| 1605 | #---------------------------------------------------------------------------- | |
| 1606 | def degree(radian) | |
| 1607 | return (radian.to_f/Math::PI) * 180 | |
| 1608 | end | |
| 1609 | #---------------------------------------------------------------------------- | |
| 1610 | # • [Numeric] : Para 4 decimals. | |
| 1611 | #---------------------------------------------------------------------------- | |
| 1612 | def to_4_dec(n) | |
| 1613 | ((n * 1000).ceil) / 1000 | |
| 1614 | end | |
| 1615 | #---------------------------------------------------------------------------- | |
| 1616 | # • [TrueClass/FalseClass] : Verifica se está na área de um triângulo. | |
| 1617 | #---------------------------------------------------------------------------- | |
| 1618 | def triangle_area(*args) | |
| 1619 | x, y, x2, y2, x3, y3 = *args | |
| 1620 | return (x2 - x) * (y3 - y) - (x3 - x) * (y2 - y) | |
| 1621 | end | |
| 1622 | #---------------------------------------------------------------------------- | |
| 1623 | # • [Numeric] : Método para calcular a distância de um objeto para com outro. | |
| 1624 | #---------------------------------------------------------------------------- | |
| 1625 | def distance_sensor(target, target2) | |
| 1626 | return (target.x - target2.x).abs + (target.y - target2.y).abs | |
| 1627 | end | |
| 1628 | #============================================================================ | |
| 1629 | # • Prime | |
| 1630 | #============================================================================ | |
| 1631 | class Prime | |
| 1632 | #-------------------------------------------------------------------------- | |
| 1633 | # • Variáveis públicas | |
| 1634 | #-------------------------------------------------------------------------- | |
| 1635 | attr_accessor :primes, :counts | |
| 1636 | #-------------------------------------------------------------------------- | |
| 1637 | # • Incluir | |
| 1638 | #-------------------------------------------------------------------------- | |
| 1639 | include Enumerables | |
| 1640 | #-------------------------------------------------------------------------- | |
| 1641 | # • Inicialização dos objetos. | |
| 1642 | #-------------------------------------------------------------------------- | |
| 1643 | def initialize | |
| 1644 | @seed ||= 1 | |
| 1645 | @primes ||= [] | |
| 1646 | @counts ||= [] | |
| 1647 | end | |
| 1648 | #-------------------------------------------------------------------------- | |
| 1649 | # • Succ | |
| 1650 | #-------------------------------------------------------------------------- | |
| 1651 | def succ | |
| 1652 | i = -1 | |
| 1653 | size = @primes.size | |
| 1654 | while i < size | |
| 1655 | if i == -1 | |
| 1656 | @seed += 1 | |
| 1657 | i += 1 | |
| 1658 | else | |
| 1659 | while @seed > @counts[i] | |
| 1660 | @counts[i] += @primes[i] | |
| 1661 | end | |
| 1662 | i = @seed != @counts[i] ? i + 1 : -1 | |
| 1663 | end | |
| 1664 | end | |
| 1665 | @primes.push @seed | |
| 1666 | @counts.push @seed + @seed | |
| 1667 | return @seed | |
| 1668 | end | |
| 1669 | alias next succ | |
| 1670 | #-------------------------------------------------------------------------- | |
| 1671 | # • Cada elemento | |
| 1672 | #-------------------------------------------------------------------------- | |
| 1673 | def each | |
| 1674 | loop { yield succ }
| |
| 1675 | end | |
| 1676 | end | |
| 1677 | #---------------------------------------------------------------------------- | |
| 1678 | # • Dentro do círculo. | |
| 1679 | #---------------------------------------------------------------------------- | |
| 1680 | def circle_in(t, b, c, d) | |
| 1681 | return -c * (Math.sqrt(1 - (t /= d.to_f) * t) - 1) + b | |
| 1682 | end | |
| 1683 | #---------------------------------------------------------------------------- | |
| 1684 | # • Fora do círculo | |
| 1685 | #---------------------------------------------------------------------------- | |
| 1686 | def circle_out(t, b, c, d) | |
| 1687 | return c * Math.sqrt(1 - (t=t/d.to_f-1)*t) + b | |
| 1688 | end | |
| 1689 | def force_range(v, min, max) | |
| 1690 | [[min, v].max, max].min | |
| 1691 | end | |
| 1692 | end | |
| 1693 | #============================================================================== | |
| 1694 | # • Keyboard | Método para usar todas as teclas do teclado. | |
| 1695 | #============================================================================== | |
| 1696 | Dax.register(:key, "Dax", 1.0) | |
| 1697 | module Key | |
| 1698 | extend self | |
| 1699 | #-------------------------------------------------------------------------- | |
| 1700 | # * Chaves diversos. | |
| 1701 | #-------------------------------------------------------------------------- | |
| 1702 | CANCEL = 0x03 # Control-Break Processing | |
| 1703 | BACKSPACE = 0x08 # Backspace Key | |
| 1704 | TAB = 0x09 # Tab Key | |
| 1705 | CLEAR = 0x0C # Clear Key | |
| 1706 | ENTER = 0x0D # Enter Key | |
| 1707 | SHIFT = 0x10 # Shift Key | |
| 1708 | CONTROL = 0x11 # Ctrl Key | |
| 1709 | MENU = 0x12 # Alt Key | |
| 1710 | PAUSE = 0x13 # Pause Key | |
| 1711 | ESC = 0x1B # Esc Key | |
| 1712 | CONVERT = 0x1C # IME Convert Key | |
| 1713 | NONCONVERT = 0x1D # IME Nonconvert Key | |
| 1714 | ACCEPT = 0x1E # IME Accept Key | |
| 1715 | SPACE = 0x20 # Space Bar Key (Space, usually blank) | |
| 1716 | PRIOR = 0x21 # Page Up Key | |
| 1717 | NEXT = 0x22 # Page Down Key | |
| 1718 | ENDS = 0x23 # End Key | |
| 1719 | HOME = 0x24 # Home Key | |
| 1720 | LEFT = 0x25 # Left Arrow Key | |
| 1721 | UP = 0x26 # Up Arrow Key | |
| 1722 | RIGHT = 0x27 # Right Arrow Key | |
| 1723 | DOWN = 0x28 # Down Arrow Key | |
| 1724 | SELECT = 0x29 # Select Key | |
| 1725 | PRINT = 0x2A # Print Key | |
| 1726 | EXECUTE = 0x2B # Execute Key | |
| 1727 | SNAPSHOT = 0x2C # Print Screen Key | |
| 1728 | DELETE = 0x2E # Delete Key | |
| 1729 | HELP = 0x2F # Help Key | |
| 1730 | LSHIFT = 0xA0 # Left Shift Key | |
| 1731 | RSHIFT = 0xA1 # Right Shift Key | |
| 1732 | LCONTROL = 0xA2 # Left Control Key (Ctrl) | |
| 1733 | RCONTROL = 0xA3 # Right Control Key (Ctrl) | |
| 1734 | LMENU = 0xA4 # Left Menu Key (Alt) | |
| 1735 | RMENU = 0xA5 # Right Menu Key (Alt) | |
| 1736 | PACKET = 0xE7 # Used to Pass Unicode Characters as Keystrokes | |
| 1737 | MOUSE_RIGHT = 0x01 # Button Mouse Right | |
| 1738 | MOUSE_LEFT = 0x02 # Button Mouse Left | |
| 1739 | MOUSE_MIDDLE = 0x04 # Button Mouse Middle | |
| 1740 | #-------------------------------------------------------------------------- | |
| 1741 | # * Chaves de números. | |
| 1742 | #-------------------------------------------------------------------------- | |
| 1743 | N0 = 0x30 # 0 Key | |
| 1744 | N1 = 0x31 # 1 Key | |
| 1745 | N2 = 0x32 # 2 Key | |
| 1746 | N3 = 0x33 # 3 Key | |
| 1747 | N4 = 0x34 # 4 Key | |
| 1748 | N5 = 0x35 # 5 Key | |
| 1749 | N6 = 0x36 # 6 Key | |
| 1750 | N7 = 0x37 # 7 Key | |
| 1751 | N8 = 0x38 # 8 Key | |
| 1752 | N9 = 0x39 # 9 Key | |
| 1753 | #-------------------------------------------------------------------------- | |
| 1754 | # * Chaves de letras | |
| 1755 | #-------------------------------------------------------------------------- | |
| 1756 | A = 0x41 # A Key | |
| 1757 | B = 0x42 # B Key | |
| 1758 | C = 0x43 # C Key | |
| 1759 | D = 0x44 # D Key | |
| 1760 | E = 0x45 # E Key | |
| 1761 | F = 0x46 # F Key | |
| 1762 | G = 0x47 # G Key | |
| 1763 | H = 0x48 # H Key | |
| 1764 | I = 0x49 # I Key | |
| 1765 | J = 0x4A # J Key | |
| 1766 | K = 0x4B # K Key | |
| 1767 | L = 0x4C # L Key | |
| 1768 | M = 0x4D # M Key | |
| 1769 | N = 0x4E # N Key | |
| 1770 | O = 0x4F # O Key | |
| 1771 | P = 0x50 # P Key | |
| 1772 | Q = 0x51 # Q Key | |
| 1773 | R = 0x52 # R Key | |
| 1774 | S = 0x53 # S Key | |
| 1775 | T = 0x54 # T Key | |
| 1776 | U = 0x55 # U Key | |
| 1777 | V = 0x56 # V Key | |
| 1778 | W = 0x57 # W Key | |
| 1779 | X = 0x58 # X Key | |
| 1780 | Y = 0x59 # Y Key | |
| 1781 | Z = 0x5A # Z Key | |
| 1782 | #-------------------------------------------------------------------------- | |
| 1783 | # * Chaves de windows | |
| 1784 | #-------------------------------------------------------------------------- | |
| 1785 | LWIN = 0x5B # Left Windows Key (Natural keyboard) | |
| 1786 | RWIN = 0x5C # Right Windows Key (Natural Keyboard) | |
| 1787 | APPS = 0x5D # Applications Key (Natural keyboard) | |
| 1788 | SLEEP = 0x5F # Computer Sleep Key | |
| 1789 | BROWSER_BACK = 0xA6 # Browser Back Key | |
| 1790 | BROWSER_FORWARD = 0xA7 # Browser Forward Key | |
| 1791 | BROWSER_REFRESH = 0xA8 # Browser Refresh Key | |
| 1792 | BROWSER_STOP = 0xA9 # Browser Stop Key | |
| 1793 | BROWSER_SEARCH = 0xAA # Browser Search Key | |
| 1794 | BROWSER_FAVORITES = 0xAB # Browser Favorites Key | |
| 1795 | BROWSER_HOME = 0xAC # Browser Start and Home Key | |
| 1796 | VOLUME_MUTE = 0xAD # Volume Mute Key | |
| 1797 | VOLUME_DOWN = 0xAE # Volume Down Key | |
| 1798 | VOLUME_UP = 0xAF # Volume Up Key | |
| 1799 | MEDIA_NEXT_TRACK = 0xB0 # Next Track Key | |
| 1800 | MEDIA_PREV_TRACK = 0xB1 # Previous Track Key | |
| 1801 | MEDIA_STOP = 0xB2 # Stop Media Key | |
| 1802 | MEDIA_PLAY_PAUSE = 0xB3 # Play/Pause Media Key | |
| 1803 | LAUNCH_MAIL = 0xB4 # Start Mail Key | |
| 1804 | LAUNCH_MEDIA_SELECT = 0xB5 # Select Media Key | |
| 1805 | LAUNCH_APP1 = 0xB6 # Start Application 1 Key | |
| 1806 | LAUNCH_APP2 = 0xB7 # Start Application 2 Key | |
| 1807 | PROCESSKEY = 0xE5 # IME Process Key | |
| 1808 | ATTN = 0xF6 # Attn Key | |
| 1809 | CRSEL = 0xF7 # CrSel Key | |
| 1810 | EXSEL = 0xF8 # ExSel Key | |
| 1811 | EREOF = 0xF9 # Erase EOF Key | |
| 1812 | PLAY = 0xFA # Play Key | |
| 1813 | ZOOM = 0xFB # Zoom Key | |
| 1814 | PA1 = 0xFD # PA1 Key | |
| 1815 | #-------------------------------------------------------------------------- | |
| 1816 | # * Chaves do Numpad | |
| 1817 | #-------------------------------------------------------------------------- | |
| 1818 | NUMPAD0 = 0x60 # Numeric Keypad 0 Key | |
| 1819 | NUMPAD1 = 0x61 # Numeric Keypad 1 Key | |
| 1820 | NUMPAD2 = 0x62 # Numeric Keypad 2 Key | |
| 1821 | NUMPAD3 = 0x63 # Numeric Keypad 3 Key | |
| 1822 | NUMPAD4 = 0x64 # Numeric Keypad 4 Key | |
| 1823 | NUMPAD5 = 0x65 # Numeric Keypad 5 Key | |
| 1824 | NUMPAD6 = 0x66 # Numeric Keypad 6 Key | |
| 1825 | NUMPAD7 = 0x67 # Numeric Keypad 7 Key | |
| 1826 | NUMPAD8 = 0x68 # Numeric Keypad 8 Key | |
| 1827 | NUMPAD9 = 0x69 # Numeric Keypad 9 Key | |
| 1828 | MULTIPLY = 0x6A # Multiply Key (*) | |
| 1829 | ADD = 0x6B # Add Key (+) | |
| 1830 | SEPARATOR = 0x6C # Separator Key | |
| 1831 | SUBTRACT = 0x6D # Subtract Key (-) | |
| 1832 | DECIMAL = 0x6E # Decimal Key (.) | |
| 1833 | DIVIDE = 0x6F # Divide Key (/) | |
| 1834 | #-------------------------------------------------------------------------- | |
| 1835 | # * Chaves de funções | |
| 1836 | #-------------------------------------------------------------------------- | |
| 1837 | F1 = 0x70 # F1 Key | |
| 1838 | F2 = 0x71 # F2 Key | |
| 1839 | F3 = 0x72 # F3 Key | |
| 1840 | F4 = 0x73 # F4 Key | |
| 1841 | F5 = 0x74 # F5 Key | |
| 1842 | F6 = 0x75 # F6 Key | |
| 1843 | F7 = 0x76 # F7 Key | |
| 1844 | F8 = 0x77 # F8 Key | |
| 1845 | F9 = 0x78 # F9 Key | |
| 1846 | F10 = 0x79 # F10 Key | |
| 1847 | F11 = 0x7A # F11 Key | |
| 1848 | F12 = 0x7B # F12 Key | |
| 1849 | F13 = 0x7C # F13 Key | |
| 1850 | F14 = 0x7D # F14 Key | |
| 1851 | F15 = 0x7E # F15 Key | |
| 1852 | F16 = 0x7F # F16 Key | |
| 1853 | F17 = 0x80 # F17 Key | |
| 1854 | F18 = 0x81 # F18 Key | |
| 1855 | F19 = 0x82 # F19 Key | |
| 1856 | F20 = 0x83 # F20 Key | |
| 1857 | F21 = 0x84 # F21 Key | |
| 1858 | F22 = 0x85 # F22 Key | |
| 1859 | F23 = 0x86 # F23 Key | |
| 1860 | F24 = 0x87 # F24 Key | |
| 1861 | #-------------------------------------------------------------------------- | |
| 1862 | # * Chaves alternativas | |
| 1863 | #-------------------------------------------------------------------------- | |
| 1864 | CAPITAL = 0x14 # Caps Lock Key | |
| 1865 | KANA = 0x15 # IME Kana Mode Key | |
| 1866 | HANGUL = 0x15 # IME Hangul Mode Key | |
| 1867 | JUNJA = 0x17 # IME Junja Mode Key | |
| 1868 | FINAL = 0x18 # IME Final Mode Key | |
| 1869 | HANJA = 0x19 # IME Hanja Mode Key | |
| 1870 | KANJI = 0x19 # IME Kanji Mode Key | |
| 1871 | MODECHANGE = 0x1F # IME Mode Change Request Key | |
| 1872 | INSERT = 0x2D # Insert Key | |
| 1873 | NUMLOCK = 0x90 # Num Lock Key | |
| 1874 | SCROLL = 0x91 # Scroll Lock Key | |
| 1875 | #-------------------------------------------------------------------------- | |
| 1876 | # * Chaves OEM, variadas | |
| 1877 | #-------------------------------------------------------------------------- | |
| 1878 | OEM_1 = 0xBA # Misc Characters (; : in USA 101/102 Keyboards) | |
| 1879 | OEM_PLUS = 0xBB # + = Key | |
| 1880 | OEM_COMMA = 0xBC # , < Key | |
| 1881 | OEM_MINUS = 0xBD # - _ Key | |
| 1882 | OEM_PERIOD = 0xBE # . > Key | |
| 1883 | OEM_2 = 0xBF # Misc Characters (/ ? in USA 101/102 Keyboards) | |
| 1884 | OEM_3 = 0xC0 # Misc Characters (` ~ in USA 101/102 Keyboards) | |
| 1885 | OEM_4 = 0xDB # Misc Characters ([ { in USA 101/102 Keyboards)
| |
| 1886 | OEM_5 = 0xDC # Misc Characters (\ | in USA 101/102 Keyboards) | |
| 1887 | OEM_6 = 0xDD # Misc Characters (] } in USA 101/102 Keyboards) | |
| 1888 | OEM_7 = 0xDE # Misc Characters (' " in USA 101/102 Keyboards)
| |
| 1889 | OEM_8 = 0xDF # Misc Characters (Varies by Keyboard) | |
| 1890 | OEM_9 = 0xE1 # OEM Specific | |
| 1891 | OEM_10 = 0x92 # OEM Specific | |
| 1892 | OEM_11 = 0x93 # OEM Specific | |
| 1893 | OEM_12 = 0x94 # OEM Specific | |
| 1894 | OEM_13 = 0x95 # OEM Specific | |
| 1895 | OEM_14 = 0x96 # OEM Specific | |
| 1896 | OEM_15 = 0xE3 # OEM Specific | |
| 1897 | OEM_16 = 0xE4 # OEM Specific | |
| 1898 | OEM_17 = 0xE6 # OEM Specific | |
| 1899 | OEM_18 = 0xE9 # OEM Specific | |
| 1900 | OEM_19 = 0xEA # OEM Specific | |
| 1901 | OEM_20 = 0xEB # OEM Specific | |
| 1902 | OEM_21 = 0xEC # OEM Specific | |
| 1903 | OEM_22 = 0xED # OEM Specific | |
| 1904 | OEM_23 = 0xEE # OEM Specific | |
| 1905 | OEM_24 = 0xEF # OEM Specific | |
| 1906 | OEM_25 = 0xF1 # OEM Specific | |
| 1907 | OEM_26 = 0xF2 # OEM Specific | |
| 1908 | OEM_27 = 0xF3 # OEM Specific | |
| 1909 | OEM_28 = 0xF4 # OEM Specific | |
| 1910 | OEM_29 = 0xF5 # OEM Specific | |
| 1911 | OEM_102 = 0xE2 # Angle Bracket or Backslash on RT-102 Keyboards | |
| 1912 | OEM_CLEAR = 0xFE # Clear Key | |
| 1913 | #-------------------------------------------------------------------------- | |
| 1914 | # * Variáveis do módulo. | |
| 1915 | #-------------------------------------------------------------------------- | |
| 1916 | @unpack_string = 'b'*256 | |
| 1917 | @last_array = '0'*256 | |
| 1918 | @press = Array.new(256, false) | |
| 1919 | @trigger = Array.new(256, false) | |
| 1920 | @repeat = Array.new(256, false) | |
| 1921 | @release = Array.new(256, false) | |
| 1922 | @repeat_counter = Array.new(256, 0) | |
| 1923 | @getKeyboardState = API::GetKeyboardState | |
| 1924 | @getAsyncKeyState = API::GetAsyncKeyState | |
| 1925 | @getKeyboardState.call(@last_array) | |
| 1926 | @last_array = @last_array.unpack(@unpack_string) | |
| 1927 | for i in 0...@last_array.size | |
| 1928 | @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true | |
| 1929 | end | |
| 1930 | #-------------------------------------------------------------------------- | |
| 1931 | # * Atualização dos objetos do módulo. | |
| 1932 | #-------------------------------------------------------------------------- | |
| 1933 | def update | |
| 1934 | @trigger = Array.new(256, false) | |
| 1935 | @repeat = Array.new(256, false) | |
| 1936 | @release = Array.new(256, false) | |
| 1937 | array = '0'*256 | |
| 1938 | @getKeyboardState.call(array) | |
| 1939 | array = array.unpack(@unpack_string) | |
| 1940 | for i in 0...array.size | |
| 1941 | if array[i] != @last_array[i] | |
| 1942 | @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true | |
| 1943 | if @repeat_counter[i] <= 0 && @press[i] | |
| 1944 | @repeat[i] = true | |
| 1945 | @repeat_counter[i] = 15 | |
| 1946 | end | |
| 1947 | if !@press[i] | |
| 1948 | @release[i] = true | |
| 1949 | else | |
| 1950 | @trigger[i] = true | |
| 1951 | end | |
| 1952 | else | |
| 1953 | if @press[i] == true | |
| 1954 | @press[i] = @getAsyncKeyState.call(i) == 0 ? false : true | |
| 1955 | @release[i] = true if !@press[i] | |
| 1956 | end | |
| 1957 | if @repeat_counter[i] > 0 && @press[i] == true | |
| 1958 | @repeat_counter[i] -= 1 | |
| 1959 | elsif @repeat_counter[i] <= 0 && @press[i] == true | |
| 1960 | @repeat[i] = true | |
| 1961 | @repeat_counter[i] = 3 | |
| 1962 | elsif @repeat_counter[i] != 0 | |
| 1963 | @repeat_counter[i] = 0 | |
| 1964 | end | |
| 1965 | end | |
| 1966 | end | |
| 1967 | @last_array = array | |
| 1968 | end | |
| 1969 | #-------------------------------------------------------------------------- | |
| 1970 | # * Get Key Pressed State | |
| 1971 | # key : key index | |
| 1972 | #-------------------------------------------------------------------------- | |
| 1973 | def press?(key) | |
| 1974 | return @press[key] | |
| 1975 | end | |
| 1976 | #-------------------------------------------------------------------------- | |
| 1977 | # * Get Key Triggered State | |
| 1978 | # key : key index | |
| 1979 | #-------------------------------------------------------------------------- | |
| 1980 | def trigger?(key) | |
| 1981 | return @trigger[key] | |
| 1982 | end | |
| 1983 | #-------------------------------------------------------------------------- | |
| 1984 | # * Get Key Repeated State | |
| 1985 | # key : key index | |
| 1986 | #-------------------------------------------------------------------------- | |
| 1987 | def repeat?(key) | |
| 1988 | return @repeat[key] | |
| 1989 | end | |
| 1990 | #-------------------------------------------------------------------------- | |
| 1991 | # * Get Key Released State | |
| 1992 | # key : key index | |
| 1993 | #-------------------------------------------------------------------------- | |
| 1994 | def release?(key) | |
| 1995 | return @release[key] | |
| 1996 | end | |
| 1997 | #---------------------------------------------------------------------------- | |
| 1998 | # • CONSTANTES. | |
| 1999 | #---------------------------------------------------------------------------- | |
| 2000 | AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(//) | |
| 2001 | @az = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".downcase!.split(//) | |
| 2002 | NUM = "0123456789".split(//) | |
| 2003 | @@string_char = @@string_num = @@string_az = "" | |
| 2004 | @@string = "" | |
| 2005 | #---------------------------------------------------------------------------- | |
| 2006 | # • [String] : Retornar a String correspondente a tecla pressionada dos números. | |
| 2007 | #---------------------------------------------------------------------------- | |
| 2008 | def stringNUM(input='trigger?') | |
| 2009 | n = "N0,N1,N2,N3,N4,N5,N6,N7,N8,N9".split(',')
| |
| 2010 | numpad = "NUMPAD0,NUMPAD1,NUMPAD2,NUMPAD3,NUMPAD4,NUMPAD5,NUMPAD6,NUMPAD7,NUMPAD8,NUMPAD9".split(',')
| |
| 2011 | n.each_with_index { |v,i| eval("return NUM[i] if #{input}(#{v})") }
| |
| 2012 | numpad.each_with_index { |v,i| eval("return NUM[i] if #{input}(#{v})") }
| |
| 2013 | return "" | |
| 2014 | end | |
| 2015 | #---------------------------------------------------------------------------- | |
| 2016 | # • [String] : Retorar a String correspondente a tecla pressionada dos alfabeto | |
| 2017 | #---------------------------------------------------------------------------- | |
| 2018 | def stringAZ(input='trigger?') | |
| 2019 | if API.get_caps_lock | |
| 2020 | AZ.each_with_index { |v,i| eval("return AZ[i] if #{input}(#{v})") }
| |
| 2021 | else | |
| 2022 | AZ.each_with_index { |v,i| eval("return @az[i] if #{input}(#{v})") }
| |
| 2023 | end | |
| 2024 | return "" | |
| 2025 | end | |
| 2026 | #---------------------------------------------------------------------------- | |
| 2027 | # • [String] : Obter a String das teclas. [ Retorna a variável @@string ] | |
| 2028 | #---------------------------------------------------------------------------- | |
| 2029 | def string(input='trigger?') | |
| 2030 | @@string_num = self.stringNUM(input) | |
| 2031 | @@string_az = self.stringAZ(input) | |
| 2032 | @@string = @@string_num + @@string_az | |
| 2033 | @@string += " " if trigger?(SPACE) | |
| 2034 | return @@string | |
| 2035 | end | |
| 2036 | end | |
| 2037 | #============================================================================== | |
| 2038 | # • Sprite | |
| 2039 | #============================================================================== | |
| 2040 | Dax.register(:sprite) | |
| 2041 | class Sprite | |
| 2042 | #---------------------------------------------------------------------------- | |
| 2043 | # • Variáveis públicas da instância. | |
| 2044 | #---------------------------------------------------------------------------- | |
| 2045 | attr_accessor :clone_sprite | |
| 2046 | #---------------------------------------------------------------------------- | |
| 2047 | # • Novo método. Modos de usos abaixo: | |
| 2048 | # * [normal] : É o método normal, na qual você não define nada. Sprite.new | |
| 2049 | # * [viewport] : É o método na qual você define um viewport. | |
| 2050 | # Sprite.new(Viewport) | |
| 2051 | # * [system] : É o método na qual você já define um bitmap que irá carregar | |
| 2052 | # uma imagem já direto da pasta System, através do Cache. | |
| 2053 | # Sprite.new("S: Nome do Arquivo")
| |
| 2054 | # * [picture] : É o método na qual você já define um bitmap que irá carregar | |
| 2055 | # uma imagem já direito da pasta Pictures, através do Cache. | |
| 2056 | # Sprite.new("P: Nome do Arquivo")
| |
| 2057 | # * [graphics] : É o método na qual você já define um bitmap com uma imagem | |
| 2058 | # que está dentro da pasta Graphics, através do Cache. | |
| 2059 | # Sprite.new("G: Nome do Arquivo.")
| |
| 2060 | # * [width, height] : É o método na qual você já define a largura e altura | |
| 2061 | # do bitmap. Sprite.new([width, height]) | |
| 2062 | # * [elements] : É o método na qual você já define a largura, altura, | |
| 2063 | # posição X, posição Y e Prioridade do bitmap. | |
| 2064 | # Sprite.new([width, height, x, y, z]) | |
| 2065 | #---------------------------------------------------------------------------- | |
| 2066 | alias new_initialize initialize | |
| 2067 | def initialize(viewport=nil) | |
| 2068 | @clone_sprite = [] | |
| 2069 | if viewport.is_a?(String) | |
| 2070 | new_initialize(nil) | |
| 2071 | if viewport.match(/S: ([^>]*)/) | |
| 2072 | self.bitmap = Cache.system($1.to_s) | |
| 2073 | elsif viewport.match(/P: ([^>]*)/) | |
| 2074 | self.bitmap = Cache.picture($1.to_s) | |
| 2075 | elsif viewport.match(/G: ([^>]*)/) | |
| 2076 | self.bitmap = Cache.load_bitmap("Graphics/", $1.to_s)
| |
| 2077 | else | |
| 2078 | self.bitmap = Bitmap.new(viewport) | |
| 2079 | end | |
| 2080 | elsif viewport.is_a?(Array) | |
| 2081 | if viewport.size == 2 | |
| 2082 | new_initialize(nil) | |
| 2083 | self.bitmap = Bitmap.new(viewport[0], viewport[1]) | |
| 2084 | elsif viewport.size == 5 | |
| 2085 | new_initialize(nil) | |
| 2086 | self.bitmap = Bitmap.new(viewport[0], viewport[1]) | |
| 2087 | self.x, self.y, self.z = viewport[2], viewport[3], viewport[4] | |
| 2088 | end | |
| 2089 | elsif viewport.is_a?(Viewport) or viewport.nil? | |
| 2090 | new_initialize(viewport) | |
| 2091 | end | |
| 2092 | end | |
| 2093 | #---------------------------------------------------------------------------- | |
| 2094 | # • Slide pela direita. | |
| 2095 | # * speed : Velocidade | point : Ponto da coordenada X que irá chegar. | |
| 2096 | #---------------------------------------------------------------------------- | |
| 2097 | def slide_right(speed, point) | |
| 2098 | self.x += speed unless self.x >= point | |
| 2099 | end | |
| 2100 | #---------------------------------------------------------------------------- | |
| 2101 | # • Slide pela esquerda. | |
| 2102 | # * speed : Velocidade | point : Ponto da coordenada X que irá chegar. | |
| 2103 | #---------------------------------------------------------------------------- | |
| 2104 | def slide_left(speed, point) | |
| 2105 | self.x -= speed unless self.x <= point | |
| 2106 | end | |
| 2107 | #---------------------------------------------------------------------------- | |
| 2108 | # • Slide por cima. | |
| 2109 | # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar. | |
| 2110 | #---------------------------------------------------------------------------- | |
| 2111 | def slide_up(speed, point) | |
| 2112 | self.y -= speed unless self.y <= point | |
| 2113 | end | |
| 2114 | #---------------------------------------------------------------------------- | |
| 2115 | # • Slide por baixo. | |
| 2116 | # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar. | |
| 2117 | #---------------------------------------------------------------------------- | |
| 2118 | def slide_down(speed, point) | |
| 2119 | self.y += speed unless self.y >= point | |
| 2120 | end | |
| 2121 | #---------------------------------------------------------------------------- | |
| 2122 | # • Define aqui uma posição fixa para um objeto. | |
| 2123 | # command : Retorna a uma base padrão. | |
| 2124 | #---------------------------------------------------------------------------- | |
| 2125 | def position(command=0) | |
| 2126 | return if command.nil? | |
| 2127 | case command | |
| 2128 | # Imagem ficará no canto esquerdo superior. Posição X | |
| 2129 | when 0 then self.x = 0 | |
| 2130 | # A posição X ficará no centro da tela. | |
| 2131 | when 1 then self.x = DMath.get_x_center_screen(self.width) | |
| 2132 | # A posição X ficará no canto direito superior. | |
| 2133 | when 2 then self.x = Graphics.width - self.width | |
| 2134 | # A posição Y ficará no canto esquerdo inferior. | |
| 2135 | when 3 then self.y = 0 | |
| 2136 | # Posicionar o Y para ficar no centro. | |
| 2137 | when 4 then self.y = DMath.get_y_center_screen(self.height) | |
| 2138 | # Posicionar o Y para ficar no fundo da tela. | |
| 2139 | when 5 then self.y = Graphics.height - self.height | |
| 2140 | # Posicionar a imagem no centro da tela. | |
| 2141 | when :center | |
| 2142 | self.x = (Graphics.width - self.width) / 2 | |
| 2143 | self.y = Graphics.height / 2 - self.height / 2 | |
| 2144 | # Posicionar no centro esquerdo da tela. | |
| 2145 | when :center_left | |
| 2146 | self.x = 0 | |
| 2147 | self.y = (Graphics.height - self.height) / 2 | |
| 2148 | # Posicionar no centro direito da tela. | |
| 2149 | when :center_right | |
| 2150 | self.x = Graphics.width - self.height | |
| 2151 | self.y = (Graphics.height - self.height) / 2 | |
| 2152 | end | |
| 2153 | end | |
| 2154 | #---------------------------------------------------------------------------- | |
| 2155 | # • [Numeric] : Tamanho geral | |
| 2156 | #---------------------------------------------------------------------------- | |
| 2157 | def size | |
| 2158 | return self.width + self.height | |
| 2159 | end | |
| 2160 | #---------------------------------------------------------------------------- | |
| 2161 | # • [Rect] : Retorna ao Rect do Bitmap. | |
| 2162 | #---------------------------------------------------------------------------- | |
| 2163 | def rect | |
| 2164 | return self.bitmap.rect | |
| 2165 | end | |
| 2166 | #---------------------------------------------------------------------------- | |
| 2167 | # • Base para clonar um Sprite. | |
| 2168 | # * depht : Prioridade no mapa. | |
| 2169 | # * clone_bitmap : Se irá clonar o bitmap. | |
| 2170 | # Exemplo: sprite = sprite2.clone | |
| 2171 | #---------------------------------------------------------------------------- | |
| 2172 | def clone(depht=0, clone_bitmap=false) | |
| 2173 | @clone_sprite.delete_if { |bitmap| bitmap.disposed? }
| |
| 2174 | cloned = Sprite.new(self.viewport) | |
| 2175 | cloned.x, cloned.y = self.x, self.y | |
| 2176 | cloned.bitmap = self.bitmap | |
| 2177 | cloned.bitmap = self.bitmap.clone if clone_bitmap | |
| 2178 | unless depht == 0 | |
| 2179 | cloned.z = self.z + depht | |
| 2180 | else | |
| 2181 | @clone_sprite.each { |sprite| sprite.z -= 1 }
| |
| 2182 | cloned.z = self.z - 1 | |
| 2183 | end | |
| 2184 | cloned.src_rect.set(self.src_rect) | |
| 2185 | ["zoom_x", "zoom_y", "angle", "mirror", "opacity", "blend_type", "visible", | |
| 2186 | "ox", "oy"].each { |meth|
| |
| 2187 | eval("cloned.#{meth} = self.#{meth}")
| |
| 2188 | } | |
| 2189 | cloned.color.set(color) | |
| 2190 | cloned.tone.set(tone) | |
| 2191 | after_clone(cloned) | |
| 2192 | @clone_sprite.push(cloned) | |
| 2193 | return cloned | |
| 2194 | end | |
| 2195 | #---------------------------------------------------------------------------- | |
| 2196 | # • Efeito após ter clonado o Sprite. | |
| 2197 | #---------------------------------------------------------------------------- | |
| 2198 | def after_clone(clone) | |
| 2199 | end | |
| 2200 | #---------------------------------------------------------------------------- | |
| 2201 | # • O que irá acontecer sê o mouse estiver em cima do sprite? | |
| 2202 | #---------------------------------------------------------------------------- | |
| 2203 | def mouse_over | |
| 2204 | end | |
| 2205 | #---------------------------------------------------------------------------- | |
| 2206 | # • O que irá acontecer sê o mouse não estiver em cima do sprite? | |
| 2207 | #---------------------------------------------------------------------------- | |
| 2208 | def mouse_no_over | |
| 2209 | end | |
| 2210 | #---------------------------------------------------------------------------- | |
| 2211 | # • O que irá acontecer sê o mouse clicar no objeto | |
| 2212 | #---------------------------------------------------------------------------- | |
| 2213 | def mouse_click | |
| 2214 | end | |
| 2215 | #---------------------------------------------------------------------------- | |
| 2216 | # • Atualização dos sprites. | |
| 2217 | #---------------------------------------------------------------------------- | |
| 2218 | alias :dax_update :update | |
| 2219 | def update(*args, &block) | |
| 2220 | - | File.open(file_name, "wb"){|file| c.each{|chunk| file.write(chunk) }}
|
| 2220 | + | |
| 2221 | unless Mouse.cursor.nil? | |
| 2222 | self.if_mouse_over { |over| over ? mouse_over : mouse_no_over }
| |
| 2223 | self.if_mouse_click { mouse_click }
| |
| 2224 | end | |
| 2225 | end | |
| 2226 | #---------------------------------------------------------------------------- | |
| 2227 | # • Inverter o lado do sprite. | |
| 2228 | #---------------------------------------------------------------------------- | |
| 2229 | def invert! | |
| 2230 | self.mirror = self.mirror ? false : true | |
| 2231 | end | |
| 2232 | end | |
| 2233 | #============================================================================== | |
| 2234 | # • Bitmap | |
| 2235 | #============================================================================== | |
| 2236 | Dax.register(:bitmap) | |
| 2237 | class Bitmap | |
| 2238 | #---------------------------------------------------------------------------- | |
| 2239 | # • Criar uma barra. | |
| 2240 | # color : Objeto de Cor [Color] | |
| 2241 | # actual : Valor atual da barra. | |
| 2242 | # max : Valor máximo da barra. | |
| 2243 | # borda : Tamanho da borda da barra. | |
| 2244 | #---------------------------------------------------------------------------- | |
| 2245 | def bar(color, actual, max, borda=1) | |
| 2246 | rate = self.width.to_p(actual, max) | |
| 2247 | self.fill_rect(borda, borda, rate-(borda*2), self.height-(borda*2), | |
| 2248 | color) | |
| 2249 | end | |
| 2250 | #---------------------------------------------------------------------------- | |
| 2251 | # • Barra em forma de gradient. | |
| 2252 | # color : Objeto de Cor, em forma de [Array] para conter 2 [Color] | |
| 2253 | # exemplo -> [Color.new(x), Color.new(y)] | |
| 2254 | # actual : Valor atual da barra. | |
| 2255 | # max : Valor máximo da barra. | |
| 2256 | # borda : Tamanho da borda da barra. | |
| 2257 | #---------------------------------------------------------------------------- | |
| 2258 | def gradient_bar(color, actual, max, borda=1) | |
| 2259 | rate = self.width.to_p(actual, max) | |
| 2260 | self.gradient_fill_rect(borda, borda, rate-(borda*2), self.height-(borda*2), | |
| 2261 | color[0], color[1], 2) | |
| 2262 | end | |
| 2263 | #-------------------------------------------------------------------------- | |
| 2264 | # * Desenho do gráfico do personagem | |
| 2265 | # character_name : nome do gráfico do personagem | |
| 2266 | # character_index : índice do gráfico de personagem | |
| 2267 | # x : coordenada X | |
| 2268 | # y : coordenada Y | |
| 2269 | #-------------------------------------------------------------------------- | |
| 2270 | def draw_character(character_name, character_index, x, y) | |
| 2271 | return unless character_name | |
| 2272 | bitmap = Cache.character(character_name) | |
| 2273 | sign = character_name[/^[\!\$]./] | |
| 2274 | if sign && sign.include?('$')
| |
| 2275 | cw = bitmap.width / 3 | |
| 2276 | ch = bitmap.height / 4 | |
| 2277 | else | |
| 2278 | cw = bitmap.width / 12 | |
| 2279 | ch = bitmap.height / 8 | |
| 2280 | end | |
| 2281 | n = character_index | |
| 2282 | src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch) | |
| 2283 | self.blt(x - cw / 2, y - ch, bitmap, src_rect) | |
| 2284 | end | |
| 2285 | #-------------------------------------------------------------------------- | |
| 2286 | # * Desenho do gráfico de personagem do herói | |
| 2287 | # actor : herói | |
| 2288 | # x : coordenada X | |
| 2289 | # y : coordenada Y | |
| 2290 | #-------------------------------------------------------------------------- | |
| 2291 | def draw_actor_graphic(actor, x, y) | |
| 2292 | draw_character(actor.character_name, actor.character_index, x, y) | |
| 2293 | end | |
| 2294 | #---------------------------------------------------------------------------- | |
| 2295 | # • Limpar uma área num formato de um círculo. | |
| 2296 | #---------------------------------------------------------------------------- | |
| 2297 | def clear_rect_circle(x, y, r) | |
| 2298 | rr = r*r | |
| 2299 | for i in 0...r | |
| 2300 | adj = Math.sqrt(rr - (i*i)).ceil | |
| 2301 | xd = x - adj | |
| 2302 | wd = 2 * adj | |
| 2303 | self.clear_rect(xd, y-i, wd, 1) | |
| 2304 | self.clear_rect(xd, y+i, wd, 1) | |
| 2305 | end | |
| 2306 | end | |
| 2307 | #---------------------------------------------------------------------------- | |
| 2308 | # • Novo modo de desenhar textos. Configurações já especificadas. | |
| 2309 | #---------------------------------------------------------------------------- | |
| 2310 | def draw_text_rect(*args) | |
| 2311 | self.draw_text(self.rect, *args) | |
| 2312 | end | |
| 2313 | #---------------------------------------------------------------------------- | |
| 2314 | # • Salvar em png. | |
| 2315 | # --- Autor : Gab! --- | |
| 2316 | #---------------------------------------------------------------------------- | |
| 2317 | def save(file_name) | |
| 2318 | def chunk(type, data) | |
| 2319 | [data.size, type, data, Zlib.crc32(type + data)].pack("NA4A*N")
| |
| 2320 | end | |
| 2321 | img_data = "" | |
| 2322 | width, height = self.width, self.height | |
| 2323 | for j in 0...(height) | |
| 2324 | img_data << "\0" | |
| 2325 | for i in 0...(width) | |
| 2326 | pos_c = self.get_pixel(i, j) | |
| 2327 | img_data << [pos_c.red, pos_c.green, pos_c.blue, pos_c.alpha].pack("C*")
| |
| 2328 | end | |
| 2329 | end | |
| 2330 | c = [ | |
| 2331 | "\x89PNG\r\n\x1a\n", | |
| 2332 | chunk("IHDR", [width, height, 8, 6, 0, 0, 0].pack("N2C5")),
| |
| 2333 | chunk("IDAT", Zlib::Deflate.deflate(img_data)),
| |
| 2334 | chunk("IEND", "")
| |
| 2335 | ] | |
| 2336 | File.open(file_name << ".png", "wb"){|file| c.each{|chunk| file.write(chunk) }}
| |
| 2337 | end | |
| 2338 | #---------------------------------------------------------------------------- | |
| 2339 | # • Modificar as cores do [Bitmap] para ficarem Negativas. | |
| 2340 | #---------------------------------------------------------------------------- | |
| 2341 | def negative | |
| 2342 | for i in 0...(self.width) | |
| 2343 | for j in 0...(self.height) | |
| 2344 | pix = self.get_pixel(i, j) | |
| 2345 | pix.red = (pix.red - 255) * -1 | |
| 2346 | pix.blue = (pix.blue - 255) * -1 | |
| 2347 | pix.green = (pix.green - 255) * -1 | |
| 2348 | self.set_pixel(i, j, pix) | |
| 2349 | end | |
| 2350 | end | |
| 2351 | end | |
| 2352 | #---------------------------------------------------------------------------- | |
| 2353 | # • Grayscale : Modificar as cores do [Bitmap] para cor cinza. | |
| 2354 | #---------------------------------------------------------------------------- | |
| 2355 | def grayscale(rect = Rect.new(0, 0, self.width, self.height)) | |
| 2356 | for i in rect.x...rect.x + rect.width | |
| 2357 | for j in rect.y...rect.y + rect.height | |
| 2358 | colour = self.get_pixel(i,j) | |
| 2359 | grey_pixel = (colour.red*0.3 + colour.green*0.59 + colour.blue*0.11) | |
| 2360 | colour.red = colour.green = colour.blue = grey_pixel | |
| 2361 | self.set_pixel(i,j,colour) | |
| 2362 | end | |
| 2363 | end | |
| 2364 | end | |
| 2365 | #---------------------------------------------------------------------------- | |
| 2366 | # • Novo fornecedor de pixel. | |
| 2367 | #---------------------------------------------------------------------------- | |
| 2368 | def set_pixel_s(x, y, color, size) | |
| 2369 | for i in 0...size | |
| 2370 | self.set_pixel(x+i, y, color) | |
| 2371 | self.set_pixel(x-i, y, color) | |
| 2372 | self.set_pixel(x, y+i, color) | |
| 2373 | self.set_pixel(x, y-i, color) | |
| 2374 | self.set_pixel(x+i, y+i, color) | |
| 2375 | self.set_pixel(x-i, y-i, color) | |
| 2376 | self.set_pixel(x+i, y-i, color) | |
| 2377 | self.set_pixel(x-i, y+i, color) | |
| 2378 | end | |
| 2379 | end | |
| 2380 | #---------------------------------------------------------------------------- | |
| 2381 | # • Desenhar uma linha. | |
| 2382 | # start_x : Início da linha em X. | |
| 2383 | # start_y : Início da linha em Y. | |
| 2384 | # end_x : Finalização da linha em X. | |
| 2385 | # end_y : Finalização da linha em Y. | |
| 2386 | #---------------------------------------------------------------------------- | |
| 2387 | def draw_line(start_x, start_y, end_x, end_y, color, size=1) | |
| 2388 | set_pixel_s(start_x, start_y, color, size) | |
| 2389 | distance = (start_x - end_x).abs + (start_y - end_y).abs | |
| 2390 | for i in 1..distance | |
| 2391 | x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i | |
| 2392 | y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i | |
| 2393 | set_pixel_s(x, y, color, size) | |
| 2394 | end | |
| 2395 | set_pixel_s(end_x, end_y, color, size) | |
| 2396 | end | |
| 2397 | #---------------------------------------------------------------------------- | |
| 2398 | # • draw_bar_gauge(x, y, current, current_max, border, colors) | |
| 2399 | # x : Coordenadas X. | |
| 2400 | # y : Coordenadas Y. | |
| 2401 | # current : Valor atual da barra. | |
| 2402 | # current_max : Valor maxímo da barra. | |
| 2403 | # border : Expressura da borda. | |
| 2404 | # colors : Cores. [0, 1, 2] | |
| 2405 | #---------------------------------------------------------------------------- | |
| 2406 | # Permite adicionar uma barra. | |
| 2407 | #---------------------------------------------------------------------------- | |
| 2408 | def draw_bar_gauge(x, y, current, current_max, colors=[]) | |
| 2409 | cw = self.width.to_p(current, current_max) | |
| 2410 | ch = self.height | |
| 2411 | self.gradient_fill_rect(x, y, self.width, self.height, colors[0], colors[1]) | |
| 2412 | src_rect = Rect.new(0, 0, cw, ch) | |
| 2413 | self.blt(x, y, self, src_rect) | |
| 2414 | end | |
| 2415 | #---------------------------------------------------------------------------- | |
| 2416 | # • draw_icon(icon_index, x, y, enabled) | |
| 2417 | # icon_index : ID do ícone. | |
| 2418 | # x : Coordenadas X. | |
| 2419 | # y : Coordenadas Y. | |
| 2420 | # enabled : Habilitar flag, translucido quando false | |
| 2421 | #---------------------------------------------------------------------------- | |
| 2422 | #---------------------------------------------------------------------------- | |
| 2423 | def draw_icon(icon_index, x, y, enabled = true) | |
| 2424 | icon_index = icon_index.nil? ? 0 : icon_index | |
| 2425 | bitmap = Cache.system("Iconset")
| |
| 2426 | rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24) | |
| 2427 | self.blt(x, y, bitmap, rect, enabled ? 255 : 128) | |
| 2428 | end | |
| 2429 | #---------------------------------------------------------------------------- | |
| 2430 | # • draw_gradation_gauge(x, y, width, height, current, current_max, border, colors, align) | |
| 2431 | # x : Coordenadas X. | |
| 2432 | # y : Coordenadas Y. | |
| 2433 | # width : Largura da barra. | |
| 2434 | # height : Altura da barra. | |
| 2435 | # current : Valor atual da barra. | |
| 2436 | # current_max : Valor maxímo da barra. | |
| 2437 | # border : Expressura da borda. | |
| 2438 | # colors : Cores. [0, 1, 2] | |
| 2439 | # align : Alinhamento. | |
| 2440 | #---------------------------------------------------------------------------- | |
| 2441 | # Permite adicionar uma barra. | |
| 2442 | #---------------------------------------------------------------------------- | |
| 2443 | def draw_gradation_gauge(x, y, current, current_max, border, colors=[]) | |
| 2444 | cw = self.width.to_p(current, current_max) | |
| 2445 | ch = self.height | |
| 2446 | self.fill_rect(x, y, self.width, self.height, colors[0]) | |
| 2447 | self.gradient_fill_rect(x+border, y+border, self.width-(border/2), self.height-(border/2), colors[1], colors[2]) | |
| 2448 | src_rect = Rect.new(0, 0, cw, ch) | |
| 2449 | self.blt(x, y, self, src_rect) | |
| 2450 | end | |
| 2451 | #-------------------------------------------------------------------------- | |
| 2452 | # • Desenho do gráfico de rosto | |
| 2453 | # face_name : nome do gráfico de face | |
| 2454 | # face_index : índice do gráfico de face | |
| 2455 | # x : coordenada X | |
| 2456 | # y : coordenada Y | |
| 2457 | # enabled : habilitar flag, translucido quando false | |
| 2458 | #-------------------------------------------------------------------------- | |
| 2459 | def draw_face(face_name, face_index, x, y, enabled = true) | |
| 2460 | bitmap = Cache.face(face_name) | |
| 2461 | rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96) | |
| 2462 | self.blt(x, y, bitmap, rect, enabled ? 255 : 128) | |
| 2463 | end | |
| 2464 | #-------------------------------------------------------------------------- | |
| 2465 | # • Desenho do gráfico de face do herói | |
| 2466 | # actor : herói | |
| 2467 | # x : coordenada X | |
| 2468 | # y : coordenada Y | |
| 2469 | # enabled : habilitar flag, translucido quando false | |
| 2470 | #-------------------------------------------------------------------------- | |
| 2471 | def draw_actor_face(actor, x, y, enabled = true) | |
| 2472 | draw_face(actor.face_name, actor.face_index, x, y, enabled) | |
| 2473 | end | |
| 2474 | #-------------------------------------------------------------------------- | |
| 2475 | # • Desenho do nível | |
| 2476 | # actor : herói | |
| 2477 | # x : coordenada X | |
| 2478 | # y : coordenada Y | |
| 2479 | #-------------------------------------------------------------------------- | |
| 2480 | def draw_actor_level(actor, x, y) | |
| 2481 | self.font.name = "Comic Sans MS" | |
| 2482 | self.font.color = ColorBasic[35] | |
| 2483 | self.font.size = 18 | |
| 2484 | self.draw_text(x, y, 32, 20, Vocab::level_a) | |
| 2485 | self.font.size = 22 | |
| 2486 | draw_text(x + 16, y, 32, 20, actor.level, 2) | |
| 2487 | end | |
| 2488 | #---------------------------------------------------------------------------- | |
| 2489 | # • Desenhar um círuclo preenchido. | |
| 2490 | #---------------------------------------------------------------------------- | |
| 2491 | def fill_circle(x, y, r, c) | |
| 2492 | rr = r*r | |
| 2493 | for i in 0...r | |
| 2494 | adj = Math.sqrt(rr - (i*i)).ceil | |
| 2495 | xd = x - adj | |
| 2496 | wd = 2 * adj | |
| 2497 | self.fill_rect(xd, y-i, wd, 1, c) | |
| 2498 | self.fill_rect(xd, y+i, wd, 1, c) | |
| 2499 | end | |
| 2500 | end | |
| 2501 | #---------------------------------------------------------------------------- | |
| 2502 | # • Desenhar um triângulo preenchido | |
| 2503 | #---------------------------------------------------------------------------- | |
| 2504 | def fill_triangle3(pts, c, pos=[0, 0]) | |
| 2505 | return if pts.size != 3 | |
| 2506 | pts.sort! {|a, b| a[1] - b[1]}
| |
| 2507 | pt1, pt2, pt3 = pts | |
| 2508 | dxt = (pt3[0] - pt1[0]) / 2 | |
| 2509 | dyt = (pt3[1] - pt1[1]) / 2 | |
| 2510 | dxm = pt2[0] - pt1[0] | |
| 2511 | dym = pt2[1] - pt1[1] | |
| 2512 | dm = dym.abs | |
| 2513 | if dm > 0 and dyt != 0 | |
| 2514 | for i in 0...(dm+2) | |
| 2515 | ix = ((dxm*i) / (dm+1)) | |
| 2516 | iy = ((dym*i) / (dm+1)) | |
| 2517 | edx = ix - (dxt * iy / dyt) | |
| 2518 | self.fill_rect(ix+pt1[0]-[edx,0].max-2+pos[0], iy+pt1[1]+pos[1], edx.abs+4, 1, c) | |
| 2519 | end | |
| 2520 | end | |
| 2521 | dxm = pt2[0] - pt3[0] | |
| 2522 | dym = pt2[1] - pt3[1] | |
| 2523 | dm = dym.abs | |
| 2524 | if dm > 0 and dyt != 0 | |
| 2525 | for i in 0...(dm+2) | |
| 2526 | ix = ((dxm*i) / (dm+1)) | |
| 2527 | iy = ((dym*i) / (dm+1)) | |
| 2528 | edx = ix - (dxt * iy / dyt) | |
| 2529 | self.fill_rect(ix+pt3[0]-[edx,0].max-2+pos[0], iy+pt3[1]+pos[1], edx.abs+4, 1, c) | |
| 2530 | end | |
| 2531 | end | |
| 2532 | end | |
| 2533 | #---------------------------------------------------------------------------- | |
| 2534 | # • Desenhar um polígono. | |
| 2535 | #---------------------------------------------------------------------------- | |
| 2536 | def fill_polygon(pts, c, pos=[0, 0]) | |
| 2537 | return if pts.size <= 2 | |
| 2538 | n = pts.size - 2 | |
| 2539 | for i in 0...n | |
| 2540 | self.fill_triangle3(pts[i..(i + 2)], c, pos) | |
| 2541 | end | |
| 2542 | end | |
| 2543 | end | |
| 2544 | #============================================================================== | |
| 2545 | # • Mouse | |
| 2546 | #============================================================================== | |
| 2547 | Dax.register(:mouse) | |
| 2548 | module Mouse | |
| 2549 | extend self | |
| 2550 | #-------------------------------------------------------------------------- | |
| 2551 | # • Inicialização dos objetos. | |
| 2552 | #-------------------------------------------------------------------------- | |
| 2553 | def start | |
| 2554 | @cursor = Sprite.new | |
| 2555 | @cursor.z = 100000 | |
| 2556 | @cursor.bitmap = Bitmap.new(1, 1) | |
| 2557 | x = Dax::Mouse_Name == "" ? 1 : 0 | |
| 2558 | API::MouseShowCursor.call(x) | |
| 2559 | @dgraphic = Dax::Mouse_Name | |
| 2560 | graphic Dax::Mouse_Name | |
| 2561 | @old_graphic = @dgraphic | |
| 2562 | update | |
| 2563 | end | |
| 2564 | #---------------------------------------------------------------------------- | |
| 2565 | # • visible = (boolean) | |
| 2566 | # * boolean : true ou false | |
| 2567 | # Tornar vísivel ou não o cursor do Mouse. | |
| 2568 | #---------------------------------------------------------------------------- | |
| 2569 | def visible=(boolean) | |
| 2570 | API::MouseShowCursor.call(boolean.boolean) | |
| 2571 | end | |
| 2572 | #-------------------------------------------------------------------------- | |
| 2573 | # • graphic(graphic_set) | |
| 2574 | # graphic_set : Se for número é um ícone; Se for string é uma imagem. | |
| 2575 | #-------------------------------------------------------------------------- | |
| 2576 | def graphic(graphic_set) | |
| 2577 | return unless graphic_set == "" or graphic_set.nil? | |
| 2578 | set_graphic | |
| 2579 | @dgraphic = graphic_set | |
| 2580 | end | |
| 2581 | #-------------------------------------------------------------------------- | |
| 2582 | # • show(visible) | |
| 2583 | # visible : True - para mostrar o mouse | False - para esconder o mouse. | |
| 2584 | #-------------------------------------------------------------------------- | |
| 2585 | def show(visible=true) | |
| 2586 | @cursor.visible = visible | |
| 2587 | end | |
| 2588 | #-------------------------------------------------------------------------- | |
| 2589 | # • update (Atualização das coordenadas) | |
| 2590 | #-------------------------------------------------------------------------- | |
| 2591 | def update | |
| 2592 | return if @cursor.nil? | |
| 2593 | @cursor.x, @cursor.y = position | |
| 2594 | end | |
| 2595 | #---------------------------------------------------------------------------- | |
| 2596 | # • Mudança do gráfico. | |
| 2597 | #---------------------------------------------------------------------------- | |
| 2598 | def set_graphic | |
| 2599 | unless @old_graphic == @dgraphic | |
| 2600 | if @dgraphic.is_a?(Fixnum) | |
| 2601 | @cursor.bitmap = Bitmap.new(24, 24) | |
| 2602 | @cursor.bitmap.draw_icon(@dgraphic.to_i, 0, 0) | |
| 2603 | else | |
| 2604 | @cursor.bitmap = Cache.picture(@dgraphic.to_s) | |
| 2605 | end | |
| 2606 | @old_graphic = @dgraphic | |
| 2607 | end | |
| 2608 | end | |
| 2609 | #-------------------------------------------------------------------------- | |
| 2610 | # • Retorna a variável '@cursor' que tem como valor a classe [Sprite]. | |
| 2611 | #-------------------------------------------------------------------------- | |
| 2612 | def cursor | |
| 2613 | @cursor | |
| 2614 | end | |
| 2615 | #-------------------------------------------------------------------------- | |
| 2616 | # • x (Coordenada X do Mouse) | |
| 2617 | #-------------------------------------------------------------------------- | |
| 2618 | def x | |
| 2619 | @cursor.x | |
| 2620 | end | |
| 2621 | #-------------------------------------------------------------------------- | |
| 2622 | # • y (Coordenada Y do Mouse) | |
| 2623 | #-------------------------------------------------------------------------- | |
| 2624 | def y | |
| 2625 | @cursor.y | |
| 2626 | end | |
| 2627 | #---------------------------------------------------------------------------- | |
| 2628 | # • Elementos das coordenadas do mouse. | |
| 2629 | #---------------------------------------------------------------------------- | |
| 2630 | def eachPos | |
| 2631 | yield(x, y, @cursor.z) | |
| 2632 | return nil | |
| 2633 | end | |
| 2634 | #-------------------------------------------------------------------------- | |
| 2635 | # • position (Posição do Mouse!) | |
| 2636 | #-------------------------------------------------------------------------- | |
| 2637 | def position | |
| 2638 | x, y = get_client_position | |
| 2639 | return x, y | |
| 2640 | end | |
| 2641 | #-------------------------------------------------------------------------- | |
| 2642 | # • get_client_position (Posição original do Mouse!) | |
| 2643 | #-------------------------------------------------------------------------- | |
| 2644 | def get_client_position | |
| 2645 | pos = [0, 0].pack('ll')
| |
| 2646 | API::CursorPosition.call(pos) | |
| 2647 | API::ScreenToClient.call(WINDOW, pos) | |
| 2648 | return pos.unpack('ll')
| |
| 2649 | end | |
| 2650 | #-------------------------------------------------------------------------- | |
| 2651 | # • find_window (Tamanho da window) | |
| 2652 | #-------------------------------------------------------------------------- | |
| 2653 | def find_window | |
| 2654 | game_name = '\0' * 256 | |
| 2655 | API::ReadIni.call('Game', 'Title', '', game_name, 255, '.\\Game.ini')
| |
| 2656 | game_name.delete!('\0') ensure game_name
| |
| 2657 | return API::FindWindow.call('RGSS Player', game_name)
| |
| 2658 | end | |
| 2659 | #-------------------------------------------------------------------------- | |
| 2660 | # • Verificação se o mouse está na área de um determinado objeto. | |
| 2661 | #-------------------------------------------------------------------------- | |
| 2662 | def in_area?(object_sprite) | |
| 2663 | return @cursor.x.between?(object_sprite.x, object_sprite.x + object_sprite.width) && | |
| 2664 | @cursor.y.between?(object_sprite.y, object_sprite.y + object_sprite.height) | |
| 2665 | end | |
| 2666 | #---------------------------------------------------------------------------- | |
| 2667 | # • Verificar se o mouse está em determinada área | |
| 2668 | #---------------------------------------------------------------------------- | |
| 2669 | def area?(x, y, width, height) | |
| 2670 | return @cursor.x.between?(x, x + width) && | |
| 2671 | @cursor.y.between?(y, y + height) | |
| 2672 | end | |
| 2673 | #---------------------------------------------------------------------------- | |
| 2674 | # • Mudar posição do cursor. | |
| 2675 | #---------------------------------------------------------------------------- | |
| 2676 | def set_mouse(pos) | |
| 2677 | SetCursorPos.call(pos.x, pos.y) | |
| 2678 | update | |
| 2679 | @cursor.x = @pos.x | |
| 2680 | @cursor.y = @pos.y | |
| 2681 | end | |
| 2682 | WINDOW = find_window | |
| 2683 | end | |
| 2684 | ||
| 2685 | #============================================================================== | |
| 2686 | # • Object | |
| 2687 | #============================================================================== | |
| 2688 | Dax.register(:object) | |
| 2689 | class Object | |
| 2690 | #---------------------------------------------------------------------------- | |
| 2691 | # • O que irá ocorrer caso o mouse esteja sobre uma sprite. | |
| 2692 | # Tem que ser um objeto Sprite. EXPLICAÇÕES NO FINAL DO SCRIPT. | |
| 2693 | #---------------------------------------------------------------------------- | |
| 2694 | def if_mouse_over(&block) | |
| 2695 | return if Mouse.cursor.nil? | |
| 2696 | return unless self.is_a?(Sprite) or self.is_a?(Window_Base) or block_given? | |
| 2697 | over ||= false | |
| 2698 | if Mouse.in_area?(self) | |
| 2699 | block.call | |
| 2700 | over = true | |
| 2701 | else | |
| 2702 | over = false | |
| 2703 | end | |
| 2704 | yield over | |
| 2705 | end | |
| 2706 | #---------------------------------------------------------------------------- | |
| 2707 | # • Retorna no bloco os nomes e quantidade de cada arquivo. Mais o nome | |
| 2708 | # separado. Mais o tipo de cada elemento. | |
| 2709 | # "Nome da Pasta".dirGlob { |filename, size| }
| |
| 2710 | #---------------------------------------------------------------------------- | |
| 2711 | def dirGlob | |
| 2712 | return unless self.is_a?(String) or File.directory?(self) | |
| 2713 | dir = Dir.glob(self.include?("/") ? self + "*" : self + "/*")
| |
| 2714 | yield dir | |
| 2715 | yield dir.size | |
| 2716 | end | |
| 2717 | #---------------------------------------------------------------------------- | |
| 2718 | # • O que irá ocorrer caso o mouse esteja sobre uma sprite, e ao clicar. | |
| 2719 | # Tem que ser um objeto Sprite. | |
| 2720 | # * button : Button : (:right - botão direito do mouse | :left - botão esq.) | |
| 2721 | # EXPLICAÇÕES NO FINAL DO SCRIPT. | |
| 2722 | #---------------------------------------------------------------------------- | |
| 2723 | def if_mouse_click(button=:left, &block) | |
| 2724 | return if Mouse.cursor.nil? | |
| 2725 | return unless self.is_a?(Sprite) or self.is_a?(Window_Base) or block_given? | |
| 2726 | button = button == :left ? 0x01 : button == :right ? 0x02 : 0x01 | |
| 2727 | block.call if Mouse.in_area?(self) and trigger?(button) | |
| 2728 | end | |
| 2729 | #---------------------------------------------------------------------------- | |
| 2730 | # • O que irá ocorrer caso o mouse esteja sobre uma sprite, e ao pressionar. | |
| 2731 | # Tem que ser um objeto Sprite. | |
| 2732 | # * button : Button : (:right - botão direito do mouse | :left - botão esq.) | |
| 2733 | #---------------------------------------------------------------------------- | |
| 2734 | def if_mouse_press(button=:left, &block) | |
| 2735 | return if Mouse.cursor.nil? | |
| 2736 | return unless self.is_a?(Sprite) or self.is_a?(Window_Base) or block_given? | |
| 2737 | button = button == :left ? 0x01 : button == :right ? 0x02 : 0x01 | |
| 2738 | block.call if Mouse.in_area?(self) and press?(button) | |
| 2739 | end | |
| 2740 | #---------------------------------------------------------------------------- | |
| 2741 | # • O que irá ocorrer caso o mouse esteja sobre uma sprite, e ao ficar clicando. | |
| 2742 | # Tem que ser um objeto Sprite. | |
| 2743 | # * button : Button : (:right - botão direito do mouse | :left - botão esq.) | |
| 2744 | #---------------------------------------------------------------------------- | |
| 2745 | def if_mouse_repeat(button=:left, &block) | |
| 2746 | return if Mouse.cursor.nil? | |
| 2747 | return unless self.is_a?(Sprite) or self.is_a?(Window_Base) or block_given? | |
| 2748 | button = button == :left ? 0x01 : button == :right ? 0x02 : 0x01 | |
| 2749 | - | def initialize |
| 2749 | + | |
| 2750 | end | |
| 2751 | #---------------------------------------------------------------------------- | |
| 2752 | # • Trigger | |
| 2753 | # * key : Chave. | |
| 2754 | # Você também pode usá-lo como condição para executar tal bloco; | |
| 2755 | #---------------------------------------------------------------------------- | |
| 2756 | # trigger?(key) { bloco que irá executar }
| |
| 2757 | #---------------------------------------------------------------------------- | |
| 2758 | def trigger?(key, &block) | |
| 2759 | ckey = key.is_a?(Symbol) ? Input.trigger?(key) : Key.trigger?(key) | |
| 2760 | return ckey unless block_given? | |
| 2761 | block.call if ckey | |
| 2762 | end | |
| 2763 | #---------------------------------------------------------------------------- | |
| 2764 | # • Press | |
| 2765 | # * key : Chave. | |
| 2766 | # Você também pode usá-lo como condição para executar tal bloco; | |
| 2767 | #---------------------------------------------------------------------------- | |
| 2768 | # press?(key) { bloco que irá executar. }
| |
| 2769 | #---------------------------------------------------------------------------- | |
| 2770 | def press?(key, &block) | |
| 2771 | ckey = key.is_a?(Symbol) ? Input.press?(key) : Key.press?(key) | |
| 2772 | return ckey unless block_given? | |
| 2773 | block.call if ckey | |
| 2774 | end | |
| 2775 | #---------------------------------------------------------------------------- | |
| 2776 | # • Repeat | |
| 2777 | # * key : Chave. | |
| 2778 | # Você também pode usá-lo como condição para executar tal bloco; | |
| 2779 | - | def save(filename="") |
| 2779 | + | |
| 2780 | - | File.open(filename, "a+").each { |file|
|
| 2780 | + | |
| 2781 | - | file.write(@text.to_s) |
| 2781 | + | |
| 2782 | def repeat?(key) | |
| 2783 | ckey = key.is_a?(Symbol) ? Input.repeat?(key) : Key.repeat?(key) | |
| 2784 | return ckey unless block_given? | |
| 2785 | block.call if ckey | |
| 2786 | end | |
| 2787 | #---------------------------------------------------------------------------- | |
| 2788 | # • Retorna em forma de número os valores true ou false. E caso seja | |
| 2789 | # 0 ou 1.. retorna a true ou false. | |
| 2790 | # Se for true, retorna a 1. | |
| 2791 | # Se for false, retorna a 0. | |
| 2792 | # Se for 1, retorna a true. | |
| 2793 | # Se for 0, retorna a false. | |
| 2794 | #---------------------------------------------------------------------------- | |
| 2795 | def boolean | |
| 2796 | return self.is_a?(Integer) ? self == 0 ? false : 1 : self ? 1 : 0 | |
| 2797 | end | |
| 2798 | #---------------------------------------------------------------------------- | |
| 2799 | # • Converte para a classe Position. | |
| 2800 | #---------------------------------------------------------------------------- | |
| 2801 | def position | |
| 2802 | return Position.new(self, self) if self.is_a?(Numeric) | |
| 2803 | return Position.new(self.x, self.y) if self.is_a?(Sprite) or self.is_a?(Window_Base) | |
| 2804 | return Position.new(self[0], self[1]) if self.is_a?(Array) | |
| 2805 | return Position.new(0, 0) | |
| 2806 | end | |
| 2807 | #---------------------------------------------------------------------------- | |
| 2808 | # • Transforma em cor. | |
| 2809 | # Se for uma Array. Exemplo: [128, 174, 111].color =># Color.new(128, 174, 111) | |
| 2810 | # Se for uma String. Exemplo: "ffffff".color =># Color.new(255,255,255) | |
| 2811 | # Se for um número, aí retorna a uma cor de acordo com o Index do ColorBasic. | |
| 2812 | #---------------------------------------------------------------------------- | |
| 2813 | def color | |
| 2814 | return Color.new(*self) if self.is_a?(Array) | |
| 2815 | return ColorBasic.hex(self) if self.is_a?(String) | |
| 2816 | return ColorBasic[self] if self.is_a?(Integer) | |
| 2817 | end | |
| 2818 | end | |
| 2819 | #============================================================================== | |
| 2820 | # • Entries *** Classe ainda não explicada ****** | |
| 2821 | #============================================================================== | |
| 2822 | Dax.register(:entries) | |
| 2823 | class Entries | |
| 2824 | #---------------------------------------------------------------------------- | |
| 2825 | # • Variável pública da instância. | |
| 2826 | #---------------------------------------------------------------------------- | |
| 2827 | attr_accessor :file | |
| 2828 | attr_reader :get_number | |
| 2829 | attr_reader :get_file | |
| 2830 | attr_reader :get_array | |
| 2831 | attr_reader :name | |
| 2832 | #---------------------------------------------------------------------------- | |
| 2833 | # • Inicialização dos objetos. | |
| 2834 | #---------------------------------------------------------------------------- | |
| 2835 | def initialize(directory, typefile) | |
| 2836 | return unless FileTest.directory?(directory) | |
| 2837 | @file = Dir.glob(directory + "/*.{" + typefile + "}")
| |
| 2838 | @file.each_index { |i| @get_number = i.to_i }
| |
| 2839 | @file.each { |i| @get_file = i.to_s }
| |
| 2840 | @file.each_with_index { |i| @get_array = i }
| |
| 2841 | @name = split @file[0] | |
| 2842 | end | |
| 2843 | #---------------------------------------------------------------------------- | |
| 2844 | # • Split | Separar | |
| 2845 | #---------------------------------------------------------------------------- | |
| 2846 | def split(file) | |
| 2847 | file.to_s.split('/').last
| |
| 2848 | end | |
| 2849 | #---------------------------------------------------------------------------- | |
| 2850 | # • Obter nome. | |
| 2851 | #---------------------------------------------------------------------------- | |
| 2852 | def name(id) | |
| 2853 | return if @file.nil? | |
| 2854 | return split(@file[id]) | |
| 2855 | end | |
| 2856 | end | |
| 2857 | #============================================================================== | |
| 2858 | # • TextBase | |
| 2859 | #============================================================================== | |
| 2860 | Dax.register(:text_base) | |
| 2861 | class TextBase | |
| 2862 | #---------------------------------------------------------------------------- | |
| 2863 | # • Inicialização dos objetos. | |
| 2864 | #---------------------------------------------------------------------------- | |
| 2865 | def initialize(filename="File_#{rand(999)}", type="a+")
| |
| 2866 | @text = "" | |
| 2867 | filename = filename.include?(".txt") ? filename : filename << ".txt"
| |
| 2868 | @file = File.open(filename, type) | |
| 2869 | end | |
| 2870 | #---------------------------------------------------------------------------- | |
| 2871 | # • Adicionar texto. | |
| 2872 | #---------------------------------------------------------------------------- | |
| 2873 | def text=(text_add) | |
| 2874 | @text += text_add | |
| 2875 | end | |
| 2876 | #---------------------------------------------------------------------------- | |
| 2877 | # • Adicionar uma nova linha. | |
| 2878 | #---------------------------------------------------------------------------- | |
| 2879 | def text(text, nspace=0) | |
| 2880 | @text += "\r\n" + (" " * nspace) + text
| |
| 2881 | end | |
| 2882 | #---------------------------------------------------------------------------- | |
| 2883 | # • Adicionar comentário; | |
| 2884 | #---------------------------------------------------------------------------- | |
| 2885 | def comment=(text_add, comment="#") | |
| 2886 | @text += comment + text_add | |
| 2887 | end | |
| 2888 | #---------------------------------------------------------------------------- | |
| 2889 | # • Adicionar uma nova linha como comentário. | |
| 2890 | #---------------------------------------------------------------------------- | |
| 2891 | def comment(text, nspace=0, comment="#") | |
| 2892 | @text += "\r\n" + (" " * nspace) + comment + text
| |
| 2893 | end | |
| 2894 | #---------------------------------------------------------------------------- | |
| 2895 | # • Salvar o texto. | |
| 2896 | #---------------------------------------------------------------------------- | |
| 2897 | def save | |
| 2898 | @file.write(@text) | |
| 2899 | @file.close | |
| 2900 | end | |
| 2901 | end | |
| 2902 | #============================================================================== | |
| 2903 | # • DRGSS | Comandos do RGSS... | |
| 2904 | #============================================================================== | |
| 2905 | Dax.register(:drgss) | |
| 2906 | module DRGSS | |
| 2907 | extend self | |
| 2908 | #---------------------------------------------------------------------------- | |
| 2909 | # • **** Método ainda não explicado **** | |
| 2910 | #---------------------------------------------------------------------------- | |
| 2911 | def recursive_delete(dir) | |
| 2912 | files = [] | |
| 2913 | Dir.foreach(dir) do |fname| | |
| 2914 | next if fname == '.' || fname == '..' | |
| 2915 | path = dir + '/' + fname | |
| 2916 | if File.directory?(path) | |
| 2917 | puts "dir #{path}"
| |
| 2918 | recursive_delete(path) | |
| 2919 | else | |
| 2920 | puts "file #{path}"
| |
| 2921 | files << path | |
| 2922 | end | |
| 2923 | end | |
| 2924 | files.each do |path| | |
| 2925 | msgbox "delete file #{path}"
| |
| 2926 | end | |
| 2927 | msgbox "delete dir #{dir}"
| |
| 2928 | Dir.rmdir(dir) | |
| 2929 | end | |
| 2930 | #---------------------------------------------------------------------------- | |
| 2931 | # • **** Método ainda não explicado **** | |
| 2932 | #---------------------------------------------------------------------------- | |
| 2933 | def delete(directory) | |
| 2934 | if File.directory?(directory) | |
| 2935 | Dir.foreach(directory) do |file_or_directory| | |
| 2936 | File.delete(directory+"/"+file_or_directory) if file_or_directory != "." and file_or_directory != ".." | |
| 2937 | end | |
| 2938 | else | |
| 2939 | begin | |
| 2940 | File.delete(directory) if File.new(directory).stat.size == 0 | |
| 2941 | rescue | |
| 2942 | msgbox "#{$!} Error in deleting zero size file "
| |
| 2943 | end | |
| 2944 | end | |
| 2945 | end | |
| 2946 | #---------------------------------------------------------------------------- | |
| 2947 | # • Extrair scripts do Database para um arquivo de extensão de texto. | |
| 2948 | # options : Caso você deixe assim: {folder: "NM"}
| |
| 2949 | # NM => Nome da pasta na qual os arquivos irão. | |
| 2950 | #---------------------------------------------------------------------------- | |
| 2951 | def extract_scripts(type=".txt",options={})
| |
| 2952 | except = options[:except] || [] | |
| 2953 | folder = options[:folder] || "" | |
| 2954 | id = 0 # | |
| 2955 | $RGSS_SCRIPTS.each do |script| | |
| 2956 | name = script[1] | |
| 2957 | data = script[3] | |
| 2958 | next if except.include? name or name.empty? or data.empty? | |
| 2959 | filename = sprintf("%03d", id) + "_" + name
| |
| 2960 | p "Writing: #{filename}"
| |
| 2961 | File.open(folder+filename+"#{type}", "wb") do |file|
| |
| 2962 | file.write data | |
| 2963 | end | |
| 2964 | id += 1 | |
| 2965 | end | |
| 2966 | end | |
| 2967 | #---------------------------------------------------------------------------- | |
| 2968 | # • Guarda todos os scripts do Database num arquivo; | |
| 2969 | #---------------------------------------------------------------------------- | |
| 2970 | def keep_scripts_in_file(filename="RGSS.rvdata2") | |
| 2971 | unless FileTest.exist?(filename) | |
| 2972 | self.extract_scripts(".txt")
| |
| 2973 | file = File.open(filename, "wb") | |
| 2974 | Dir.glob("./*.{txt}").each_with_index { |v,i|
| |
| 2975 | next unless v.match(/(\d+){3}_(\w*)/)
| |
| 2976 | file.write(IO.readlines(v).to_s) | |
| 2977 | File.delete(v) | |
| 2978 | } | |
| 2979 | file.close | |
| 2980 | end | |
| 2981 | end | |
| 2982 | #---------------------------------------------------------------------------- | |
| 2983 | # • **** Método ainda não explicado **** | |
| 2984 | #---------------------------------------------------------------------------- | |
| 2985 | def load_scripts(type=".txt",options={})
| |
| 2986 | skip = options[:skip] || [] | |
| 2987 | folder = options[:folder] || "" | |
| 2988 | begin | |
| 2989 | Dir.foreach(folder) do |file| | |
| 2990 | file_id = file[0,3].to_i | |
| 2991 | break if file_id == options[:limit] | |
| 2992 | next if file == "." or file == ".." or File.extname(file) != "#{type}" or skip.include?(file_id)
| |
| 2993 | r = load(folder+"#{file}")
| |
| 2994 | p "Loaded: #{r}"
| |
| 2995 | end | |
| 2996 | end | |
| 2997 | end | |
| 2998 | end | |
| 2999 | #============================================================================== | |
| 3000 | # • OutlineFillRect **** Método ainda não explicado **** | |
| 3001 | #============================================================================== | |
| 3002 | Dax.register(:outline_fill_rect) | |
| 3003 | class OutlineFillRect < Sprite | |
| 3004 | #---------------------------------------------------------------------------- | |
| 3005 | # • Inicialização dos objetos. | |
| 3006 | #---------------------------------------------------------------------------- | |
| 3007 | def initialize(object, max=2, color=ColorBasic[-1]) | |
| 3008 | super([object.width, object.height]) | |
| 3009 | @object = object | |
| 3010 | self.x, self.y, self.z = object.x, object.y, object.z | |
| 3011 | self.bitmap.fill_rect(0, 0, max, self.height, color) | |
| 3012 | self.bitmap.fill_rect(self.width-max, 0, max, self.height, color) | |
| 3013 | self.bitmap.fill_rect(0, 0, self.width, max, color) | |
| 3014 | self.bitmap.fill_rect(0, self.height-max, self.width, max, color) | |
| 3015 | end | |
| 3016 | #---------------------------------------------------------------------------- | |
| 3017 | # • Renovação dos objetos. | |
| 3018 | #---------------------------------------------------------------------------- | |
| 3019 | - | self.bitmap.draw_text_rect(@text) |
| 3019 | + | |
| 3020 | self.bitmap.dispose unless self.bitmap.disposed? | |
| 3021 | super | |
| 3022 | end | |
| 3023 | #---------------------------------------------------------------------------- | |
| 3024 | # • Atualização das coordenadas. | |
| 3025 | #---------------------------------------------------------------------------- | |
| 3026 | def update | |
| 3027 | self.x, self.y, self.z = @object.x, @object.y, @object.z | |
| 3028 | end | |
| 3029 | end | |
| 3030 | #============================================================================== | |
| 3031 | # • Backup Complete | |
| 3032 | #============================================================================== | |
| 3033 | Dax.register(:backup) | |
| 3034 | module Backup | |
| 3035 | extend self | |
| 3036 | # Criar as pastas. | |
| 3037 | def make_past | |
| 3038 | Dir.mkdir("Backup") unless File.directory?("Backup")
| |
| 3039 | ["Data", "System", "Movies", "Graphics", "Audio", "Audio/BGM", "Audio/BGS", "Audio/ME", "Audio/SE"].each { |i|
| |
| 3040 | Dir.mkdir("Backup/#{i}") unless File.directory?("Backup/#{i}")
| |
| 3041 | } | |
| 3042 | end | |
| 3043 | # Cópiar da pasta system. | |
| 3044 | def system | |
| 3045 | list = Dir.glob('System/*')
| |
| 3046 | list.size.times { |i|API::CopyFile.call(list[i], "Backup/" + list[i], true.boolean)}
| |
| 3047 | end | |
| 3048 | # Cópiar da pasta Movies. | |
| 3049 | def movies | |
| 3050 | movies = Dir.glob("Movies/*")
| |
| 3051 | movies.size.times { |i| API::CopyFile.call(movies[i], "Backup/" + movies[i], true.boolean)}
| |
| 3052 | end | |
| 3053 | # Cópiar da pasta Audio. | |
| 3054 | def audio | |
| 3055 | bgm = Dir.glob('Audio/BGM/*')
| |
| 3056 | bgs = Dir.glob('Audio/BGS/*')
| |
| 3057 | me = Dir.glob('Audio/ME/*')
| |
| 3058 | se = Dir.glob('Audio/SE/*')
| |
| 3059 | bgm.size.times { |i| API::CopyFile.call(bgm[i], "Backup/" + bgm[i], true.boolean)}
| |
| 3060 | bgs.size.times { |i| API::CopyFile.call(bgs[i], "Backup/" + bgs[i], true.boolean) }
| |
| 3061 | me.size.times { |i| API::CopyFile.call(me[i], "Backup/" + me[i], true.boolean) }
| |
| 3062 | se.size.times { |i| API::CopyFile.call(se[i], "Backup/" + se[i], true.boolean) }
| |
| 3063 | end | |
| 3064 | # Cópiar da pasta Data | |
| 3065 | def data | |
| 3066 | data = Dir.glob('Data/*')
| |
| 3067 | data.size.times { |i| API::CopyFile.call(data[i], "Backup/" + data[i], true.boolean) }
| |
| 3068 | end | |
| 3069 | # Cópiar da pasta Graphics. | |
| 3070 | def graphics | |
| 3071 | ["Animations", "Battlebacks1", "Battlebacks2", "Battlers", "Characters", | |
| 3072 | "Faces", "Parallaxes", "Pictures", "System", "Titles1", "Titles2", | |
| 3073 | "Tilesets"].each { |dirs|
| |
| 3074 | Dir.mkdir("Backup/Graphics/#{dirs}") unless File.directory?("Backup/Graphics/#{dirs}")
| |
| 3075 | d = Dir.glob("Graphics/#{dirs}/*")
| |
| 3076 | d.size.times { |v| API::CopyFile.call(d[v], "Backup/" + d[v], true.boolean) }
| |
| 3077 | } | |
| 3078 | end | |
| 3079 | # Executar | |
| 3080 | def run(audios=false, graphic=false) | |
| 3081 | return unless $TEST | |
| 3082 | make_past | |
| 3083 | movies | |
| 3084 | data | |
| 3085 | system | |
| 3086 | audio if audios | |
| 3087 | graphics if graphic | |
| 3088 | end | |
| 3089 | end | |
| 3090 | #============================================================================== | |
| 3091 | # * SceneManager | |
| 3092 | #============================================================================== | |
| 3093 | Dax.register :scenemanager | |
| 3094 | Dax.required_class("SceneManager"){
| |
| 3095 | class << SceneManager | |
| 3096 | #---------------------------------------------------------------------------- | |
| 3097 | # • **** Método ainda não explicado **** | |
| 3098 | #---------------------------------------------------------------------------- | |
| 3099 | def symbol(scene_symbol) | |
| 3100 | eval("self.call(#{scene_symbol.to_s})")
| |
| 3101 | end | |
| 3102 | end | |
| 3103 | } | |
| 3104 | #============================================================================== | |
| 3105 | # • Sprite_Text | |
| 3106 | #============================================================================== | |
| 3107 | Dax.register(:sprite_text) | |
| 3108 | class Sprite_Text < Sprite | |
| 3109 | #---------------------------------------------------------------------------- | |
| 3110 | # • Variáveis públicas da instância. | |
| 3111 | #---------------------------------------------------------------------------- | |
| 3112 | attr_accessor :text # Mudar de texto... | |
| 3113 | attr_accessor :align | |
| 3114 | #---------------------------------------------------------------------------- | |
| 3115 | # • Inicialização dos objetos. | |
| 3116 | #---------------------------------------------------------------------------- | |
| 3117 | def initialize(x, y, width, height, text, align=0) | |
| 3118 | super([width, height]) | |
| 3119 | self.x, self.y = x, y | |
| 3120 | @text = text | |
| 3121 | @align = align | |
| 3122 | self.bitmap.draw_text_rect(@text, align) | |
| 3123 | end | |
| 3124 | #---------------------------------------------------------------------------- | |
| 3125 | # • Renovação dos objetos. | |
| 3126 | #---------------------------------------------------------------------------- | |
| 3127 | def dispose | |
| 3128 | self.bitmap.dispose | |
| 3129 | super | |
| 3130 | end | |
| 3131 | #---------------------------------------------------------------------------- | |
| 3132 | # • Atualização dos objetos. | |
| 3133 | #---------------------------------------------------------------------------- | |
| 3134 | def update | |
| 3135 | self.bitmap.clear | |
| 3136 | super | |
| 3137 | self.bitmap.draw_text_rect(@text, @align) | |
| 3138 | end | |
| 3139 | def name=(value=nil) | |
| 3140 | self.bitmap.font.name = name || Font.default_name.to_s | |
| 3141 | end | |
| 3142 | #---------------------------------------------------------------------------- | |
| 3143 | # • Negrito na fonte? | |
| 3144 | #---------------------------------------------------------------------------- | |
| 3145 | def bold=(value=nil) | |
| 3146 | self.bitmap.font.bold = value || true | |
| 3147 | end | |
| 3148 | #---------------------------------------------------------------------------- | |
| 3149 | # • Itálico na fonte? | |
| 3150 | #---------------------------------------------------------------------------- | |
| 3151 | def italic=(value=nil) | |
| 3152 | self.bitmap.font.italic = value || true | |
| 3153 | end | |
| 3154 | #---------------------------------------------------------------------------- | |
| 3155 | # • Sombra na fonte? | |
| 3156 | #---------------------------------------------------------------------------- | |
| 3157 | def shadow=(value=nil) | |
| 3158 | self.bitmap.font.shadow = value || true | |
| 3159 | end | |
| 3160 | #---------------------------------------------------------------------------- | |
| 3161 | # • Borda na fonte? | |
| 3162 | #---------------------------------------------------------------------------- | |
| 3163 | def outline=(value=nil) | |
| 3164 | self.bitmap.font.outline = value || true | |
| 3165 | end | |
| 3166 | #---------------------------------------------------------------------------- | |
| 3167 | # • Mudar a cor da fonte: | |
| 3168 | #---------------------------------------------------------------------------- | |
| 3169 | def color=(color=nil) | |
| 3170 | self.bitmap.font.color = color || -1.color | |
| 3171 | end | |
| 3172 | #---------------------------------------------------------------------------- | |
| 3173 | # • Mudar a cor da borda da fonte. | |
| 3174 | #---------------------------------------------------------------------------- | |
| 3175 | def out_color=(out_color=nil) | |
| 3176 | self.bitmap.font.out_color = out_color || 7.color | |
| 3177 | end | |
| 3178 | end | |
| 3179 | #============================================================================== | |
| 3180 | # • StringSprite : Permite digitar pelo teclado. | |
| 3181 | #============================================================================== | |
| 3182 | Dax.register :key_string_sprite | |
| 3183 | class KeyStringSprite < Sprite_Text | |
| 3184 | attr_reader :text | |
| 3185 | #-------------------------------------------------------------------------- | |
| 3186 | # • Inicialização dos objetos. | |
| 3187 | #-------------------------------------------------------------------------- | |
| 3188 | def initialize(x, y, width, height, input="trigger?") | |
| 3189 | super(x, y, width, height, "") | |
| 3190 | @input = input | |
| 3191 | end | |
| 3192 | #-------------------------------------------------------------------------- | |
| 3193 | # • Renovação dos objetos. | |
| 3194 | #-------------------------------------------------------------------------- | |
| 3195 | def dispose | |
| 3196 | super | |
| 3197 | end | |
| 3198 | #-------------------------------------------------------------------------- | |
| 3199 | # • Atualização dos objetos. | |
| 3200 | #-------------------------------------------------------------------------- | |
| 3201 | def update | |
| 3202 | @text += Key.string(@input) unless Key.string(@input) == "" | |
| 3203 | @text = DString.backslash(@text) if Key.trigger?(Key::BACKSPACE) | |
| 3204 | super | |
| 3205 | end | |
| 3206 | end | |
| 3207 | #============================================================================== | |
| 3208 | # • Sprite_Icon | |
| 3209 | #============================================================================== | |
| 3210 | Dax.register(:sprite_icon) | |
| 3211 | class Sprite_Icon < Sprite | |
| 3212 | #---------------------------------------------------------------------------- | |
| 3213 | # • Variáveis públicas da instância. | |
| 3214 | #---------------------------------------------------------------------------- | |
| 3215 | attr_accessor :icon_index # Mudar de ícone. | |
| 3216 | attr_accessor :enabled # Tornar opaco ou não. | |
| 3217 | #---------------------------------------------------------------------------- | |
| 3218 | # • Inicialização dos objetos. | |
| 3219 | #---------------------------------------------------------------------------- | |
| 3220 | def initialize(x, y, icon_index, enabled=true) | |
| 3221 | super([24, 24]) | |
| 3222 | self.x, self.y = x, y | |
| 3223 | @icon_index = icon_index.to_i | |
| 3224 | @enabled = enabled | |
| 3225 | self.bitmap.draw_icon(@icon_index, 0, 0, @enabled) | |
| 3226 | end | |
| 3227 | #---------------------------------------------------------------------------- | |
| 3228 | # • Renovação dos objetos. | |
| 3229 | #---------------------------------------------------------------------------- | |
| 3230 | def dispose | |
| 3231 | self.bitmap.dispose | |
| 3232 | super | |
| 3233 | end | |
| 3234 | #---------------------------------------------------------------------------- | |
| 3235 | # • Atualização dos objetos. | |
| 3236 | #---------------------------------------------------------------------------- | |
| 3237 | def update | |
| 3238 | self.bitmap.clear | |
| 3239 | super | |
| 3240 | self.bitmap.draw_icon(@icon_index, 0, 0, @enabled) | |
| 3241 | end | |
| 3242 | end | |
| 3243 | #============================================================================== | |
| 3244 | - | def script |
| 3244 | + | |
| 3245 | #============================================================================== | |
| 3246 | Dax.register(:opacity) | |
| 3247 | module Opacity | |
| 3248 | extend self | |
| 3249 | @key ||= {}
| |
| 3250 | #---------------------------------------------------------------------------- | |
| 3251 | # • Efeito de opacidade que vai aumentando e diminuindo. | |
| 3252 | # sprite : Objeto na qual sofrerá o efeito. [Sprite] | |
| 3253 | # speed : Velocidade na qual o efeito irá acontencer. | |
| 3254 | # max : Valor máximo na qual irá ser atingido. | |
| 3255 | # min : Valor minímo na qual irá ser atingido. | |
| 3256 | #---------------------------------------------------------------------------- | |
| 3257 | def sprite_opacity(sprite, speed, max, min, hash=nil) | |
| 3258 | @key[hash.nil? ? hash.__id__ : hash] || false | |
| 3259 | unless @key[hash] | |
| 3260 | sprite.opacity += speed unless sprite.opacity >= max | |
| 3261 | @key[hash] = sprite.opacity >= max | |
| 3262 | else | |
| 3263 | sprite.opacity -= speed unless sprite.opacity <= min | |
| 3264 | @key[hash] = false if sprite.opacity <= min | |
| 3265 | end | |
| 3266 | end | |
| 3267 | #---------------------------------------------------------------------------- | |
| 3268 | # • Efeito de opacidade por fora. | |
| 3269 | # sprite : Objeto na qual sofrerá o efeito. [Sprite] | |
| 3270 | # speed : Velocidade na qual o efeito irá acontencer. | |
| 3271 | # max : Valor máximo na qual irá ser atingido. | |
| 3272 | #---------------------------------------------------------------------------- | |
| 3273 | def sprite_opacity_out(sprite, speed, max) | |
| 3274 | sprite.opacity += speed unless sprite.opacity >= max | |
| 3275 | end | |
| 3276 | #---------------------------------------------------------------------------- | |
| 3277 | # • Efeito de opacidade por dentro. | |
| 3278 | # sprite : Objeto na qual sofrerá o efeito. [Sprite] | |
| 3279 | # speed : Velocidade na qual o efeito irá acontencer. | |
| 3280 | # min : Valor minímo na qual irá ser atingido. | |
| 3281 | #---------------------------------------------------------------------------- | |
| 3282 | def sprite_opacity_in(sprite, speed, min) | |
| 3283 | sprite.opacity -= speed unless sprite.opacity <= min | |
| 3284 | end | |
| 3285 | #-------------------------------------------------------------------------- | |
| 3286 | # • Efeito de fade out em massa | |
| 3287 | # time : duração (em milesegundo) | |
| 3288 | #-------------------------------------------------------------------------- | |
| 3289 | def fadeout_all(time = 1000) | |
| 3290 | RPG::BGM.fade(time) | |
| 3291 | RPG::BGS.fade(time) | |
| 3292 | RPG::ME.fade(time) | |
| 3293 | Graphics.fadeout(time * Graphics.frame_rate / 1000) | |
| 3294 | RPG::BGM.stop | |
| 3295 | RPG::BGS.stop | |
| 3296 | RPG::ME.stop | |
| 3297 | end | |
| 3298 | #---------------------------------------------------------------------------- | |
| 3299 | # • Limpar variável. | |
| 3300 | #---------------------------------------------------------------------------- | |
| 3301 | def clear | |
| 3302 | @key.clear | |
| 3303 | end | |
| 3304 | end | |
| 3305 | #============================================================================== | |
| 3306 | # • Rpg | |
| 3307 | #============================================================================== | |
| 3308 | Dax.register(:rpg) | |
| 3309 | module Rpg | |
| 3310 | def self.data_manager | |
| 3311 | end | |
| 3312 | #============================================================================ | |
| 3313 | # • Hud | |
| 3314 | #============================================================================ | |
| 3315 | module Hud | |
| 3316 | ||
| 3317 | end | |
| 3318 | #============================================================================ | |
| 3319 | # • Menu | |
| 3320 | #============================================================================ | |
| 3321 | module Menu | |
| 3322 | extend self | |
| 3323 | def include_item?(item) | |
| 3324 | item.is_a?(RPG::Item) && !item.key_item? | |
| 3325 | end | |
| 3326 | #-------------------------------------------------------------------------- | |
| 3327 | # • *** Método aidna não explicado **** | |
| 3328 | #-------------------------------------------------------------------------- | |
| 3329 | def cursor_up(variable, max) | |
| 3330 | variable += 1 unless variable > max | |
| 3331 | variable = 0 if variable > max | |
| 3332 | return variable | |
| 3333 | end | |
| 3334 | #-------------------------------------------------------------------------- | |
| 3335 | # • *** Método aidna não explicado **** | |
| 3336 | #-------------------------------------------------------------------------- | |
| 3337 | def cursor_down(variable, max) | |
| 3338 | variable -= 1 unless variable < 0 | |
| 3339 | variable = max if variable < 0 | |
| 3340 | return variable | |
| 3341 | end | |
| 3342 | end | |
| 3343 | #============================================================================ | |
| 3344 | # • Battle | |
| 3345 | #============================================================================ | |
| 3346 | module Battle | |
| 3347 | end | |
| 3348 | #============================================================================ | |
| 3349 | # • Title | |
| 3350 | #============================================================================ | |
| 3351 | module Title | |
| 3352 | end | |
| 3353 | end | |
| 3354 | #============================================================================== | |
| 3355 | # • String | |
| 3356 | #============================================================================== | |
| 3357 | Dax.register :shortcut | |
| 3358 | class String | |
| 3359 | #---------------------------------------------------------------------------- | |
| 3360 | # • *** Método aidna não explicado **** | |
| 3361 | #---------------------------------------------------------------------------- | |
| 3362 | def call | |
| 3363 | if self.match(/G: ([^>]*)/) | |
| 3364 | return "Graphics/#{$1}"
| |
| 3365 | elsif self.match(/C:(\w+):([^>]*)/) | |
| 3366 | case $1 | |
| 3367 | when "S" | |
| 3368 | return Cache.system($2.to_s) | |
| 3369 | when "P" | |
| 3370 | return Cache.picture($2.to_s) | |
| 3371 | when "Pl" | |
| 3372 | return Cache.parallax($2.to_s) | |
| 3373 | when "C" | |
| 3374 | return Cache.character($2.to_s) | |
| 3375 | when "A" | |
| 3376 | return Cache.animation($2.to_s) | |
| 3377 | when "B1" | |
| 3378 | return Cache.battleback1($2.to_s) | |
| 3379 | when "B2" | |
| 3380 | return Cache.battleback2($2.to_s) | |
| 3381 | when "B" | |
| 3382 | return Cache.battler($2.to_s) | |
| 3383 | when "F" | |
| 3384 | return Cache.face($2.to_s) | |
| 3385 | when "T1" | |
| 3386 | return Cache.title1($2.to_s) | |
| 3387 | when "T2" | |
| 3388 | return Cache.title2($2.to_s) | |
| 3389 | when "T" | |
| 3390 | return Cache.tileset($2.to_s) | |
| 3391 | end | |
| 3392 | end | |
| 3393 | end | |
| 3394 | end | |
| 3395 | #============================================================================== | |
| 3396 | # • Txt | |
| 3397 | #============================================================================== | |
| 3398 | Dax.register(:read, "Dax") | |
| 3399 | module Read | |
| 3400 | extend self | |
| 3401 | #---------------------------------------------------------------------------- | |
| 3402 | # • Verificar valor numérico após uma palavra em um arquivo. | |
| 3403 | #---------------------------------------------------------------------------- | |
| 3404 | def numeric(file, tag) | |
| 3405 | IO.readlines(file).each do |line| | |
| 3406 | return $1.to_i if line.match(/#{tag} (\d+)/)
| |
| 3407 | end | |
| 3408 | end | |
| 3409 | #---------------------------------------------------------------------------- | |
| 3410 | # • Verificar valor de uma palavra(string única) após uma palavra em um arquivo | |
| 3411 | #---------------------------------------------------------------------------- | |
| 3412 | def string(file, tag) | |
| 3413 | IO.readlines(file).each do |line| | |
| 3414 | return $1.to_s if line.match(/#{tag} (\w+)/)
| |
| 3415 | end | |
| 3416 | end | |
| 3417 | #---------------------------------------------------------------------------- | |
| 3418 | # • Verificar um conteúdo após uma palavra de um arquivo. | |
| 3419 | #---------------------------------------------------------------------------- | |
| 3420 | def content(file, tag) | |
| 3421 | IO.readlines(file).each do |line| | |
| 3422 | return $1 if line.match(/#{tag} ([^>]*)/)
| |
| 3423 | end | |
| 3424 | end | |
| 3425 | #---------------------------------------------------------------------------- | |
| 3426 | # • Multiplo número.. | |
| 3427 | #---------------------------------------------------------------------------- | |
| 3428 | def multiple_numeric(file, tag) | |
| 3429 | IO.readlines(file).each do |line| | |
| 3430 | return [$1.to_i, $2.to_i] if line.match(/#{tag} (\d+), (\d+)/)
| |
| 3431 | end | |
| 3432 | end | |
| 3433 | #---------------------------------------------------------------------------- | |
| 3434 | # • Multiplo string.. | |
| 3435 | #---------------------------------------------------------------------------- | |
| 3436 | def multiple_string(file, tag) | |
| 3437 | IO.readlines(file).each do |line| | |
| 3438 | return [$1.to_s, $2.to_s] if line.match(/#{tag} (\w+), (\w+)/)
| |
| 3439 | end | |
| 3440 | end | |
| 3441 | #---------------------------------------------------------------------------- | |
| 3442 | # • Triplo número. | |
| 3443 | #---------------------------------------------------------------------------- | |
| 3444 | def triple_numeric(file, tag) | |
| 3445 | IO.readlines(file).each do |line| | |
| 3446 | return [$1.to_i, $2.to_i, $3.to_i] if line.match(/#{tag} (\d+), (\d+), (\d+)/)
| |
| 3447 | end | |
| 3448 | end | |
| 3449 | #---------------------------------------------------------------------------- | |
| 3450 | # • Triplo string. | |
| 3451 | #---------------------------------------------------------------------------- | |
| 3452 | def triple_string(file, tag) | |
| 3453 | IO.readlines(file).each do |line| | |
| 3454 | return [$1.to_s, $2.to_s, $3.to_s] if line.match(/#{tag} (\w+), (\w+), (\w+)/)
| |
| 3455 | end | |
| 3456 | end | |
| 3457 | # true or false | |
| 3458 | def of(file, tag) | |
| 3459 | IO.readlines(file).each do |line| | |
| 3460 | return $1.to_s == "true" ? true : false if line.match(/#{tag} ([^>]*)/)
| |
| 3461 | end | |
| 3462 | end | |
| 3463 | end | |
| 3464 | ||
| 3465 | #============================================================================== | |
| 3466 | # • Background | |
| 3467 | #============================================================================== | |
| 3468 | Dax.register :background | |
| 3469 | module Background | |
| 3470 | extend self | |
| 3471 | @background ||= {}
| |
| 3472 | #---------------------------------------------------------------------------- | |
| 3473 | # • Plano de fundo padrão... | |
| 3474 | #---------------------------------------------------------------------------- | |
| 3475 | def default(alpha=128, key=nil) | |
| 3476 | @background[key.__id__] = Sprite.new | |
| 3477 | @background[key.__id__].bitmap = SceneManager.background_bitmap | |
| 3478 | @background[key.__id__].color.set(16, 16, 16, alpha) | |
| 3479 | end | |
| 3480 | #---------------------------------------------------------------------------- | |
| 3481 | # • Plano de fundo padrão renovado. | |
| 3482 | #---------------------------------------------------------------------------- | |
| 3483 | def default_dispose | |
| 3484 | return if @background.nil? | |
| 3485 | @background.each_value(&:dispose) | |
| 3486 | end | |
| 3487 | # Definir um sprite de fundo | |
| 3488 | def define_back(color="ffffff".color, key=nil) | |
| 3489 | @background[key.__id__] = Sprite.new([Graphics.width, Graphics.height]) | |
| 3490 | @background[key.__id__].bitmap.fill_rect(@background[key.__id__].rect, color) | |
| 3491 | end | |
| 3492 | end | |
| 3493 | #============================================================================== | |
| 3494 | # * Window_Base | |
| 3495 | #============================================================================== | |
| 3496 | Dax.register(:window_base) | |
| 3497 | Dax.required_class("Window_Base") {
| |
| 3498 | class Window_Base < Window | |
| 3499 | #---------------------------------------------------------------------------- | |
| 3500 | # • Slide pela direita. | |
| 3501 | # * speed : Velocidade | point : Ponto da coordenada X que irá chegar. | |
| 3502 | #---------------------------------------------------------------------------- | |
| 3503 | def slide_right(speed, point) | |
| 3504 | self.x += speed unless self.x >= point | |
| 3505 | end | |
| 3506 | #---------------------------------------------------------------------------- | |
| 3507 | # • Slide pela esquerda. | |
| 3508 | # * speed : Velocidade | point : Ponto da coordenada X que irá chegar. | |
| 3509 | #---------------------------------------------------------------------------- | |
| 3510 | def slide_left(speed, point) | |
| 3511 | self.x -= speed unless self.x <= point | |
| 3512 | end | |
| 3513 | #---------------------------------------------------------------------------- | |
| 3514 | # • Slide por cima. | |
| 3515 | # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar. | |
| 3516 | #---------------------------------------------------------------------------- | |
| 3517 | def slide_up(speed, point) | |
| 3518 | self.y -= speed unless self.y <= point | |
| 3519 | end | |
| 3520 | #---------------------------------------------------------------------------- | |
| 3521 | # • Slide por baixo. | |
| 3522 | # * speed : Velocidade | point : Ponto da coordenada Y que irá chegar. | |
| 3523 | #---------------------------------------------------------------------------- | |
| 3524 | def slide_down(speed, point) | |
| 3525 | self.y += speed unless self.y >= point | |
| 3526 | end | |
| 3527 | #---------------------------------------------------------------------------- | |
| 3528 | # • Define aqui uma posição fixa para um objeto. | |
| 3529 | # command : Retorna a uma base padrão. | |
| 3530 | #---------------------------------------------------------------------------- | |
| 3531 | def position(command=0) | |
| 3532 | return if command.nil? | |
| 3533 | case command | |
| 3534 | # Imagem ficará no canto esquerdo superior. Posição X | |
| 3535 | when 0 then self.x = 0 | |
| 3536 | # A posição X ficará no centro da tela. | |
| 3537 | when 1 then self.x = DMath.get_x_center_screen(self.width) | |
| 3538 | # A posição X ficará no canto direito superior. | |
| 3539 | when 2 then self.x = Graphics.width - self.width | |
| 3540 | # A posição Y ficará no canto esquerdo inferior. | |
| 3541 | when 3 then self.y = 0 | |
| 3542 | # Posicionar o Y para ficar no centro. | |
| 3543 | when 4 then self.y = DMath.get_y_center_screen(self.height) | |
| 3544 | # Posicionar o Y para ficar no fundo da tela. | |
| 3545 | when 5 then self.y = Graphics.height - self.height | |
| 3546 | # Posicionar a imagem no centro da tela. | |
| 3547 | when :center | |
| 3548 | self.x = (Graphics.width - self.width) / 2 | |
| 3549 | self.y = Graphics.height / 2 - self.height / 2 | |
| 3550 | # Posicionar no centro esquerdo da tela. | |
| 3551 | when :center_left | |
| 3552 | self.x = 0 | |
| 3553 | self.y = (Graphics.height - self.height) / 2 | |
| 3554 | # Posicionar no centro direito da tela. | |
| 3555 | when :center_right | |
| 3556 | self.x = Graphics.width - self.height | |
| 3557 | self.y = (Graphics.height - self.height) / 2 | |
| 3558 | end | |
| 3559 | end | |
| 3560 | end | |
| 3561 | } | |
| 3562 | #============================================================================== | |
| 3563 | # • Map | |
| 3564 | #============================================================================== | |
| 3565 | Dax.register(:map) | |
| 3566 | module Map | |
| 3567 | extend self | |
| 3568 | #---------------------------------------------------------------------------- | |
| 3569 | # • Mapeiar área. | |
| 3570 | # map : Objeto [SPRITE].. que será escaniado.. | |
| 3571 | # scan_sprite : Objeto [SPRITE].. que irá projetar o scan. | |
| 3572 | # color : Cor do scan. | |
| 3573 | #---------------------------------------------------------------------------- | |
| 3574 | def char_area(map, scan_sprite, color=ColorBasic[-1]) | |
| 3575 | _table = Table.new(map.width, map.height) | |
| 3576 | for x in 0..._table.xsize | |
| 3577 | for y in 0..._table.ysize | |
| 3578 | next if map.bitmap.get_pixel(x, y).alpha == 0 | |
| 3579 | scan_sprite.bitmap.set_pixel(x, y, color) | |
| 3580 | end | |
| 3581 | end | |
| 3582 | end | |
| 3583 | #---------------------------------------------------------------------------- | |
| 3584 | # • Colidir com determinada cor de um objeto sprite. | |
| 3585 | # ar : [largura, altura, bloqueio da esquerda, bloqueio de cima] | |
| 3586 | # object : Objeto a colidir. [SPRITE] | |
| 3587 | # map : Mapa. [SPRITE] | |
| 3588 | # color : Cor, na qual quando o objeto colidir com está cor.. ativa. | |
| 3589 | #--------------------------------------------------------------------------- | |
| 3590 | def collide_with_color(object, map, color, ar=[28,30,30,30]) | |
| 3591 | (ar[0]...object.width).each { |w| (ar[1]...object.height).each { |h|
| |
| 3592 | _r = map.bitmap.get_pixel(object.x+w, object.y+h) == color[:right] | |
| 3593 | _l = map.bitmap.get_pixel(object.x+ar[2]-w, object.y+h) == color[:left] | |
| 3594 | _d = map.bitmap.get_pixel(object.x+w, object.y+h) == color[:down] | |
| 3595 | _u = map.bitmap.get_pixel(object.x+w, object.y+ar[3]-h) == color[:up] | |
| 3596 | return {right: _r, left: _l, down: _d, up: _u}
| |
| 3597 | }} | |
| 3598 | end | |
| 3599 | end | |
| 3600 | #============================================================================== | |
| 3601 | # • VS | Variables & Switches | |
| 3602 | #============================================================================== | |
| 3603 | Dax.register(:vs) | |
| 3604 | module VS | |
| 3605 | #---------------------------------------------------------------------------- | |
| 3606 | # • Função do módulo. | |
| 3607 | #---------------------------------------------------------------------------- | |
| 3608 | module_function | |
| 3609 | #---------------------------------------------------------------------------- | |
| 3610 | # • Desligar a quantia predestinada de switches... | |
| 3611 | #---------------------------------------------------------------------------- | |
| 3612 | def off_switche(value=9999) | |
| 3613 | Dax.required_class("$game_switches"){value.times { |index| $game_switches[index] = false }
| |
| 3614 | $game_switches.on_change} | |
| 3615 | end | |
| 3616 | #---------------------------------------------------------------------------- | |
| 3617 | # • Ativar a quantia predestinada de switches... | |
| 3618 | #---------------------------------------------------------------------------- | |
| 3619 | def on_switche(value=9999) | |
| 3620 | Dax.required_class("$game_switches"){value.times { |index| $game_switches[index] = true }
| |
| 3621 | $game_switches.on_change} | |
| 3622 | end | |
| 3623 | #---------------------------------------------------------------------------- | |
| 3624 | # • Salvar as variáveis do jogo em um arquivo | |
| 3625 | # *args : IDs delas.. exemplo: 1, 2, 3, 4 | |
| 3626 | #---------------------------------------------------------------------------- | |
| 3627 | def save_game_variable(*args) | |
| 3628 | Dax.required_class("$game_variables"){
| |
| 3629 | Dax.required_file("savedGameVariables.rvdata2"){File.delete("savedGameVariables.rvdata2")}
| |
| 3630 | i = [*args] | |
| 3631 | sgv = [{}]
| |
| 3632 | (0...i.size-1).each { |index| sgv[0][index] = $game_variables[index] }
| |
| 3633 | save_data(sgv, "savedGameVariables.rvdata2") | |
| 3634 | } | |
| 3635 | end | |
| 3636 | #---------------------------------------------------------------------------- | |
| 3637 | # • Carregar as variáveis do jogo dum arquivo | |
| 3638 | # *args : IDs delas.. exemplo: 1, 2, 3, 4 | |
| 3639 | #---------------------------------------------------------------------------- | |
| 3640 | def load_game_variable(*args) | |
| 3641 | Dax.required_class("$game_variables"){
| |
| 3642 | Dax.required_file("savedGameVariables.rvdata2"){
| |
| 3643 | i = [*args] | |
| 3644 | sgv = load_data("savedGameVariables.rvdata2")
| |
| 3645 | (0...i.size-1).each { |index| $game_variables[index] = sgv[0][index]}
| |
| 3646 | ||
| 3647 | }} | |
| 3648 | end | |
| 3649 | #---------------------------------------------------------------------------- | |
| 3650 | # • Salvar as switches do jogo em um arquivo | |
| 3651 | # *args : IDs delas.. exemplo: 1, 2, 3, 4 | |
| 3652 | #---------------------------------------------------------------------------- | |
| 3653 | def save_switches_variable(*args) | |
| 3654 | Dax.required_class("$game_switches"){
| |
| 3655 | Dax.required_file("savedGameSwitches.rvdata2"){File.delete("savedGameSwitches.rvdata2")}
| |
| 3656 | i = [*args] | |
| 3657 | sgs= [{}]
| |
| 3658 | (0...i.size-1).each { |index| sgs[0][index] = $game_switches[index] }
| |
| 3659 | save_data(sgs, "savedGameSwitches.rvdata2") | |
| 3660 | } | |
| 3661 | end | |
| 3662 | #---------------------------------------------------------------------------- | |
| 3663 | # • Carregar as variáveis do jogo dum arquivo | |
| 3664 | # *args : IDs delas.. exemplo: 1, 2, 3, 4 | |
| 3665 | #---------------------------------------------------------------------------- | |
| 3666 | def load_game_variable(*args) | |
| 3667 | Dax.required_class("$game_switches"){
| |
| 3668 | Dax.required_file("savedGameSwitches.rvdata2"){
| |
| 3669 | i = [*args] | |
| 3670 | sgs = load_data("savedGameSwitches.rvdata2")
| |
| 3671 | (0...i.size-1).each { |index| $game_switches[index] = sgs[0][index]}
| |
| 3672 | ||
| 3673 | }} | |
| 3674 | end | |
| 3675 | end | |
| 3676 | #============================================================================== | |
| 3677 | # • Sound Base | |
| 3678 | #============================================================================== | |
| 3679 | Dax.register(:sound_base) | |
| 3680 | module Sound_Base | |
| 3681 | #---------------------------------------------------------------------------- | |
| 3682 | # • Função do módulo. | |
| 3683 | #---------------------------------------------------------------------------- | |
| 3684 | module_function | |
| 3685 | #---------------------------------------------------------------------------- | |
| 3686 | # • Executar um som. | |
| 3687 | #---------------------------------------------------------------------------- | |
| 3688 | def play(name, volume, pitch, type = :se) | |
| 3689 | case type | |
| 3690 | when :se ; RPG::SE.new(name, volume, pitch).play rescue valid?(name) | |
| 3691 | when :me ; RPG::ME.new(name, volume, pitch).play rescue valid?(name) | |
| 3692 | when :bgm ; RPG::BGM.new(name, volume, pitch).play rescue valid?(name) | |
| 3693 | when :bgs ; RPG::BGS.new(name, volume, pitch).play rescue valid?(name) | |
| 3694 | end | |
| 3695 | end | |
| 3696 | #---------------------------------------------------------------------------- | |
| 3697 | # • Validar som. | |
| 3698 | #---------------------------------------------------------------------------- | |
| 3699 | def valid?(name) | |
| 3700 | raise("Arquivo de som não encontrado: #{name}")
| |
| 3701 | exit | |
| 3702 | end | |
| 3703 | end | |
| 3704 | #============================================================================== | |
| 3705 | # • Position. | |
| 3706 | #============================================================================== | |
| 3707 | Dax.register :position | |
| 3708 | class Position | |
| 3709 | #---------------------------------------------------------------------------- | |
| 3710 | # • Variáveis públicas da instância. | |
| 3711 | #---------------------------------------------------------------------------- | |
| 3712 | attr_accessor :x # Variável que retorna ao valor que indica a posição X. | |
| 3713 | attr_accessor :y # Variável que retorna ao valor que indica a posição Y. | |
| 3714 | #---------------------------------------------------------------------------- | |
| 3715 | # • Inicialização dos objetos. | |
| 3716 | #---------------------------------------------------------------------------- | |
| 3717 | def initialize(x, y) | |
| 3718 | @x = x || 0 | |
| 3719 | @y = y || 0 | |
| 3720 | end | |
| 3721 | #---------------------------------------------------------------------------- | |
| 3722 | # • Somar com outra posição. | |
| 3723 | #---------------------------------------------------------------------------- | |
| 3724 | def +(position) | |
| 3725 | position = position.position unless position.is_a?(Position) | |
| 3726 | Position.new(self.x + position.x, self.y + position.y) | |
| 3727 | end | |
| 3728 | #---------------------------------------------------------------------------- | |
| 3729 | # • Subtrair com outra posição. | |
| 3730 | #---------------------------------------------------------------------------- | |
| 3731 | def -(position) | |
| 3732 | position = position.position unless position.is_a?(Position) | |
| 3733 | Position.new(self.x - position.x, self.y - position.y) | |
| 3734 | end | |
| 3735 | #---------------------------------------------------------------------------- | |
| 3736 | # • Multiplicar com outra posição. | |
| 3737 | #---------------------------------------------------------------------------- | |
| 3738 | def *(position) | |
| 3739 | position = position.position unless position.is_a?(Position) | |
| 3740 | Position.new(self.x * position.x, self.y * position.y) | |
| 3741 | end | |
| 3742 | #---------------------------------------------------------------------------- | |
| 3743 | # • Dividir com outra posição. | |
| 3744 | #---------------------------------------------------------------------------- | |
| 3745 | def /(position) | |
| 3746 | position = position.position unless position.is_a?(Position) | |
| 3747 | return if (self.x or position.x or self.y or position.y) <= 0 | |
| 3748 | Position.new(self.x / position.x, self.y / position.y) | |
| 3749 | end | |
| 3750 | #---------------------------------------------------------------------------- | |
| 3751 | # • Comparar com outra posição. | |
| 3752 | #---------------------------------------------------------------------------- | |
| 3753 | def ==(position) | |
| 3754 | position = position.position unless position.is_a?(Position) | |
| 3755 | return self.x == position.x && self.y == position.y | |
| 3756 | end | |
| 3757 | #---------------------------------------------------------------------------- | |
| 3758 | # • Converter em string. | |
| 3759 | #---------------------------------------------------------------------------- | |
| 3760 | def to_s | |
| 3761 | return "position x: #{self.x}\nposition y: #{self.y}"
| |
| 3762 | end | |
| 3763 | end | |
| 3764 | #============================================================================== | |
| 3765 | # • Vector | |
| 3766 | #============================================================================== | |
| 3767 | Dax.register(:vector) | |
| 3768 | class Vector | |
| 3769 | #---------------------------------------------------------------------------- | |
| 3770 | # • Inicialização dos objetos. x, y, w, h | |
| 3771 | #---------------------------------------------------------------------------- | |
| 3772 | def initialize(*args) | |
| 3773 | @vector = *args | |
| 3774 | end | |
| 3775 | #---------------------------------------------------------------------------- | |
| 3776 | # • Rotacionar | |
| 3777 | #---------------------------------------------------------------------------- | |
| 3778 | def rotate(angle) | |
| 3779 | x = @vector[0] * Math.cos(Math::PI / 180 * angle) - @vector[1] * Math.sin(Math::PI / 180 * angle) | |
| 3780 | y = @vector[0] * Math.sin(Math::PI / 180 * angle) + @vector[1] * Math.cos(Math::PI / 180 * angle) | |
| 3781 | temp = @vector.dup | |
| 3782 | temp[0], temp[1] = x, y | |
| 3783 | return Vector.new(*temp) | |
| 3784 | end | |
| 3785 | #---------------------------------------------------------------------------- | |
| 3786 | # • Somar com outra classe Vector | |
| 3787 | #---------------------------------------------------------------------------- | |
| 3788 | def +(v) | |
| 3789 | return Vector.new(*@vector.map.each_index{|s,i| s + v[i]}) if v.is_a?(Vector)
| |
| 3790 | return Vector.new(*@vector.map.each_index{|s,i| s + v[i]}) if v.is_a?(Array)
| |
| 3791 | return Vector.new(*@vector.map{|s| + v}) if v.is_a?(Numeric)
| |
| 3792 | return nil | |
| 3793 | end | |
| 3794 | #---------------------------------------------------------------------------- | |
| 3795 | # • Multiplicar com Matrix. | |
| 3796 | #---------------------------------------------------------------------------- | |
| 3797 | def *(matrix) | |
| 3798 | result = [] | |
| 3799 | for i in 0..(matrix.size-1) | |
| 3800 | data = 0 | |
| 3801 | for j in 0..(@vector.size-1) | |
| 3802 | data += @vector[j] * matrix[j][i] | |
| 3803 | end | |
| 3804 | result.push(data) | |
| 3805 | end | |
| 3806 | return Vector.new(*result) | |
| 3807 | end | |
| 3808 | #---------------------------------------------------------------------------- | |
| 3809 | # • Arr. | |
| 3810 | #---------------------------------------------------------------------------- | |
| 3811 | def [](index) | |
| 3812 | return @vector[index] | |
| 3813 | end | |
| 3814 | #---------------------------------------------------------------------------- | |
| 3815 | # • Tamanho. | |
| 3816 | #---------------------------------------------------------------------------- | |
| 3817 | def size | |
| 3818 | @vector.size | |
| 3819 | end | |
| 3820 | #---------------------------------------------------------------------------- | |
| 3821 | # • Converter para array. | |
| 3822 | #---------------------------------------------------------------------------- | |
| 3823 | def to_a | |
| 3824 | @vector | |
| 3825 | end | |
| 3826 | # x | |
| 3827 | def x; return @vector[0]; end; | |
| 3828 | # Y | |
| 3829 | def y; return @vector[1]; end; | |
| 3830 | # z | |
| 3831 | def z; return @vector[2]; end; | |
| 3832 | # w | |
| 3833 | def w; return @vector[3]; end; | |
| 3834 | end | |
| 3835 | #============================================================================== | |
| 3836 | # • Matrix | |
| 3837 | #============================================================================== | |
| 3838 | Dax.register(:matrix) | |
| 3839 | class Matrix | |
| 3840 | #---------------------------------------------------------------------------- | |
| 3841 | # • Inicialização dos objetos. | |
| 3842 | #---------------------------------------------------------------------------- | |
| 3843 | def initialize(*args) | |
| 3844 | @arr = Array.new(4) { |i| Vector.new(*args[i]) }
| |
| 3845 | end | |
| 3846 | #---------------------------------------------------------------------------- | |
| 3847 | # • Multiplicar. | |
| 3848 | #---------------------------------------------------------------------------- | |
| 3849 | def *(a) | |
| 3850 | result = [] | |
| 3851 | for i in 0..(a.size-1) | |
| 3852 | result.push(@arr[i] * a) | |
| 3853 | end | |
| 3854 | return Matrix.new(*result) | |
| 3855 | end | |
| 3856 | #---------------------------------------------------------------------------- | |
| 3857 | # • [] | |
| 3858 | #---------------------------------------------------------------------------- | |
| 3859 | def [](index) | |
| 3860 | return @arr[index] | |
| 3861 | end | |
| 3862 | #---------------------------------------------------------------------------- | |
| 3863 | # • Tamanho | |
| 3864 | #---------------------------------------------------------------------------- | |
| 3865 | def size | |
| 3866 | return @arr.size | |
| 3867 | end | |
| 3868 | #---------------------------------------------------------------------------- | |
| 3869 | # • Criar rotação em z. | |
| 3870 | #---------------------------------------------------------------------------- | |
| 3871 | def self.create_rotation_z(angle) | |
| 3872 | cos = Math.cos(Math::PI/180 * angle) | |
| 3873 | sin = Math.sin(Math::PI/180 * angle) | |
| 3874 | return Matrix.new( | |
| 3875 | [ cos, sin, 0, 0], | |
| 3876 | [-sin, cos, 0, 0], | |
| 3877 | [ 0, 0, 1, 0], | |
| 3878 | [ 0, 0, 0, 1] | |
| 3879 | ) | |
| 3880 | end | |
| 3881 | #---------------------------------------------------------------------------- | |
| 3882 | # • Rotação em X | |
| 3883 | #---------------------------------------------------------------------------- | |
| 3884 | def self.create_rotation_x(angle) | |
| 3885 | cos = Math.cos(Math::PI/180 * angle) | |
| 3886 | sin = Math.sin(Math::PI/180 * angle) | |
| 3887 | return Matrix.new( | |
| 3888 | [ 1, 0, 0, 0], | |
| 3889 | [ 0, cos, sin, 0], | |
| 3890 | [ 0,-sin, cos, 0], | |
| 3891 | [ 0, 0, 0, 1] | |
| 3892 | ) | |
| 3893 | end | |
| 3894 | #---------------------------------------------------------------------------- | |
| 3895 | # • Rotação em Y | |
| 3896 | #---------------------------------------------------------------------------- | |
| 3897 | def self.create_rotation_y(angle) | |
| 3898 | cos = Math.cos(Math::PI/180 * angle) | |
| 3899 | sin = Math.sin(Math::PI/180 * angle) | |
| 3900 | return Matrix.new( | |
| 3901 | [ cos, 0,-sin, 0], | |
| 3902 | [ 0, 1, 0, 0], | |
| 3903 | [ sin, 0, cos, 0], | |
| 3904 | [ 0, 0, 0, 1] | |
| 3905 | ) | |
| 3906 | end | |
| 3907 | #---------------------------------------------------------------------------- | |
| 3908 | # • Transição. | |
| 3909 | #---------------------------------------------------------------------------- | |
| 3910 | def self.create_transration(x, y, z) | |
| 3911 | return Matrix.new( | |
| 3912 | [ 1, 0, 0, 0], | |
| 3913 | [ 0, 1, 0, 0], | |
| 3914 | [ 0, 0, 1, 0], | |
| 3915 | [ x, y, z, 1] | |
| 3916 | ) | |
| 3917 | end | |
| 3918 | #---------------------------------------------------------------------------- | |
| 3919 | # • Para array | |
| 3920 | #---------------------------------------------------------------------------- | |
| 3921 | def to_a | |
| 3922 | @arr.map {|v|v.to_a}.flatten
| |
| 3923 | - | Dax.rgss_script.each_with_index { |data, index|
|
| 3923 | + | |
| 3924 | end | |
| 3925 | #============================================================================== | |
| 3926 | # • Animation | |
| 3927 | #============================================================================== | |
| 3928 | Dax.register :animation | |
| 3929 | class Animation | |
| 3930 | attr_reader :size, :frame_size, :index, :max_width, :max_height | |
| 3931 | #---------------------------------------------------------------------------- | |
| 3932 | # • Inicialização. | |
| 3933 | #---------------------------------------------------------------------------- | |
| 3934 | def initialize(size, frame_size, wait=1) | |
| 3935 | @size = size | |
| 3936 | @frame_size = frame_size | |
| 3937 | @index = 0 | |
| 3938 | @max_width = @size[0] / @frame_size[0] | |
| 3939 | @max_height = @size[1] / @frame_size[1] | |
| 3940 | @wait = wait | |
| 3941 | @time = 0 | |
| 3942 | end | |
| 3943 | #---------------------------------------------------------------------------- | |
| 3944 | # • Animação na horizontal. | |
| 3945 | #---------------------------------------------------------------------------- | |
| 3946 | def horz | |
| 3947 | @time += 1 unless @time >= @wait | |
| 3948 | if @time >= @wait | |
| 3949 | @index = Rpg::Menu.cursor_up(@index, @max_width) | |
| 3950 | @time = 0 | |
| 3951 | end | |
| 3952 | end | |
| 3953 | #---------------------------------------------------------------------------- | |
| 3954 | # • Animação na vertical. | |
| 3955 | #---------------------------------------------------------------------------- | |
| 3956 | def vert | |
| 3957 | @time += 1 unless @time >= @wait | |
| 3958 | if @time >= @wait | |
| 3959 | @index = Rpg::Menu.cursor_up(@index, @max_height) | |
| 3960 | @time = 0 | |
| 3961 | end | |
| 3962 | end | |
| 3963 | end | |
| 3964 | #============================================================================== | |
| 3965 | # • Sprite_Anime_Horz | |
| 3966 | #============================================================================== | |
| 3967 | Dax.register :sprite_anime_horz | |
| 3968 | class Sprite_Anime_Horz < Sprite | |
| 3969 | #---------------------------------------------------------------------------- | |
| 3970 | # • Inicialização dos objetos | |
| 3971 | # filename : Nome do arquivo. | |
| 3972 | # frame_size : Tamanho de cada frame. | |
| 3973 | # wait : Tempo de espera para mudar de um frame para outro. | |
| 3974 | #---------------------------------------------------------------------------- | |
| 3975 | def initialize(filename, frame_size, wait=1) | |
| 3976 | @bitmap = Bitmap.new(filename) | |
| 3977 | super(frame_size) | |
| 3978 | @animation = Animation.new([@bitmap.width, @bitmap.height], | |
| 3979 | frame_size, wait) | |
| 3980 | end | |
| 3981 | #---------------------------------------------------------------------------- | |
| 3982 | # • Renovação dos objetos. | |
| 3983 | #---------------------------------------------------------------------------- | |
| 3984 | def dispose | |
| 3985 | self.bitmap.dispose | |
| 3986 | super | |
| 3987 | end | |
| 3988 | #---------------------------------------------------------------------------- | |
| 3989 | # • Atualização dos objetos. | |
| 3990 | #---------------------------------------------------------------------------- | |
| 3991 | def update | |
| 3992 | self.bitmap.clear | |
| 3993 | super | |
| 3994 | @animation.horz | |
| 3995 | rect = Rect.new(@animation.index % @animation.max_width * @animation.frame_size[0], | |
| 3996 | 0, *@animation.frame_size) | |
| 3997 | self.bitmap.blt(0, 0, @bitmap, rect) | |
| 3998 | end | |
| 3999 | end | |
| 4000 | #============================================================================== | |
| 4001 | # • Sprite_Anime_Vert | |
| 4002 | #============================================================================== | |
| 4003 | Dax.register :sprite_anime_vert | |
| 4004 | class Sprite_Anime_Vert < Sprite | |
| 4005 | #---------------------------------------------------------------------------- | |
| 4006 | # • Inicialização dos objetos | |
| 4007 | # filename : Nome do arquivo. | |
| 4008 | # frame_size : Tamanho de cada frame. | |
| 4009 | # wait : Tempo de espera para mudar de um frame para outro. | |
| 4010 | #---------------------------------------------------------------------------- | |
| 4011 | def initialize(filename, frame_size, wait=1) | |
| 4012 | @bitmap = Bitmap.new(filename) | |
| 4013 | super(frame_size) | |
| 4014 | @animation = Animation.new([@bitmap.width, @bitmap.height], | |
| 4015 | frame_size, wait) | |
| 4016 | end | |
| 4017 | #---------------------------------------------------------------------------- | |
| 4018 | # • Renovação dos objetos. | |
| 4019 | #---------------------------------------------------------------------------- | |
| 4020 | def dispose | |
| 4021 | self.bitmap.dispose | |
| 4022 | super | |
| 4023 | end | |
| 4024 | #---------------------------------------------------------------------------- | |
| 4025 | # • Atualização dos objetos. | |
| 4026 | #---------------------------------------------------------------------------- | |
| 4027 | def update | |
| 4028 | self.bitmap.clear | |
| 4029 | super | |
| 4030 | @animation.vert | |
| 4031 | rect = Rect.new(0, | |
| 4032 | @animation.index % @animation.max_height * @animation.frame_size[1], *@animation.frame_size) | |
| 4033 | self.bitmap.blt(0, 0, @bitmap, rect) | |
| 4034 | end | |
| 4035 | end | |
| 4036 | #============================================================================== | |
| 4037 | # • Desativar scripts : Para fazer, basta por no nome do script da lista, | |
| 4038 | # [D]. | |
| 4039 | #============================================================================== | |
| 4040 | Dax.register(:disable_script) | |
| 4041 | $RGSS_SCRIPTS.each_with_index { |data, index|
| |
| 4042 | $RGSS_SCRIPTS.at(index)[2] = $RGSS_SCRIPTS.at(index)[3] = "" if data.at(1).include?("[D]")
| |
| 4043 | } | |
| 4044 | #============================================================================== | |
| 4045 | # • Salvar scripts em arquivo de texto : Para fazer, basta por no nome do script | |
| 4046 | # da lista, [S]. | |
| 4047 | #============================================================================== | |
| 4048 | $RGSS_SCRIPTS.each_with_index { |rgss, index|
| |
| 4049 | if rgss.at(1).include?("[S]")
| |
| 4050 | File.open("#{rgss.at(1)}.txt", "wb") { |file|
| |
| 4051 | file.write(String($RGSS_SCRIPTS.at(index)[3])) | |
| 4052 | file.close | |
| 4053 | } | |
| 4054 | end | |
| 4055 | } | |
| 4056 | #============================================================================== | |
| 4057 | # • Cache | |
| 4058 | #============================================================================== | |
| 4059 | Dax.register :cache | |
| 4060 | Dax.required_class("Cache") {
| |
| 4061 | class << Cache | |
| 4062 | #---------------------------------------------------------------------------- | |
| 4063 | # • Variáveis públicas da instância | |
| 4064 | #---------------------------------------------------------------------------- | |
| 4065 | attr_accessor :cache # Variável cache. | |
| 4066 | end | |
| 4067 | } | |
| 4068 | #============================================================================== | |
| 4069 | # * DataManager | |
| 4070 | #============================================================================== | |
| 4071 | unless defined?(DataManager) | |
| 4072 | Mouse.start | |
| 4073 | Rpg.data_manager | |
| 4074 | else | |
| 4075 | class << DataManager | |
| 4076 | alias :new_init :init | |
| 4077 | def init | |
| 4078 | Rpg.data_manager | |
| 4079 | Mouse.start | |
| 4080 | new_init | |
| 4081 | end | |
| 4082 | end | |
| 4083 | end | |
| 4084 | #============================================================================== | |
| 4085 | # * Input | |
| 4086 | #============================================================================== | |
| 4087 | class << Input | |
| 4088 | alias :upft :update | |
| 4089 | def update | |
| 4090 | upft | |
| 4091 | Key.update | |
| 4092 | end | |
| 4093 | end | |
| 4094 | #============================================================================== | |
| 4095 | # • Graphics | |
| 4096 | #============================================================================== | |
| 4097 | class << Graphics | |
| 4098 | alias :uptf :update | |
| 4099 | def update | |
| 4100 | uptf | |
| 4101 | Mouse.update | |
| 4102 | end | |
| 4103 | end | |
| 4104 | #============================================================================== | |
| 4105 | # • Explicações, comentários... Um Báu! | |
| 4106 | #============================================================================== | |
| 4107 | __END__ | |
| 4108 | :regexp_symbol | |
| 4109 | #============================================================================== | |
| 4110 | # • Regexp Symbol | |
| 4111 | #============================================================================== | |
| 4112 | ||
| 4113 | Símbolos: | |
| 4114 | ||
| 4115 | [x]|[abc] : Um único caractér de: a, b ou c | |
| 4116 | [^x]|[^abc] : Qualquer caractér exceto: a, b, ou c | |
| 4117 | [a-z] : Um único caractér no intervalo de a...z | |
| 4118 | [a-zA-Z] : Um único caractér no intervalo de a...z ou A...Z | |
| 4119 | ^ : Começo da linha. | |
| 4120 | $ : Fim da linha. | |
| 4121 | \A : Começo da string. | |
| 4122 | \z : Fim da string. | |
| 4123 | . : Um único caractér | |
| 4124 | \s : Qualquer carácter com espaço | |
| 4125 | \S : Qualquer carácter sem espaço | |
| 4126 | \d : Qualquer dígito | |
| 4127 | \D : Qualquer um que não seja um dígito | |
| 4128 | \w : Qualquer palavra | |
| 4129 | \W : Qualquer um que não seja uma palavra. | |
| 4130 | \b : Qualquer limite de palavra. | |
| 4131 | (...) : Capturar tudo fechado. | |
| 4132 | (x|y)|(a|b) : A(X) ou B(Y) | |
| 4133 | x? : Zero ou um de x. | |
| 4134 | x* : Zero ou mais de x. | |
| 4135 | x+ : Um ou mais de x. | |
| 4136 | x{3} : Exatamente 3 de x.
| |
| 4137 | x{3,} : Exatamente 3 ou mais de um de x.
| |
| 4138 | x{3,6} : Entre 3 e 6 de x.
| |
| 4139 | ||
| 4140 | Opções: | |
| 4141 | ||
| 4142 | /i : Sem case sensitive | |
| 4143 | /m : Para mais de uma linha | |
| 4144 | /x : Ingnorar espaços brancos | |
| 4145 | /o : Executar o #{...}, alterações apenas uma vez.
| |
| 4146 | ||
| 4147 | /<tagName>(.*?)<\/tagName>/im | |
| 4148 | ||
| 4149 | <tagName> | |
| 4150 | type: skill | |
| 4151 | id: 2 | |
| 4152 | forced: true | |
| 4153 | </tagName> | |
| 4154 | ||
| 4155 | p = -> { [1, 2] }
| |
| 4156 | ||
| 4157 | msgbox_p(p.call) | |
| 4158 | ||
| 4159 | ============================================================================== | |
| 4160 | **** Método : 'if_mouse_over' | |
| 4161 | O que esse método trata? Trata-se de que quando o Mouse estiver por cima de | |
| 4162 | determinado objeto.. algo irá acontecer. | |
| 4163 | Como eu configuro a ação que irá ocorrer caso o Mouse esteja por cima de | |
| 4164 | determinado objeto? | |
| 4165 | Bom, o método só irá funcionar com objetos que são da classe [Sprite], e ele | |
| 4166 | retorna a um bloco(somente se definir)! Exemplo: | |
| 4167 | sprite.if_mouse_over # Chamou o método.. Mais agora para definir o bloco basta | |
| 4168 | usar as {chaves} e dentro da chave o bloco que irá ser executado. Ex:
| |
| 4169 | sprite.if_mouse_over {
| |
| 4170 | Comando que irá se executar caso o Mouse esteja por cima do determinado objeto. | |
| 4171 | } | |
| 4172 | - | x | --- | null byte |
| 4172 | + | |
| 4173 | o Mouse esteja por cima de determinado objeto acontece algo, e quando ele não | |
| 4174 | estiver ele executa outra coisa? | |
| 4175 | Simples basta chamar a variável 'over', como chamar? Após o '{' usa-se
| |
| 4176 | |over| .. Essa variável retorna caso o Mouse esteja por cima ou não de um objeto | |
| 4177 | com os valores true or false.. Um exemplo abaixo. | |
| 4178 | sprite.if_mouse_over { |over|
| |
| 4179 | sprite.opacity = over ? 255 : 128 | |
| 4180 | } | |
| 4181 | # O Exemplo acima.. Quando o Mouse estiver por cima.. a opacidade ficará com o | |
| 4182 | valor de '255'.. e quando não estiver ficará em '128'. | |
| 4183 | ============================================================================== | |
| 4184 | *** Método : 'if_mouse_click' | |
| 4185 | O que esse método trata? Trata-se de que quando o Mouse estiver por cima de | |
| 4186 | determinado objeto e a clicar nele(com o botão direito/esquerdo). algo irá acontecer | |
| 4187 | Como eu configuro a ação que irá ocorrer caso o Mouse esteja por cima de | |
| 4188 | determinado objeto ao ser clicado? O mesmo método do de cima. | |
| 4189 | Bom, o método só irá funcionar com objetos que são da classe [Sprite], e ele | |
| 4190 | retorna a um bloco(somente se definir)! Exemplo: | |
| 4191 | sprite.if_mouse_click(button) {
| |
| 4192 | Comando que irá se executar caso o sprite seja clicado com o Mouse. | |
| 4193 | } | |
| 4194 | * button * O button naturalmente e o botão esquerdo.. Então se quiser não | |
| 4195 | precisa o configurar.. Mais caso queira olhe abaixo os valores a por em () | |
| 4196 | button : Button : (:right - botão direito do mouse | :left - botão esq.) | |
| 4197 | Um Exemplo abaixo : | |
| 4198 | sprite.if_mouse_click { msgbox("Você clicou em mim!") }
| |
| 4199 | ============================================================================== | |
| 4200 | S = Struct.new("S", :methods)
| |
| 4201 | # past RGSSAD.. quando encriptado; | |
| 4202 | # my = "%01d %06d %02d" % [4, 15646, 21] | |
| 4203 | # fruit = ["apple","red","banana","yellow"] | |
| 4204 | #Hash[*fruit] | |
| 4205 | #=> {"apple"=>"red", "banana"=>"yellow"}
| |
| 4206 | ||
| 4207 | #---------------------------------------------------------------------------- | |
| 4208 | # • [Array] Renova todos os sprites e depois deleta. | |
| 4209 | #---------------------------------------------------------------------------- | |
| 4210 | def spriteDelete | |
| 4211 | self.each_with_index { |sprite, index|
| |
| 4212 | return unless sprite.is_a?(Sprite) | |
| 4213 | sprite.dispose | |
| 4214 | self.delete_at(index) | |
| 4215 | } | |
| 4216 | end | |
| 4217 | ||
| 4218 | ceil arredonda para cima; | |
| 4219 | floor arredonda para baixo; | |
| 4220 | round arredonda para o número mais próximo; | |
| 4221 | ||
| 4222 | --Pegado do site : http://www.ruby-doc.org/ | |
| 4223 | ||
| 4224 | Integer | Array | | |
| 4225 | Directive | Element | Meaning | |
| 4226 | --------------------------------------------------------------------------- | |
| 4227 | C | Integer | 8-bit unsigned (unsigned char) | |
| 4228 | S | Integer | 16-bit unsigned, native endian (uint16_t) | |
| 4229 | L | Integer | 32-bit unsigned, native endian (uint32_t) | |
| 4230 | Q | Integer | 64-bit unsigned, native endian (uint64_t) | |
| 4231 | | | | |
| 4232 | c | Integer | 8-bit signed (signed char) | |
| 4233 | s | Integer | 16-bit signed, native endian (int16_t) | |
| 4234 | l | Integer | 32-bit signed, native endian (int32_t) | |
| 4235 | q | Integer | 64-bit signed, native endian (int64_t) | |
| 4236 | | | | |
| 4237 | S_, S! | Integer | unsigned short, native endian | |
| 4238 | I, I_, I! | Integer | unsigned int, native endian | |
| 4239 | L_, L! | Integer | unsigned long, native endian | |
| 4240 | Q_, Q! | Integer | unsigned long long, native endian (ArgumentError | |
| 4241 | | | if the platform has no long long type.) | |
| 4242 | | | (Q_ and Q! is available since Ruby 2.1.) | |
| 4243 | | | | |
| 4244 | s_, s! | Integer | signed short, native endian | |
| 4245 | i, i_, i! | Integer | signed int, native endian | |
| 4246 | l_, l! | Integer | signed long, native endian | |
| 4247 | q_, q! | Integer | signed long long, native endian (ArgumentError | |
| 4248 | | | if the platform has no long long type.) | |
| 4249 | | | (q_ and q! is available since Ruby 2.1.) | |
| 4250 | | | | |
| 4251 | S> L> Q> | Integer | same as the directives without ">" except | |
| 4252 | s> l> q> | | big endian | |
| 4253 | S!> I!> | | (available since Ruby 1.9.3) | |
| 4254 | L!> Q!> | | "S>" is same as "n" | |
| 4255 | s!> i!> | | "L>" is same as "N" | |
| 4256 | l!> q!> | | | |
| 4257 | | | | |
| 4258 | S< L< Q< | Integer | same as the directives without "<" except | |
| 4259 | s< l< q< | | little endian | |
| 4260 | S!< I!< | | (available since Ruby 1.9.3) | |
| 4261 | L!< Q!< | | "S<" is same as "v" | |
| 4262 | s!< i!< | | "L<" is same as "V" | |
| 4263 | l!< q!< | | | |
| 4264 | | | | |
| 4265 | n | Integer | 16-bit unsigned, network (big-endian) byte order | |
| 4266 | N | Integer | 32-bit unsigned, network (big-endian) byte order | |
| 4267 | v | Integer | 16-bit unsigned, VAX (little-endian) byte order | |
| 4268 | V | Integer | 32-bit unsigned, VAX (little-endian) byte order | |
| 4269 | | | | |
| 4270 | U | Integer | UTF-8 character | |
| 4271 | w | Integer | BER-compressed integer | |
| 4272 | ||
| 4273 | Float | | | |
| 4274 | Directive | | Meaning | |
| 4275 | --------------------------------------------------------------------------- | |
| 4276 | D, d | Float | double-precision, native format | |
| 4277 | F, f | Float | single-precision, native format | |
| 4278 | E | Float | double-precision, little-endian byte order | |
| 4279 | e | Float | single-precision, little-endian byte order | |
| 4280 | G | Float | double-precision, network (big-endian) byte order | |
| 4281 | g | Float | single-precision, network (big-endian) byte order | |
| 4282 | ||
| 4283 | String | | | |
| 4284 | Directive | | Meaning | |
| 4285 | --------------------------------------------------------------------------- | |
| 4286 | A | String | arbitrary binary string (space padded, count is width) | |
| 4287 | a | String | arbitrary binary string (null padded, count is width) | |
| 4288 | Z | String | same as ``a'', except that null is added with * | |
| 4289 | B | String | bit string (MSB first) | |
| 4290 | b | String | bit string (LSB first) | |
| 4291 | H | String | hex string (high nibble first) | |
| 4292 | h | String | hex string (low nibble first) | |
| 4293 | u | String | UU-encoded string | |
| 4294 | M | String | quoted printable, MIME encoding (see RFC2045) | |
| 4295 | m | String | base64 encoded string (see RFC 2045, count is width) | |
| 4296 | | | (if count is 0, no line feed are added, see RFC 4648) | |
| 4297 | P | String | pointer to a structure (fixed-length string) | |
| 4298 | p | String | pointer to a null-terminated string | |
| 4299 | ||
| 4300 | Misc. | | | |
| 4301 | Directive | | Meaning | |
| 4302 | --------------------------------------------------------------------------- | |
| 4303 | @ | --- | moves to absolute position | |
| 4304 | X | --- | back up a byte | |
| 4305 | x | --- | null byte | |
| 4306 | --------------------------------------------------------------------------- | |
| 4307 | module MyModule | |
| 4308 | NOME = "Algo" | |
| 4309 | end | |
| 4310 | ||
| 4311 | autoload(:MyModule, "my_module.rb") | |
| 4312 | print MyModule::NOME #=> "Algo" | |
| 4313 | ||
| 4314 | # Constante base para ponteiros números em formato Float. Regexp | |
| 4315 | FLOAT_RE = /^-?((\d+(\.\d+)?)|(\.\d+))([eE][-+]?[\d]+)?$/ | |
| 4316 | # Constante base para ponteiros de parameters. Regexp | |
| 4317 | PARAM_RE = /^-(-|\.$|[^\d\.])/ |