Esempio n. 1
0
def parse_pos_mark_arg(arg_str):
    arg_str_arr = arg_str.split('.')
    if len(arg_str_arr) < 2:
        return exps_int(arg_str), 0
    if arg_str_arr[1] != '5' or len(arg_str_arr) > 2:
        raise ValueError("Invalid position mark")
    return exps_int(arg_str_arr[0]), 2
Esempio n. 2
0
    def collect(self) -> SsbLabelJumpBlueprint:
        if self.scn_var_target is None:
            raise SsbCompilerError(_("No variable for assignment."))
        if self.operator not in [
                SsbOperator.EQ, SsbOperator.LE, SsbOperator.LT, SsbOperator.GE,
                SsbOperator.GT
        ]:
            raise SsbCompilerError(
                f(
                    _("The only supported operators for scn if "
                      "conditions are ==,<,<=,>,>= (line {self.ctx.start.line})"
                      )))

        scn_value = exps_int(str(self.ctx.INTEGER(0)))
        level_value = exps_int(str(self.ctx.INTEGER(1)))

        if self.operator == SsbOperator.LE:
            return SsbLabelJumpBlueprint(
                self.compiler_ctx, self.ctx, OP_BRANCH_SCENARIO_NOW_BEFORE,
                [self.scn_var_target, scn_value, level_value])
        if self.operator == SsbOperator.LT:
            return SsbLabelJumpBlueprint(
                self.compiler_ctx, self.ctx, OP_BRANCH_SCENARIO_BEFORE,
                [self.scn_var_target, scn_value, level_value])
        if self.operator == SsbOperator.GE:
            return SsbLabelJumpBlueprint(
                self.compiler_ctx, self.ctx, OP_BRANCH_SCENARIO_NOW_AFTER,
                [self.scn_var_target, scn_value, level_value])
        if self.operator == SsbOperator.GT:
            return SsbLabelJumpBlueprint(
                self.compiler_ctx, self.ctx, OP_BRANCH_SCENARIO_AFTER,
                [self.scn_var_target, scn_value, level_value])
        return SsbLabelJumpBlueprint(
            self.compiler_ctx, self.ctx, OP_BRANCH_SCENARIO_NOW,
            [self.scn_var_target, scn_value, level_value])
    def collect(self) -> List[SsbOperation]:
        if self.var_target is None:
            raise SsbCompilerError(_("No variable for assignment set."))

        return [
            self._generate_operation(OPS_FLAG__SET_SCENARIO, [
                self.var_target,
                exps_int(str(self.ctx.INTEGER(0))),
                exps_int(str(self.ctx.INTEGER(1)))
            ])
        ]
 def collect(self) -> Tuple[int, int]:  # position, offset
     self.ctx: ExplorerScriptParser.Position_marker_argContext
     offset = 0
     if self.ctx.POINT_FIVE():
         offset = 2
     pos = exps_int(str(self.ctx.INTEGER()))
     return pos, offset
Esempio n. 5
0
 def collect(self) -> Union[int, SsbOpParamConstant]:
     self.ctx: ExplorerScriptParser.Integer_likeContext
     if self.ctx.INTEGER():
         return exps_int(str(self.ctx.INTEGER()))
     if self.ctx.IDENTIFIER():
         return SsbOpParamConstant(str(self.ctx.IDENTIFIER()))
     if self.ctx.VARIABLE():
         return SsbOpParamConstant(str(self.ctx.VARIABLE()))
     raise SsbCompilerError("Unknown 'integer like'.")
Esempio n. 6
0
    def collect(self) -> SsbOperation:
        if self.scn_var_target is None:
            raise SsbCompilerError(_("No variable set for scn switch condition."))

        index = exps_int(str(self.ctx.INTEGER()))
        if index == 0:
            return self._generate_operation(OP_SWITCH_SCENARIO, [self.scn_var_target])
        elif index == 1:
            return self._generate_operation(OP_SWITCH_SCENARIO_LEVEL, [self.scn_var_target])
        raise SsbCompilerError(f(_("Index for scn() if condition must be 0 or 1 (line {self.ctx.start.line}).")))
Esempio n. 7
0
    def collect(self) -> any:
        """Collects routine info and operations."""
        linked_to = -1
        linked_to_name = None
        integer_like = self._linked_to_target
        try:
            linked_to = exps_int(integer_like)
        except:
            linked_to_name = integer_like.name

        if str(self.ctx.FOR_TARGET()) == 'for_actor':
            routine_info = SsbRoutineInfo(SsbRoutineType.ACTOR, linked_to, linked_to_name)
        elif str(self.ctx.FOR_TARGET()) == 'for_object':
            routine_info = SsbRoutineInfo(SsbRoutineType.OBJECT, linked_to, linked_to_name)
        else:
            routine_info = SsbRoutineInfo(SsbRoutineType.PERFORMER, linked_to, linked_to_name)

        return routine_info, self.collect_ops()
Esempio n. 8
0
    def collect(self) -> List[SsbOperation]:
        if self.var_target is None:
            raise SsbCompilerError(_("No variable for assignment."))
        if self.operator is None:
            raise SsbCompilerError(_("No operator set for assignment."))
        if self.value is None:
            raise SsbCompilerError(_("No value set for assignment."))

        if self.ctx.INTEGER():
            index = exps_int(str(self.ctx.INTEGER()))
            # CalcBit / SetPerformance
            if self.value_is_a_variable:
                raise SsbCompilerError(
                    f(
                        _("value(X) can not be used with index based assignments "
                          "(line {self.ctx.start.line}).")))
            if str(self.var_target
                   ) == self.compiler_ctx.performance_progress_list_var_name:
                return [
                    self._generate_operation(OPS_FLAG__SET_PERFORMANCE,
                                             [index, self.value])
                ]
            return [
                self._generate_operation(OPS_FLAG__CALC_BIT,
                                         [self.var_target, index, self.value])
            ]

        # CalcValue / CalcVariable / Set
        if self.value_is_a_variable:
            return [
                self._generate_operation(
                    OPS_FLAG__CALC_VARIABLE,
                    [self.var_target, self.operator.value, self.value])
            ]
        if self.operator == SsbCalcOperator.ASSIGN:
            return [
                self._generate_operation(OPS_FLAG__SET,
                                         [self.var_target, self.value])
            ]
        return [
            self._generate_operation(
                OPS_FLAG__CALC_VALUE,
                [self.var_target, self.operator.value, self.value])
        ]
Esempio n. 9
0
    def collect(self) -> SsbLabelJumpBlueprint:
        self.ctx: ExplorerScriptParser.If_h_bitContext
        if self.var_target is None:
            raise SsbCompilerError(_("No variable in if condition."))

        var_target_name = None
        if hasattr(self.var_target, 'name'):
            var_target_name = self.var_target.name

        index = exps_int(str(self.ctx.INTEGER()))
        is_simple_positive = self.ctx.NOT() is None

        if var_target_name == self.compiler_ctx.performance_progress_list_var_name:
            return SsbLabelJumpBlueprint(
                self.compiler_ctx, self.ctx, OP_BRANCH_PERFORMANCE,
                [index, 1 if is_simple_positive else 0])
        elif not is_simple_positive:
            raise SsbCompilerError(
                f(
                    _("The variable {var_target_name} can not be used with 'not' "
                      "(line {self.ctx.start.line}).")))
        return SsbLabelJumpBlueprint(self.compiler_ctx, self.ctx,
                                     OP_BRANCH_BIT, [self.var_target, index])
Esempio n. 10
0
 def get_new_routine_id(self, old_id: int) -> int:
     return exps_int(str(self.ctx.INTEGER()))