Permanent
Creation

RPGツクールXP/VX用のRGSS素材です。
一部英語版対応です。 (A few materials can be used for English RPG MAKER XP/VX.)
競合率はルファーの独断と偏見なのでたまにハズレます。


#==============================================================================
# ■ 小物ライブラリ
#------------------------------------------------------------------------------
#  RGSS スクリプティングを援助するメソッド集です。
# (C) ルファー
# WebSite  https://tkoolerlufar.pages.dev/
#==============================================================================

=begin
  =対応RGSS
  1 2

  =他の素材との競合の可能性
  ... ほぼ皆無

  =RPGツクールXPでの導入方法
  最上部に新セクションを作成して、このプログラムをそこにコピーする

  =更新履歴
  2010/03/01 Fixnum のビット数に関する定数を追加
             C++やJavaでおなじみの「this」を追加
  2008/02/03 Object#or?, Object#not?を撤去
             Enumerable#include? で代用してください
             詳しくはRPGツクールXP ヘルプのRGSSリファレンスを見てください
  ----/--/-- 公開

  =再定義しているメソッド
  なし

  =新規定義しているメソッド
  Kernel#msgbox (組み込み関数)
  Kernel#errmsg (組み込み関数)
  Object#this
  Bitmap#draw_textfile

  =新規定義している定数
  Fixnum::SIZE
  Fixnum::MAXIMUM
  Fixnum::MINIMUM
=end
#----------------------------------------------------------------------------
# ● メッセージボックス
#     (末尾に「スペースキーを押してください」をつけるだけ。
#       ほかは print と同じ)
#     書式:
#     msgbox(str)
#     str  :表示する文字列
#----------------------------------------------------------------------------
def msgbox(m)
  begin
    print m + "\n-スペースキーを押してください-"
  rescue Exception
    $@ = caller
    raise
  end
end
#----------------------------------------------------------------------------
# ● エラーメッセージボックス
#     (エラーメッセージ用の、メッセージボックス表示メソッド)
#     書式:
#     errsg(str)
#     str  :エラーメッセージ
#----------------------------------------------------------------------------
def errmsg(e)
  begin
    print(($DEBUG ? "" : "エラーが発生しました。\nエラー内容と発生したタイ" +
      "ミングを\n作者に伝えてください。\nエラー内容:\n") + e.to_s)
  rescue Exception
    $@ = caller
    raise
  end
end
#----------------------------------------------------------------------------
# ◆ Object クラス
#----------------------------------------------------------------------------
class Object
  #--------------------------------------------------------------------------
  # ● 「これ」=>「自身」
  #--------------------------------------------------------------------------
  def this
    self
  end
end
#----------------------------------------------------------------------------
# ◆ Fixnum クラス
#----------------------------------------------------------------------------
class Fixnum
  #--------------------------------------------------------------------------
  # ○ 定数
  #--------------------------------------------------------------------------
  i = 1
  n = 1
  while n.instance_of?(self)
    i += 1
    n <<= 1
  end
  SIZE = i                              # ビット数
  MAXIMUM = (1 << i - 1) - 1            # 最大値
  MINIMUM = -(1 << i - 1)               # 最小値
end
#----------------------------------------------------------------------------
# ◆ Bitmap クラス
#----------------------------------------------------------------------------
class Bitmap
  #--------------------------------------------------------------------------
  # ● テキストファイルの内容の描画
  #     書式:
  #     draw_textfile(filename, x, y, width, height)
  #     draw_textfile(filename, rect)
  #     filename  : テキストファイルの名前
  #     x         : 描画先 X 座標
  #     y         : 描画先 Y 座標
  #     width     : 描画幅
  #     height    : 行の高さ
  #     rect      : 描画先の矩形
  #--------------------------------------------------------------------------
  def draw_textfile(*args)
    # なが~い引数チェック
    type_error_message = String.new
    filename = args[0]
    unless args[0].instance_of?(String)
      type_error_message.concat(
        "filename は文字列で指定してください(#{filename.inspect})\n")
    end
    if args.length == 5
      x, y, width, height = args[1..4]
      unless x.instance_of?(Integer)
        type_error_message.concat(
        "x は整数で指定してください(#{x.inspect})\n")
      end
      unless y.instance_of?(Integer)
        type_error_message.concat(
        "y は整数で指定してください(#{y.inspect})\n")
      end
      unless width.instance_of?(Integer)
        type_error_message.concat(
        "width は整数で指定してください(#{width.inspect})\n")
      end
      unless height.instance_of?(Integer)
        type_error_message.concat(
        "height は整数で指定してください(#{height.inspect})\n")
      end
    elsif args.length == 2
      rect = args[1]
      unless rect.instance_of?(Rect)
        type_error_message.concat(
        "rect は整数で指定してください(#{rect.inspect})\n")
      end
    else
      raise(ArgumentError, sprintf("%s(%d%sの引数)",
        "Bitmap#draw_textfile の引数は2つまたは5つにしてください",
        args.length, args.length % 10 != 0 ? "つ" : ""), caller)
    end
    unless type_error_message.empty?
      raise(TypeError, type_error_message, caller)
    end
    p filename, x, y, width, height if $DEBUG
    # メイン処理ここから
    begin
      open(filename) do |file|
        a = file.readlines()
        cy = y;
        for i in a
          self.draw_text(x, y + cy, width, height, i)
          cy += height
        end
      end
    rescue SystemCallError
      $@ = caller
      raise
    end
  end
end

戻る