Files
2025-09-29 00:52:08 +02:00

224 lines
9.5 KiB
Plaintext
Executable File

#
# File:: <%= OS::Path::normalise( output ) %>
# Template:: <%= template %>
# Description:: Map exporter build output ERB template.
#
# Author:: David Muir <david.muir@rockstarnorth.com>
# Date:: <%= Time::now() %>
#
# == Template Arguments ==
# output
# template
# args[:rebuild]- Bool - Convert system rebuild.
# args[:patch] - Bool - Whether its a patch build or not (default: false).
# args[:level] - String - Level name (content-tree filter).
# args[:maps] - Hash of Arrays - Key: map name, Value: Array of symbols indicating what to resource and build.
# (:metadata, :textures, :animation, :geometry, :bound_static, :bound_dynamic)
#
#----------------------------------------------------------------------------
# Uses
#----------------------------------------------------------------------------
require 'pipeline/config/filter'
require 'pipeline/config/projects'
require 'pipeline/config/project'
require 'pipeline/gui/exception_dialog'
require 'pipeline/log/log'
require 'pipeline/os/path'
require 'pipeline/projectutil/data_convert'
require 'pipeline/projectutil/data_zip'
require 'pipeline/resourcing/convert'
require 'pipeline/resourcing/util'
require 'pipeline/resourcing/converters/converter_map_collision'
include Pipeline
#----------------------------------------------------------------------------
# Implementation
#----------------------------------------------------------------------------
if ( __FILE__ == $0 ) then
config = Pipeline::Config::instance( )
project = config.project
log = Pipeline::Log::new( OS::Path::get_basename( __FILE__ ) )
begin
rebuild = <%= args[:rebuild].nil? ? false : args[:rebuild] %>
patch = <%= args[:patch].nil? ? false : args[:patch] %>
patch_collision = <%= args[:patch_collision].nil? ? false : args[:patch_collision] %>
level_name = "<%= args[:level] %>"
resource = <%= args[:resource].nil? ? false : args[:resource] %>
use_ap3 = <%= args[:use_ap3].nil? ? false : args[:use_ap3] %>
lookup_dependencies = <%= args[:lookup_dependencies].nil? ? true : args[:lookup_dependencies] %>
project.load_content( nil, false, lambda { |filename, sourcedoc| Pipeline::filter_level( level_name, filename, sourcedoc ) } )
map_nodes = {}
<% args[:maps].each_pair do |map_name, map| %>
map_content_node = project.content.find_first( '<%= map_name %>', 'map' )
map_output_node = project.content.find_first( '<%= map_name %>', 'mapzip' )
if ( map_content_node.nil? or map_output_node.nil? ) then
log.error( "Failed to find map input and output content nodes for '<%= map_name %>' map." )
else
map_nodes['<%= map_name %>'] = {}
map_nodes['<%= map_name %>'][:map] = map_content_node
map_nodes['<%= map_name %>'][:output] = map_output_node
map_nodes['<%= map_name %>'][:generic] = ( not map_content_node.exportinstances )
map_nodes['<%= map_name %>'][:content] = [ <%= map.collect do |item| ":#{item}, "; end %> ]
end
<% end %>
#------------------------------------------------------------------------
# INITIALISE CONVERT SYSTEM
#------------------------------------------------------------------------
convert = Resourcing::ConvertSystem::instance()
convert.setup( project, nil, true, rebuild, false )
geo_content_nodes = []
txd_content_nodes = []
convert_files = []
preview_group = Content::Group::new( 'map_preview_group' )
output_group = Content::Group::new( 'map_output_group' )
map_nodes.each_pair do |map_name, map_node|
stream_dir = OS::Path.combine( project.cache, 'raw', 'script', map_name )
# Create a container for the map conponent content
component_group = Content::Group.new( 'map_content_group' )
log.info( "Packing assets for #{map_name}..." )
static_content = nil
dynamic_content = nil
if( (not patch) or patch_collision ) then
log.info( "\tStatic Collision..." )
static_content_filename = OS::Path::combine( stream_dir, 'bnd_static.xml' )
static_content = Content::MapBounds.new( static_content_filename, project, map_name, "bound_static", "ibn", map_node[:generic], true )
component_group.add_child( static_content )
log.info( "\tQueuing Dynamic Collision..." )
dynamic_content_filename = OS::Path::combine( stream_dir, 'bnd_dynamic.xml' )
dynamic_content = Content::MapBounds.new( dynamic_content_filename, project, map_name, OS::Path.combine("bound_dynamic", map_name) , "ibd", map_node[:generic], false )
component_group.add_child( dynamic_content )
end
log.info( "\tQueuing Animation..." )
anim_content_filename = OS::Path::combine( stream_dir, 'anim.xml' )
anim_content = Content::MapAnim.new( anim_content_filename, project, map_name, map_node[:generic] )
component_group.add_child( anim_content )
log.info( "\tQueuing Geometry..." )
geo_content_filename = OS::Path::combine( stream_dir, 'map.xml' )
geo_content = Content::MapGeo.new( geo_content_filename, project, map_name, map_node[:generic], "maps" )
component_group.add_child( geo_content )
log.info( "\tQueuing Textures..." )
txd_content_filename = OS::Path::combine( stream_dir, 'txd.xml' )
txd_content = Content::MapTxd.new( txd_content_filename, project, map_name, map_node[:generic] )
component_group.add_child( txd_content )
log.info( "\tQueuing Occlusion..." )
occl_content_filename = OS::Path::combine( stream_dir, 'occlusion.xml' )
occl_content = Content::MapOcclusion::new( occl_content_filename, project, map_name )
component_group.add_child( occl_content )
component_group.children.each do | content_group |
next unless ( content_group.methods.include?( 'build' ) )
# This builds the individual asset zip files.
content_group.build()
end
convert.build( component_group )
# DHM 2011/09/21; Wanted to remove the file search but would need to add
# a new map content component to represent the map metadata.
stream_dir = Pipeline::OS::Path.combine( project.cache, 'raw', 'maps', map_name )
pack_file_list = OS::FindEx.find_files( OS::Path::combine( stream_dir, '*.i*' ), false)
pack_file_list += OS::FindEx.find_files( OS::Path::combine( stream_dir, '*.i*.zip' ), false)
pack_file_list += OS::FindEx.find_files( OS::Path::combine( stream_dir, map_name + '_collision.zip' ), false)
pack_file_list << occl_content.filename if ( File::exists?( occl_content.filename ) )
pack_file_list.uniq!
log.info( "Building map #{map_name} [#{pack_file_list.size} files]..." )
pack_file_list.each do |pack_file|
map_node[:output].add_input( Content::File::from_filename( pack_file ) )
end
# Add our node to our output group if its not already
# been added.
output_group.add_child( map_node[:output] ) unless \
( output_group.children.include?( map_node[:output] ) )
# Add the output node destination file to the queue for
# files to be converted.
convert_files << map_node[:output].filename
if( patch ) then
component_group.remove_child( geo_content )# we'll resource this seperately (see call to MapConverterAssetCombine.build_preview() below)
component_group.remove_child( txd_content )# we'll resource this seperately (see call to MapConverterAssetCombine.build_preview() below)
geo_content_nodes << geo_content
txd_content_nodes << txd_content
if( patch_collision ) then
# we'll resource these seperately for patched collision (see call to MapConverterCollision.build_preview() below)
component_group.remove_child( static_content )
component_group.remove_child( dynamic_content )
end
else
# Handling this here rather than the old "output_group" means
# we don't unneccessarily build data twice.
log.info( "Building Map Zip: #{map_node[:output].filename}..." )
output_filename = map_node[:output].filename
ProjectUtil::data_zip_create( output_filename, pack_file_list, true )
end
Resourcing::create_target_content_from_indepenent( component_group, preview_group, project, project.preview )
end
if( patch ) then
map_zip_nodes = []
map_nodes.each_pair do |map_name, map_node|
map_zip_nodes << map_node[:output]
end
branch = config.project.branches[config.project.default_branch]
patch_content_group = Content::Group.new( 'patch_content' )
Pipeline::Resourcing::Converters::MapConverterAssetCombine.build_preview( config, branch, map_zip_nodes, geo_content_nodes, txd_content_nodes, patch_content_group )
if ( patch_collision ) then
Pipeline::Resourcing::Converters::MapConverterCollision.build_preview( config, branch, map_zip_nodes, patch_content_group )
end
Resourcing::create_target_content_from_indepenent( patch_content_group, preview_group, project, project.preview )
end
# Handle all platform conversion in a single step.
status = true
if ( patch ) then
status = convert.build( preview_group )
else
if ( resource and not use_ap3 ) then
log.info( "Convert files..." )
convert_files.uniq!
status = ProjectUtil::data_convert_file( convert_files, rebuild, false, true, lookup_dependencies )
end
end
exit( status ? 0 : 1 )
rescue SystemExit => ex
exit( ex.status )
rescue Exception => ex
log.exception( ex, "Unhandled exception during build_map." )
GUI::ExceptionDialog::show_dialog( ex )
exit( 1 )
end
end
# <%= OS::Path::normalise( output ) %>