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

Project1

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

[已经过期] 这个来自苹果梨的脚本如何修改?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
1351
在线时间
16 小时
注册时间
2010-10-30
帖子
3
跳转到指定楼层
1
发表于 2015-3-7 18:59:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
#==============================================================================
# ◎ GPRA_TextStream
#------------------------------------------------------------------------------
# ◎ TXT文件读取流类
#------------------------------------------------------------------------------
# 制作者:绿梨子红苹果
# 个人主页:vbgm.9126.com
# E-Mail:[email protected]
# QQ:42378361
#------------------------------------------------------------------------------
# 附加说明:TXT文件需要是UTF-8编码(Windows自带记事本支持),其它的好似会乱码
#==============================================================================

class TextStream
  #--------------------------------------------------------------------------
  # ● 初始化状态
  #--------------------------------------------------------------------------
  def initialize
    @file_name = "" # 记录已经打开文件名称
    @line_label = "" # 记录行号标签
    @is_open = false # 用于记录文件是否打开
    @txt_file = nil # 用于打开文件
    @t = nil # 记录每行文字
    @p = 0 #记录行号
  end
  #--------------------------------------------------------------------------
  # ● 打开文件
  #--------------------------------------------------------------------------
  def open(file_name,line_label="",reload=false)
   
    # 文件名改变的时候,或者文件没有打开的时候打开文件
    if (file_name != @file_name) or !@is_open or reload
      
      #文件已经打开的时候首先关闭文件
      if @is_open
        @txt_file.close
      end
        
      # 测试文本文件是否存在
      if !FileTest.exist?("Text/" + file_name + ".txt")
        # 初始化变量
        @file_name = ""
        @line_label = ""
        @is_open = false
        @txt_file = nil
        @t = nil
        @p = 0
        # 返回错误值
        return(false)
      end
      
      #如果通过了测试,说明文件存在,那么就打开它
      @txt_file = File.open ("Text/" + file_name + ".txt")
      #读取所有行的文字
      @t=@txt_file.readlines
      #把行“指针”设定为0
      @p=0
      
      #如果行号非空
      if line_label != ""
          #搜索到指定的行号,直到文件结尾才结束
          for @p in [email protected]
              #打开下一行文字
              t=@t[@p]
              #当此行是行号时(左右为匹配的方括号)
              if t[0,1] == "[" and t[-2,1] == "]"
                  #判断是不是要找的行号
                  if t == "[" + line_label + "]\n"
                      #是的话说明找到了,停在下行,并退出循环
                      @p+=1
                      break
                  end
              end
          end
      end
      
      #设定变量
      @file_name = file_name
      @line_label = line_label
      @is_open = true
        
    end

    #行号改变的时候重新搜索行号
    if line_label != @line_label
   
        #首先把指针移动到文件开头
        @p=0
        
        #如果行号非空
        if line_label != "" and line_label != nil
            #搜索到指定的行号,直到文件结尾才结束
            for @p in [email protected]
                #打开下一行文字
                t=@t[@p]
                #当此行是行号时(左右为匹配的方括号)
                if t[0,1] == "[" and t[-2,1] == "]"
                    #判断是不是要找的行号
                    if t == "[" + line_label + "]\n"
                        #是的话说明找到了,停在下行,并退出循环
                        @p+=1
                        break
                    end
                end
            end
        end
           
        #设定变量
        @line_label = line_label
        @is_open = true
        
    end
   
    return(true)
   
  end
  #--------------------------------------------------------------------------
  # ● 关闭文件
  #--------------------------------------------------------------------------
  def close
    @txt_file.close
    @is_open=false
  end
  #--------------------------------------------------------------------------
  # ● 获取文字色
  #     n : 文字色编号 (0~7)
  #--------------------------------------------------------------------------
  def text_color(n)
    case n
    when 0
      return Color.new(255, 255, 255, 255)
    when 1
      return Color.new(128, 128, 255, 255)
    when 2
      return Color.new(255, 128, 128, 255)
    when 3
      return Color.new(128, 255, 128, 255)
    when 4
      return Color.new(128, 255, 255, 255)
    when 5
      return Color.new(255, 128, 255, 255)
    when 6
      return Color.new(255, 255, 128, 255)
    when 7
      return Color.new(192, 192, 192, 255)
    else
      normal_color
    end
  end
  #--------------------------------------------------------------------------
  # ● 获取普通文字色
  #--------------------------------------------------------------------------
  def normal_color
    return Color.new(255, 255, 255, 255)
  end
  #--------------------------------------------------------------------------
  # ● 获取无效文字色
  #--------------------------------------------------------------------------
  def disabled_color
    return Color.new(255, 255, 255, 128)
  end
  #--------------------------------------------------------------------------
  # ● 获取系统文字色
  #--------------------------------------------------------------------------
  def system_color
    return Color.new(192, 224, 255, 255)
  end
  #--------------------------------------------------------------------------
  # ● 获取危机文字色
  #--------------------------------------------------------------------------
  def crisis_color
    return Color.new(255, 255, 64, 255)
  end
  #--------------------------------------------------------------------------
  # ● 获取战斗不能文字色
  #--------------------------------------------------------------------------
  def knockout_color
    return Color.new(255, 64, 0)
  end
  #--------------------------------------------------------------------------
  # ● 生成描绘用的状态字符串
  #     actor       : 角色
  #     width       : 描画目标的宽度
  #     need_normal : [正常] 是否为必须 (true / false)
  #--------------------------------------------------------------------------
  def make_battler_state_text(battler, width, need_normal)
    # 获取括号的宽
    brackets_width = self.contents.text_size("[]").width
    # 生成状态名字符串
    text = ""
    for i in battler.states
      if $data_states.rating >= 1
        if text == ""
          text = $data_states.name
        else
          new_text = text + "/" + $data_states.name
          text_width = self.contents.text_size(new_text).width
          if text_width > width - brackets_width
            break
          end
          text = new_text
        end
      end
    end
    # 状态名空的字符串是 "[正常]" 的情况下
    if text == ""
      if need_normal
        text = "[正常]"
      end
    else
      # 加上括号
      text = "[" + text + "]"
    end
    # 返回完成后的文字类
    return text
  end
  #--------------------------------------------------------------------------
  # ● 读入一行文字,文件已结束返回"[END]"
  #--------------------------------------------------------------------------
  def get_text(len=4)
   
    t="" # 临时变量
    s="" # 返回值
    l=0 # 已打开的行数
   
    #如果文件已经关闭,直接返回结束标志
    if !@is_open
        return("\\~\\/[END]")
    end
   
    #如果文件已经读到了末尾
    if @p>[email protected]
        #关闭文件
        @txt_file.close
        #设置标志变量
        @is_open = false
        #返回结束标志
        return("\\~\\/[END]")
    end
      
    #打开一行文字
    t=@t[@p]
    #读入字符串,终止条件是文件结束、遇到行号或者已经打开需要行数的文字
    while l<len
        #否则的话就加入到字符串s末尾
        s = s + t
        #l自增
        l += 1
        #@p自增
        @p += 1
        #打开一行文字
        t=@t[@p]
        #当下行是行号(左右为匹配的方括号)或者已经结束时退出,否则就会进入下次循环
        if t==nil or (t[0,1] == "[" and t[-2,1] == "]")
          #加入"[END]"到字符串s末尾
          s = s + "[END]"
          #关闭文件
          @txt_file.close
          #设置标志变量
          @is_open = false
          #终止循环
          break
        end
    end
   
    if s.size > 0
      #字符串非空的时候返回字符串
      return s
    else
      #否则可能是文件结束了所以返回结束标志
      return "\\~\\/[END]"
    end
      
  end
end
我希望这个脚本能够在读取txt文本后能识别/v[]之类的语言。

Lv5.捕梦者

梦石
0
星屑
33069
在线时间
5103 小时
注册时间
2012-11-19
帖子
4878

开拓者

2
发表于 2015-3-7 20:56:30 | 只看该作者
/v 之类的啥? 显示变量值?

点评

其实也就是想要支持正则式……→ →  发表于 2015-3-9 13:54
xp vx va mv  va mz 各类型脚本/插件定制
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-21 10:50

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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