Project1

标题: [代码缩进美化]...貌似鸡肋 [打印本页]

作者: 沙漠点灰    时间: 2012-10-31 18:40
标题: [代码缩进美化]...貌似鸡肋
网上找的脚本不少是没有缩进的(例如:人物跟随) ...让人看得蛋疼....所以本工程应运而生...
RGSS1,2,3全支持....不过本工程是RX的,所以建议安装RMXP,当然没有也行..但是请继续看下去..

将脚本文件复制到本工程根目录下...直接运行Game.exe就行....

对于没有RMXP的..
[pre lang="ruby" line="1"]class Array
  def indentation(i)
    return self if self == []
    self.del_tem!
    ary = [" "] * i
    unshift(*ary)
  end
  def del_tem!
    while self[0] == " "
      self.delete_at(0)
    end
  end
end
class String
  def in_in?(ary)
    ary1 = self.split("")
    ary1.size.times{|i|return false if ary1 != ary}
    true
  end
end
Word1 = ["class ","ensure","def ","while ","for ","if(",
"loop ","if ","begin","module ","unless ","until "]

Word2 = ["rescue","when ","else","elsif ","elsif("]
show = Sprite.new
show.bitmap = Bitmap.new(640,32)
show.y = 100
show.bitmap.draw_text(show.bitmap.rect, "请将Scripts.*文件放入根目录",1)
40.times{|i|Graphics.update}
show.bitmap.clear
show.bitmap.draw_text(show.bitmap.rect, "读取脚本文件",1)
40.times{|i|Graphics.update}
file = Dir["Scripts.*"]
begin
  scripts = load_data(file[0])
  show.bitmap.clear
  show.bitmap.draw_text(show.bitmap.rect, "读取#{file[0]}成功",1)
  40.times{|i|Graphics.update}
rescue
  show.bitmap.clear
  show.bitmap.draw_text(show.bitmap.rect, "读取失败",1)
  40.times{|i|Graphics.update}
  exit
end
$lines = 0;$in_ = 0;$tem = false
scripts.size.times{|t|
  sc_new = "";$in_ = 0
  sc = Zlib::Inflate.inflate(scripts[t][2])
  sc.each_line{|line|$tem = false
    $lines += 1;$lines%=100
    Graphics.update if $lines == 0
    line_a = line.split("")
    line_a.del_tem!
    Word1.each{|w|$tem = true if w.in_in?(line_a)}
    Word2.each{|w|$in_ -= 2 if w.in_in?(line_a) and $tem = true}
    $in_ -= 2 if "end".in_in?(line_a)
    $in_ = [$in_,0].max
    line_a.indentation(line_a[0] == "=" ? 0 : $in_)
    sc_new += line_a.to_s
    $in_ += 2 if $tem
  }
  scripts[t][2] = Zlib::Deflate.deflate(sc_new,6)
  show.bitmap.clear
  show.bitmap.draw_text(show.bitmap.rect, "处理中#{t}/#{scripts.size}",1)
}
save_data(scripts, file[0])
show.bitmap.clear
show.bitmap.draw_text(show.bitmap.rect, "处理完毕",1)
10.times{|i|Graphics.update}[/pre]

复制到你的脚本文件到你游戏根目录下,把该脚本复制游戏脚本里,最好是第一行,运行,关闭RMVX/A,把根目录下的脚本文件移动到
Data文件夹里覆盖。

当然,以免发生不可预料的事,强烈建议使用前备份脚本文件

(, 下载次数: 94)
作者: Mr丶木头    时间: 2012-11-3 21:26
呵呵,这种脚本对于我们脚本初学者是很实用的,谢谢大婶啦!
作者: 论坛助理    时间: 2012-11-7 13:57
用这个脚本测试调整了这个脚本本身,除了{}内的内容没缩进,其他的都一致了,很不错。
如果能对{…}内的文字也缩进一下就好了。
作者: 九夜神尊    时间: 2012-11-12 21:07
标题错了,绝非鸡助。个人会花一个小时时间来处理缩进。有这脚本真的好多了。

不光是网上下载的脚本,自己复制粘贴一脚本到新的位置,也许就会出现缩进不对的情况。

作者: enghao_lim    时间: 2012-11-15 17:47
我的做法是,打开UE,format source code,结束。




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X5.0