Files
gtav-src/tools_ng/lib/util/data_regenerate_map_ide.rb
T
2025-09-29 00:52:08 +02:00

131 lines
4.8 KiB
Ruby
Executable File

#
# File:: %RS_TOOLSLIB%/util/data_regenerate_map_ide.rb
# Description:: Regenerate all map data IDE from SceneXml.
#
# Author:: David Muir <david.muir@rockstarnorth.com>
# Date:: 10 August 2011
#
#----------------------------------------------------------------------------
# Uses
#----------------------------------------------------------------------------
require 'pipeline/config/projects'
require 'pipeline/config/project'
require 'pipeline/os/getopt'
require 'pipeline/os/path'
require 'pipeline/log/log'
require 'pipeline/projectutil/data_convert'
require 'pipeline/projectutil/data_map'
require 'pipeline/scm/perforce'
#-----------------------------------------------------------------------------
# Constants
#-----------------------------------------------------------------------------
OPTIONS = [
[ '--project', '-p', Getopt::REQUIRED, 'project data to fetch (e.g. jimmy, gta5).' ],
[ '--continue', '-c', Getopt::REQUIRED, 'continue from a particular map zip (e.g. vb_39).' ],
[ '--level', '-l', Getopt::REQUIRED, 'process a single level map data (e.g. mdtestbed).' ],
[ '--group', '-g', Getopt::REQUIRED, 'process a group (folder) of map data (e.g. _citye, downtown_01).' ],
[ '--map', '-m', Getopt::REQUIRED, 'process a single map (e.g. v_int_1).' ],
[ '--nop4', '-n', Getopt::BOOLEAN, 'disable Perforce integration.' ],
]
MOUNT = 'pack:/'
#----------------------------------------------------------------------------
# Implementation
#----------------------------------------------------------------------------
if ( __FILE__ == $0 ) then
g_AppName = OS::Path::get_basename( __FILE__ )
g_Log = Pipeline::Log.new( g_AppName )
g_Config = Pipeline::Config::instance()
begin
#---------------------------------------------------------------------
# Parse Command Line
#---------------------------------------------------------------------
opts, trailing = OS::Getopt.getopts( OPTIONS )
if ( opts['help'] ) then
puts OS::Getopt.usage( OPTIONS )
exit( 1 )
end
g_ProjectName = ( nil == opts['project'] ) ? ENV['RS_PROJECT']: opts['project']
project_exists = ( g_Config.projects.has_key?( g_ProjectName ) )
if ( not project_exists ) then
puts OS::Getopt.usage( OPTIONS )
puts "\nError project: #{g_ProjectName} does not exist or its configuration is unreadable."
exit( 2 )
end
g_Project = g_Config.projects[ g_ProjectName ]
if ( not g_Project.enabled ) then
puts "\nError project: #{g_ProjectName} is not enabled on this machine. Re-run installer."
exit( 3 )
end
g_Project.load_config( )
g_ContinueMap = opts['continue'].nil? ? nil : opts['continue']
g_Continue = ( not g_ContinueMap.nil? )
g_Level = opts['level'].nil? ? nil : opts['level']
g_Group = opts['group'].nil? ? nil : opts['group']
g_Map = opts['map'].nil? ? nil : opts['map']
g_UseP4 = opts['nop4'].nil? ? true : false
Dir::chdir( g_Project.export )
if ( g_UseP4 ) then
g_Perforce = SCM::Perforce.new
g_Perforce.connect()
cl = g_Perforce.create_changelist( "Map metadata regeneration." )
end
g_Files = []
# Now for the main processing loop...
ProjectUtil::data_map_for_each( g_Project, g_Level, g_Group ) do |mapzip|
if ( g_Continue and
( 0 == OS::Path::get_basename( mapzip.name ).casecmp( g_ContinueMap ) ) ) then
g_Continue = false
elsif ( g_Continue ) then
g_Log.info( "Skipping #{OS::Path::get_basename( mapzip.name )}..." )
next
end
if ( not g_Map.nil? ) then
next unless ( g_Map == mapzip.name )
end
zip_file = mapzip.filename
next unless ( File::exists?( zip_file ) )
next unless ( mapzip.is_a?( Pipeline::Content::MapZip ) )
next unless ( mapzip.inputs[0].is_a?( Pipeline::Content::Map ) )
definitions = mapzip.inputs[0].exportdefinitions
next unless ( definitions )
build_dir = g_Project.build
scenexml = OS::Path::replace_ext( zip_file, 'xml' )
ide_file = OS::Path::replace_ext( zip_file, 'ide' )
if ( g_UseP4 and g_Perforce.exists?( ide_file ) ) then
g_Perforce.run_edit( '-t', 'text', ide_file )
g_Perforce.run_reopen( '-t', 'text+l', '-c', cl.to_s, ide_file )
elsif ( not File::writable?( ide_file ) )
FileUtils::chmod( 0666, ide_file )
end
filenames = ProjectUtil::data_map_export_ide( scenexml, ide_file, build_dir )
g_Files << ide_file
if ( filenames.nil? ) then
g_Log.error( "No IDE files generated by map export for #{OS::Path::get_basename( zip_file )}." )
end
end
ProjectUtil::data_convert_file( g_Files, true )
rescue SystemExit => ex
exit( ex.status )
rescue Exception => ex
puts "\n#{g_AppName} unhandled exception: #{ex.message}"
puts ex.backtrace.join("\n\t")
end
end
# %RS_TOOLSLIB%/util/data_regenerate_map_ide.rb