Esempio n. 1
0
        public VarWorld(string name) : base(Access.Public, Usage.Static, name, Compiler.RootScope)
        {
            Compiler.Scope[] scopesSetTime = InnerScope.CreateChildren(1);
            ParameterInfo[]  infoSetTime   = new ParameterInfo[] {
                new ParameterInfo(
                    (true, VarString.StaticTypeName, "time", scopesSetTime[0])
                    )
            };
            Methods.Add("SetTime", arguments => {
                (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoSetTime, arguments);
                match.Grab(arguments);

                switch (index)
                {
                case 0:
                    new Spy(null, $"time set {match["time"].Value.GetConstant()}", null);
                    return(null);

                default: throw new MissingOverloadException($"{TypeName}.SetTime", index, arguments);
                }
            });

            Compiler.Scope[] scopesAddTime = InnerScope.CreateChildren(1);
            ParameterInfo[]  infoAddTime   = new ParameterInfo[] {
                new ParameterInfo(
                    (true, VarString.StaticTypeName, "time", scopesAddTime[0])
                    )
            };
            Methods.Add("AddTime", arguments => {
                (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoAddTime, arguments);
                match.Grab(arguments);

                string amount;
                switch (index)
                {
                case 0:
                    amount = match["time"].Value.GetConstant();
                    goto AddTime;

                    AddTime:
                    new Spy(null, $"time add {amount}", null);
                    return(null);

                default: throw new MissingOverloadException($"{TypeName}.AddTime", index, arguments);
                }
            });

            Compiler.Scope[] scopesGetTime = InnerScope.CreateChildren(2);
            ParameterInfo[]  infoGetTime   = new ParameterInfo[] {
                new ParameterInfo(
                    (true, VarString.StaticTypeName, "type", scopesGetTime[0])
                    ),
            };
            Methods.Add("GetTime", arguments => {
                (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoGetTime, arguments);
                match.Grab(arguments);

                VarInt result = new VarInt(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope);
                string type;
                switch (index)
                {
                case 0:
                    type = match[0].Value.GetConstant();
                    result.SetValue(-1);
                    goto GetTime;

                case 1:
                    type = match[0].Value.GetConstant();
                    result.SetValue(match[1].Value as VarSelector, match[2].Value as VarObjective);
                    goto GetTime;

                    GetTime:
                    new Spy(null, $"execute store result score {result.Selector.GetConstant()} {result.Objective.GetConstant()} run time query {type}", null);
                    return(result);

                default: throw new MissingOverloadException($"{TypeName}.GetTime", index, arguments);
                }
            });
        }
Esempio n. 2
0
        public VarScoreboard(string name) : base(Access.Public, Usage.Static, name, Compiler.RootScope)
        {
            Compiler.Scope[] scopesGetScore = InnerScope.CreateChildren(1);
            ParameterInfo[]  infoGetScore   = new ParameterInfo[] {
                new ParameterInfo(
                    (true, VarSelector.StaticTypeName, "selection", scopesGetScore[0]),
                    (true, VarObjective.StaticTypeName, "from", scopesGetScore[0])
                    )
            };
            Methods.Add("GetScore", arguments => {
                (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoGetScore, arguments);
                match.Grab(arguments);

                VarInt value = new VarInt(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope);
                VarSelector selector;
                VarObjective objective;
                switch (index)
                {
                case 0:
                    selector  = match[0].Value as VarSelector;
                    objective = match[1].Value as VarObjective;
                    goto GetScore;

                    GetScore:
                    value.SetValue(selector, objective);
                    return(value);

                default: throw new MissingOverloadException($"{TypeName}.GetScore", index, arguments);
                }
            });

            Compiler.Scope[] scopesSetScore = InnerScope.CreateChildren(2);
            ParameterInfo[]  infoSetScore   = new ParameterInfo[] {
                new ParameterInfo(
                    (true, VarSelector.StaticTypeName, "targets", scopesSetScore[0]),
                    (true, VarObjective.StaticTypeName, "storage", scopesSetScore[0]),
                    (true, VarInt.StaticTypeName, "from", scopesSetScore[0])
                    ),
                new ParameterInfo(
                    (true, VarSelector.StaticTypeName, "targets", scopesSetScore[1]),
                    (true, VarObjective.StaticTypeName, "storage", scopesSetScore[1]),
                    (true, VarSelector.StaticTypeName, "selection", scopesSetScore[1]),
                    (true, VarObjective.StaticTypeName, "from", scopesSetScore[1])
                    )
            };
            Methods.Add("SetScore", arguments => {
                (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoSetScore, arguments);
                match.Grab(arguments);

                (VarSelector Selector, VarObjective Objective)to, from;
                int fromConst;
                switch (index)
                {
                case 0: {
                    var toSel   = match[0].Value as VarSelector;
                    var toObj   = match[1].Value as VarObjective;
                    to          = (toSel, toObj);
                    var fromInt = match[2].Value as VarInt;
                    if (fromInt.Usage == Usage.Constant)
                    {
                        fromConst = fromInt.Constant;
                        goto SetScoreConst;
                    }
                    else
                    {
                        from = (fromInt.Selector, fromInt.Objective);
                        goto SetScore;
                    }
                }

                case 1: {
                    var toSel   = match[0].Value as VarSelector;
                    var toObj   = match[1].Value as VarObjective;
                    to          = (toSel, toObj);
                    var fromSel = match[2].Value as VarSelector;
                    var fromObj = match[3].Value as VarObjective;
                    from        = (fromSel, fromObj);
                    goto SetScore;
                }

                    SetScore:
                    new Spy(null, $"scoreboard players operation " +
                            $"{to.Selector.GetConstant()} {to.Objective.GetConstant()} = " +
                            $"{from.Selector.GetConstant()} {from.Objective.GetConstant()}", null);
                    return(null);

                    SetScoreConst:
                    new Spy(null, $"scoreboard players set " +
                            $"{to.Selector.GetConstant()} {to.Objective.GetConstant()} " +
                            $"{fromConst}", null);
                    return(null);

                default: throw new MissingOverloadException($"{TypeName}.SetScore", index, arguments);
                }
            });