simvx.core.input.players

Who an action belongs to, when more than one person is playing.

Routing decides which tree an input reaches; ownership decides which player it belongs to, and the two are orthogonal. A player is an input identity: the devices paired to it, and its own action state and edges.

Input.players                          # mapping; player 0 is the default
two = Input.add_player()
two.pair(Input.controllers[1])            # join takes a pad out of the unpaired pool
node.input_player = two                # Input queries in this subtree answer for two

Device state is never per player. Input.is_key_pressed is a fact about the keyboard, and stays one whoever is holding what. Only what resolves from a binding is owned: the action queries, the action edges, and the action events delivered to handlers.

Player 0 is the default and owns every unpaired device, so a single-player game never sees this dimension: one implicit player owns everything, every query resolves to it, and the fast path through the resolver is the one that was there before players existed.

The join and leave flow, split-screen viewports and per-player UI focus are deliberately not built. This is the seam they will sit on.

Module Contents

Classes

InputPlayer

One player’s input identity. Read them through Input.players.

Data

API

simvx.core.input.players.__all__

[‘InputPlayer’]

simvx.core.input.players.DEFAULT_PLAYER

0

class simvx.core.input.players.InputPlayer(state: simvx.core.input.state._Input, player_id: int)[source]

One player’s input identity. Read them through Input.players.

A game with one player never touches this: Input.pressed("jump") answers for the default player, which owns everything. A co-op game pairs a pad to each player and sets input_player on each player’s subtree, and the same call inside that subtree answers for that player.

Initialization

__slots__

(‘_id’, ‘_state’, ‘_pads’, ‘_desk’)

__repr__() → str[source]
property id: int[source]

The player’s id, which is the key it has in Input.players.

property is_default: bool[source]

Whether this is player 0, which owns every device nobody else claimed.

property devices: tuple[simvx.core.input.players.PairableDevice, ...][source]

What is paired to this player, explicitly.

Empty for the default player of a game that paired nothing, which still owns every device: what it owns is everything unclaimed rather than a list, so there is nothing to enumerate.

pair(device: simvx.core.input.players.PairableDevice) → None[source]

Take device for this player, out of the unpaired pool.

Args: device: A :class:~.devices.ControllerDevice from Input.controllers, or InputMethod.KEYBOARD_MOUSE for the desk. A device may be paired to more than one player, which is how one keyboard is split between two: the pairing says who hears it and the bindings say what each of them hears.

unpair(device: simvx.core.input.players.PairableDevice) → None[source]

Give device back to the unpaired pool. Unpairing what was never paired does nothing.

owns(device: simvx.core.input.players.PairableDevice) → bool[source]

Whether input from device belongs to this player.

True for anything explicitly paired, and for the default player also for anything no other player claimed.

pressed(action: str) → bool[source]

Is action open for this player?

just_pressed(action: str) → bool[source]

Did action open for this player during this frame?

just_released(action: str) → bool[source]

Did action close for this player during this frame?

value(action: str) → bool | float | simvx.core.math.types.Vec2[source]

What action reads for this player, in the type its bindings gave it.

get_action_strength(action: str) → float[source]

How hard this player is pushing action, 0.0 to 1.0.