def test_factory_func(): class Foo: pass f = factory(lambda: Foo()) a = f() b = f() assert isinstance(a, Foo) assert isinstance(b, Foo) assert a is not b
def test_create_aspect_with_factory_function_defaults(world): class Foo: pass aspect = Aspect( [Component_A], overrides={ Component_A: dict(i=factory(lambda: 1)), }, ) [a] = aspect() assert a.i == 1
map_entity = base.ecs_world.create_entity(name="Level geometry") game_map.add(map_entity) # Player character = Aspect( [ wecs.mechanics.clock.Clock, wecs.panda3d.prototype.Model, wecs.panda3d.prototype.Geometry, wecs.panda3d.character.CharacterController, ], overrides={ wecs.mechanics.clock.Clock: dict(clock=lambda: factory(wecs.mechanics.clock.panda3d_clock), ), }, ) def peter_bumper(): return { 'bumper': dict( shape=CollisionSphere, center=Vec3(0.0, 0.0, 1.0), radius=0.7, ), }
shape=CollisionSphere, center=Vec3(0.0, 0.0, 0.25), radius=0.5, ), } walking = Aspect( [ panda3d.WalkingMovement, panda3d.CrouchingMovement, panda3d.SprintingMovement, panda3d.InertialMovement, panda3d.BumpingMovement, panda3d.FallingMovement, panda3d.JumpingMovement ], overrides={ panda3d.BumpingMovement: dict(solids=factory(rebecca_bumper)), panda3d.FallingMovement: dict(solids=factory(rebecca_lifter)), }, ) avatar = Aspect([character, walking], overrides={panda3d.Model: dict(model_name='rebecca.bam')}) def spectator_bumper(): return dict(solids={ 'bumper': dict( shape=CollisionSphere, center=Vec3(0.0, 0.0, 0.0), radius=0.1, ),
# There are characters, which are points in space that can be moved # around using the `CharacterController`, using either player input or # AI control. # They are spawned at one of the map's spawn points. character = Aspect( [ wecs.mechanics.clock.Clock, wecs.panda3d.prototype.Model, wecs.panda3d.character.CharacterController, wecs.panda3d.spawnpoints.SpawnAt, ], overrides={ wecs.mechanics.clock.Clock: dict(clock=lambda: factory(wecs.mechanics.clock.panda3d_clock), ), }, ) # Avatars are characters which have (presumably humanoid) animated # models that can walk around. Their entities can be found using the # mouse cursor or other collision sensors. animated = Aspect([ wecs.panda3d.prototype.Actor, wecs.panda3d.animation.Animation, ], ) walking = Aspect( [ wecs.panda3d.character.WalkingMovement,
map_entity = base.ecs_world.create_entity(name="Level geometry") game_map.add(map_entity) # There are characters, which are points in space that can be moved # around using the `CharacterController`, using either player input or # AI control. character = Aspect( [ wecs.mechanics.clock.Clock, wecs.panda3d.prototype.Model, wecs.panda3d.character.CharacterController, ], overrides={ wecs.mechanics.clock.Clock: dict(clock=lambda: factory(wecs.mechanics.clock.panda3d_clock), ), wecs.panda3d.character.CharacterController: dict(gravity=Vec3(0, 0, -30), ), }, ) # Avatars are characters which have (presumably humanoid) animated # models that can walk around. Their entities can be found using the # mouse cursor or other collision sensors. animated = Aspect([ wecs.panda3d.prototype.Actor, wecs.panda3d.animation.Animation, ], ) walking = Aspect([
panda3d.Floating, # Scale by speed for floating panda3d.Walking, # Scale by speed for walk / run / crouch / sprint panda3d.Inertiing, # Clamp movement speed delta by inertia panda3d.Bumping, # Bump into things (and out again). panda3d.Falling, # Fall, or stand on the ground. panda3d.Jumping, # Impart upward impulse. panda3d.ExecuteMovement, # Turn intention into actual movement # We're done with character movement, now adjust the cameras. panda3d.UpdateCameras, panda3d.CollideCamerasWithTerrain, ] game_map = Aspect( [panda3d.Position, panda3d.Model, panda3d.Scene, Map], overrides={ panda3d.Position: dict(value=factory(lambda: Point3(0, 0, 0))), panda3d.Model: dict(model_name='roadE.bam'), panda3d.Scene: dict(node=base.render), }, ) # Populate the world with the map, the player character, and a few NPCs # Map game_map.add(base.ecs_world.create_entity()) # Player player_avatar = Aspect([aspects.player_character, mechanics.Stamina]) player_avatar.add( base.ecs_world.create_entity(), overrides={panda3d.Position: dict(value=Point3(50, 290, 0))},