Skip to content

Commit

Permalink
Add GlobalInput result
Browse files Browse the repository at this point in the history
This allows sharing @global relays among different items.
  • Loading branch information
TeamSpen210 committed Jun 23, 2016
1 parent ba5ec61 commit 88a743c
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions src/conditions/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
"""
import operator

from typing import Dict, Optional

import conditions
import srctools
from conditions import (
make_flag, make_result,
make_flag, make_result, make_result_setup,
ALL_INST,
)
from instanceLocs import resolve as resolve_inst
from srctools import Vec, Entity
from srctools import Property, Vec, Entity, Output


@make_flag('instance')
Expand Down Expand Up @@ -190,3 +192,67 @@ def res_replace_instance(inst: Entity, res):
new_ent['origin'] = origin
new_ent['angles'] = angles
new_ent['targetname'] = inst['targetname']


GLOBAL_INPUT_ENTS = {} # type: Dict[Optional[str], Entity]


@make_result_setup('GlobalInput')
def res_global_input_setup(res):
target = res['target', ''] or None
name = res['name', ''] or None
output = res['output', 'OnTrigger']
param = res['param', '']
delay = srctools.conv_float(res['delay', ''])
inp_name, inp_command = Output.parse_name(res['input'])

return name, inp_name, inp_command, output, delay, param, target


@make_result('GlobalInput')
def res_global_input(inst: Entity, res: Property):
"""Trigger an input either on map spawn, or when a relay is triggered.
Arguments:
- "Input": the input to use, either a name or an instance: command.
- "Target": If set, a local name to send commands to.
- "Delay": Number of seconds to delay the input.
- "Name": If set the name of the logic_relay which must be triggered.
If not set the output will fire OnMapSpawn.
- "Output": The name of the output, defaulting to OnTrigger. Ignored
if Name is not set.
- "Param": The parameter for the output.
"""
name, inp_name, inp_command, output, delay, param, target = res.value

name = conditions.resolve_value(inst, name)
target = conditions.resolve_value(inst, target)

try:
glob_ent = GLOBAL_INPUT_ENTS[name]
except KeyError:
if name is None:
glob_ent = GLOBAL_INPUT_ENTS[None] = inst.map.create_ent(
classname='logic_auto',
origin=inst['origin'],
)
else:
glob_ent = GLOBAL_INPUT_ENTS[name] = inst.map.create_ent(
classname='logic_relay',
targetname=name,
origin=inst['origin'],
)

out = Output(
out=('OnMapSpawn' if name is None else output),
targ=(
conditions.local_name(inst, target)
if target else
inst['targetname']
),
inp=inp_command,
inst_in=inp_name,
delay=delay,
param=conditions.resolve_value(inst, param),
)
glob_ent.add_out(out)

0 comments on commit 88a743c

Please sign in to comment.