本文整理汇总了Python中utils.conv_bool函数的典型用法代码示例。如果您正苦于以下问题:Python conv_bool函数的具体用法?Python conv_bool怎么用?Python conv_bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了conv_bool函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
)
开发者ID:Stendec-UA,项目名称:BEE2.4,代码行数:60,代码来源:packageLoader.py
示例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
开发者ID:goodDOS,项目名称:BEE2.4,代码行数:60,代码来源:positioning.py
示例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.
开发者ID:goodDOS,项目名称:BEE2.4,代码行数:52,代码来源:scaffold.py
示例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)
开发者ID:GLiTcH2,项目名称:BEE2.4,代码行数:13,代码来源:test_utils.py
示例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,
)
开发者ID:xDadiKx,项目名称:BEE2.4,代码行数:15,代码来源:packageLoader.py
示例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
开发者ID:xDadiKx,项目名称:BEE2.4,代码行数:28,代码来源:conditions.py
示例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)
开发者ID:xDadiKx,项目名称:BEE2.4,代码行数:33,代码来源:conditions.py
示例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(' ')
开发者ID:Coolasp1e,项目名称:BEE2.4,代码行数:29,代码来源:randomise.py
示例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
开发者ID:NotFirestorm348,项目名称:BEE2.4,代码行数:26,代码来源:conditions.py
示例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']
开发者ID:Coolasp1e,项目名称:BEE2.4,代码行数:32,代码来源:instances.py
示例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'
))
开发者ID:GLiTcH2,项目名称:BEE2.4,代码行数:34,代码来源:voiceLine.py
示例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)
开发者ID:NotFirestorm348,项目名称:BEE2.4,代码行数:45,代码来源:conditions.py
示例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)
开发者ID:goodDOS,项目名称:BEE2.4,代码行数:11,代码来源:globals.py
示例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)
开发者ID:NotFirestorm348,项目名称:BEE2.4,代码行数:39,代码来源:packageLoader.py
示例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
开发者ID:Coolasp1e,项目名称:BEE2.4,代码行数:15,代码来源:custItems.py
示例16: res_add_overlay_inst
def res_add_overlay_inst(inst, res):
"""Add another instance on top of this one."""
print("adding overlay", res["file"])
overlay_inst = VMF.create_ent(
classname="func_instance",
targetname=inst["targetname", ""],
file=resolve_inst(res["file", ""])[0],
angles=inst["angles", "0 0 0"],
origin=inst["origin"],
fixup_style=res["fixup_style", "0"],
)
if utils.conv_bool(res["copy_fixup", "1"]):
# Copy the fixup values across from the original instance
for fixup, value in inst.fixup.items():
overlay_inst.fixup[fixup] = value
开发者ID:xDadiKx,项目名称:BEE2.4,代码行数:15,代码来源:conditions.py
示例17: res_vactube_setup
def res_vactube_setup(res):
group = res['group', 'DEFAULT_GROUP']
if group not in VAC_CONFIGS:
# Store our values in the CONFIGS dictionary
config, inst_configs = VAC_CONFIGS[group] = {}, {}
else:
# Grab the already-filled values, and add to them
config, inst_configs = VAC_CONFIGS[group]
for block in res.find_all("Instance"):
# Configuration info for each instance set..
conf = {
# The three sizes of corner instance
('corner', 1): block['corner_small_inst', ''],
('corner', 2): block['corner_medium_inst', ''],
('corner', 3): block['corner_large_inst', ''],
('corner_temp', 1): block['temp_corner_small', ''],
('corner_temp', 2): block['temp_corner_medium', ''],
('corner_temp', 3): block['temp_corner_large', ''],
# Straight instances connected to the next part
'straight': block['straight_inst', ''],
# Supports attach to the 4 sides of the straight part,
# if there's a brush there.
'support': block['support_inst', ''],
'is_tsection': utils.conv_bool(block['is_tsection', '0']),
('entry', 'wall'): block['entry_inst'],
('entry', 'floor'): block['entry_floor_inst'],
('entry', 'ceiling'): block['entry_ceil_inst'],
'exit': block['exit_inst'],
}
for prop in block.find_all("File"):
try:
size, file = prop.value.split(":", 1)
except ValueError:
size = 1
file = prop.value
inst_configs[resolve_inst(file)[0]] = conf, utils.conv_int(size, 1)
return group
开发者ID:GLiTcH2,项目名称:BEE2.4,代码行数:48,代码来源:vactubes.py
示例18: res_cust_output_setup
def res_cust_output_setup(res):
conds = [
Condition.parse(sub_res)
for sub_res in res
if sub_res.name == 'targcondition'
]
outputs = list(res.find_all('addOut'))
dec_con_count = utils.conv_bool(res["decConCount", '0'], False)
sign_type = IND_PANEL_TYPES.get(res['sign_type', None], None)
if sign_type is None:
sign_act = sign_deact = (None, '')
else:
# The outputs which trigger the sign.
sign_act = VLib.Output.parse_name(res['sign_activate', ''])
sign_deact = VLib.Output.parse_name(res['sign_deactivate', ''])
return outputs, dec_con_count, conds, sign_type, sign_act, sign_deact
开发者ID:goodDOS,项目名称:BEE2.4,代码行数:18,代码来源:custItems.py
示例19: flag_angles
def flag_angles(inst, flag):
"""Check that a instance is pointed in a direction.
The value should be either just the angle to check, or a block of
options:
- Angle: A unit vector (XYZ value) pointing in a direction, or some
keywords: +z, -y, N/S/E/W, up/down, floor/ceiling, or walls
- From_dir: The direction the unrotated instance is pointed in.
This lets the flag check multiple directions
- Allow_inverse: If true, this also returns True if the instance is
pointed the opposite 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
inst_normal = from_dir.rotate_by_str(angle)
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
)
开发者ID:goodDOS,项目名称:BEE2.4,代码行数:44,代码来源:positioning.py
示例20: make_static_pist
def make_static_pist(ent, res):
"""Convert a regular piston into a static version.
This is done to save entities and improve lighting."""
bottom_pos = ent.fixup["bottom_level", "-1"]
if ent.fixup["connectioncount", "0"] != "0" or ent.fixup["disable_autodrop", "0"] != "0": # can it move?
if int(bottom_pos) > 0:
# The piston doesn't go fully down, use alt instances.
val = res.value["bottom_" + bottom_pos]
if val: # Only if defined
ent["file"] = val
else: # we are static
val = res.value[
"static_" + (ent.fixup["top_level", "1"] if utils.conv_bool(ent.fixup["start_up"], False) else bottom_pos)
]
if val:
ent["file"] = val
开发者ID:xDadiKx,项目名称:BEE2.4,代码行数:19,代码来源:conditions.py
注:本文中的utils.conv_bool函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论