Class: NPG::Project

Inherits:
Directory show all
Defined in:
lib/npg/project.rb

Constant Summary collapse

LDRHeader =
%{
   module NPG
      class << self
       def rgss_run
   begin
     Dir.chdir NPG::Path 
     $RGSS_SCRIPTS = open(NPG::RGSSScripts, "rb") do |f| Marshal.load(f) end
     $RGSS_SCRIPTS.each_with_index{|x, i|
       x[3] = Zlib::Inflate.inflate(x[2])
     }
     type = (defined? msgbox) ? "{%04d}" : "Section%03d"
     $RGSS_SCRIPTS.each_with_index{|x, i|
       eval x[3], TOPLEVEL_BINDING, type % (i+1), 1
     }
   rescue Object
     x = $!.backtrace.unshift($!.to_s).join("\n")
     open(".npg/error.txt", "w") do |f|
                f.write x
  f.write "\n"
     end
   end
  end
  end
   end



module Kernel
 alias oreq require
 def rb(code, args = nil)
open "run.rb", "w" do |f|
  f.write "
    class Output
      def <<(obj)
        puts [Marshal.dump(obj)].pack('M')
      end
    end
    $output = Output.new
  begin
  "
  f.write code
  f.write "
rescue LoadError
    $output << LoadError
  end
  "
end
system "ruby run.rb \#{args}> list.txt"
Marshal.load File.read('list.txt').unpack("M").first
end

 private :rb
 $:.concat rb %{ $output << $: }
 def require(a)
 u = rb %{$output << Gem.find_files(ARGV[0])}, a
 raise u if u.is_a?(Exception)
 u.select(&FileTest.method(:file?)).any?{|req|oreq req}
 end
 
 Object::RUBY_VERSION = rb %{$output << RUBY_VERSION} 
 require 'rubygems'
 alias require oreq
end
   
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Directory

#[]

Constructor Details

#initialize(path = nil) ⇒ Project



25
26
27
# File 'lib/npg/project.rb', line 25

def initialize(path = nil)
  self.path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



24
25
26
# File 'lib/npg/project.rb', line 24

def path
  @path
end

Instance Method Details

#config_fileObject



164
165
166
# File 'lib/npg/project.rb', line 164

def config_file
  File.join(self.path, "Game.ini")
end

#executableObject



41
42
43
# File 'lib/npg/project.rb', line 41

def executable
  File.join(self.path, "Game.exe")
end

#handleObject



45
46
47
# File 'lib/npg/project.rb', line 45

def handle
  PGHandle.new File.join self.path, ".npg"
end

#iniObject



168
169
170
# File 'lib/npg/project.rb', line 168

def ini
  a = IniParse.parse File.read config_file
end

#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