Skip to content

Commit b129b61

Browse files
committed
Updated Entity docs
1 parent 9779663 commit b129b61

File tree

1 file changed

+135
-36
lines changed
  • addons/source-python/packages/source-python/entities

1 file changed

+135
-36
lines changed

addons/source-python/packages/source-python/entities/entity.py

Lines changed: 135 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,18 @@
8989
# >> CLASSES
9090
# =============================================================================
9191
class Entity(BaseEntity):
92-
"""Class used to interact directly with entities."""
92+
"""Class used to interact directly with entities.
93+
94+
Beside the standard way of doing stuff via methods and properties this
95+
class also provides dynamic attributes that depend on the entity that is
96+
being accessed with this class. You can print all dynamic properties by
97+
iterating over the following generators:
98+
99+
1. :attr:`properties`
100+
2. :attr:`inputs`
101+
3. :attr:`outputs`
102+
4. :attr:`keyvalues`
103+
"""
93104

94105
def __init__(self, index):
95106
"""Initialize the Entity object."""
@@ -165,7 +176,13 @@ def __dir__(self):
165176

166177
@classmethod
167178
def create(cls, classname):
168-
"""Create a new networked entity with the given classname."""
179+
"""Create a new networked entity with the given classname.
180+
181+
:param str classname:
182+
Classname of the entity to create.
183+
:raise ValueError:
184+
Raised if the given classname is not a networked entity.
185+
"""
169186
entity = BaseEntity.create(classname)
170187
if entity.is_networked():
171188
return cls(entity.index)
@@ -212,13 +229,16 @@ def _obj(cls, ptr):
212229

213230
@property
214231
def index(self):
215-
"""Return the entity's index."""
232+
"""Return the entity's index.
233+
234+
:rtype: int
235+
"""
216236
return self._index
217-
237+
218238
@property
219239
def owner(self):
220240
"""Return the entity's owner.
221-
241+
222242
:return: None if the entity has no owner.
223243
:rtype: Entity
224244
"""
@@ -263,11 +283,18 @@ def keyvalues(self):
263283
yield from server_class.keyvalues
264284

265285
def get_color(self):
266-
"""Return the entity's color as a Color instance."""
286+
"""Return the entity's color.
287+
288+
:rtype: Color
289+
"""
267290
return self.render_color
268291

269292
def set_color(self, color):
270-
"""Set the entity's color."""
293+
"""Set the entity's color.
294+
295+
:param Color color:
296+
Color to set.
297+
"""
271298
# Set the entity's render mode
272299
self.render_mode = RenderMode.TRANS_COLOR
273300

@@ -283,11 +310,18 @@ def set_color(self, color):
283310
doc="""Property to get/set the entity's color values.""")
284311

285312
def get_model(self):
286-
"""Return the entity's model."""
313+
"""Return the entity's model.
314+
315+
:rtype: Model
316+
"""
287317
return Model(self.model_name)
288318

289319
def set_model(self, model):
290-
"""Set the entity's model to the given model."""
320+
"""Set the entity's model to the given model.
321+
322+
:param Model model:
323+
The model to set.
324+
"""
291325
self.model_index = model.index
292326
self.model_name = model.path
293327

@@ -523,7 +557,14 @@ def _callback(*args, **kwargs):
523557
return delay
524558

525559
def get_input(self, name):
526-
"""Return the InputFunction instance for the given name."""
560+
"""Return the input function matching the given name.
561+
562+
:parma str name:
563+
Name of the input function.
564+
:rtype: InputFunction
565+
:raise ValueError:
566+
Raised if the input function wasn't found.
567+
"""
527568
# Loop through each server class for the entity
528569
for server_class in self.server_classes:
529570

@@ -540,11 +581,27 @@ def get_input(self, name):
540581
name, self.classname))
541582

542583
def call_input(self, name, *args, **kwargs):
543-
"""Call the InputFunction instance for the given name."""
584+
"""Call the input function matching the given name.
585+
586+
:param str name:
587+
Name of the input function.
588+
:param args:
589+
Optional arguments that should be passed to the input function.
590+
:param kwargs:
591+
Optional keyword arguments that should be passed to the input
592+
function.
593+
:raise ValueError:
594+
Raised if the input function wasn't found.
595+
"""
544596
self.get_input(name)(*args, **kwargs)
545597

546598
def lookup_attachment(self, name):
547-
"""Return the attachment index matching the given name."""
599+
"""Return the attachment index matching the given name.
600+
601+
:param str name:
602+
The name of the attachment.
603+
:rtype: int
604+
"""
548605
# Get the ModelHeader instance of the entity
549606
model_header = self.model_header
550607

