class NPG::Project
Constants
- LDRHeader
Attributes
path[RW]
Public Class Methods
new(path = nil)
click to toggle source
# File lib/npg/project.rb, line 25 def initialize(path = nil) self.path = path end
Public Instance Methods
config_file()
click to toggle source
# File lib/npg/project.rb, line 164 def config_file File.join(self.path, "Game.ini") end
executable()
click to toggle source
# File lib/npg/project.rb, line 41 def executable File.join(self.path, "Game.exe") end
handle()
click to toggle source
# File lib/npg/project.rb, line 45 def handle PGHandle.new File.join self.path, ".npg" end
ini()
click to toggle source
# File lib/npg/project.rb, line 168 def ini a = IniParse.parse File.read config_file end
path=(val)
click to toggle source
# File lib/npg/project.rb, line 29 def path=(val) val = File.expand_path val if FileTest.directory?(val) @path = val elsif FileTest.file?(val) @path = File.dirname(val) else raise Error::ENOENT, val end val = val.encode("UTF-8") end
run(opt = {})
click to toggle source
# File lib/npg/project.rb, line 49 def run(opt = {}) opt = { exe: executable, cmdline: nil, console: false, debug: false, }.update(opt) npg = handle if code = opt[:code] code = code.encode("UTF-8") FileUtils.cp self["Game.exe"], npg["Game.exe"] open npg["Game.ini"], 'w' do |f| f.write\ %{[Game] Scripts=npgldr RTP=#{ini["Game"]["RTP"]} RTP1=#{ini["Game"]["RTP1"]} RTP2=#{ini["Game"]["RTP2"]} RTP3=#{ini["Game"]["RTP3"]} Title=#{ini["Game"]["Title"]} Library=../#{ini["Game"]["Library"]} } end realcode = [LDRHeader, %{ NPG::StartupPath = Dir.getwd NPG::Path = #{path.inspect} NPG::RGSSScripts = #{ini["Game"]["Scripts"].inspect} }, code].join("\n\n") x = [[0, "npgldr", Zlib::Deflate.deflate(realcode)]] open npg["npgldr"], 'w' do |f| Marshal.dump(x, f) end opt.update exe: npg["Game.exe"] end File.delete npg["error.txt"] if FileTest.file?(npg["error.txt"]) cmdline = Shellwords.shelljoin([opt[:exe], opt[:cmdline], opt[:console] ? "console" : nil, opt[:debug] ? "debug": nil, opt[:debug] ? "test": nil, ].compact.map{|x| Shellwords.escape(x) }) system cmdline if FileTest.file?(npg["error.txt"]) raise File.read(npg["error.txt"]) end end