本文整理匯總了Python中srctools.Vec.from_str方法的典型用法代碼示例。如果您正苦於以下問題:Python Vec.from_str方法的具體用法?Python Vec.from_str怎麽用?Python Vec.from_str使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類srctools.Vec
的用法示例。
在下文中一共展示了Vec.from_str方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: res_replace_instance
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def res_replace_instance(inst: Entity, res: Property):
"""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 srctools.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 access 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']
示例2: join_markers
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def join_markers(inst_a, inst_b, is_start=False):
"""Join two marker ents together with corners.
This returns a list of solids used for the vphysics_motion trigger.
"""
origin_a = Vec.from_str(inst_a['ent']['origin'])
origin_b = Vec.from_str(inst_b['ent']['origin'])
norm_a = Vec(-1, 0, 0).rotate_by_str(inst_a['ent']['angles'])
norm_b = Vec(-1, 0, 0).rotate_by_str(inst_b['ent']['angles'])
config = inst_a['conf']
if norm_a == norm_b:
# Either straight-line, or s-bend.
dist = (origin_a - origin_b).mag()
if origin_a + (norm_a * dist) == origin_b:
make_straight(
origin_a,
norm_a,
dist,
config,
is_start,
)
# else: S-bend, we don't do the geometry for this..
return
if norm_a == -norm_b:
# U-shape bend..
make_ubend(
origin_a,
origin_b,
norm_a,
config,
max_size=inst_a['size'],
)
return
try:
corner_ang, flat_angle = CORNER_ANG[norm_a.as_tuple(), norm_b.as_tuple()]
if origin_a[flat_angle] != origin_b[flat_angle]:
# It needs to be flat in this angle!
raise ValueError
except ValueError:
# The tubes need two corners to join together - abort for that.
return
else:
make_bend(
origin_a,
origin_b,
norm_a,
norm_b,
corner_ang,
config,
max_size=inst_a['size'],
)
示例3: res_sendificator
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def res_sendificator(vmf: VMF, inst: Entity):
"""Implement Sendificators."""
# For our version, we know which sendtor connects to what laser,
# so we can couple the logic together (avoiding @sendtor_mutex).
sendtor_name = inst['targetname']
sendtor = connections.ITEMS[sendtor_name]
sendtor.enable_cmd += (Output(
'',
'@{}_las_relay_*'.format(sendtor_name),
'Trigger',
delay=0.01,
), )
for ind, conn in enumerate(list(sendtor.outputs), start=1):
las_item = conn.to_item
conn.remove()
try:
targ_offset, targ_normal = SENDTOR_TARGETS[las_item.name]
except KeyError:
LOGGER.warning('"{}" is not a Sendificator target!', las_item.name)
continue
angles = Vec.from_str(las_item.inst['angles'])
targ_offset = targ_offset.copy()
targ_normal = targ_normal.copy().rotate(*angles)
targ_offset.localise(
Vec.from_str(las_item.inst['origin']),
angles,
)
relay_name = '@{}_las_relay_{}'.format(sendtor_name, ind)
relay = vmf.create_ent(
'logic_relay',
targetname=relay_name,
origin=targ_offset,
angles=targ_normal.to_angle(),
)
relay.add_out(
Output('OnTrigger', '!self', 'RunScriptCode', '::sendtor_source <- self;'),
Output('OnTrigger', '@sendtor_fire', 'Trigger'),
)
if not las_item.inputs:
# No other inputs, make it on always. PeTI automatically turns
# it off when inputs are connected, which is annoying.
las_item.inst.fixup['$start_enabled'] = '1'
is_on = True
else:
is_on = las_item.inst.fixup.bool('$start_enabled')
relay['StartDisabled'] = not is_on
las_item.enable_cmd += (Output('', relay_name, 'Enable'),)
las_item.disable_cmd += (Output('', relay_name, 'Disable'),)
LOGGER.info('Relay: {}', relay)
示例4: res_unst_scaffold_setup
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def res_unst_scaffold_setup(res: Property):
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': srctools.conv_bool(block['isPiston', '0']),
'rotate_logic': srctools.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 instanceLocs.resolve(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.
示例5: res_camera_setup
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def res_camera_setup(res: Property):
return {
'cam_off': Vec.from_str(res['CamOff', '']),
'yaw_off': Vec.from_str(res['YawOff', '']),
'pitch_off': Vec.from_str(res['PitchOff', '']),
'yaw_inst': instanceLocs.resolve_one(res['yawInst', '']),
'pitch_inst': instanceLocs.resolve_one(res['pitchInst', '']),
'yaw_range': srctools.conv_int(res['YawRange', ''], 90),
'pitch_range': srctools.conv_int(res['YawRange', ''], 90),
}
示例6: res_make_funnel_light
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def res_make_funnel_light(inst: Entity):
"""Place a light for Funnel items."""
oran_on = inst.fixup.bool('$start_reversed')
need_blue = need_oran = False
name = ''
if inst.fixup['$connectioncount_polarity'] != '0':
import vbsp
if not vbsp.settings['style_vars']['funnelallowswitchedlights']:
# Allow disabling adding switchable lights.
return
name = conditions.local_name(inst, 'light')
need_blue = need_oran = True
else:
if oran_on:
need_oran = True
else:
need_blue = True
loc = Vec(0, 0, -56)
loc.localise(Vec.from_str(inst['origin']), Vec.from_str(inst['angles']))
if need_blue:
inst.map.create_ent(
classname='light',
targetname=name + '_b' if name else '',
spawnflags=int(oran_on), # 1 = Initially Dark
origin=loc,
_light='50 120 250 50',
_lightHDR='-1 -1 -1 1',
_lightscaleHDR=2,
_fifty_percent_distance=48,
_zero_percent_distance=96,
_hardfalloff=1,
_distance=0,
style=0,
)
if need_oran:
inst.map.create_ent(
classname='light',
targetname=name + '_o' if name else '',
spawnflags=int(not oran_on),
origin=loc,
_light='250 120 50 50',
_lightHDR='-1 -1 -1 1',
_lightscaleHDR=2,
_fifty_percent_distance=48,
_zero_percent_distance=96,
_hardfalloff=1,
_distance=0,
style=0,
)
示例7: res_monitor
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def res_monitor(inst: Entity, res: Property) -> None:
"""Result for the monitor component.
"""
import vbsp
(
break_inst,
bullseye_name,
bullseye_loc,
bullseye_parent,
) = res.value
ALL_MONITORS.append(Monitor(inst))
has_laser = vbsp.settings['has_attr']['laser']
# Allow turrets if the monitor is setup to allow it, and the actor should
# be shot.
needs_turret = bullseye_name and vbsp_options.get(bool, 'voice_studio_should_shoot')
inst.fixup['$is_breakable'] = has_laser or needs_turret
# We need to generate an ai_relationship, which makes turrets hate
# a bullseye.
if needs_turret:
loc = Vec(bullseye_loc)
loc.localise(
Vec.from_str(inst['origin']),
Vec.from_str(inst['angles']),
)
bullseye_name = local_name(inst, bullseye_name)
inst.map.create_ent(
classname='npc_bullseye',
targetname=bullseye_name,
parentname=local_name(inst, bullseye_parent),
spawnflags=221186, # Non-solid, invisible, etc..
origin=loc,
)
relation = inst.map.create_ent(
classname='ai_relationship',
targetname='@monitor_turr_hate',
spawnflags=2, # Notify turrets about monitor locations
disposition=1, # Hate
origin=loc,
subject='npc_portal_turret_floor',
target=bullseye_name,
)
MONITOR_RELATIONSHIP_ENTS.append(relation)
示例8: get_config
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def get_config(
node: item_chain.Node,
) -> Tuple[str, Vec]:
"""Compute the config values for a node."""
orient = (
'floor' if
Vec(0, 0, 1).rotate_by_str(node.inst['angles']) == (0, 0, 1)
else 'wall'
)
# Find the offset used for the platform.
offset = (node.conf['off_' + orient]).copy() # type: Vec
if node.conf['is_piston']:
# Adjust based on the piston position
offset.z += 128 * srctools.conv_int(
node.inst.fixup[
'$top_level' if
node.inst.fixup[
'$start_up'] == '1'
else '$bottom_level'
]
)
offset.rotate_by_str(node.inst['angles'])
offset += Vec.from_str(node.inst['origin'])
return orient, offset
示例9: find_glass_items
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def find_glass_items(config, vmf: VMF) -> Iterator[Tuple[str, Vec, Vec, Vec, dict]]:
"""Find the bounding boxes for all the glass items matching a config.
This yields (targetname, min, max, normal, config) tuples.
"""
# targetname -> min, max, normal, config
glass_items = {}
for inst in vmf.by_class['func_instance']: # type: Entity
try:
conf = config[inst['file'].casefold()]
except KeyError:
continue
targ = inst['targetname']
norm = Vec(x=1).rotate_by_str(inst['angles'])
origin = Vec.from_str(inst['origin']) - 64 * norm
try:
bbox_min, bbox_max, group_norm, group_conf = glass_items[targ]
except KeyError:
# First of this group..
bbox_min, bbox_max = origin.copy(), origin.copy()
group_norm = norm.copy()
glass_items[targ] = bbox_min, bbox_max, group_norm, conf
else:
bbox_min.min(origin)
bbox_max.max(origin)
assert group_norm == norm, '"{}" is inconsistently rotated!'.format(targ)
assert group_conf is conf, '"{}" has multiple configs!'.format(targ)
inst.remove()
for targ, (bbox_min, bbox_max, norm, conf) in glass_items.items():
yield targ, bbox_min, bbox_max, norm, conf
示例10: track_scan
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def track_scan(
tr_set: Set[Entity],
track_inst: Dict[Tuple[float, float, float], Entity],
start_track: Entity,
middle_file: str,
x_dir: int,
):
"""Build a set of track instances extending from a point.
:param track_inst: A dictionary mapping origins to track instances
:param start_track: The instance we start on
:param middle_file: The file for the center track piece
:param x_dir: The direction to look (-1 or 1)
"""
track = start_track
move_dir = Vec(x_dir*128, 0, 0).rotate_by_str(track['angles'])
while track:
tr_set.add(track)
next_pos = Vec.from_str(track['origin']) + move_dir
track = track_inst.get(next_pos.as_tuple(), None)
if track is None:
return
if track['file'].casefold() != middle_file:
# If the next piece is an end section, add it then quit
tr_set.add(track)
return
示例11: res_glass_hole
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def res_glass_hole(inst: Entity, res: Property):
"""Add Glass/grating holes. The value should be 'large' or 'small'."""
hole_type = HoleType(res.value)
normal = Vec(z=-1).rotate_by_str(inst['angles'])
origin = Vec.from_str(inst['origin']) // 128 * 128 + 64
if test_hole_spot(origin, normal, hole_type):
HOLES[origin.as_tuple(), normal.as_tuple()] = hole_type
inst['origin'] = origin
inst['angles'] = normal.to_angle()
return
# Test the opposite side of the glass too.
inv_origin = origin + 128 * normal
inv_normal = -normal
if test_hole_spot(inv_origin, inv_normal, hole_type):
HOLES[inv_origin.as_tuple(), inv_normal.as_tuple()] = hole_type
inst['origin'] = inv_origin
inst['angles'] = inv_normal.to_angle()
else:
# Remove the instance, so this does nothing.
inst.remove()
示例12: mon_remove_bullseyes
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def mon_remove_bullseyes(inst: Entity) -> Optional[object]:
"""Remove bullsyes used for cameras."""
if not BULLSYE_LOCS:
return RES_EXHAUSTED
if inst['file'].casefold() not in instanceLocs.resolve('<ITEM_CATAPULT_TARGET>'):
return
origin = Vec(0, 0, -64)
origin.localise(Vec.from_str(inst['origin']), Vec.from_str(inst['angles']))
origin = origin.as_tuple()
LOGGER.info('Pos: {} -> ', origin, BULLSYE_LOCS[origin])
if BULLSYE_LOCS[origin]:
BULLSYE_LOCS[origin] -= 1
inst.remove()
示例13: res_make_tag_coop_spawn
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def res_make_tag_coop_spawn(vmf: VMF, inst: Entity, res: Property):
"""Create the spawn point for ATLAS in the entry corridor.
It produces either an instance or the normal spawn entity. This is required since ATLAS may need to have the paint gun logic.
The two parameters `origin` and `facing` must be set to determine the required position.
If `global` is set, the spawn point will be absolute instead of relative to the current instance.
"""
if vbsp.GAME_MODE != 'COOP':
return RES_EXHAUSTED
is_tag = vbsp_options.get(str, 'game_id') == utils.STEAM_IDS['TAG']
origin = res.vec('origin')
normal = res.vec('facing', z=1)
# Some styles might want to ignore the instance we're running on.
if not res.bool('global'):
origin = origin.rotate_by_str(inst['angles'])
normal = normal.rotate_by_str(inst['angles'])
origin += Vec.from_str(inst['origin'])
angles = normal.to_angle()
if is_tag:
vmf.create_ent(
classname='func_instance',
targetname='paint_gun',
origin=origin - (0, 0, 16),
angles=angles,
# Generated by the BEE2 app.
file='instances/bee2/tag_coop_gun.vmf',
)
# Blocks ATLAS from having a gun
vmf.create_ent(
classname='info_target',
targetname='supress_blue_portalgun_spawn',
origin=origin,
angles='0 0 0',
)
# Allows info_target to work
vmf.create_ent(
classname='env_global',
targetname='no_spawns',
globalstate='portalgun_nospawn',
initialstate=1,
spawnflags=1, # Use initial state
origin=origin,
)
vmf.create_ent(
classname='info_coop_spawn',
targetname='@coop_spawn_blue',
ForceGunOnSpawn=int(not is_tag),
origin=origin,
angles=angles,
enabled=1,
StartingTeam=3, # ATLAS
)
return RES_EXHAUSTED
示例14: resolve_offset
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def resolve_offset(inst, value: str, scale: float=1, zoff: float=0) -> Vec:
"""Retrieve an offset from an instance var. This allows several special values:
* $var to read from a variable
* <piston_start> or <piston> to get the unpowered position of a piston plat
* <piston_end> to get the powered position of a piston plat
* <piston_top> to get the extended position of a piston plat
* <piston_bottom> to get the retracted position of a piston plat
If scale is set, read values are multiplied by this, and zoff is added to Z.
"""
value = value.casefold()
# Offset the overlay by the given distance
# Some special placeholder values:
if value == '<piston_start>' or value == '<piston>':
if inst.fixup.bool(const.FixupVars.PIST_IS_UP):
value = '<piston_top>'
else:
value = '<piston_bottom>'
elif value == '<piston_end>':
if inst.fixup.bool(const.FixupVars.PIST_IS_UP):
value = '<piston_bottom>'
else:
value = '<piston_top>'
if value == '<piston_bottom>':
offset = Vec(
z=inst.fixup.int(const.FixupVars.PIST_BTM) * 128,
)
elif value == '<piston_top>':
offset = Vec(
z=inst.fixup.int(const.FixupVars.PIST_TOP) * 128,
)
else:
# Regular vector
offset = Vec.from_str(resolve_value(inst, value)) * scale
offset.z += zoff
offset.localise(
Vec.from_str(inst['origin']),
Vec.from_str(inst['angles']),
)
return offset
示例15: res_water_splash_setup
# 需要導入模塊: from srctools import Vec [as 別名]
# 或者: from srctools.Vec import from_str [as 別名]
def res_water_splash_setup(res: Property):
parent = res['parent']
name = res['name']
scale = srctools.conv_float(res['scale', ''], 8.0)
pos1 = Vec.from_str(res['position', ''])
calc_type = res['type', '']
pos2 = res['position2', '']
fast_check = srctools.conv_bool(res['fast_check', ''])
return name, parent, scale, pos1, pos2, calc_type, fast_check