本文整理汇总了Python中srctools.Property.int方法的典型用法代码示例。如果您正苦于以下问题:Python Property.int方法的具体用法?Python Property.int怎么用?Python Property.int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类srctools.Property
的用法示例。
在下文中一共展示了Property.int方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: res_make_tag_fizzler_setup
# 需要导入模块: from srctools import Property [as 别名]
# 或者: from srctools.Property import int [as 别名]
def res_make_tag_fizzler_setup(res: Property):
"""We need this to pre-parse the fizzler type."""
if 'ioconf' in res:
fizz_type = ItemType.parse('<TAG_FIZZER>', res.find_key('ioconf'))
else:
fizz_type = None
# The distance from origin the double signs are seperated by.
sign_offset = res.int('signoffset', 16)
return (
sign_offset,
fizz_type,
res['frame_double'],
res['frame_single'],
res['blue_sign', ''],
res['blue_off_sign', ''],
res['oran_sign', ''],
res['oran_off_sign', ''],
)
示例2: widget_minute_seconds
# 需要导入模块: from srctools import Property [as 别名]
# 或者: from srctools.Property import int [as 别名]
def widget_minute_seconds(parent: tk.Frame, var: tk.StringVar, conf: Property) -> tk.Widget:
"""A widget for specifying times - minutes and seconds.
The value is saved as seconds.
Max specifies the largest amount.
"""
max_value = conf.int('max', 60)
min_value = conf.int('min', 0)
if min_value > max_value:
raise ValueError('Bad min and max values!')
values = timer_values(min_value, max_value)
# Stores the 'pretty' value in the actual textbox.
disp_var = tk.StringVar()
existing_value = var.get()
def update_disp(var_name: str, var_index: str, operation: str) -> None:
"""Whenever the string changes, update the displayed text."""
seconds = conv_int(var.get(), -1)
if min_value <= seconds <= max_value:
disp_var.set('{}:{:02}'.format(seconds // 60, seconds % 60))
else:
LOGGER.warning('Bad timer value "{}" for "{}"!', var.get(), conf['id'])
# Recurse, with a known safe value.
var.set(values[0])
# Whenever written to, call this.
var.trace_add('write', update_disp)
def set_var():
"""Set the variable to the current value."""
try:
minutes, seconds = disp_var.get().split(':')
var.set(str(int(minutes) * 60 + int(seconds)))
except (ValueError, TypeError):
pass
def validate(reason: str, operation_type: str, cur_value: str, new_char: str, new_value: str):
"""Validate the values for the text.
This is called when the textbox is modified, to allow cancelling bad
inputs.
Reason is the reason this was fired: 'key', 'focusin', 'focusout', 'forced'.
operation_type is '1' for insert, '0' for delete', '-1' for programmatic changes.
cur_val is the value before the change occurs.
new_char is the added/removed text.
new_value is the value after the change, if accepted.
"""
if operation_type == '0' or reason == 'forced':
# Deleting or done by the program, allow that always.
return True
if operation_type == '1': # Inserted text.
# Disallow non number and colons
if new_char not in '0123456789:':
return False
# Only one colon.
if ':' in cur_value and new_char == ':':
return False
# Don't allow more values if it has more than 2 numbers after
# the colon - if there is one, and it's not in the last 3 characters.
if ':' in new_value and ':' not in new_value[-3:]:
return False
if reason == 'focusout':
# When leaving focus, apply range limits and set the var.
try:
str_min, str_sec = new_value.split(':')
seconds = int(str_min) * 60 + int(str_sec)
except (ValueError, TypeError):
seconds = min_value
else:
if seconds < min_value:
seconds = min_value
if seconds > max_value:
seconds = max_value
var.set(str(seconds)) # This then re-writes the textbox.
return True
validate_cmd = parent.register(validate)
spinbox = tk.Spinbox(
parent,
exportselection=False,
textvariable=disp_var,
command=set_var,
wrap=True,
values=values,
width=5,
validate='all',
# These define which of the possible values will be passed along.
# http://tcl.tk/man/tcl8.6/TkCmd/spinbox.htm#M26
validatecommand=(validate_cmd, '%V', '%d', '%s', '%S', '%P'),
)
# We need to set this after, it gets reset to the first one.
#.........这里部分代码省略.........
示例3: res_goo_debris
# 需要导入模块: from srctools import Property [as 别名]
# 或者: from srctools.Property import int [as 别名]
def res_goo_debris(res: Property):
"""Add random instances to goo squares.
Options:
- file: The filename for the instance. The variant files should be
suffixed with `_1.vmf`, `_2.vmf`, etc.
- space: the number of border squares which must be filled with goo
for a square to be eligible - defaults to 1.
- weight, number: see the `Variant` result, a set of weights for the
options
- chance: The percentage chance a square will have a debris item
- offset: A random xy offset applied to the instances.
"""
import brushLoc
space = res.int('spacing', 1)
rand_count = res.int('number', None)
if rand_count:
rand_list = weighted_random(
rand_count,
res['weights', ''],
)
else:
rand_list = None # type: Optional[List[int]]
chance = res.int('chance', 30) / 100
file = res['file']
offset = res.int('offset', 0)
if file.endswith('.vmf'):
file = file[:-4]
goo_top_locs = {
pos.as_tuple()
for pos, block in
brushLoc.POS.items()
if block.is_goo and block.is_top
}
if space == 0:
# No spacing needed, just copy
possible_locs = [Vec(loc) for loc in goo_top_locs]
else:
possible_locs = []
for x, y, z in goo_top_locs:
# Check to ensure the neighbouring blocks are also
# goo brushes (depending on spacing).
for x_off, y_off in utils.iter_grid(
min_x=-space,
max_x=space + 1,
min_y=-space,
max_y=space + 1,
stride=1,
):
if x_off == y_off == 0:
continue # We already know this is a goo location
if (x + x_off, y + y_off, z) not in goo_top_locs:
break # This doesn't qualify
else:
possible_locs.append(brushLoc.grid_to_world(Vec(x,y,z)))
LOGGER.info(
'GooDebris: {}/{} locations',
len(possible_locs),
len(goo_top_locs),
)
suff = ''
for loc in possible_locs:
random.seed('goo_debris_{}_{}_{}'.format(loc.x, loc.y, loc.z))
if random.random() > chance:
continue
if rand_list is not None:
suff = '_' + str(random.choice(rand_list) + 1)
if offset > 0:
loc.x += random.randint(-offset, offset)
loc.y += random.randint(-offset, offset)
loc.z -= 32 # Position the instances in the center of the 128 grid.
VMF.create_ent(
classname='func_instance',
file=file + suff + '.vmf',
origin=loc.join(' '),
angles='0 {} 0'.format(random.randrange(0, 3600)/10)
)
return RES_EXHAUSTED