设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1338|回复: 0
打印 上一主题 下一主题

简易调试控制台

[复制链接]

…あたしは天使なんかじゃないわ

梦石
0
星屑
2207
在线时间
4033 小时
注册时间
2010-10-4
帖子
10779

开拓者贵宾

跳转到指定楼层
1
发表于 2014-9-21 19:56:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 taroxd 于 2015-2-10 14:32 编辑

RUBY 代码复制
  1. #--------------------------------------------------------------------------
  2. # ● require Taroxd基础设置 快进游戏
  3. #    简易调试控制台
  4. #--------------------------------------------------------------------------
  5.  
  6. if $TEST
  7.  
  8. module Taroxd::Console
  9.  
  10.   KEY = :F5
  11.  
  12.   exit_help = 'exit 为真时,返回游戏。'
  13.  
  14.   HELP = <<-EOF.gsub(/^ {4}/, '')
  15.  
  16.     在控制台中可以执行任意脚本。下面是一些快捷方式。
  17.  
  18.     exit
  19.       退出控制台并返回游戏。
  20.  
  21.     help
  22.       显示这段帮助。
  23.  
  24.     recover(exit = true)
  25.       完全恢复。#{exit_help}
  26.  
  27.     save(index = 0, exit = true)
  28.       存档到指定位置。#{exit_help}
  29.  
  30.     load(index = 0, exit = true)
  31.       从指定位置读档。#{exit_help}
  32.  
  33.     kill(hp = 0, exit = true)
  34.       将敌方全体的 HP 设为 hp。仅战斗中可用。#{exit_help}
  35.  
  36.     suicide(hp = 0, exit = true)
  37.       将己方全体的 HP 设为 hp。#{exit_help}
  38.  
  39.     fast_forward(*args)
  40.       调用 Taroxd::FastForward
  41.  
  42.     ff(*args)
  43.       调用 Taroxd::FastForward 并返回游戏。
  44.  
  45.   EOF
  46.  
  47.   class << self
  48.  
  49.     EXIT_IDENTIFIER = Object.new   # 返回该值时,退出控制台并回到游戏
  50.  
  51.     # 获取窗口句柄
  52.     console = Win32API.new('Kernel32', 'GetConsoleWindow', '', 'L').call
  53.     game = Win32API.new('user32', 'GetActiveWindow', '', 'L').call
  54.     hwnd = game
  55.     set_window_pos = Win32API.new('user32', 'SetWindowPos', 'LLLLLLL', 'L')
  56.  
  57.     # 切换窗口
  58.     define_method :switch_window do
  59.       hwnd = hwnd == game ? console : game
  60.       set_window_pos.call(hwnd, 0, 0, 0, 0, 0, 3)
  61.     end
  62.  
  63.     # 如果按下按键,则进入控制台
  64.     def update
  65.       start if Input.trigger?(KEY)
  66.     end
  67.  
  68.     alias_method :get_binding, :binding
  69.  
  70.     # 进入控制台
  71.     def start
  72.       switch_window
  73.       binding = get_binding
  74.       begin
  75.         while (line = gets)
  76.           next unless line[/\S/]
  77.           _ = eval(line, binding)
  78.           if _.equal?(EXIT_IDENTIFIER)
  79.             switch_window
  80.             Input.update    # 防止按下的 Enter 被游戏判定
  81.             break
  82.           end
  83.           print '=> '
  84.           p _
  85.         end
  86.       rescue => e
  87.         p e
  88.         retry
  89.       end
  90.     end
  91.  
  92.     def exit
  93.       EXIT_IDENTIFIER
  94.     end
  95.  
  96.     def help
  97.       puts HELP
  98.     end
  99.  
  100.     def recover(to_exit = true)
  101.       $game_party.recover_all
  102.       !to_exit || exit
  103.     end
  104.  
  105.     def save(index = 0, to_exit = true)
  106.       Sound.play_save
  107.       DataManager.save_game_without_rescue(index)
  108.       !to_exit || exit
  109.     end
  110.  
  111.     def load(index = 0, to_exit = true)
  112.       DataManager.load_game_without_rescue(index)
  113.       Sound.play_load
  114.       $game_system.on_after_load
  115.       SceneManager.goto(Scene_Map)
  116.       !to_exit || exit
  117.     end
  118.  
  119.     def kill(hp = 0, to_exit = true)
  120.       return to_exit && exit unless $game_party.in_battle
  121.       $game_troop.each { |a| a.hp = hp }
  122.       !to_exit || exit
  123.     end
  124.  
  125.     def suicide(hp = 0, to_exit = true)
  126.       $game_party.each { |a| a.hp = hp }
  127.       !to_exit || exit
  128.     end
  129.  
  130.     define_method :fast_forward, Taroxd::FastForward
  131.  
  132.     def ff(*args)
  133.       fast_forward(*args)
  134.       exit
  135.     end
  136.   end
  137. end
  138.  
  139. Scene_Base.send :def_after, :update, Taroxd::Console.method(:update)
  140.  
  141. end # if $TEST

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-1 09:00

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表