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

Project1

 找回密码
 注册会员
搜索
查看: 1853|回复: 3

[原创发布] 【无用脚本】Debuger调试器(阉割版1.0)

[复制链接]

Lv2.观梦者

梦石
0
星屑
870
在线时间
75 小时
注册时间
2017-7-10
帖子
27
发表于 2019-6-20 18:52:27 | 显示全部楼层 |阅读模式

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

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

x
    因为自己设计游戏时候需要经常调试脚本,之前调试都是使用默认的p或print方法进行查看,真的受不了他的窗口弹出,激活和置顶机制,所以优化了一种 “船新” 的Debuger调试器。该版本还属于测试阶段,有问题欢迎反馈,常年更新。
    什么是阉割版?   答:有很多其它次要功能没有加入,代码没有优化。
    有没有正式版?   答:随缘制作,目前不想做,因为工程暂时没用到,欢迎有能力的人将它完善。

使用方法
    将调试器插入脚本编辑器顶端,在后面使用一个全局变量来创建一个debuger对象,具体如下图:
    1.png
    2.png

    当我们需要观察输出时,可以这样:
    3.png

    它的显示效果如下图:
    4.png
    5.png

    在显示的时候,您可以使用方向键来控制画面,毕竟信息比较多,一次性显示不完。
    当您想退出输出界面时,您可以按下Esc键退出。

代码区:

  #--------------------------------------------------------------------------
  # 作者:Daviant(蚂蚁)
  #--------------------------------------------------------------------------

class Debuger
  #--------------------------------------------------------------------------
  # ● 初始化
  #--------------------------------------------------------------------------
  def initialize
    @time = Graphics.frame_count # 获取刷新次数
    @p = 0 # Y轴偏移
    @px = 0 # X轴偏移
    @line = 0 # 当前行
    @col = 0 # 当前列
    @f = 16 # 字体大小
  end
  #--------------------------------------------------------------------------
  # ● 创建
  #--------------------------------------------------------------------------
  def create
    dispose # 先把之前的状态全部释放
    @sprite = Sprite.new
    @bitmap = Bitmap.new(6400, 6400*2)
    @content = Bitmap.new(640, 480)
    @content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
    @sprite.bitmap = @content
    @bitmap.font.color = Color.new(0,255,0) #初始化颜色
    @bitmap.font.size = @f
  end
  #--------------------------------------------------------------------------
  # ● 释放
  #--------------------------------------------------------------------------
  def dispose
    if @sprite
      @sprite.dispose
    end
    if @bitmap
      @bitmap.dispose
      @content.dispose
    end
  end
  #--------------------------------------------------------------------------
  # ● 写文本到Debuger
  # text        : 输出内容
  #--------------------------------------------------------------------------
  def write( text )
      while ((c = text.slice!(/./m)) != nil )
        if c == "\n"
          @line = @line + 1
          @col = 0
        elsif c == "\001"
          # 这里可以扩展颜色管理
          @bitmap.font.bold = false
          @bitmap.font.color = Color.new(0,255,0)
        elsif c == "\002" # 内容样式
          @bitmap.font.bold = false
          @bitmap.font.color = Color.new(0,174,192)
        elsif c == "\003" # 内容样式2
          @bitmap.font.bold = false
          @bitmap.font.color = Color.new(237,144,243)
        elsif c == "\004" # 属性样式
          @bitmap.font.bold = false
          @bitmap.font.color = Color.new(243,220,144)
        elsif c == "\005" # 方法样式
          @bitmap.font.color = Color.new(243,150,144)
          @bitmap.font.bold = true
        else
          if c[0] > 33 && c[0] < 128
            @bitmap.draw_text(@col, (@line-1)*@f, 640, @f, c)
            @col = @col + @f/2
          else
            @bitmap.draw_text(@col, (@line-1)*@f, 640, @f, c)
            @col = @col + @f
          end
        end
      end
  end
  #--------------------------------------------------------------------------
  # ● 输出
  # vars        : 要观察的信息变量
  # f           : 字体大小
  #--------------------------------------------------------------------------
  def log( vars, f = 22 )
    # 初始化
    @p = 0
    @px = 0
    @line = 0
    @col = 0
    @f = f
    create
    # 创建信息
    message = "\n"
    message = message + "  \001所属类: \002"+vars.class.to_s+"\n"
    message = message + "  \001内容: \003"+vars.to_s + "\n"
    t = vars.methods
    i = 0
    attrs = []
    attrsM = ""
    metsM = ""
    mets = []
    logic = false
    for i in 0...t.length
        # 获取属性表
        c = t
        logic = c[0]  > 64 && c[0] < 91
        logic = logic || c[0]  > 96 && c[0] < 124
        logic = logic || c[0]  > 127
        if logic && c[c.length-1] == 61
         # p c[0].to_s + "  " + c[c.length-1].to_s
         #p c
          attrs.push(c.slice(0, c.length - 1))
          tmp = " "
          tmp = eval("vars."+attrs[attrs.length-1]).to_s
          attrsM = attrsM + "   \004" + attrs[attrs.length-1] + ":\002"+ tmp +"\n"
        else
            mets.push(c)
        end
      end
      # 获取方法表
      for i in 0...attrs.length
        mets.delete(attrs)
      end
      for i in 0...mets.length
        metsM = metsM + "   \002[ \005"+mets+" \002]\n"
      end
    # 拼接信息
    message = message + "  \001属性: \002共"+attrs.length.to_s+"个 \n"
    message = message + attrsM + "\n"
    message = message + "  \001方法:\002共"+mets.length.to_s+"个 \n"
    message = message + metsM + "\n\001"
    # 写出
    write( message )
    @content.blt(0, 0, @bitmap, Rect.new(@px*@f/2,@p*24,640,480))
    @sprite.z = 10000
    Graphics.transition
    # 等待操作
    wait
  end
  #--------------------------------------------------------------------------
  # ● 等待
  #--------------------------------------------------------------------------
  def wait
    loop do
      Graphics.update
      Input.update
      if Input.press?(Input::UP)
        @p = @p - 1
        @content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
        @content.blt(0, 0, @bitmap, Rect.new(@px*@f/4,@p*6,640,480))
      end
      if Input.press?(Input::DOWN)
        @p = @p + 1
        @content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
        @content.blt(0, 0, @bitmap, Rect.new(@px*@f/4,@p*6,640,480))
      end
      
      if Input.press?(Input::LEFT)
        @px = @px + 1
        @content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
        @content.blt(0, 0, @bitmap, Rect.new(@px*@f/4,@p*6,640,480))
      end
      if Input.press?(Input::RIGHT)
        @px = @px - 1
        @content.fill_rect(0, 0, 640, 480, Color.new(0,0,0, 150))
        @content.blt(0, 0, @bitmap, Rect.new(@px*@f/4,@p*6,640,480))
      end
      if Input.trigger?(Input::B)
        dispose
        break
      end
    end
  end
