Exemple #1
0
        public override Variable Construct(ArgumentInfo passed)
        {
            if (ConstructorScopes is null)
            {
                ConstructorScopes = InnerScope.CreateChildren(1);
            }
            if (ConstructorOverloads is null)
            {
                ConstructorOverloads = new ParameterInfo[] {
                    new ParameterInfo((true, VarSelector.StaticTypeName, "selector", ConstructorScopes[0]))
                }
            }
            ;
            (ParameterInfo match, int index) = ParameterInfo.HighestMatch(ConstructorOverloads, passed);
            match.Grab(passed);

            switch (index)
            {
            case 0:
                var value = new VarEntity(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope);
                value.Selector.InvokeOperation(Operation.Set, match[0].Value as VarSelector, Compiler.CurrentScriptTrace);
                value.Constructed = true;
                return(value);

            default: throw new InvalidArgumentsException("Could not find a constructor overload that matches the given arguments.", Compiler.CurrentScriptTrace);
            }
        }
Exemple #2
0
        public override Variable Construct(ArgumentInfo arguments)
        {
            if (ConstructorScopes is null)
            {
                ConstructorScopes = InnerScope.CreateChildren(1);
            }
            if (ConstructorOverloads is null)
            {
                ConstructorOverloads = new ParameterInfo[] {
                    new ParameterInfo((true, VarString.StaticTypeName, "json", ConstructorScopes[0]))
                }
            }
            ;
            (ParameterInfo match, int index) = ParameterInfo.HighestMatch(ConstructorOverloads, arguments);
            match.Grab(arguments);

            switch (index)
            {
            case 0:
                string  value = (match[0].Value as VarString).GetConstant();
                VarJson json  = new VarJson(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope);
                json.SetValue(value);
                return(json);

            default: throw new MissingOverloadException($"{TypeName} constructor", index, arguments);
            }
        }
Exemple #3
0
 public override Variable Construct(ArgumentInfo arguments)
 {
     if (ConstructorScopes is null)
     {
         ConstructorScopes = InnerScope.CreateChildren(1);
     }
     (ParameterInfo match, int index) = ParameterInfo.HighestMatch(new ParameterInfo[] {
         new (bool, string, string, Compiler.Scope)[] { (true, VarString.StaticTypeName, "value", ConstructorScopes[0]) }
Exemple #4
0
        public override Variable Construct(ArgumentInfo arguments)
        {
            if (ConstructorScopes is null)
            {
                ConstructorScopes = InnerScope.CreateChildren(3);
            }
            if (ConstructorOverloads is null)
            {
                ConstructorOverloads = new ParameterInfo[] {
                    new ParameterInfo(),
                    new ParameterInfo((true, VarString.StaticTypeName, "type", ConstructorScopes[0])),
                    new ParameterInfo((true, VarString.StaticTypeName, "type", ConstructorScopes[1]), (true, VarString.StaticTypeName, "name", ConstructorScopes[1])),
                }
            }
            ;
            (ParameterInfo match, int index) = ParameterInfo.HighestMatch(ConstructorOverloads, arguments);
            match.Grab(arguments);

            string name, type;

            switch (index)
            {
            case 1:
                name = GetNextID();
                type = "dummy";
                goto Construct;

            case 2:
                name = GetNextID();
                type = (match["type"].Value as VarString).GetConstant();
                goto Construct;

            case 3:
                name = (match["name"].Value as VarString).GetConstant();
                type = (match["type"].Value as VarString).GetConstant();
                goto Construct;

Construct:
                var value = new VarObjective(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope)
                {
                    Type = type, ID = name
                };
                if (ObjectiveIDs.ContainsKey(value.ID))
                {
                    throw new Compiler.InternalError($"Duplicate {StaticTypeName} ID created.", arguments.ScriptTrace);
                }
                else
                {
                    ObjectiveIDs.Add(value.ID, this);
                }
                value.Constructed = true;
                return(value);

            default: throw new MissingOverloadException("Objective constructor", index, arguments);
            }
Exemple #5
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);
                }
            });
        }
Exemple #6
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);
                }
            });