本文整理汇总了Python中property_parser.Property.export方法的典型用法代码示例。如果您正苦于以下问题:Python Property.export方法的具体用法?Python Property.export怎么用?Python Property.export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类property_parser.Property
的用法示例。
在下文中一共展示了Property.export方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_instance_data
# 需要导入模块: from property_parser import Property [as 别名]
# 或者: from property_parser.Property import export [as 别名]
def build_instance_data(editoritems: Property):
"""Build a property tree listing all of the instances for each item.
as well as another listing the input and output commands.
VBSP uses this to reduce duplication in VBSP_config files.
This additionally strips custom instance definitions from the original
list.
"""
instance_locs = Property("AllInstances", [])
cust_inst = Property("CustInstances", [])
commands = Property("Connections", [])
root_block = Property(None, [instance_locs, cust_inst, commands])
for item in editoritems.find_all("Item"):
instance_block = Property(item['Type'], [])
instance_locs.append(instance_block)
comm_block = Property(item['Type'], [])
for inst_block in item.find_all("Exporting", "instances"):
for inst in inst_block.value[:]: # type: Property
if inst.name.isdigit():
# Direct Portal 2 value
instance_block.append(
Property('Instance', inst['Name'])
)
else:
# It's a custom definition, remove from editoritems
inst_block.value.remove(inst)
cust_inst.set_key(
(item['type'], inst.name),
# Allow using either the normal block format,
# or just providing the file - we don't use the
# other values.
inst['name'] if inst.has_children() else inst.value,
)
# Look in the Inputs and Outputs blocks to find the io definitions.
# Copy them to property names like 'Input_Activate'.
for io_type in ('Inputs', 'Outputs'):
for block in item.find_all('Exporting', io_type, CONN_NORM):
for io_prop in block:
comm_block[
io_type[:-1] + '_' + io_prop.real_name
] = io_prop.value
# The funnel item type is special, having the additional input type.
# Handle that specially.
if item['type'] == 'item_tbeam':
for block in item.find_all('Exporting', 'Inputs', CONN_FUNNEL):
for io_prop in block:
comm_block['TBEAM_' + io_prop.real_name] = io_prop.value
# Only add the block if the item actually has IO.
if comm_block.value:
commands.append(comm_block)
return root_block.export()
示例2: gen_sound_manifest
# 需要导入模块: from property_parser import Property [as 别名]
# 或者: from property_parser.Property import export [as 别名]
def gen_sound_manifest(additional, excludes):
"""Generate a new game_sounds_manifest.txt file.
This includes all the current scripts defined, plus any custom ones.
Excludes is a list of scripts to remove from the listing - this allows
overriding the sounds without VPK overrides.
"""
if not additional:
return # Don't pack, there aren't any new sounds..
orig_manifest = os.path.join(
'..',
SOUND_MAN_FOLDER.get(CONF['game_id', ''], 'portal2'),
'scripts',
'game_sounds_manifest.txt',
)
try:
with open(orig_manifest) as f:
props = Property.parse(f, orig_manifest).find_key(
'game_sounds_manifest', [],
)
except FileNotFoundError: # Assume no sounds
props = Property('game_sounds_manifest', [])
scripts = [prop.value for prop in props.find_all('precache_file')]
for script in additional:
scripts.append(script)
# For our packed scripts, force the game to load them
# (we know they're used).
scripts.append('!' + script)
for script in excludes:
try:
scripts.remove(script)
except ValueError:
LOGGER.warning(
'"{}" should be excluded, but it\'s'
' not in the manifest already!',
script,
)
# Build and unbuild it to strip other things out - Valve includes a bogus
# 'new_sound_scripts_must_go_below_here' entry..
new_props = Property('game_sounds_manifest', [
Property('precache_file', file)
for file in scripts
])
inject_loc = os.path.join('bee2', 'inject', 'soundscript_manifest.txt')
with open(inject_loc, 'w') as f:
for line in new_props.export():
f.write(line)
LOGGER.info('Written new soundscripts_manifest..')
示例3: build_instance_data
# 需要导入模块: from property_parser import Property [as 别名]
# 或者: from property_parser.Property import export [as 别名]
def build_instance_data(editoritems: Property):
"""Build a property tree listing all of the instances for each item.
as well as another listing the input and output commands.
VBSP uses this to reduce duplication in VBSP_config files.
"""
instance_locs = Property("AllInstances", [])
commands = Property("Connections", [])
root_block = Property(None, [instance_locs, commands])
for item in editoritems.find_all("Item"):
instance_block = Property(item['Type'], [])
instance_locs.append(instance_block)
comm_block = Property(item['Type'], [])
for inst_block in item.find_all("Exporting", "instances"):
for inst in inst_block:
instance_block.append(
Property('Instance', inst['Name'])
)
# Look in the Inputs and Outputs blocks to find the io definitions.
# Copy them to property names like 'Input_Activate'.
for io_type in ('Inputs', 'Outputs'):
for block in item.find_all('Exporting', io_type, CONN_NORM):
for io_prop in block:
comm_block[
io_type[:-1] + '_' + io_prop.real_name
] = io_prop.value
# The funnel item type is special, having the additional input type.
# Handle that specially.
if item['type'] == 'item_tbeam':
for block in item.find_all('Exporting', 'Inputs', CONN_FUNNEL):
for io_prop in block:
comm_block['TBEAM_' + io_prop.real_name] = io_prop.value
# Only add the block if the item actually has IO.
if comm_block.value:
commands.append(comm_block)
return root_block.export()
示例4: gen_part_manifest
# 需要导入模块: from property_parser import Property [as 别名]
# 或者: from property_parser.Property import export [as 别名]
def gen_part_manifest(additional):
"""Generate a new particle system manifest file.
This includes all the current ones defined, plus any custom ones.
"""
if not additional:
return # Don't pack, there aren't any new particles..
orig_manifest = os.path.join(
'..',
GAME_FOLDER.get(CONF['game_id', ''], 'portal2'),
'particles',
'particles_manifest.txt',
)
try:
with open(orig_manifest) as f:
props = Property.parse(f, orig_manifest).find_key(
'particles_manifest', [],
)
except FileNotFoundError: # Assume no particles
props = Property('particles_manifest', [])
parts = [prop.value for prop in props.find_all('file')]
for particle in additional:
parts.append(particle)
# Build and unbuild it to strip comments and similar lines.
new_props = Property('particles_manifest', [
Property('file', file)
for file in parts
])
inject_loc = os.path.join('bee2', 'inject', 'particles_manifest.txt')
with open(inject_loc, 'w') as f:
for line in new_props.export():
f.write(line)
LOGGER.info('Written new particles_manifest..')
示例5: gen_sound_manifest
# 需要导入模块: from property_parser import Property [as 别名]
# 或者: from property_parser.Property import export [as 别名]
def gen_sound_manifest(additional, has_music=False):
"""Generate a new game_sounds_manifest.txt file.
This includes all the current scripts defined, plus any custom ones.
"""
orig_manifest = os.path.join(
'..',
SOUND_MAN_FOLDER.get(CONF['game_id', ''], 'portal2'),
'scripts',
'game_sounds_manifest.txt',
)
try:
with open(orig_manifest) as f:
props = Property.parse(f, orig_manifest).find_key(
'game_sounds_manifest', [],
)
except FileNotFoundError: # Assume no sounds
props = Property('game_sounds_manifest', [])
scripts = [prop.value for prop in props.find_all('precache_file')]
for script in additional:
scripts.append(script)
# Build and unbuild it to strip other things out - Valve includes a bogus
# 'new_sound_scripts_must_go_below_here' entry..
new_props = Property('game_sounds_manifest', [
Property('precache_file', file)
for file in scripts
])
inject_loc = os.path.join('bee2', 'inject', 'soundscript_manifest.txt')
with open(inject_loc, 'w') as f:
for line in new_props.export():
f.write(line)
LOGGER.info('Written new soundscripts_manifest..')
示例6: export
# 需要导入模块: from property_parser import Property [as 别名]
# 或者: from property_parser.Property import export [as 别名]
def export(
self,
style,
all_items,
music,
skybox,
voice,
style_vars,
elevator,
):
"""Generate the editoritems.txt and vbsp_config.
- If no backup is present, the original editoritems is backed up
- We unlock the mandatory items if specified
-
"""
print('--------------------')
print('Exporting Items and Style for "' + self.name + '"!')
print('Style =', style)
print('Music =', music)
print('Voice =', voice)
print('Skybox =', skybox)
print('Elevator = ', elevator)
print('Style Vars:\n {')
for key, val in style_vars.items():
print(' {} = {!s}'.format(key, val))
print(' }')
vbsp_config = style.config.copy()
# Editoritems.txt is composed of a "ItemData" block, holding "Item" and
# "Renderables" sections.
editoritems = Property("ItemData", *style.editor.find_all('Item'))
for item in sorted(all_items):
item_block, editor_parts, config_part = all_items[item].export()
editoritems += item_block
editoritems += editor_parts
vbsp_config += config_part
if voice is not None:
vbsp_config += voice.config
if skybox is not None:
vbsp_config.set_key(
('Textures', 'Special', 'Sky'),
skybox.material,
)
vbsp_config += skybox.config
if music is not None:
if music.sound is not None:
vbsp_config.set_key(
('Options', 'music_SoundScript'),
music.sound,
)
if music.inst is not None:
vbsp_config.set_key(
('Options', 'music_instance'),
music.inst,
)
vbsp_config.set_key(('Options', 'music_ID'), music.id)
vbsp_config += music.config
vbsp_config.set_key(('Options', 'BEE2_loc'),
os.path.dirname(os.getcwd()) # Go up one dir to our actual location
)
# If there are multiple of these blocks, merge them together
vbsp_config.merge_children('Conditions',
'InstanceFiles',
'Options',
'StyleVars',
'Textures')
vbsp_config.ensure_exists('StyleVars')
vbsp_config['StyleVars'] += [
Property(key, utils.bool_as_int(val))
for key, val in
style_vars.items()
]
for name, file, ext in FILES_TO_BACKUP:
item_path = self.abs_path(file + ext)
backup_path = self.abs_path(file + '_original' + ext)
if os.path.isfile(item_path) and not os.path.isfile(backup_path):
print('Backing up original ' + name + '!')
shutil.copy(item_path, backup_path)
# This is the connections "heart" icon and "error" icon
editoritems += style.editor.find_key("Renderables", [])
# Build a property tree listing all of the instances for each item
all_instances = Property("AllInstances", [])
for item in editoritems.find_all("Item"):
item_prop = Property(item['Type'], [])
all_instances.append(item_prop)
for inst_block in item.find_all("Exporting", "instances"):
for inst in inst_block:
#.........这里部分代码省略.........
示例7: export
# 需要导入模块: from property_parser import Property [as 别名]
# 或者: from property_parser.Property import export [as 别名]
def export(
self,
style,
all_items,
music,
skybox,
voice,
style_vars,
elevator,
pack_list,
editor_sounds,
should_refresh=False,
):
"""Generate the editoritems.txt and vbsp_config.
- If no backup is present, the original editoritems is backed up.
- We unlock the mandatory items if specified.
-
"""
LOGGER.info('-' * 20)
LOGGER.info('Exporting Items and Style for "{}"!', self.name)
LOGGER.info('Style = {}', style)
LOGGER.info('Music = {}', music)
LOGGER.info('Voice = {}', voice)
LOGGER.info('Skybox = {}', skybox)
LOGGER.info('Elevator = {}', elevator)
LOGGER.info('Style Vars:')
LOGGER.info(' {')
for key, val in style_vars.items():
LOGGER.info(' {} = {!s}', key, val)
LOGGER.info(' }')
LOGGER.info('{} Pack Lists!', len(pack_list))
LOGGER.info('{} Editor Sounds!', len(editor_sounds))
LOGGER.info('-' * 20)
# VBSP, VRAD, editoritems
export_screen.set_length('BACK', len(FILES_TO_BACKUP))
export_screen.set_length(
'CONF',
# VBSP_conf, Editoritems, instances, gameinfo, pack_lists,
# editor_sounds, template VMF
7 +
# Don't add the voicelines to the progress bar if not selected
(0 if voice is None else len(VOICE_PATHS)),
)
# files in compiler/
export_screen.set_length('COMP', len(os.listdir('../compiler')))
if should_refresh:
export_screen.set_length('RES', extract_packages.res_count)
else:
export_screen.skip_stage('RES')
export_screen.show()
export_screen.grab_set_global() # Stop interaction with other windows
vbsp_config = style.config.copy()
# Editoritems.txt is composed of a "ItemData" block, holding "Item" and
# "Renderables" sections.
editoritems = Property("ItemData", list(style.editor.find_all('Item')))
for item in sorted(all_items):
item_block, editor_parts, config_part = all_items[item].export()
editoritems += item_block
editoritems += editor_parts
vbsp_config += config_part
if voice is not None:
vbsp_config += voice.config
if skybox is not None:
vbsp_config.set_key(
('Textures', 'Special', 'Sky'),
skybox.material,
)
vbsp_config += skybox.config
if style.has_video:
if elevator is None:
# Use a randomised video
vbsp_config.set_key(
('Elevator', 'type'),
'RAND',
)
elif elevator.id == 'VALVE_BLUESCREEN':
# This video gets a special script and handling
vbsp_config.set_key(
('Elevator', 'type'),
'BSOD',
)
else:
# Use the particular selected video
vbsp_config.set_key(
('Elevator', 'type'),
'FORCE',
)
vbsp_config.set_key(
('Elevator', 'horiz'),
elevator.horiz_video,
#.........这里部分代码省略.........