end





代码API手册
  ⚪write    【将文本写出到debuger界面。该方法需要与wait一起使用】
        参数1:str字符串文本
        返回:  空

  ⚪log    【输出你的输入信息】
        参数1:要观察的对象
        参数2:可选参数。字体大小,默认22
        返回:  空

  ⚪wait    【等待渲染】
        返回:  空

脚本附件下载
Debuger.zip (1.55 KB, 下载次数: 54)

评分

参与人数 2+2 收起 理由
mariofans + 1 塞糖
FacLos + 1 塞糖

查看全部评分

Lv3.寻梦者

梦石
0
星屑
2605
在线时间
896 小时
注册时间
2011-4-30
帖子
131

开拓者

发表于 2019-6-22 19:49:06 | 显示全部楼层
不错,挺直观的,用methods获取方法这种操作是我没想过的
主要还是不能在运行中实时查看,各种调试脚本也都多多少少有这种问题
之前糊过这个玩意能实现实时查看和执行代码,实际上也就是先eval再instance而已,反正我觉得这玩意只是用来给懂行的脚本师看的就没加什么傻瓜化的操作。。。
不过这个还是用.Net程序和魔改自编译exe配合实现的,只能作为定制品,不具有可移植性。。。
Test.png

点评

为了更好的观测数据,前天我又改良了一下,你可以看一下帖子里那个动图演示效果,还算比较理想。 https://rpg.blue/thread-477682-1-1.html http  发表于 2019-6-23 00:53
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
870
在线时间
75 小时
注册时间
2017-7-10
帖子
27
 楼主| 发表于 2019-6-23 00:45:50 | 显示全部楼层
mariofans 发表于 2019-6-22 19:49
不错,挺直观的,用methods获取方法这种操作是我没想过的
主要还是不能在运行中实时查看,各种调试脚本也都 ...

想过通过其它语言写一个动态链接库来做中间交互,做了一半还是没做了,我发现我不是很喜欢通过其它窗口来观察数据,虽然这样能做到非堵塞,其次这样做还需要一个中间的东西,每次开新工程还要把这些东西加入,导出时候还要记得删除…其实通过改良后的第二个脚本,我发现我这样做的插件在数据观测上还是挺直接的,我决定多改良几代试试效果,毕竟这也是最近做游戏临时做的一个插件,顺便分享了一下…
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-3-29 21:45

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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