How to use the esper.Processor function in esper

To help you get started, we’ve selected a few esper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benmoran56 / esper / examples / benchmark_cache.py View on Github external
class Damageable:
    def __init__(self):
        self.defense = 45


class Brain:
    def __init__(self):
        self.smarts = 9000


##########################
#  Define some Processors:
##########################
class MovementProcessor(esper.Processor):
    def __init__(self):
        super().__init__()

    def process(self):
        for ent, (vel, pos) in self.world.get_components(Velocity, Position):
            pos.x += vel.x
            pos.y += vel.y
            print("Current Position: {}".format((int(pos.x), int(pos.y))))


#############################
# Set up some dummy entities:
#############################
def create_entities(world, number):
    for _ in range(number // 2):
        world.create_entity(Position(), Velocity(), Health(), Command())
github benmoran56 / esper / tests / test_cached_world.py View on Github external
self.z = None


class ComponentD:
    def __init__(self):
        self.direction = "left"
        self.previous = "right"


class ComponentE:
    def __init__(self):
        self.items = {"itema": None, "itemb": 1000}
        self.points = [a + 2 for a in list(range(44))]


class CorrectProcessorA(esper.Processor):
    def __init__(self):
        super().__init__()

    def process(self):
        pass


class CorrectProcessorB(esper.Processor):
    def __init__(self):
        super().__init__()

    def process(self):
        pass


class IncorrectProcessor:
github benmoran56 / esper / tests / test_cached_world.py View on Github external
def test_add_processor(populated_world):
    assert len(populated_world._processors) == 0
    correct_processor_a = CorrectProcessorA()
    assert isinstance(correct_processor_a, esper.Processor)
    populated_world.add_processor(correct_processor_a)
    assert len(populated_world._processors) == 1
    assert isinstance(populated_world._processors[0], esper.Processor)
github benmoran56 / esper / examples / pysdl2_example.py View on Github external
self.y = y


class Renderable:
    def __init__(self, texture, width, height, posx, posy):
        self.texture = texture
        self.x = posx
        self.y = posy
        self.w = width
        self.h = height


################################
#  Define some Processors:
################################
class MovementProcessor(esper.Processor):
    def __init__(self, minx, maxx, miny, maxy):
        super().__init__()
        self.minx = minx
        self.maxx = maxx
        self.miny = miny
        self.maxy = maxy

    def process(self):
        # This will iterate over every Entity that has BOTH of these components:
        for ent, (vel, rend) in self.world.get_components(Velocity, Renderable):
            # Update the Renderable Component's position by it's Velocity:
            rend.x += vel.x
            rend.y += vel.y
            # An example of keeping the sprite inside screen boundaries. Basically,
            # adjust the position back inside screen boundaries if it tries to go outside:
            rend.x = max(self.minx, rend.x)
github eyeCube / Softly-Roguelike / src / processors.py View on Github external
# Fluids
#

class Fluids:
    _fluids={}
    @classmethod
    def _flow(self):
        pass
    # TODO: use numpy to flow fluids...
    @classmethod
    def flow(self):
        Fluids._flow()
# end class

# Fluid Processor Fluids Processor
class FluidProcessor(esper.Processor):
    def process(self):
        Fluids.flow()
##    def fluidsat(self,x,y):
##        return self._fluids.get((x,y,), ())
# end class


    
#
# Stats Upkeep processor
#

class UpkeepProcessor(esper.Processor): # TODO: test this
    def process(self):
        # just query some components that match entities
github eyeCube / Softly-Roguelike / src / processors.py View on Github external
- the entity AI can decide what to do about this component
        '''
        # what happens when job is unfinished? Maybe makes a
        # half-finished crafting item? Half-eaten food object?
        if qa.cancelfunc:  #pass in qa.data, qa.ap; possibly modify qa ...
            qa.cancelfunc(ent, qa)  # ... before copying into PausedAction
        self.world.add_component(ent, cmp.PausedAction(qa))
        self.world.remove_component(ent, cmp.DelayedAction)
# end class
#

#
# Actors processor
# and Action Queues processor
#
class ActorsProcessor(esper.Processor):
    def process(self):
        world=self.world

        # give AP to all actors
        for ent,actor in world.get_component(cmp.Actor):
            if rog.on(ent,DEAD):
                actor.ap=0
                continue
            spd=max(MIN_SPD, rog.getms(ent, 'spd'))
            actor.ap = min(actor.ap + spd, spd)
        
        # Action Queues
        for ent, (qa, actor) in self.world.get_components(
            cmp.DelayedAction, cmp.Actor ):
            
            # process interruptions and cancelled / paused jobs
github benmoran56 / esper / examples / pyglet_example.py View on Github external
def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y


class Renderable:
    def __init__(self, sprite):
        self.sprite = sprite
        self.w = sprite.width
        self.h = sprite.height


################################
#  Define some Processors:
################################
class MovementProcessor(esper.Processor):
    def __init__(self, minx, maxx, miny, maxy):
        super().__init__()
        self.minx = minx
        self.miny = miny
        self.maxx = maxx
        self.maxy = maxy

    def process(self, dt):
        # This will iterate over every Entity that has BOTH of these components:
        for ent, (vel, rend) in self.world.get_components(Velocity, Renderable):
            # Update the Renderable Component's position by it's Velocity:
            # An example of keeping the sprite inside screen boundaries. Basically,
            # adjust the position back inside screen boundaries if it is outside:
            new_x = max(self.minx, rend.sprite.x + vel.x)
            new_y = max(self.miny, rend.sprite.y + vel.y)
            new_x = min(self.maxx - rend.w, new_x)
github eyeCube / Softly-Roguelike / src / processors.py View on Github external
rog.set_status(ent, cmp.StatusExsanguination())
            elif body.blood <= body.bloodMax * ( # critical
                bloodratio + (1 - bloodratio)*0.5):
                rog.set_status(ent, cmp.StatusHazy())
# end class
                

#
# Homeostasis Processor
#

# Ran once every few turns or so.
# Concerned with body processes that are sub-critical.
# BodyProcessor is the critical body processes processor.

class HomeostasisProcessor(esper.Processor):
    def process(self):
        world = self.world
        for ent, (body, meters) in world.get_components(
            cmp.Body, cmp.Meters):
            
            # maintain heat equilibrium
            meters = self.world.component_for_entity(ent, cmp.Meters)
            if meters.temp > BODY_TEMP+1:
                rog.set_status(ent, cmp.StatusSweat())
            elif meters.temp < BODY_TEMP-1:
                rog.set_status(ent, cmp.StatusShiver())

            # TODO: Hot and Chilly/Cold statuses
            
            # digestion: get calories (satiation) from food consumed
github eyeCube / Softly-Roguelike / src / processors.py View on Github external
rog.make(ent, DIRTY_STATS)
                meters.bleed = max(0, meters.bleed - BLEED_METERLOSS)
            # rads meter
# end class



#
# Body Maintainence Processor / Body Processor
#

# Ran every turn.
# This processor focuses on critical and hyper-critical body conditions.
# HomeostasisProcessor worries about regulating less extreme conditions.

class BodyProcessor(esper.Processor):
    def process(self):
        for ent, (body, meters) in world.get_components(
            cmp.Body, cmp.Meters):
            
            # get body temperature information based on body plan
            bodytemp, plus, minus = BODY_TEMP.get[body.plan]
            bloodpc, bloodratio = BODY_BLOOD.get[body.plan]
            
            # too thirsty? (too little hydration?/too dehydrated?)
            if body.hydration <= body.hydrationMax*0.9: # hyper-critical
                entities.dehydrate(ent)
            # too hungry? (too little calories?)
            if body.satiation <= 0: # hyper-critical
                entities.starve(ent)
            # too hot?
            if meters.temp > bodytemp + plus: # hyper-critical
github eyeCube / Softly-Roguelike / processors.py View on Github external
#

class FOV:
    _list = []
    @classmethod
    def getList(cls): return cls._list
    @classmethod
    def clear(cls): cls._list = []
    # register an entity to have its FOV updated this turn
    @classmethod
    def add(cls, ent):
        if not rog.world().has_component(ent, cmp.SenseSight):
            return      # reject ents that cannot see
        cls._list.append(ent)
    
class FOVProcessor(esper.Processor):
    def process(self):
        for ent in FOV.getList():
            rog.fov_compute(ent)
        FOV.clear()


        
#
# Action Queue
#

# Stores the data for tasks that take entities multiple turns to finish
# call "queue" to add a new task,
#   "get" to get the Action object,
#   "pay" to spend a certain number of AP towards finishing the task