Method: NPG::Project#run

Defined in:
lib/npg/project.rb

#run(opt = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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