@@ -569,24 +626,38 @@ def emit_sound(
569626
download=False, stream=False):
570627
"""Emit a sound from this entity.
571628
572-
:param str sample: Sound file relative to the "sounds" directory.
573-
:param RecipientFilter recipients: Recipients to emit the sound to.
574-
:param int index: Index of the entity to emit the sound from.
575-
:param float volume: Volume of the sound.
576-
:param Attenuation attenuation: How far the sound should reaches.
577-
:param int channel: Channel to emit the sound with.
578-
:param SoundFlags flags: Flags of the sound.
579-
:param Pitch pitch: Pitch of the sound.
580-
:param Vector origin: Origin of the sound.
581-
:param Vector direction: Direction of the sound.
582-
:param tuple origins: Origins of the sound.
583-
:param bool update_positions: Whether or not the positions should be
584-
updated.
585-
:param float sound_time: Time to play the sound for.
586-
:param int speaker_entity: Index of the speaker entity.
587-
:param bool download: Whether or not the sample should be added to the
588-
downloadables.
589-
:param bool stream: Whether or not the sound should be streamed.
629+
:param str sample:
630+
Sound file relative to the ``sounds`` directory.
631+
:param RecipientFilter recipients:
632+
Recipients to emit the sound to.
633+
:param int index:
634+
Index of the entity to emit the sound from.
635+
:param float volume:
636+
Volume of the sound.
637+
:param Attenuation attenuation:
638+
How far the sound should reaches.
639+
:param int channel:
640+
Channel to emit the sound with.
641+
:param SoundFlags flags:
642+
Flags of the sound.
643+
:param Pitch pitch:
644+
Pitch of the sound.
645+
:param Vector origin:
646+
Origin of the sound.
647+
:param Vector direction:
648+
Direction of the sound.
649+
:param tuple origins:
650+
Origins of the sound.
651+
:param bool update_positions:
652+
Whether or not the positions should be updated.
653+
:param float sound_time:
654+
Time to play the sound for.
655+
:param int speaker_entity:
656+
Index of the speaker entity.
657+
:param bool download:
658+
Whether or not the sample should be added to the downloadables.
659+
:param bool stream:
660+
Whether or not the sound should be streamed.
590661
"""
591662
# Get the correct Sound class...
592663
if not stream:
@@ -609,14 +680,24 @@ def emit_sound(
609680
def stop_sound(self, sample, channel=Channel.AUTO):
610681
"""Stop the given sound from being emitted by this entity.
611682
612-
:param str sample: Sound file relative to the "sounds" directory.
613-
:param Channel channel: The channel of the sound.
683+
:param str sample:
684+
Sound file relative to the ``sounds`` directory.
685+
:param Channel channel:
686+
The channel of the sound.
614687
"""
615688
engine_sound.stop_sound(self.index, channel, sample)
616689

617690
def is_in_solid(
618691
self, mask=ContentMasks.ALL, generator=BaseEntityGenerator):
619-
"""Return whether or not the entity is in solid."""
692+
"""Return whether or not the entity is in solid.
693+
694+
:param ContentMasks mask:
695+
Contents the ray can possibly collide with.
696+
:param generator:
697+
A callable that returns an iterable which contains
698+
:class:`BaseEntity` instances that are ignored by the ray.
699+
:rtype: bool
700+
"""
620701
# Get a Ray object of the entity physic box
621702
ray = Ray(self.origin, self.origin, self.mins, self.maxs)
622703

@@ -634,7 +715,24 @@ def take_damage(
634715
self, damage, damage_type=DamageTypes.GENERIC, attacker_index=None,
635716
weapon_index=None, hitgroup=HitGroup.GENERIC, skip_hooks=False,
636717
**kwargs):
637-
"""Method used to hurt the entity with the given arguments."""
718+
"""Deal damage to the entity.
719+
720+
:param int damage:
721+
Amount of damage to deal.
722+
:param DamageTypes damage_type:
723+
Type of the dealed damage.
724+
:param int attacker_index:
725+
If not None, the index will be used as the attacker.
726+
:param int weapon_index:
727+
If not None, the index will be used as the weapon. This method
728+
also tries to retrieve the attacker from the weapon, if
729+
``attacker_index`` wasn't set.
730+
:param HitGroup hitgroup:
731+
The hitgroup where the damage should be applied.
732+
:param bool skip_hooks:
733+
If True, the damage will be dealed directly by skipping any
734+
registered hooks.
735+
"""
638736
# Import Entity classes
639737
# Doing this in the global scope causes cross import errors
640738
from weapons.entity import Weapon
@@ -730,7 +828,7 @@ def take_damage(
730828
@wrap_entity_mem_func
731829
def teleport(self, origin=None, angle=None, velocity=None):
732830
"""Change the origin, angle and/or velocity of the entity.
733-
831+
734832
:param Vector origin:
735833
New location of the entity.
736834
:param QAngle angle:
@@ -762,7 +860,8 @@ def set_parent(self, parent, attachment=INVALID_ATTACHMENT_INDEX):
762860
def _on_entity_deleted(base_entity):
763861
"""Called when an entity is removed.
764862
765-
:param BaseEntity base_entity: The removed entity.
863+
:param BaseEntity base_entity:
864+
The removed entity.
766865
"""
767866
# Make sure the entity is networkable...
768867
if not base_entity.is_networked():

0 commit comments

Comments
 (0)