本文整理汇总了Python中property_parser.Property类的典型用法代码示例。如果您正苦于以下问题:Python Property类的具体用法?Python Property怎么用?Python Property使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Property类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_music_script
def generate_music_script(data: Property, pack_list):
"""Generate a soundscript file for music."""
# We also pack the filenames used for the tracks - that way funnel etc
# only get packed when needed. Stock sounds are in VPKS or in aperturetag/,
# we don't check there.
# The voice attrs used in the map - we can skip tracks
voice_attr = CONF['VoiceAttr', ''].casefold().split(';')
funnel = data.find_key('tbeam', '')
bounce = data.find_key('bouncegel', '')
speed = data.find_key('speedgel', '')
# The sounds must be present, and the items should be in the map.
has_funnel = funnel.value and (
'funnel' in voice_attr or
'excursionfunnel' in voice_attr
)
has_bounce = bounce.value and (
'bouncegel' in voice_attr or
'bluegel' in voice_attr
)
# Speed-gel sounds also play when flinging, so keep it always.
with open(os.path.join('bee2', 'inject', 'music_script.txt'), 'w') as file:
# Write the base music track
file.write(MUSIC_START.format(name='', vol='1'))
write_sound(file, data.find_key('base'), pack_list, snd_prefix='#*')
file.write(MUSIC_BASE)
# The 'soundoperators' section is still open now.
# Add the operators to play the auxilluary sounds..
if has_funnel:
file.write(MUSIC_FUNNEL_MAIN)
if has_bounce:
file.write(MUSIC_GEL_BOUNCE_MAIN)
if speed.value:
file.write(MUSIC_GEL_SPEED_MAIN)
# End the main sound block
file.write(MUSIC_END)
if has_funnel:
# Write the 'music.BEE2_funnel' sound entry
file.write('\n')
file.write(MUSIC_START.format(name='_funnel', vol='1'))
write_sound(file, funnel, pack_list, snd_prefix='*')
file.write(MUSIC_FUNNEL_STACK)
if has_bounce:
file.write('\n')
file.write(MUSIC_START.format(name='_gel_bounce', vol='0.5'))
write_sound(file, bounce, pack_list, snd_prefix='*')
file.write(MUSIC_GEL_STACK)
if speed.value:
file.write('\n')
file.write(MUSIC_START.format(name='_gel_speed', vol='0.5'))
write_sound(file, speed, pack_list, snd_prefix='*')
file.write(MUSIC_GEL_STACK)
示例2: parse_item_folder
def parse_item_folder(folders, zip_file):
for fold in folders:
prop_path = 'items/' + fold + '/properties.txt'
editor_path = 'items/' + fold + '/editoritems.txt'
config_path = 'items/' + fold + '/vbsp_config.cfg'
try:
with zip_file.open(prop_path, 'r') as prop_file:
props = Property.parse(
prop_file, prop_path,
).find_key('Properties')
with zip_file.open(editor_path, 'r') as editor_file:
editor = Property.parse(editor_file, editor_path)
except KeyError as err:
# Opening the files failed!
raise IOError(
'"items/' + fold + '" not valid!'
'Folder likely missing! '
) from err
editor_iter = Property.find_all(editor, 'Item')
folders[fold] = {
'auth': sep_values(props['authors', '']),
'tags': sep_values(props['tags', '']),
'desc': list(desc_parse(props)),
'ent': props['ent_count', '??'],
'url': props['infoURL', None],
'icons': {p.name: p.value for p in props['icon', []]},
'all_name': props['all_name', None],
'all_icon': props['all_icon', None],
'vbsp': Property(None, []),
# The first Item block found
'editor': next(editor_iter),
# Any extra blocks (offset catchers, extent items)
'editor_extra': list(editor_iter),
}
if LOG_ENT_COUNT and folders[fold]['ent'] == '??':
print('Warning: "{}" has missing entity count!'.format(prop_path))
# If we have at least 1, but not all of the grouping icon
# definitions then notify the author.
num_group_parts = (
(folders[fold]['all_name'] is not None)
+ (folders[fold]['all_icon'] is not None)
+ ('all' in folders[fold]['icons'])
)
if 0 < num_group_parts < 3:
print(
'Warning: "{}" has incomplete grouping icon definition!'.format(
prop_path)
)
try:
with zip_file.open(config_path, 'r') as vbsp_config:
folders[fold]['vbsp'] = Property.parse(vbsp_config, config_path)
except KeyError:
folders[fold]['vbsp'] = Property(None, [])
示例3: parse
def parse(cls, data):
"""Parse a style definition."""
info = data.info
selitem_data = get_selitem_data(info)
base = info['base', '']
has_video = utils.conv_bool(info['has_video', '1'])
sugg = info.find_key('suggested', [])
sugg = (
sugg['quote', '<NONE>'],
sugg['music', '<NONE>'],
sugg['skybox', 'SKY_BLACK'],
sugg['goo', 'GOO_NORM'],
sugg['elev', '<NONE>'],
)
corridors = info.find_key('corridors', [])
corridors = {
'sp_entry': corridors.find_key('sp_entry', []),
'sp_exit': corridors.find_key('sp_exit', []),
'coop': corridors.find_key('coop', []),
}
short_name = selitem_data.short_name or None
if base == '':
base = None
folder = 'styles/' + info['folder']
config = folder + '/vbsp_config.cfg'
with data.zip_file.open(folder + '/items.txt', 'r') as item_data:
items = Property.parse(
item_data,
data.pak_id+':'+folder+'/items.txt'
)
try:
with data.zip_file.open(config, 'r') as vbsp_config:
vbsp = Property.parse(
vbsp_config,
data.pak_id+':'+config,
)
except KeyError:
vbsp = None
return cls(
style_id=data.id,
name=selitem_data.name,
author=selitem_data.auth,
desc=selitem_data.desc,
icon=selitem_data.icon,
editor=items,
config=vbsp,
base_style=base,
short_name=short_name,
suggested=sugg,
has_video=has_video,
corridor_names=corridors,
)
示例4: gen_sound_manifest
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..')
示例5: __init__
def __init__(
self,
style_id,
selitem_data: 'SelitemData',
editor,
config=None,
base_style=None,
suggested=None,
has_video=True,
corridor_names=utils.EmptyMapping,
):
self.id = style_id
self.selitem_data = selitem_data
self.editor = editor
self.base_style = base_style
self.bases = [] # Set by setup_style_tree()
self.suggested = suggested or {}
self.has_video = has_video
self.corridor_names = {
'sp_entry': corridor_names.get('sp_entry', Property('', [])),
'sp_exit': corridor_names.get('sp_exit', Property('', [])),
'coop': corridor_names.get('coop', Property('', [])),
}
if config is None:
self.config = Property(None, [])
else:
self.config = config
示例6: parse
def parse(posfile, propfile, path):
"Parse through the given palette file to get all data."
props = Property.parse(propfile, path + ':properties.txt')
name = "Unnamed"
opts = {}
for option in props:
if option.name == "name":
name = option.value
else:
opts[option.name.casefold()] = option.value
pos = []
for dirty_line in posfile:
line = utils.clean_line(dirty_line)
if line:
# Lines follow the form
# "ITEM_BUTTON_FLOOR", 2
# for subtype 3 of the button
if line.startswith('"'):
val = line.split('",')
if len(val) == 2:
pos.append((
val[0][1:], # Item ID
int(val[1].strip()), # Item subtype
))
else:
LOGGER.warning('Malformed row "{}"!', line)
return None
return Palette(name, pos, opts, filename=path)
示例7: load_conf
def load_conf():
"""Read the config and build our dictionaries."""
global INST_SPECIAL
with open('bee2/instances.cfg') as f:
prop_block = Property.parse(
f, 'bee2/instances.cfg'
).find_key('Allinstances')
for prop in prop_block:
INSTANCE_FILES[prop.real_name] = [
inst.value.casefold()
for inst in
prop
]
INST_SPECIAL = {
key.casefold(): resolve(val_string)
for key, val_string in
SPECIAL_INST.items()
}
INST_SPECIAL['indpan'] = (
INST_SPECIAL['indpancheck'] +
INST_SPECIAL['indpantimer']
)
INST_SPECIAL['white_frames'] = (
resolve('<ITEM_ENTRY_DOOR:7>') + resolve('<ITEM_EXIT_DOOR:4>')
)
INST_SPECIAL['black_frames'] = (
resolve('<ITEM_ENTRY_DOOR:8>') + resolve('<ITEM_EXIT_DOOR:5>')
)
示例8: __init__
def __init__(
self,
style_id,
name,
author,
desc,
icon,
editor,
config=None,
base_style=None,
short_name=None,
suggested=None,
has_video=True,
corridor_names=utils.EmptyMapping,
):
self.id = style_id
self.auth = author
self.name = name
self.desc = desc
self.icon = icon
self.short_name = name if short_name is None else short_name
self.editor = editor
self.base_style = base_style
self.bases = [] # Set by setup_style_tree()
self.suggested = suggested or {}
self.has_video = has_video
self.corridor_names = {
'sp_entry': corridor_names.get('sp_entry', Property('', [])),
'sp_exit': corridor_names.get('sp_exit', Property('', [])),
'coop': corridor_names.get('coop', Property('', [])),
}
if config is None:
self.config = Property(None, [])
else:
self.config = config
示例9: get_config
def get_config(prop_block, zip_file, folder, pak_id='', prop_name='config'):
"""Extract a config file refered to by the given property block.
Looks for the prop_name key in the given prop_block.
If the keyvalue has a value of "", an empty tree is returned.
If it has children, a copy of them is returned.
Otherwise the value is a filename in the zip which will be parsed.
"""
prop_block = prop_block.find_key(prop_name, "")
if prop_block.has_children():
prop = prop_block.copy()
prop.name = None
return prop
if prop_block.value == '':
return Property(None, [])
path = os.path.join(folder, prop_block.value) + '.cfg'
try:
with zip_file.open(path) as f:
return Property.parse(f,
pak_id + ':' + path,
)
except KeyError:
print('"{}:{}" not in zip!'.format(pak_id, path))
return Property(None, [])
示例10: parse
def parse(cls, data):
"""Parse a skybox definition."""
config_dir = data.info['config', '']
selitem_data = get_selitem_data(data.info)
mat = data.info['material', 'sky_black']
if config_dir == '': # No config at all
config = Property(None, [])
else:
path = 'skybox/' + config_dir + '.cfg'
try:
with data.zip_file.open(path, 'r') as conf:
config = Property.parse(conf)
except KeyError:
print(config_dir + '.cfg not in zip!')
config = Property(None, [])
return cls(
data.id,
selitem_data.name,
selitem_data.icon,
config,
mat,
selitem_data.auth,
selitem_data.desc,
selitem_data.short_name,
)
示例11: find_packages
def find_packages(pak_dir, zips, zip_name_lst):
"""Search a folder for packages, recursing if necessary."""
found_pak = False
for name in os.listdir(pak_dir): # Both files and dirs
name = os.path.join(pak_dir, name)
is_dir = os.path.isdir(name)
if name.endswith('.zip') and os.path.isfile(name):
zip_file = ZipFile(name)
elif is_dir:
zip_file = FakeZip(name)
if 'info.txt' in zip_file.namelist(): # Is it valid?
zips.append(zip_file)
zip_name_lst.append(os.path.abspath(name))
print('Reading package "' + name + '"')
with zip_file.open('info.txt') as info_file:
info = Property.parse(info_file, name + ':info.txt')
pak_id = info['ID']
disp_name = info['Name', pak_id]
packages[pak_id] = PackageData(
zip_file,
info,
name,
disp_name,
)
found_pak = True
else:
if is_dir:
# This isn't a package, so check the subfolders too...
print('Checking subdir "{}" for packages...'.format(name))
find_packages(name, zips, zip_name_lst)
else:
zip_file.close()
print('ERROR: Bad package "{}"!'.format(name))
if not found_pak:
print('No packages in folder!')
示例12: __init__
def __init__(
self,
style_id,
name,
author,
desc,
icon,
editor,
config=None,
base_style=None,
short_name=None,
suggested=None,
has_video=True,
):
self.id = style_id
self.auth = author
self.name = name
self.desc = desc
self.icon = icon
self.short_name = name if short_name is None else short_name
self.editor = editor
self.base_style = base_style
self.bases = [] # Set by setup_style_tree()
self.suggested = suggested or {}
self.has_video = has_video
if config is None:
self.config = Property(None, [])
else:
self.config = config
示例13: load_conf
def load_conf(prop_block: Property):
"""Read the config and build our dictionaries."""
global INST_SPECIAL
for prop in prop_block.find_key("Allinstances"):
INSTANCE_FILES[prop.real_name] = [inst.value.casefold() for inst in prop]
INST_SPECIAL = {key.casefold(): resolve(val_string) for key, val_string in SPECIAL_INST.items()}
# Several special items which use multiple item types!
# Checkmark and Timer indicator panels:
INST_SPECIAL["indpan"] = INST_SPECIAL["indpancheck"] + INST_SPECIAL["indpantimer"]
INST_SPECIAL["door_frame"] = INST_SPECIAL["door_frame_sp"] + INST_SPECIAL["door_frame_coop"]
INST_SPECIAL["white_frame"] = INST_SPECIAL["white_frame_sp"] + INST_SPECIAL["white_frame_coop"]
INST_SPECIAL["black_frame"] = INST_SPECIAL["black_frame_sp"] + INST_SPECIAL["black_frame_coop"]
# Arrival_departure_ents is set in both entry doors - it's usually the same
# though.
INST_SPECIAL["transitionents"] = resolve("<ITEM_ENTRY_DOOR:11>") + resolve("<ITEM_COOP_ENTRY_DOOR:4>")
# Laser items have the offset and centered item versions.
INST_SPECIAL["lasercatcher"] = resolve("<ITEM_LASER_CATCHER_CENTER>") + resolve("<ITEM_LASER_CATCHER_OFFSET>")
INST_SPECIAL["laseremitter"] = resolve("<ITEM_LASER_EMITTER_CENTER>") + resolve("<ITEM_LASER_EMITTER_OFFSET>")
INST_SPECIAL["laserrelay"] = resolve("<ITEM_LASER_RELAY_CENTER>") + resolve("<ITEM_LASER_RELAY_OFFSET>")
示例14: load_config
def load_config():
global CONF
LOGGER.info('Loading Settings...')
try:
with open("bee2/vrad_config.cfg") as config:
CONF = Property.parse(config, 'bee2/vrad_config.cfg').find_key(
'Config', []
)
except FileNotFoundError:
pass
LOGGER.info('Config Loaded!')
示例15: gen_part_manifest
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..')