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
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Directory

#[]

Constructor Details

#initialize(path = nil) ⇒ Project

Returns a new instance of Project.



27
28
29
# File 'lib/npg/project.rb', line 27

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

Instance Attribute Details

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#config_fileObject



126
127
128
# File 'lib/npg/project.rb', line 126

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

#executableObject



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

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

#handleObject



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

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

#iniObject



130
131
132
# File 'lib/npg/project.rb', line 130

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

#run(opt = {}) ⇒ Object



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
97
# File 'lib/npg/project.rb', line 50

def run(opt = {})
  opt = {
    exe:    executable,
    cmdline: nil,
    console: false,
    debug:   false,
  }.update(opt)
  npg = handle
  if code = opt[:code]
  
    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