本文整理汇总了Python中srctools.Property.set_key方法的典型用法代码示例。如果您正苦于以下问题:Python Property.set_key方法的具体用法?Python Property.set_key怎么用?Python Property.set_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类srctools.Property
的用法示例。
在下文中一共展示了Property.set_key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_instance_data
# 需要导入模块: from srctools import Property [as 别名]
# 或者: from srctools.Property import set_key [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", [])
item_classes = Property("ItemClasses", [])
root_block = Property(None, [instance_locs, item_classes, 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)
# Allow the name to start with 'bee2_' also to match
# the <> definitions - it's ignored though.
name = inst.name
if name[:5] == "bee2_":
name = name[5:]
cust_inst.set_key(
(item["type"], 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
# Fizzlers don't work correctly with outputs. This is a signal to
# conditions.fizzler, but it must be removed in editoritems.
if item["ItemClass", ""].casefold() == "itembarrierhazard":
for block in item.find_all("Exporting", "Outputs"):
if CONN_NORM in block:
del block[CONN_NORM]
# Record the itemClass for each item type.
item_classes[item["type"]] = item["ItemClass", "ItemBase"]
# Only add the block if the item actually has IO.
if comm_block.value:
commands.append(comm_block)
return root_block.export()