Beispiel #1
0
def construct_simple(base, var_type):
    identifier = "%s_%s" % (var_type.identifier, base.identifier_suffix)
    class_name = str(camel_case(identifier))
    suffixed_type_name = lazy(lambda s: "%s %s" % (var_type.name, s), six.text_type)
    class_ns = {
        "bindings": {
            "v1": Binding(suffixed_type_name("1"), type=var_type),
            "v2": Binding(suffixed_type_name("2"), type=var_type, constant_use=ConstantUse.VARIABLE_OR_CONSTANT),
        },
        "identifier": identifier
    }
    return type(class_name, (base,), class_ns)
Beispiel #2
0
class AddOrderLogEntry(Action):
    identifier = "add_order_log_entry"
    order = Binding("Order", Model("E-Commerce.Order"), constant_use=ConstantUse.VARIABLE_ONLY)
    message = Binding("Message", Text, constant_use=ConstantUse.VARIABLE_OR_CONSTANT)
    message_identifier = Binding("Message Identifier", Text, constant_use=ConstantUse.VARIABLE_OR_CONSTANT)

    def execute(self, context):
        order = self.get_value(context, "order")
        if not order:  # pragma: no cover
            return
        message = self.get_value(context, "message")
        message_identifier = self.get_value(context, "message_identifier") or None
        assert isinstance(order, Order)
        order.add_log_entry(message=message, identifier=message_identifier)
Beispiel #3
0
class Empty(Condition):
    identifier = "empty"
    description = _(u"Check whether the bound value `value` is empty or zero.")
    name = _("Empty")
    v = Binding("Value")

    def test(self, context):
        return not bool(self.get_value(context, "v"))
Beispiel #4
0
class NonEmpty(Condition):
    identifier = "non_empty"
    description = _(u"Check whether the bound value `value` exists and is non-empty and non-zero.")
    name = _("Non-Empty")
    v = Binding("Value")

    def test(self, context):
        return bool(self.get_value(context, "v"))
Beispiel #5
0
class AddNotification(Action):
    identifier = "add_notification"
    recipient_type = Binding(
        "Recipient Type",
        type=Enum(RecipientType),
        constant_use=ConstantUse.CONSTANT_ONLY,
        default=RecipientType.ADMINS
    )
    recipient = Binding(
        "Recipient",
        type=Model(settings.AUTH_USER_MODEL),
        constant_use=ConstantUse.VARIABLE_OR_CONSTANT,
        required=False
    )
    priority = Binding("Priority", type=Enum(Priority), constant_use=ConstantUse.CONSTANT_ONLY, default=Priority.NORMAL)
    message = TemplatedBinding("Message", type=Text, constant_use=ConstantUse.CONSTANT_ONLY, required=True)
    message_identifier = Binding("Message Identifier", Text, constant_use=ConstantUse.CONSTANT_ONLY, required=False)
    url = Binding("URL", type=URL, constant_use=ConstantUse.VARIABLE_OR_CONSTANT)

    def execute(self, context):
        """
        :type context: E-Commerce.notify.script.Context
        """
        values = self.get_values(context)
        if values["recipient_type"] == RecipientType.SPECIFIC_USER:
            if not values["recipient"]:
                context.log(logging.WARN, "Misconfigured AddNotification -- no recipient for specific user")
                return
        Notification.objects.create(
            recipient_type=values["recipient_type"],
            recipient=values["recipient"],
            priority=values["priority"],
            identifier=values.get("message_identifier"),
            message=values["message"][:140],
            url=values["url"],
            shop=context.shop
        )
