Skip to content

Commit 27a7042

Browse files
committed
Overhaul of Entity Transmit.
1 parent d739f6e commit 27a7042

File tree

8 files changed

+505
-1572
lines changed

8 files changed

+505
-1572
lines changed

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

100644100755
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
# Source.Python Imports
6868
# Entities
6969
from _entities._entity import BaseEntity
70+
from _entities._transmit import TransmitManager
7071

7172

7273
# =============================================================================
@@ -779,6 +780,71 @@ def set_parent(self, parent, attachment=INVALID_ATTACHMENT_INDEX):
779780

780781
return [parent, attachment]
781782

783+
# =========================================================================
784+
# >> ENTITY TRANSMIT FUNCTIONALITY
785+
# =========================================================================
786+
def hide(self):
787+
"""Hide the entity from all players."""
788+
TransmitManager.hide(self.index)
789+
790+
def hide_from(self, player_index):
791+
"""Hide the entity from player.
792+
793+
:param int player_index:
794+
The target player index to hide this entity.
795+
"""
796+
TransmitManager.hide_from(self.index, player_index)
797+
798+
def show(self):
799+
"""Show the entity to all players."""
800+
TransmitManager.show(self.index)
801+
802+
def show_from(self, player_index):
803+
"""Show the entity to player.
804+
805+
:param int player_index:
806+
The target player index to show this entity.
807+
"""
808+
TransmitManager.show_from(self.index, player_index)
809+
810+
def reset(self):
811+
"""Reset the entity's hidden/shown state."""
812+
TransmitManager.reset(self.index)
813+
814+
def reset_from(self, player_index):
815+
"""Reset the player's entity hidden/shown state.
816+
817+
:param int player_index:
818+
The target player index to reset the player's hidden/shown state.
819+
"""
820+
TransmitManager.reset_from(self.index, player_index)
821+
822+
def is_hidden(self):
823+
"""Return True if the entity is hidden from any player.
824+
825+
:rtype: bool
826+
"""
827+
return TransmitManager.is_hidden(self.index)
828+
829+
def is_hidden_from(self, player_index):
830+
"""Return True if the entity is hidden from the player.
831+
832+
:param int player_index:
833+
The target player index to check if the entity is hidden.
834+
:rtype: bool
835+
"""
836+
return TransmitManager.is_hidden_from(self.index, player_index)
837+
838+
def get_hidden_player(self):
839+
"""Get the players where the entity is hidden.
840+
841+
:return:
842+
A tuple containing :class:`players.entity.Player` instances
843+
in which the entity is hidden.
844+
:rtype: tuple
845+
"""
846+
return TransmitManager.get_hidden_player(self.index)
847+
782848

783849
# =============================================================================
784850
# >> LISTENERS
@@ -814,3 +880,6 @@ def _on_entity_deleted(base_entity):
814880
# Invalidate the internal entity caches for this entity
815881
for cls in _entity_classes:
816882
cls.cache.pop(index, None)
883+
884+
# Reset the entity's hidden state.
885+
TransmitManager.reset(index)

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,34 @@
1515
from filters.entities import EntityIter
1616
# Listeners
1717
from listeners import on_entity_created_listener_manager
18-
from listeners import on_entity_deleted_listener_manager
1918

2019

2120
# ============================================================================
2221
# >> FORWARD IMPORTS
2322
# ============================================================================
2423
# Source.Python
2524
# Entities
26-
from _entities._transmit import transmit_manager
25+
from _entities._transmit import TransmitManager
2726

2827

2928
# ============================================================================
3029
# >> ALL DECLARATION
3130
# ============================================================================
3231
__all__ = (
33-
'transmit_manager',
32+
'TransmitManager',
33+
'reset_hidden_state',
3434
)
3535

3636

3737
# ============================================================================
3838
# >> CLASSES
3939
# ============================================================================
4040

41+
42+
# =============================================================================
43+
# >> FUNCTIONS
44+
# =============================================================================
45+
def reset_hidden_state():
46+
"""Reset all entities' hidden/shown state."""
47+
TransmitManager.reset_all()
48+

addons/source-python/packages/source-python/players/_base.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@
7373
from auth.manager import auth_manager
7474

7575

76+
# =============================================================================
77+
# >> FORWARD IMPORTS
78+
# =============================================================================
79+
# Source.Python Imports
80+
# Entities
81+
from _entities._transmit import TransmitManager
82+
83+
7684
# =============================================================================
7785
# >> CLASSES
7886
# =============================================================================
@@ -994,6 +1002,56 @@ def drop_weapon(self, weapon, target=None, velocity=None):
9941002
"""
9951003
return [weapon, target, velocity]
9961004

1005+
# =========================================================================
1006+
# >> PLAYER TRANSMIT FUNCTIONALITY
1007+
# =========================================================================
1008+
def hide_entity(self, entity_index):
1009+
"""Hide the entity from player.
1010+
1011+
:param int entity_index:
1012+
The target entity index to hide from the player.
1013+
"""
1014+
TransmitManager.hide_from(entity_index, self.index)
1015+
1016+
def show_entity(self, entity_index):
1017+
"""Show the entity to player.
1018+
1019+
:param int entity_index:
1020+
The target entity index to show the entity to player.
1021+
"""
1022+
TransmitManager.show_from(entity_index, self.index)
1023+
1024+
def reset_entity(self, entity_index):
1025+
"""Reset the player's entity hidden/shown state.
1026+
1027+
:param int entity_index:
1028+
The target entity_index to reset the player's hidden/shown state.
1029+
"""
1030+
TransmitManager.reset_from(entity_index, self.index)
1031+
1032+
def reset_player(self):
1033+
"""Reset the player's hidden/shown state on all entities."""
1034+
TransmitManager.reset_player(self.index)
1035+
1036+
def is_entity_hidden(self, entity_index):
1037+
"""Return True if the entity is hidden from the player.
1038+
1039+
:param int entity_index:
1040+
The target entity index to check if the entity is hidden.
1041+
:rtype: bool
1042+
"""
1043+
return TransmitManager.is_hidden_from(entity_index, self.index)
1044+
1045+
def get_hidden_entity(self):
1046+
"""Get the entities that are hidden from the player.
1047+
1048+
:return:
1049+
A tuple containing :class:`entities.entity.Entity` instances
1050+
that are hidden from the player.
1051+
:rtype: tuple
1052+
"""
1053+
return TransmitManager.get_hidden_entity(self.index)
1054+
9971055

9981056
# =============================================================================
9991057
# >> HELPER FUNCTIONS

0 commit comments

Comments
 (0)