Module: RGSS

Defined in:
lib/openrgss/rgss.rb

Overview

The following built-in functions are defined in RGSS.

Defined Under Namespace

Modules: Drawable

Constant Summary collapse

Log =
Logger.new(STDOUT)

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.load_extObject

get_file的自动补全扩展名,以点开头的扩展名字符串的数组



20
21
22
# File 'lib/openrgss/rgss.rb', line 20

def load_ext
  @load_ext
end

.load_pathObject

get_file的读取路径,目录字符串的数组



17
18
19
# File 'lib/openrgss/rgss.rb', line 17

def load_path
  @load_path
end

.resourcesObject

屏幕上显示的资源,Drawable的数组



23
24
25
# File 'lib/openrgss/rgss.rb', line 23

def resources
  @resources
end

.show_fpsObject

显示帧率



26
27
28
# File 'lib/openrgss/rgss.rb', line 26

def show_fps
  @show_fps
end

.titleObject

标题



14
15
16
# File 'lib/openrgss/rgss.rb', line 14

def title
  @title
end

Class Method Details

.get_file(filename) ⇒ Object

在load_path指定的目录中查找文件,会自动补全Autoload_Extname里指定的扩展面给,默认为 .png, .jpg, .gif, .bmp, .ogg, .wma, .mp3, .wav, .mid

在Audio和Bitmap的内部自动调用

如果找不到文件,将返回filename本身



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/openrgss/rgss.rb', line 39

def get_file(filename)
  ([nil] + RGSS.load_path).each do |directory|
    ([''] + load_ext).each do |extname|
      path = File.expand_path filename + extname, directory
      if File.exist? path
        return path
      end
    end
  end
  filename
end

.initObject

初始化RGSS引擎,将会在rgss_main内部自动调用



53
54
55
56
57
58
59
# File 'lib/openrgss/rgss.rb', line 53

def init
  SDL.init SDL::INIT_EVERYTHING
  Graphics.entity = SDL::Screen.open(Graphics.width, Graphics.height, 0, SDL::HWSURFACE|SDL::HWPALETTE)
  SDL::Mixer.open(SDL::Mixer::DEFAULT_FREQUENCY, SDL::Mixer::DEFAULT_FORMAT, SDL::Mixer::DEFAULT_CHANNELS, 1536)
  SDL::TTF.init
  self.title = @title
end

.updateObject

引擎的更新,将在Graphics.update和Input.update的内部自动调用



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/openrgss/rgss.rb', line 75

def update
  if @show_fps and @fps != Graphics.real_fps
    SDL::WM.set_caption("#{title} - #{Graphics.real_fps}fps", title)
    @fps = Graphics.real_fps
  end

  while event = SDL::Event.poll
    case event
    when SDL::Event::Quit
      exit
    when SDL::Event::KeyDown, SDL::Event::KeyUp
      Input.events << event
    else #when
         #Log.debug "unhandled event: #{event}"
    end
  end
end

Instance Method Details

#load_data(filename) ⇒ Object

Loads the data file indicated by filename and restores the object.

$data_actors = load_data("Data/Actors.rvdata2")

This function is essentially the same as:

File.open(filename, "rb") { |f|
  obj = Marshal.load(f)
}

However, it differs in that it can load files from within encrypted archives.



132
133
134
135
136
# File 'lib/openrgss/rgss.rb', line 132

def load_data(filename)
  File.open(filename, "rb") { |f|
    obj = Marshal.load(f)
  }
end

#msgbox(*args) ⇒ Object

Outputs the arguments to the message box. If a non-string object has been supplied as an argument, it will be converted into a string with to_s and output.

Returns nil.

(Not Implemented in OpenRGSS)



158
159
160
161
162
163
164
165
166
# File 'lib/openrgss/rgss.rb', line 158

def msgbox(*args)
  if RUBY_PLATFORM['mingw'] or RUBY_PLATFORM['mswin']
    require 'dl'
    @@messagebox ||= DL::CFunc.new(DL.dlopen('user32')['MessageBoxA'], DL::TYPE_LONG, 'MessageBox')
    @@messagebox.call([0, args.collect { |arg| arg.to_s }.join("\n"), RGSS.title, 0].pack('L!ppL!').unpack('L!*'))
  else
    puts args
  end
end

#msgbox_p(*args) ⇒ Object

Outputs obj to the message box in a human-readable format. Identical to the following code (see Object#inspect):

msgbox obj.inspect, "\n", obj2.inspect, "\n", ...

Returns nil.

(Not Implemented in OpenRGSS)



175
176
177
# File 'lib/openrgss/rgss.rb', line 175

def msgbox_p(*args)
  msgbox args.collect { |obj| obj.inspect }.join("\n")
end

#rgss_mainObject

Evaluates the provided block one time only.

Detects a reset within a block with a press of the F12 key and returns to the beginning if reset.

rgss_main { SceneManager.run }


100
101
102
103
104
105
106
107
108
# File 'lib/openrgss/rgss.rb', line 100

def rgss_main
  RGSS.init
  begin
    yield
  rescue RGSSReset
    RGSS.resources.clear
    retry
  end
end

#rgss_stopObject

Stops script execution and only repeats screen refreshing. Defined for use in script introduction.

Equivalent to the following.

loop { Graphics.update }


116
117
118
# File 'lib/openrgss/rgss.rb', line 116

def rgss_stop

end

#save_data(obj, filename) ⇒ Object

Saves the object obj to the data file indicated by filename.

save_data($data_actors, "Data/Actors.rvdata2")

This function is the same as:

File.open(filename, "wb") { |f|
  Marshal.dump(obj, f)
}


147
148
149
150
151
# File 'lib/openrgss/rgss.rb', line 147

def save_data(obj, filename)
  File.open(filename, "wb") { |f|
    Marshal.dump(obj, f)
  }
end