Beispiel #6
0
class SendEmail(Action):
    EMAIL_CONTENT_TYPE_CHOICES = (
        ('plain', _('Plain text')),
        ('html', _('HTML'))
    )

    identifier = "send_email"
    template_use = TemplateUse.MULTILINGUAL
    template_fields = {
        "subject": forms.CharField(required=True, label=_(u"Subject")),
        "body_template": forms.CharField(
            required=False,
            label=_("Body Template"),
            help_text=_(
                "You can use this template to wrap the HTML body with your custom static template."
                "Mark the spot for the HTML body with %html_body%."
            ),
            widget=forms.Textarea()
        ),
        "body": forms.CharField(required=True, label=_("Email Body"), widget=TextEditorWidget()),
        "content_type": forms.ChoiceField(
            required=True, label=_(u"Content type"),
            choices=EMAIL_CONTENT_TYPE_CHOICES, initial=EMAIL_CONTENT_TYPE_CHOICES[0][0]
        )
    }

    from_email = Binding(
        _("From email"),
        type=Email,
        constant_use=ConstantUse.VARIABLE_OR_CONSTANT,
        required=False,
        help_text=_(
            'The from email to be used. It can either be binded to a variable or be a constant like '
            '[email protected] or even "Store Support" <*****@*****.**>.'
        )
    )
    recipient = Binding(_("Recipient"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT, required=True)
    reply_to_address = Binding(_("Reply-To"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT)
    language = Binding(_("Language"), type=Language, constant_use=ConstantUse.VARIABLE_OR_CONSTANT, required=True)
    fallback_language = Binding(
        _("Fallback language"), type=Language, constant_use=ConstantUse.CONSTANT_ONLY,
        default=settings.PARLER_DEFAULT_LANGUAGE_CODE
    )
    send_identifier = Binding(
        _("Send Identifier"), type=Text, constant_use=ConstantUse.CONSTANT_ONLY, required=False,
        help_text=_(
            "If set, this identifier will be logged into the event's log target. If the identifier has already "
            "been logged, the e-mail won't be sent again."
        )
    )

    def execute(self, context):
        """
        :param context: Script Context
        :type context: E-Commerce.notify.script.Context
        """
        recipient = self.get_value(context, "recipient")
        if not recipient:
            context.log(logging.INFO, "%s: Not sending mail, no recipient", self.identifier)
            return

        send_identifier = self.get_value(context, "send_identifier")
        if send_identifier and context.log_entry_queryset.filter(identifier=send_identifier).exists():
            context.log(
                logging.INFO,
                "%s: Not sending mail, have sent it already (%r)",
                self.identifier,
                send_identifier
            )
            return

        languages = [language for language in [
            self.get_value(context, "language"),
            self.get_value(context, "fallback_language"),
        ] if language and language in dict(settings.LANGUAGES).keys()]

        if not languages:
            languages = [settings.PARLER_DEFAULT_LANGUAGE_CODE]

        strings = self.get_template_values(context, languages)

        subject = strings.get("subject")
        body = strings.get("body")
        body_template = strings.get("body_template")

        if body_template and "%html_body%" in body_template:
            body = body_template.replace("%html_body%", body)

        content_type = strings.get("content_type")
        if not (subject and body):
            context.log(
                logging.INFO,
                "%s: Not sending mail to %s, either subject or body empty",
                self.identifier,
                recipient
            )
            return

        reply_to = self.get_value(context, "reply_to_address")
        reply_to = [reply_to] if reply_to else None  # Push email to a list, unless it is None

        from_email = self.get_value(context, "from_email") or None
        subject = " ".join(subject.splitlines())  # Email headers may not contain newlines
        message = EmailMessage(subject=subject, body=body, to=[recipient], reply_to=reply_to, from_email=from_email)
        message.content_subtype = content_type
        message.send()
        context.log(logging.INFO, "%s: Mail sent to %s :)", self.identifier, recipient)

        if send_identifier:
            context.add_log_entry_on_log_target("Email sent to %s: %s" % (recipient, subject), send_identifier)
def setMonster(num, package):
    for i in range(num):

        # Grabs the image locations from the package parameter and puts them in the according variable.
        binding.monsterlist.append(
            binding.Enemy(enemypositionsx[random.randint(0, 22)],
                          enemypositionsy[random.randint(0, 10)]))
        binding.monsterlist[i].down1 = tk.PhotoImage(file=package[0])
        binding.monsterlist[i].down2 = tk.PhotoImage(file=package[1])
        binding.monsterlist[i].down3 = tk.PhotoImage(file=package[2])
        binding.monsterlist[i].up1 = tk.PhotoImage(file=package[3])
        binding.monsterlist[i].up2 = tk.PhotoImage(file=package[4])
        binding.monsterlist[i].up3 = tk.PhotoImage(file=package[5])
        binding.monsterlist[i].left1 = tk.PhotoImage(file=package[6])
        binding.monsterlist[i].left2 = tk.PhotoImage(file=package[7])
        binding.monsterlist[i].left3 = tk.PhotoImage(file=package[8])
        binding.monsterlist[i].right1 = tk.PhotoImage(file=package[9])
        binding.monsterlist[i].right2 = tk.PhotoImage(file=package[10])
        binding.monsterlist[i].right3 = tk.PhotoImage(file=package[11])

        # This block of code inlarges the images by 2 so they appear bigger than they are on the tile map in battle.
        binding.monsterlist[i].right3 = binding.monsterlist[i].right3.zoom(
            2, 2)
        binding.monsterlist[i].right2 = binding.monsterlist[i].right2.zoom(
            2, 2)
        binding.monsterlist[i].right1 = binding.monsterlist[i].right1.zoom(
            2, 2)
        binding.monsterlist[i].left3 = binding.monsterlist[i].left3.zoom(2, 2)
        binding.monsterlist[i].left2 = binding.monsterlist[i].left2.zoom(2, 2)
        binding.monsterlist[i].left1 = binding.monsterlist[i].left1.zoom(2, 2)
        binding.monsterlist[i].up3 = binding.monsterlist[i].up3.zoom(2, 2)
        binding.monsterlist[i].up2 = binding.monsterlist[i].up2.zoom(2, 2)
        binding.monsterlist[i].up1 = binding.monsterlist[i].up1.zoom(2, 2)
        binding.monsterlist[i].down1 = binding.monsterlist[i].down1.zoom(2, 2)
        binding.monsterlist[i].down2 = binding.monsterlist[i].down2.zoom(2, 2)
        binding.monsterlist[i].down3 = binding.monsterlist[i].down3.zoom(2, 2)
        binding.monsterlist[i].img = binding.monsterlist[i].down1

        # Creates lists of all the images that go the same way so it is easy to cycle through them.
        binding.monsterlist[i].aLeft = [
            binding.monsterlist[i].left1, binding.monsterlist[i].left2,
            binding.monsterlist[i].left3
        ]
        binding.monsterlist[i].aRight = [
            binding.monsterlist[i].right1, binding.monsterlist[i].right2,
            binding.monsterlist[i].right3
        ]
        binding.monsterlist[i].aUp = [
            binding.monsterlist[i].up1, binding.monsterlist[i].up2,
            binding.monsterlist[i].up3
        ]
        binding.monsterlist[i].aDown = [
            binding.monsterlist[i].down1, binding.monsterlist[i].down2,
            binding.monsterlist[i].down3
        ]

        # These lists are then put in a dictionary for easy access.
        binding.monsterlist[i].anim = {
            0: binding.monsterlist[i].aUp,
            1: binding.monsterlist[i].aRight,
            2: binding.monsterlist[i].aDown,
            3: binding.monsterlist[i].aLeft
        }

        # At the end of package are the stats of the monsters and here they are put into variables from package.
        binding.monsterlist[i].health = package[12]
        binding.monsterlist[i].speed = package[13]
        binding.monsterlist[i].speedgain = package[14]
        binding.monsterlist[i].damage = package[15]
Beispiel #8
0
class SetDebugFlag(Action):
    identifier = "set_debug_flag"
    flag_name = Binding("Flag Name", Text, constant_use=ConstantUse.CONSTANT_ONLY, default="debug")

    def execute(self, context):
        context.set(self.get_value(context, "flag_name"), True)
Beispiel #9
0
def test_binding_fallthrough():
    ctx = Context.from_variables()
    b = Binding("x", default="foo")
    assert b.get_value(ctx, {"variable": "var"}) == "foo"
    assert b.get_value(ctx, {}) == "foo"
Beispiel #10
0
def test_model_type_matching():
    assert empty_iterable(Binding("x", type=Model("E-Commerce.Contact")).get_matching_types(ATestEvent.variables))
    assert Binding("x", type=Model("E-Commerce.Order")).get_matching_types(ATestEvent.variables) == {"order"}
Beispiel #11
0
def test_text_type_matches_all():
    assert Binding("x", type=Text).get_matching_types(ATestEvent.variables) == set(ATestEvent.variables.keys())
Beispiel #12
0
def test_simple_type_matching():
    assert Binding("x", type=Language).get_matching_types(ATestEvent.variables) == {"order_language"}
Beispiel #13
0
    def fixedUpdate(self):

        #This collosal segment of code checks to see which direction the player is moving and calls functions based on that
        if self.moveCounter >=5: #This line makes it so that the player does not walk too fast

            self.moveCounter = 0
            if self.mL and self.leftTime>self.rightTime and self.leftTime > self.downTime and self.leftTime> self.upTime:
                #this try and except checks to see if there is a tile where the player is trying to walk, and if there is not it calls the loadsection function to load the next map segment
                try:
                    self.map[self.PY][self.PX - 1].CODE = self.map[self.PY][self.PX - 1].CODE
                except:
                    self.loadSection("-x")
                #This part checks the collision detection for the player
                sceneMove = False
                try:
                    if self.pCol(self.PX-1,self.PY) != True:
                        sceneMove = True
                except:
                    sceneMove = False

                if self.PX <= 0:
                    self.loadSection("-x")
                elif sceneMove:
                    #This section runs the animation counter for the player and actually moves the player
                    self.player = self.playerLeft[self.aniCounter]
                    self.aniCounter += 1
                    if self.aniCounter > 3:
                        self.aniCounter = 0

                    self.PX -= 1
                    C1.delete("all")
                    #This calls the draw function to redraw the screen
                    self.draw()

            #all of the rest of these statements are near identical to the first as they are just the other directions
            if self.mR and self.rightTime>self.leftTime and self.rightTime > self.downTime and self.rightTime> self.upTime:

                try:
                    self.map[self.PY][self.PX + 1].CODE = self.map[self.PY][self.PX + 1].CODE
                except:
                    self.loadSection("+x")

                sceneMove = False
                try:
                    if self.pCol(self.PX + 1, self.PY) != True:
                        sceneMove = True
                except:
                    sceneMove = False
                if self.PX >= len(self.map[self.PY]) - 1:
                    self.loadSection("+x")
                elif  sceneMove:
                    self.player = self.playerRight[self.aniCounter]
                    self.aniCounter += 1
                    if self.aniCounter > 3:
                        self.aniCounter = 0
                    self.PX += 1
                    C1.delete("all")

                    self.draw()


            if self.mU and self.upTime>self.leftTime and self.upTime > self.downTime and self.upTime> self.rightTime:

                try:
                    self.map[self.PY - 1][self.PX].CODE = self.map[self.PY - 1][self.PX].CODE
                except:
                    self.loadSection("-y")

                sceneMove = False
                try:
                    if self.pCol(self.PX, self.PY-1) != True:
                        sceneMove = True
                except:
                    sceneMove = False

                if self.PY <= 0:
                    self.loadSection("-y")
                elif  sceneMove:
                    self.player = self.playerUp[self.aniCounter]
                    self.aniCounter += 1
                    if self.aniCounter > 3:
                        self.aniCounter = 0
                    self.PY -= 1
                    C1.delete("all")

                    self.draw()


            if self.mD and self.downTime>self.leftTime and self.downTime > self.rightTime and self.downTime> self.upTime:

                try:
                    self.map[self.PY + 1][self.PX].CODE = self.map[self.PY + 1][self.PX].CODE
                except:
                    self.loadSection("+y")

                sceneMove = False
                try:
                    if self.pCol(self.PX, self.PY+1) != True:
                        sceneMove = True
                except:
                    sceneMove = False
                if self.PY >= len(self.map) - 1:
                    self.loadSection("+y")

                elif  sceneMove:

                    self.player = self.playerDown[self.aniCounter]
                    self.aniCounter += 1
                    if self.aniCounter > 3:
                        self.aniCounter = 0
                    self.PY += 1

                    C1.delete("all")
                    self.draw()
        #This trys to call villagers movement function if they exist on the map
        try:
            for i in range(len(self.village.bMap)):
                #print(self.village.bMap[i].villager.moveVectorTime)
                self.moveVillager(i)

                self.village.bMap[i].villager.moveTimer +=1
        except:
            pass
        #This section runs the movement of the enemies
        self.moveCounter+=1
        for i in range(len(enemyList)):
            #This part checks to see if the enemy is in range and chasing and then runs the chase AI
            if abs(enemyList[i].x - self.PX) <= enemyList[i].chaseRange and abs(enemyList[i].y - self.PY) <= enemyList[i].chaseRange:
                y = self.enemyChase(enemyList[i])
                if enemyList[i].chase:
                    if enemyList[i].moveCounter >= 15:
                        try:

                            if abs(self.PX - enemyList[i].x) > abs(self.PY - enemyList[i].y):
                                vv = int(round(math.sin(y)))
                                enemyList[i].dir = -vv +2
                                enemyList[i].x += vv
                                C1.move(enemyList[i].pos,self.tileSize*vv,0)
                            else:
                                vv = int(round(math.cos(y)))
                                enemyList[i].dir = -vv +1
                                enemyList[i].y -= vv
                                C1.move(enemyList[i].pos,0,self.tileSize*-vv)
                            """
                            if int(round(math.sin(y)))== -1:
                                enemyList[i].dir = 3
                                enemyList[i].x -=1
                                C1.move(enemyList[i].pos, -32,0)

                            elif int(round(math.sin(y)))== 1:
                                enemyList[i].dir = 1
                                enemyList[i].x += 1
                                C1.move(enemyList[i].pos,32,0)

                            if int(round(math.cos(y))) == -1:
                                enemyList[i].dir = 2
                                enemyList[i].y +=1
                                C1.move(enemyList[i].pos,0,32)
                            elif int(round(math.cos(y))) == 1:
                                enemyList[i].dir = 0
                                enemyList[i].y -=1
                                C1.move(enemyList[i].pos,0,-32)
                            """
                            #("x" + str(enemyList[i].x),enemyList[i].y)
                        except:

                            continue
                        enemyList[i].moveCounter = 0
                    else:

                        enemyList[i].moveCounter +=1
            #If the enemy is not chasing this runs the enemy wander AI, or the eWander function
            if enemyList[i].chase != True:
                if enemyList[i].moveCounter >= 45:
                    self.eWander(i)
                    enemyList[i].moveCounter =0
                else:
                    enemyList[i].moveCounter +=1


                    #print(enemyList[i].aniCounter)
            #optimize?
            #Here we call animations for all of the enemies based on their movement direction
            if enemyList[i].dir == 0:
                C1.itemconfig(enemyList[i].pos, image = enemyList[i].aUp[enemyList[i].aniCounter])
            elif enemyList[i].dir == 1:
                C1.itemconfig(enemyList[i].pos, image = enemyList[i].aRight[enemyList[i].aniCounter])
            elif enemyList[i].dir == 2:
                C1.itemconfig(enemyList[i].pos, image = enemyList[i].aDown[enemyList[i].aniCounter])
            elif enemyList[i].dir == 3:
                C1.itemconfig(enemyList[i].pos, image = enemyList[i].aLeft[enemyList[i].aniCounter])
            if self.aniTime >=15:
                if enemyList[i].aniCounter<=1:
                    enemyList[i].aniCounter += 1
                elif enemyList[i].aniCounter >= 2:
                    enemyList[i].aniCounter = 0
                if i == len(enemyList)-1:
                    self.aniTime = 0
        self.aniTime +=1
        #This section runs a battle if you run into an enemy, and selects that enemy for removal once the battle is over
        if self.inBattle != True:
            for i in range(len(enemyList)):
                if enemyList[i].x == self.PX and enemyList[i].y == self.PY:
                    self.enemyToRemove = i
                    self.inBattle = True
                    self.mL = False
                    self.mR = False
                    self.mU = False
                    self.mD = False
                    root.unbind("<Left>")
                    root.unbind("<Right>")
                    root.unbind("<Up>")
                    root.unbind("<Down>")
                    root.unbind("<z>")
                    root.unbind("<KeyRelease-Left>")
                    root.unbind("<KeyRelease-Right>")
                    root.unbind("<KeyRelease-Down>")
                    root.unbind("<KeyRelease-Up>")
                    #this turns off the timer so that it does not continue while the user is in battle
                    self.timerRun = False
                    self.battle1 = binding.Battle(root, self.inventoryDisplay.primaryWeapon,
                                                  self.inventoryDisplay.secondaryWeapon)
                    #This runs a function in enemyData to set the monsters in the battle to the type seen on the map
                    eD.setMonster(3,eD.enemyDict[enemyList[i].type])
        """
        try:
            if self.menu.killIt ==True:
                del self.menu
                root.bind("<a>", self.onLeftPress)
                root.bind("<d>", self.onRightPress)
                root.bind("<w>", self.onUpPress)
                root.bind("<s>", self.onDownPress)
                root.bind("<Return>")
                root.bind("<Left>", self.onLeftPress)
                root.bind("<Right>", self.onRightPress)
                root.bind("<Up>", self.onUpPress)
                root.bind("<Down>", self.onDownPress)
                self.draw()
        except:
            pass
        """
        #This checks to see if a battle is occuring and if it is whether it has been won, and then resets the game back to the main screen
        try:
            if self.battle1.battleWon:
                self.inBattle = False

                enemyList.pop(self.enemyToRemove)
                #These bind all of the keys back to the main game/overworld
                root.bind("<a>", self.onLeftPress)
                root.bind("<d>", self.onRightPress)
                root.bind("<w>", self.onUpPress)
                root.bind("<s>", self.onDownPress)

                root.bind("<KeyRelease-a>", self.onLeftUp)
                root.bind("<KeyRelease-d>", self.onRightUp)
                root.bind("<KeyRelease-s>", self.onDownUp)
                root.bind("<KeyRelease-w>", self.onUpUp)


                root.bind("<KeyRelease-a>", self.onLeftUp)
                root.bind("<KeyRelease-d>", self.onRightUp)
                root.bind("<KeyRelease-s>", self.onDownUp)
                root.bind("<KeyRelease-w>", self.onUpUp)
                root.bind("<Left>", self.onLeftPress)
                root.bind("<Right>", self.onRightPress)
                root.bind("<Up>", self.onUpPress)
                root.bind("<Down>", self.onDownPress)
                root.bind("<z>", self.NPCInteractions)
                root.bind("<KeyRelease-Left>", self.onLeftUp)
                root.bind("<KeyRelease-Right>", self.onRightUp)
                root.bind("<KeyRelease-Down>", self.onDownUp)
                root.bind("<KeyRelease-Up>", self.onUpUp)
                self.battle1.battleWon = False
                del self.battle1

        except:
            pass
        #This part runs the timer every 17 milliseconds if it is being run at the current moment
        if self.timerRun == True:
            root.after(17,self.fixedUpdate)