# Released under the MIT License. See LICENSE for details.#"""Various utilities useful for gameplay."""from__future__importannotationsfromtypingimportTYPE_CHECKINGimportbascenev1asbsifTYPE_CHECKING:pass
[docs]classSharedObjects:"""Various common components for use in games. Category: Gameplay Classes Objects contained here are created on-demand as accessed and shared by everything in the current activity. This includes things such as standard materials. """_STORENAME=bs.storagename()def__init__(self)->None:activity=bs.getactivity()ifself._STORENAMEinactivity.customdata:raiseRuntimeError('Use SharedObjects.get() to fetch the'' shared instance for this activity.')self._object_material:bs.Material|None=Noneself._player_material:bs.Material|None=Noneself._pickup_material:bs.Material|None=Noneself._footing_material:bs.Material|None=Noneself._attack_material:bs.Material|None=Noneself._death_material:bs.Material|None=Noneself._region_material:bs.Material|None=Noneself._railing_material:bs.Material|None=None
[docs]@classmethoddefget(cls)->SharedObjects:"""Fetch/create the instance of this class for the current activity."""activity=bs.getactivity()shobs=activity.customdata.get(cls._STORENAME)ifshobsisNone:shobs=SharedObjects()activity.customdata[cls._STORENAME]=shobsassertisinstance(shobs,SharedObjects)returnshobs
@propertydefplayer_material(self)->bs.Material:"""a bascenev1.Material to be applied to player parts. Generally, materials related to the process of scoring when reaching a goal, etc will look for the presence of this material on things that hit them. """ifself._player_materialisNone:self._player_material=bs.Material()returnself._player_material@propertydefobject_material(self)->bs.Material:"""A bascenev1.Material that should be applied to any small, normal, physical objects such as bombs, boxes, players, etc. Other materials often check for the presence of this material as a prerequisite for performing certain actions (such as disabling collisions between initially-overlapping objects) """ifself._object_materialisNone:self._object_material=bs.Material()returnself._object_material@propertydefpickup_material(self)->bs.Material:"""A bascenev1.Material; collision shapes used for picking things up will have this material applied. To prevent an object from being picked up, you can add a material that disables collisions against things containing this material. """ifself._pickup_materialisNone:self._pickup_material=bs.Material()returnself._pickup_material@propertydeffooting_material(self)->bs.Material:"""Anything that can be 'walked on' should have this bascenev1.Material applied; generally just terrain and whatnot. A character will snap upright whenever touching something with this material so it should not be applied to props, etc. """ifself._footing_materialisNone:self._footing_material=bs.Material()returnself._footing_material@propertydefattack_material(self)->bs.Material:"""A bascenev1.Material applied to explosion shapes, punch shapes, etc. An object not wanting to receive impulse/etc messages can disable collisions against this material. """ifself._attack_materialisNone:self._attack_material=bs.Material()returnself._attack_material@propertydefdeath_material(self)->bs.Material:"""A bascenev1.Material that sends a ba.DieMessage() to anything that touches it; handy for terrain below a cliff, etc. """ifself._death_materialisNone:mat=self._death_material=bs.Material()mat.add_actions(('message','their_node','at_connect',bs.DieMessage()))returnself._death_material@propertydefregion_material(self)->bs.Material:"""A bascenev1.Material used for non-physical collision shapes (regions); collisions can generally be allowed with this material even when initially overlapping since it is not physical. """ifself._region_materialisNone:self._region_material=bs.Material()returnself._region_material@propertydefrailing_material(self)->bs.Material:"""A bascenev1.Material with a very low friction/stiffness/etc that can be applied to invisible 'railings' useful for gently keeping characters from falling off of cliffs. """ifself._railing_materialisNone:mat=self._railing_material=bs.Material()mat.add_actions(('modify_part_collision','collide',False))mat.add_actions(('modify_part_collision','stiffness',0.003))mat.add_actions(('modify_part_collision','damping',0.00001))mat.add_actions(conditions=('they_have_material',self.player_material),actions=(('modify_part_collision','collide',True),('modify_part_collision','friction',0.0),),)returnself._railing_material