本文整理汇总了Python中utils.conv_bool函数的典型用法代码示例。如果您正苦于以下问题:Python conv_bool函数的具体用法?Python conv_bool怎么用?Python conv_bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了conv_bool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
def parse(cls, data):
"""Parse an item definition."""
versions = {}
def_version = None
folders = {}
unstyled = utils.conv_bool(data.info['unstyled', '0'])
glob_desc = list(desc_parse(data.info))
desc_last = utils.conv_bool(data.info['AllDescLast', '0'])
all_config = get_config(
data.info,
data.zip_file,
'items',
pak_id=data.pak_id,
prop_name='all_conf',
)
needs_unlock = utils.conv_bool(data.info['needsUnlock', '0'])
for ver in data.info.find_all('version'):
vals = {
'name': ver['name', 'Regular'],
'id': ver['ID', 'VER_DEFAULT'],
'is_wip': utils.conv_bool(ver['wip', '0']),
'is_dep': utils.conv_bool(ver['deprecated', '0']),
'styles': {},
'def_style': None,
}
for sty_list in ver.find_all('styles'):
for sty in sty_list:
if vals['def_style'] is None:
vals['def_style'] = sty.value
vals['styles'][sty.real_name] = sty.value
folders[sty.value] = True
versions[vals['id']] = vals
if def_version is None:
def_version = vals
parse_item_folder(folders, data.zip_file, data.pak_id)
for ver in versions.values():
if ver['def_style'] in folders:
ver['def_style'] = folders[ver['def_style']]
for sty, fold in ver['styles'].items():
ver['styles'][sty] = folders[fold]
if not versions:
raise ValueError('Item "' + data.id + '" has no versions!')
return cls(
data.id,
versions=versions,
def_version=def_version,
needs_unlock=needs_unlock,
all_conf=all_config,
unstyled=unstyled,
glob_desc=glob_desc,
desc_last=desc_last,
)
示例2: flag_brush_at_loc
def flag_brush_at_loc(inst, flag):
"""Checks to see if a wall is present at the given location.
- Pos is the position of the brush, where `0 0 0` is the floor-position
of the brush.
- Dir is the normal the face is pointing. (0 0 -1) is 'up'.
- Type defines the type the brush must be:
- "Any" requires either a black or white brush.
- "None" means that no brush must be present.
- "White" requires a portalable surface.
- "Black" requires a non-portalable surface.
- SetVar defines an instvar which will be given a value of "black",
"white" or "none" to allow the result to be reused.
- If gridPos is true, the position will be snapped so it aligns with
the 128 brushes (Useful with fizzler/light strip items).
- RemoveBrush: If set to 1, the brush will be removed if found.
Only do this to EmbedFace brushes, since it will remove the other
sides as well.
"""
from conditions import VMF
pos = Vec.from_str(flag['pos', '0 0 0'])
pos.z -= 64 # Subtract so origin is the floor-position
pos = pos.rotate_by_str(inst['angles', '0 0 0'])
# Relative to the instance origin
pos += Vec.from_str(inst['origin', '0 0 0'])
norm = Vec.from_str(flag['dir', '0 0 -1']).rotate_by_str(
inst['angles', '0 0 0']
)
if utils.conv_bool(flag['gridpos', '0']):
for axis in 'xyz':
# Don't realign things in the normal's axis -
# those are already fine.
if norm[axis] == 0:
pos[axis] = pos[axis] // 128 * 128 + 64
result_var = flag['setVar', '']
should_remove = utils.conv_bool(flag['RemoveBrush', False], False)
des_type = flag['type', 'any'].casefold()
brush = SOLIDS.get(pos.as_tuple(), None)
if brush is None or brush.normal != norm:
br_type = 'none'
else:
br_type = str(brush.color)
if should_remove:
VMF.remove_brush(
brush.solid,
)
if result_var:
inst.fixup[result_var] = br_type
if des_type == 'any' and br_type != 'none':
return True
return des_type == br_type
示例3: res_unst_scaffold_setup
def res_unst_scaffold_setup(res):
group = res["group", "DEFAULT_GROUP"]
if group not in SCAFFOLD_CONFIGS:
# Store our values in the CONFIGS dictionary
targ_inst, links = SCAFFOLD_CONFIGS[group] = {}, {}
else:
# Grab the already-filled values, and add to them
targ_inst, links = SCAFFOLD_CONFIGS[group]
for block in res.find_all("Instance"):
conf = {
# If set, adjusts the offset appropriately
"is_piston": utils.conv_bool(block["isPiston", "0"]),
"rotate_logic": utils.conv_bool(block["AlterAng", "1"], True),
"off_floor": Vec.from_str(block["FloorOff", "0 0 0"]),
"off_wall": Vec.from_str(block["WallOff", "0 0 0"]),
"logic_start": block["startlogic", ""],
"logic_end": block["endLogic", ""],
"logic_mid": block["midLogic", ""],
"logic_start_rev": block["StartLogicRev", None],
"logic_end_rev": block["EndLogicRev", None],
"logic_mid_rev": block["EndLogicRev", None],
"inst_wall": block["wallInst", ""],
"inst_floor": block["floorInst", ""],
"inst_offset": block["offsetInst", None],
# Specially rotated to face the next track!
"inst_end": block["endInst", None],
}
for logic_type in ("logic_start", "logic_mid", "logic_end"):
if conf[logic_type + "_rev"] is None:
conf[logic_type + "_rev"] = conf[logic_type]
for inst in resolve_inst(block["file"]):
targ_inst[inst] = conf
# We need to provide vars to link the tracks and beams.
for block in res.find_all("LinkEnt"):
# The name for this set of entities.
# It must be a '@' name, or the name will be fixed-up incorrectly!
loc_name = block["name"]
if not loc_name.startswith("@"):
loc_name = "@" + loc_name
links[block["nameVar"]] = {
"name": loc_name,
# The next entity (not set in end logic)
"next": block["nextVar"],
# A '*' name to reference all the ents (set on the start logic)
"all": block["allVar", None],
}
return group # We look up the group name to find the values.
示例4: test_conv_bool
def test_conv_bool(self):
for val in true_strings:
self.assertTrue(utils.conv_bool(val))
for val in false_strings:
self.assertFalse(utils.conv_bool(val))
# Check that bools pass through
self.assertTrue(utils.conv_bool(True))
self.assertFalse(utils.conv_bool(False))
# None passes through the default
for val in def_vals:
self.assertIs(utils.conv_bool(None, val), val)
示例5: parse
def parse(cls, data):
name = data.info['name']
unstyled = utils.conv_bool(data.info['unstyled', '0'])
default = utils.conv_bool(data.info['enabled', '0'])
styles = [
prop.value
for prop in data.info.find_all('Style')
]
return cls(
data.id,
name,
styles,
unstyled=unstyled,
default=default,
)
示例6: res_add_global_inst
def res_add_global_inst(_, res):
"""Add one instance in a location.
Once this is executed, it will be ignored thereafter.
"""
if res.value is not None:
if utils.conv_bool(res["allow_multiple", "0"]) or res["file"] not in GLOBAL_INSTANCES:
# By default we will skip adding the instance
# if was already added - this is helpful for
# items that add to original items, or to avoid
# bugs.
new_inst = VLib.Entity(
VMF,
keys={
"classname": "func_instance",
"targetname": res["name", ""],
"file": resolve_inst(res["file"])[0],
"angles": res["angles", "0 0 0"],
"origin": res["position", "0 0 -10000"],
"fixup_style": res["fixup_style", "0"],
},
)
GLOBAL_INSTANCES.add(res["file"])
if new_inst["targetname"] == "":
new_inst["targetname"] = "inst_"
new_inst.make_unique()
VMF.add_ent(new_inst)
return True # Remove this result
示例7: flag_angles
def flag_angles(inst, flag):
"""Check that a instance is pointed in a direction."""
angle = inst["angles", "0 0 0"]
if flag.has_children():
targ_angle = flag["direction", "0 0 0"]
from_dir = flag["from_dir", "0 0 1"]
if from_dir.casefold() in DIRECTIONS:
from_dir = Vec(DIRECTIONS[from_dir.casefold()])
else:
from_dir = Vec.from_str(from_dir, 0, 0, 1)
allow_inverse = utils.conv_bool(flag["allow_inverse", "0"])
else:
targ_angle = flag.value
from_dir = Vec(0, 0, 1)
allow_inverse = False
if angle == targ_angle:
return True # Check for exact match
normal = DIRECTIONS.get(targ_angle.casefold(), None)
if normal is None:
return False # If it's not a special angle,
# so it failed the exact match
angle = Vec.from_str(angle, 0, 0, 0)
inst_normal = from_dir.rotate(angle.x, angle.y, angle.z)
if normal == "WALL":
# Special case - it's not on the floor or ceiling
return not (inst_normal == (0, 0, 1) or inst_normal == (0, 0, -1))
else:
return inst_normal == normal or (allow_inverse and -inst_normal == normal)
示例8: res_rand_vec
def res_rand_vec(inst, res):
"""A modification to RandomNum which generates a random vector instead.
'decimal', 'seed' and 'ResultVar' work like RandomNum. min/max x/y/z
are for each section. If the min and max are equal that number will be used
instead.
"""
is_float = utils.conv_bool(res['decimal'])
var = res['resultvar', '$random']
seed = res['seed', 'random']
random.seed(inst['origin'] + inst['angles'] + 'random_' + seed)
if is_float:
func = random.uniform
else:
func = random.randint
value = Vec()
for axis in 'xyz':
max_val = utils.conv_float(res['max_' + axis, 0.0])
min_val = utils.conv_float(res['min_' + axis, 0.0])
if min_val == max_val:
value[axis] = min_val
else:
value[axis] = func(min_val, max_val)
inst.fixup[var] = value.join(' ')
示例9: res_add_global_inst
def res_add_global_inst(_, res):
"""Add one instance in a location.
Once this is executed, it will be ignored thereafter.
"""
if res.value is not None:
if (res['file'] not in GLOBAL_INSTANCES or
utils.conv_bool(res['allow_multiple', '0'], True)):
# By default we will skip adding the instance
# if was already added - this is helpful for
# items that add to original items, or to avoid
# bugs.
new_inst = VLib.Entity(VMF, keys={
"classname": "func_instance",
"targetname": res['name', ''],
"file": resolve_inst(res['file'])[0],
"angles": res['angles', '0 0 0'],
"origin": res['position', '0 0 -10000'],
"fixup_style": res['fixup_style', '0'],
})
GLOBAL_INSTANCES.append(res['file'])
if new_inst['targetname'] == '':
new_inst['targetname'] = "inst_"
new_inst.make_unique()
VMF.add_ent(new_inst)
res.value = None # Disable this
示例10: res_replace_instance
def res_replace_instance(inst: VLib.Entity, res):
"""Replace an instance with another entity.
'keys' and 'localkeys' defines the new keyvalues used.
'targetname' and 'angles' are preset, and 'origin' will be used to offset
the given amount from the current location.
If 'keep_instance' is true, the instance entity will be kept instead of
removed.
"""
import vbsp
origin = Vec.from_str(inst['origin'])
angles = inst['angles']
if not utils.conv_bool(res['keep_instance', '0'], False):
inst.remove() # Do this first to free the ent ID, so the new ent has
# the same one.
# We copy to allow us to still acess the $fixups and other values.
new_ent = inst.copy(des_id=inst.id)
new_ent.clear_keys()
# Ensure there's a classname, just in case.
new_ent['classname'] = 'info_null'
vbsp.VMF.add_ent(new_ent)
conditions.set_ent_keys(new_ent, inst, res)
origin += Vec.from_str(new_ent['origin']).rotate_by_str(angles)
new_ent['origin'] = origin
new_ent['angles'] = angles
new_ent['targetname'] = inst['targetname']
示例11: generate_resp_script
def generate_resp_script(file, allow_dings):
"""Write the responses section into a file."""
use_dings = allow_dings
config = ConfigFile('resp_voice.cfg', root='bee2')
file.write("BEE2_RESPONSES <- {\n")
for section in QUOTE_DATA.find_key('CoopResponses', []):
if not section.has_children() and section.name == 'use_dings':
# Allow overriding specifically for the response script
use_dings = utils.conv_bool(section.value, allow_dings)
continue
voice_attr = RESP_HAS_NAMES.get(section.name, '')
if voice_attr and not map_attr[voice_attr]:
continue
# This response catagory isn't present
section_data = ['\t{} = [\n'.format(section.name)]
for index, line in enumerate(section):
if not config.getboolean(section.name, "line_" + str(index), True):
# It's disabled!
continue
section_data.append(
'\t\tCreateSceneEntity("{}"),\n'.format(line['choreo'])
)
if len(section_data) != 1:
for line in section_data:
file.write(line)
file.write('\t],\n')
file.write('}\n')
file.write('BEE2_PLAY_DING = {};\n'.format(
'true' if use_dings else 'false'
))
示例12: res_cust_output
def res_cust_output(inst, res):
"""Add an additional output to the instance with any values.
Always points to the targeted item.
"""
over_name = '@' + inst['targetname'] + '_indicator'
for toggle in VMF.by_class['func_instance']:
if toggle.fixup['indicator_name', ''] == over_name:
toggle_name = toggle['targetname']
break
else:
toggle_name = '' # we want to ignore the toggle instance, if it exists
# Make this a set to ignore repeated targetnames
targets = {o.target for o in inst.outputs if o.target != toggle_name}
kill_signs = utils.conv_bool(res["remIndSign", '0'], False)
dec_con_count = utils.conv_bool(res["decConCount", '0'], False)
targ_conditions = list(res.find_all("targCondition"))
pan_files = resolve_inst('[indPan]')
if kill_signs or dec_con_count or targ_conditions:
for con_inst in VMF.by_class['func_instance']:
if con_inst['targetname'] in targets:
if kill_signs and con_inst in pan_files:
VMF.remove_ent(con_inst)
if targ_conditions:
for cond in targ_conditions:
cond.value.test(con_inst)
if dec_con_count and 'connectioncount' in con_inst.fixup:
# decrease ConnectionCount on the ents,
# so they can still process normal inputs
try:
val = int(con_inst.fixup['connectioncount'])
con_inst.fixup['connectioncount'] = str(val-1)
except ValueError:
# skip if it's invalid
utils.con_log(
con_inst['targetname'] +
' has invalid ConnectionCount!'
)
for targ in targets:
for out in res.find_all('addOut'):
add_output(inst, out, targ)
示例13: flag_is_preview
def flag_is_preview(_, flag):
"""Checks if the preview mode status equals the given value.
If preview mode is enabled, the player will start before the entry
door, and restart the map after reaching the exit door. If false,
they start in the elevator.
Preview mode is always False when publishing.
"""
import vbsp
return vbsp.IS_PREVIEW == utils.conv_bool(flag.value, False)
示例14: parse
def parse(cls, data):
"""Parse an item definition."""
versions = {}
def_version = None
folders = {}
needs_unlock = utils.conv_bool(data.info['needsUnlock', '0'])
for ver in data.info.find_all('version'):
vals = {
'name': ver['name', 'Regular'],
'id': ver['ID', 'VER_DEFAULT'],
'is_wip': utils.conv_bool(ver['wip', '0']),
'is_dep': utils.conv_bool(ver['deprecated', '0']),
'styles': {},
'def_style': None,
}
for sty_list in ver.find_all('styles'):
for sty in sty_list:
if vals['def_style'] is None:
vals['def_style'] = sty.value
vals['styles'][sty.real_name] = sty.value
folders[sty.value] = True
versions[vals['id']] = vals
if def_version is None:
def_version = vals
parse_item_folder(folders, data.zip_file)
for ver in versions.values():
if ver['def_style'] in folders:
ver['def_style'] = folders[ver['def_style']]
for sty, fold in ver['styles'].items():
ver['styles'][sty] = folders[fold]
if not versions:
raise ValueError('Item "' + data.id + '" has no versions!')
return cls(data.id, versions, def_version, needs_unlock)
示例15: res_change_inputs_setup
def res_change_inputs_setup(res: Property):
vals = {}
for prop in res:
out_key = VLib.Output.parse_name(prop.real_name)
if prop.has_children():
vals[out_key] = (
prop['inst_in', None],
prop['input'],
prop['params', ''],
utils.conv_float(prop['delay', 0.0]),
1 if utils.conv_bool(prop['only_once', '0']) else -1,
)
else:
vals[out_key] = None
return vals